~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to render/imagebuffer.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright ļæ½ļæ½ļæ½ļæ½ 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Declares the CqImageBuffer class responsible for rendering the primitives and storing the results.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
//? Is imagebuffer.h included already?
 
27
#ifndef IMAGEBUFFER_H_INCLUDED 
 
28
//{
 
29
#define IMAGEBUFFER_H_INCLUDED 1
 
30
 
 
31
#include        "aqsis.h"
 
32
 
 
33
#include        <vector>
 
34
 
 
35
#include        "bitvector.h"
 
36
#include        "micropolygon.h"
 
37
#include        "renderer.h"
 
38
#include        "ri.h"
 
39
#include        "sstring.h"
 
40
#include        "surface.h"
 
41
#include        "color.h"
 
42
#include        "vector2d.h"
 
43
#include    "imagepixel.h"
 
44
#include    "bucket.h"
 
45
 
 
46
START_NAMESPACE( Aqsis )
 
47
 
 
48
 
 
49
 
 
50
//-----------------------------------------------------------------------
 
51
/**
 
52
  The main image and related data, also responsible for processing the rendering loop.
 
53
 
 
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.).
 
58
  
 
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.
 
65
 
 
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. 
 
68
 
 
69
  \see CqBucket, CqBasicSurface, CqRenderer
 
70
 */
 
71
 
 
72
class CqImageBuffer
 
73
{
 
74
public:
 
75
    CqImageBuffer() :
 
76
            m_fQuit( TqFalse ),
 
77
            m_fDone( TqTrue ),
 
78
            m_iXRes( 0 ),
 
79
            m_iYRes( 0 ),
 
80
            m_cXBuckets( 0 ),
 
81
            m_cYBuckets( 0 ),
 
82
            m_XBucketSize( 0 ),
 
83
            m_YBucketSize( 0 ),
 
84
            m_PixelXSamples( 0 ),
 
85
            m_PixelYSamples( 0 ),
 
86
            m_FilterXWidth( 0 ),
 
87
            m_FilterYWidth( 0 ),
 
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 )
 
95
    {}
 
96
    virtual     ~CqImageBuffer();
 
97
 
 
98
    CqVector2D  BucketPosition() const;
 
99
    CqVector2D  BucketPosition(TqInt x, TqInt y) const;
 
100
    CqVector2D  BucketSize() const;
 
101
    CqVector2D  BucketSize( TqInt x, TqInt y) const;
 
102
 
 
103
    /** Get the horizontal resolution of this image.
 
104
     * \return Integer horizontal resolution.
 
105
     */
 
106
    TqInt       iXRes() const
 
107
    {
 
108
        return ( m_iXRes );
 
109
    }
 
110
    /** Get the vertical resolution of this image.
 
111
     * \return Integer vertical resolution.
 
112
     */
 
113
    TqInt       iYRes() const
 
114
    {
 
115
        return ( m_iYRes );
 
116
    }
 
117
    /** Get the minimum horizontal pixel to render.
 
118
     * \return Integer minimum pixel index.
 
119
     */
 
120
    TqInt       CropWindowXMin() const
 
121
    {
 
122
        return ( m_CropWindowXMin );
 
123
    }
 
124
    /** Get the minimum vertical pixel to render.
 
125
     * \return Integer minimum pixel index.
 
126
     */
 
127
    TqInt       CropWindowYMin() const
 
128
    {
 
129
        return ( m_CropWindowYMin );
 
130
    }
 
131
    /** Get the maximum horizontal pixel to render.
 
132
     * \return Integer maximum pixel index.
 
133
     */
 
134
    TqInt       CropWindowXMax() const
 
135
    {
 
136
        return ( m_CropWindowXMax );
 
137
    }
 
138
    /** Get the maximum vertical pixel to render.
 
139
     * \return Integer maximum pixel index.
 
140
     */
 
141
    TqInt       CropWindowYMax() const
 
142
    {
 
143
        return ( m_CropWindowYMax );
 
144
    }
 
145
    /** Get the number of buckets in the horizontal direction.
 
146
     * \return Integer horizontal bucket count.
 
147
     */
 
148
    TqInt       cXBuckets() const
 
149
    {
 
150
        return ( m_cXBuckets );
 
151
    }
 
152
    /** Get the number of buckets in the vertical direction.
 
153
     * \return Integer vertical bucket count.
 
154
     */
 
155
    TqInt       cYBuckets() const
 
156
    {
 
157
        return ( m_cYBuckets );
 
158
    }
 
159
    /** Get the horizontal bucket size.
 
160
     * \return Integer horizontal bucket size.
 
161
     */
 
162
    TqInt       XBucketSize() const
 
163
    {
 
164
        return ( m_XBucketSize );
 
165
    }
 
166
    /** Get the vertical bucket size.
 
167
     * \return Integer vertical bucket size.
 
168
     */
 
169
    TqInt       YBucketSize() const
 
170
    {
 
171
        return ( m_YBucketSize );
 
172
    }
 
173
    /** Get the number of horizontal samples per pixel.
 
174
     * \return Integer sample count.
 
175
     */
 
176
    TqInt       PixelXSamples() const
 
177
    {
 
178
        return ( m_PixelXSamples );
 
179
    }
 
180
    /** Get the number of vertical samples per pixel.
 
181
     * \return Integer sample count.
 
182
     */
 
183
    TqInt       PixelYSamples() const
 
184
    {
 
185
        return ( m_PixelYSamples );
 
186
    }
 
187
    /** Get the width of the pixel filter in the horizontal direction.
 
188
     * \return Integer filter width, in pixels.
 
189
     */
 
190
    TqInt       FilterXWidth() const
 
191
    {
 
192
        return ( m_FilterXWidth );
 
193
    }
 
194
    /** Get the width of the pixel filter in the vertical direction.
 
195
     * \return Integer filter width, in pixels.
 
196
     */
 
197
    TqInt       FilterYWidth() const
 
198
    {
 
199
        return ( m_FilterYWidth );
 
200
    }
 
201
    /** Get the near clipping distance.
 
202
     * \return Float distance from the camera that objects must be to be visible.
 
203
     */
 
204
    TqFloat     ClippingNear() const
 
205
    {
 
206
        return ( m_ClippingNear );
 
207
    }
 
208
    /** Get the far clipping distance.
 
209
     * \return Float distance from the camera that objects will be clipped from view.
 
210
     */
 
211
    TqFloat     ClippingFar() const
 
212
    {
 
213
        return ( m_ClippingFar );
 
214
    }
 
215
    /** Get the display.
 
216
     * \return Integer display mode as a member of enum Mode.
 
217
     */
 
218
    TqInt       DisplayMode() const
 
219
    {
 
220
        return ( m_DisplayMode );
 
221
    }
 
222
    /** Get the column index of the bucket currently being processed.
 
223
     * \return Integer bucket index.
 
224
     */
 
225
    TqInt       CurrentBucketCol() const
 
226
    {
 
227
        return ( m_CurrentBucketCol );
 
228
    }
 
229
    /** Get the row index of the bucket currently being processed.
 
230
     * \return Integer bucket index.
 
231
     */
 
232
    TqInt       CurrentBucketRow() const
 
233
    {
 
234
        return ( m_CurrentBucketRow );
 
235
    }
 
236
    /** Move to the next bucket to process.
 
237
     */
 
238
    bool NextBucket()
 
239
    {
 
240
        m_CurrentBucketCol++;
 
241
        if( m_CurrentBucketCol >= m_cXBuckets )
 
242
        {
 
243
            m_CurrentBucketCol = 0;
 
244
            m_CurrentBucketRow++;
 
245
            if( m_CurrentBucketRow >= m_cYBuckets )
 
246
                return( TqFalse );
 
247
        }
 
248
        return( TqTrue );
 
249
    }
 
250
    /** Get a pointer to the current bucket
 
251
     */
 
252
    CqBucket& CurrentBucket()
 
253
    {
 
254
        return( m_Buckets[CurrentBucketRow()][CurrentBucketCol()] );
 
255
    }
 
256
    /** Get a pointer to the bucket at position x,y in the grid.
 
257
     */
 
258
    CqBucket& Bucket( TqInt x, TqInt y)
 
259
    {
 
260
        return( m_Buckets[y][x] );
 
261
    }
 
262
 
 
263
    void        DeleteImage();
 
264
    void        SaveImage( const char* strName );
 
265
 
 
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 );
 
275
    void        RenderImage();
 
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.
 
279
     */
 
280
    TqBool      fDone() const
 
281
    {
 
282
        return ( m_fDone );
 
283
    }
 
284
 
 
285
    virtual     void    SetImage();
 
286
    virtual     void    Quit();
 
287
    virtual     void    Release();
 
288
 
 
289
    // Callbacks to overridden image buffer class to allow display/processing etc.
 
290
    virtual     void    BucketComplete()
 
291
    {
 
292
    }
 
293
    virtual     void    ImageComplete()
 
294
    {}
 
295
    virtual     TqBool  IsCurrentBucketEmpty();
 
296
 
 
297
private:
 
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.
 
300
 
 
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.
 
318
 
 
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.
 
322
 
 
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
 
326
    {
 
327
        TqBool m_IsMatte;
 
328
        TqBool m_Occludes;
 
329
        CqColor m_Colour;
 
330
        CqColor m_Opacity;
 
331
    };
 
332
    SqMpgSampleInfo m_CurrentMpgSampleInfo;
 
333
};
 
334
 
 
335
 
 
336
//-----------------------------------------------------------------------
 
337
 
 
338
END_NAMESPACE( Aqsis )
 
339
 
 
340
//}  // End of #ifdef IMAGEBUFFER_H_INCLUDED
 
341
#endif
 
342
 
 
343