2
// Copyright ļæ½ļæ½ļæ½ļæ½ 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Declares the CqImageBuffer class responsible for rendering the primitives and storing the results.
23
\author Paul C. Gregory (pgregory@aqsis.com)
26
//? Is imagebuffer.h included already?
27
#ifndef IMAGEBUFFER_H_INCLUDED
29
#define IMAGEBUFFER_H_INCLUDED 1
35
#include "bitvector.h"
36
#include "micropolygon.h"
43
#include "imagepixel.h"
46
START_NAMESPACE( Aqsis )
50
//-----------------------------------------------------------------------
52
The main image and related data, also responsible for processing the rendering loop.
54
Before the image can be rendered the image buffer has to be initialised by calling the
55
SetImage() method. The parameters for the creation of the buffer are read from the
56
current options (this includes things like the image resolution, bucket size,
57
number of pixel samples, etc.).
59
After the buffer is initialized the surfaces (gprims) that are to be rendered
60
can be added to the buffer. This is done by calling PostSurface() for each gprim.
61
(note: before calling this method the gprim has to be transformed into camera space!)
62
All the gprims that can be culled at this point (i.e. CullSurface() returns true)
63
won't be stored inside the buffer. If a gprim can't be culled it is assigned to
64
the first bucket that touches its bound.
66
Once all the gprims are posted to the buffer the image can be rendered by calling
67
RenderImage(). Now all buckets will be processed one after another.
69
\see CqBucket, CqBasicSurface, CqRenderer
88
m_CropWindowXMin( 0 ),
89
m_CropWindowYMin( 0 ),
90
m_CropWindowXMax( 0 ),
91
m_CropWindowYMax( 0 ),
92
m_DisplayMode( ModeRGB ),
93
m_CurrentBucketCol( 0 ),
94
m_CurrentBucketRow( 0 )
96
virtual ~CqImageBuffer();
98
CqVector2D BucketPosition() const;
99
CqVector2D BucketPosition(TqInt x, TqInt y) const;
100
CqVector2D BucketSize() const;
101
CqVector2D BucketSize( TqInt x, TqInt y) const;
103
/** Get the horizontal resolution of this image.
104
* \return Integer horizontal resolution.
110
/** Get the vertical resolution of this image.
111
* \return Integer vertical resolution.
117
/** Get the minimum horizontal pixel to render.
118
* \return Integer minimum pixel index.
120
TqInt CropWindowXMin() const
122
return ( m_CropWindowXMin );
124
/** Get the minimum vertical pixel to render.
125
* \return Integer minimum pixel index.
127
TqInt CropWindowYMin() const
129
return ( m_CropWindowYMin );
131
/** Get the maximum horizontal pixel to render.
132
* \return Integer maximum pixel index.
134
TqInt CropWindowXMax() const
136
return ( m_CropWindowXMax );
138
/** Get the maximum vertical pixel to render.
139
* \return Integer maximum pixel index.
141
TqInt CropWindowYMax() const
143
return ( m_CropWindowYMax );
145
/** Get the number of buckets in the horizontal direction.
146
* \return Integer horizontal bucket count.
148
TqInt cXBuckets() const
150
return ( m_cXBuckets );
152
/** Get the number of buckets in the vertical direction.
153
* \return Integer vertical bucket count.
155
TqInt cYBuckets() const
157
return ( m_cYBuckets );
159
/** Get the horizontal bucket size.
160
* \return Integer horizontal bucket size.
162
TqInt XBucketSize() const
164
return ( m_XBucketSize );
166
/** Get the vertical bucket size.
167
* \return Integer vertical bucket size.
169
TqInt YBucketSize() const
171
return ( m_YBucketSize );
173
/** Get the number of horizontal samples per pixel.
174
* \return Integer sample count.
176
TqInt PixelXSamples() const
178
return ( m_PixelXSamples );
180
/** Get the number of vertical samples per pixel.
181
* \return Integer sample count.
183
TqInt PixelYSamples() const
185
return ( m_PixelYSamples );
187
/** Get the width of the pixel filter in the horizontal direction.
188
* \return Integer filter width, in pixels.
190
TqInt FilterXWidth() const
192
return ( m_FilterXWidth );
194
/** Get the width of the pixel filter in the vertical direction.
195
* \return Integer filter width, in pixels.
197
TqInt FilterYWidth() const
199
return ( m_FilterYWidth );
201
/** Get the near clipping distance.
202
* \return Float distance from the camera that objects must be to be visible.
204
TqFloat ClippingNear() const
206
return ( m_ClippingNear );
208
/** Get the far clipping distance.
209
* \return Float distance from the camera that objects will be clipped from view.
211
TqFloat ClippingFar() const
213
return ( m_ClippingFar );
216
* \return Integer display mode as a member of enum Mode.
218
TqInt DisplayMode() const
220
return ( m_DisplayMode );
222
/** Get the column index of the bucket currently being processed.
223
* \return Integer bucket index.
225
TqInt CurrentBucketCol() const
227
return ( m_CurrentBucketCol );
229
/** Get the row index of the bucket currently being processed.
230
* \return Integer bucket index.
232
TqInt CurrentBucketRow() const
234
return ( m_CurrentBucketRow );
236
/** Move to the next bucket to process.
240
m_CurrentBucketCol++;
241
if( m_CurrentBucketCol >= m_cXBuckets )
243
m_CurrentBucketCol = 0;
244
m_CurrentBucketRow++;
245
if( m_CurrentBucketRow >= m_cYBuckets )
250
/** Get a pointer to the current bucket
252
CqBucket& CurrentBucket()
254
return( m_Buckets[CurrentBucketRow()][CurrentBucketCol()] );
256
/** Get a pointer to the bucket at position x,y in the grid.
258
CqBucket& Bucket( TqInt x, TqInt y)
260
return( m_Buckets[y][x] );
264
void SaveImage( const char* strName );
266
void PostSurface( const boost::shared_ptr<CqBasicSurface>& pSurface );
267
TqBool CullSurface( CqBound& Bound, const boost::shared_ptr<CqBasicSurface>& pSurface );
268
TqBool OcclusionCullSurface( const boost::shared_ptr<CqBasicSurface>& pSurface );
269
void AddMPG( CqMicroPolygon* pmpgNew );
270
TqBool PushMPGForward( CqMicroPolygon* pmpg, TqInt Col, TqInt Row );
271
TqBool PushMPGDown( CqMicroPolygon*, TqInt Col, TqInt Row );
272
void RenderMPGs( long xmin, long xmax, long ymin, long ymax );
273
void RenderMicroPoly( CqMicroPolygon* pMPG, long xmin, long xmax, long ymin, long ymax );
274
void RenderSurfaces( long xmin, long xmax, long ymin, long ymax );
276
void StoreSample( CqMicroPolygon* pMPG, CqImagePixel* pie2, TqInt m, TqInt n, TqFloat D );
277
/** Get completion status of this rendered image.
278
* \return bool indicating finished or not.
285
virtual void SetImage();
287
virtual void Release();
289
// Callbacks to overridden image buffer class to allow display/processing etc.
290
virtual void BucketComplete()
293
virtual void ImageComplete()
295
virtual TqBool IsCurrentBucketEmpty();
298
TqBool m_fQuit; ///< Set by system if a quit has been requested.
299
TqBool m_fDone; ///< Set when the render of this image has completed.
301
TqInt m_iXRes; ///< Integer horizontal image resolution.
302
TqInt m_iYRes; ///< Integer vertical image resolution.
303
TqInt m_cXBuckets; ///< Integer horizontal bucket count.
304
TqInt m_cYBuckets; ///< Integer vertical bucket count.
305
TqInt m_XBucketSize; ///< Integer horizontal bucket size.
306
TqInt m_YBucketSize; ///< Integer vertical bucket size.
307
TqInt m_PixelXSamples; ///< Integer horizontal sample per pixel count.
308
TqInt m_PixelYSamples; ///< Integer vertical sample per pixel count.
309
TqInt m_FilterXWidth; ///< Integer horizontal pixel filter width in pixels.
310
TqInt m_FilterYWidth; ///< Integer vertical pixel filter width in pixels.
311
TqInt m_CropWindowXMin; ///< Integer minimum horizontal pixel to render.
312
TqInt m_CropWindowYMin; ///< Integer minimum vertical pixel to render.
313
TqInt m_CropWindowXMax; ///< Integer maximum horizontal pixel to render.
314
TqInt m_CropWindowYMax; ///< Integer maximum vertical pixel to render.
315
TqFloat m_ClippingNear; ///< Near clipping distance.
316
TqFloat m_ClippingFar; ///< Far clipping distance.
317
TqInt m_DisplayMode; ///< Integer display mode, a member of the enum Mode.
319
std::vector<std::vector<CqBucket> > m_Buckets; ///< Array of bucket storage classes (row/col)
320
TqInt m_CurrentBucketCol; ///< Column index of the bucket currently being processed.
321
TqInt m_CurrentBucketRow; ///< Row index of the bucket currently being processed.
323
// This struct is used to hold info about a mpg that is used when rendering the mpg.
324
// It caches the info for use by multiple samples.
325
struct SqMpgSampleInfo
332
SqMpgSampleInfo m_CurrentMpgSampleInfo;
336
//-----------------------------------------------------------------------
338
END_NAMESPACE( Aqsis )
340
//} // End of #ifdef IMAGEBUFFER_H_INCLUDED