1 /* $Id: swrast.h,v 1.24 2002/04/19 14:05:50 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * \file swrast/swrast.h
30 * \brief Defines basic structures for sw_rasterizer.
31 * \author Keith Whitwell <keithw@valinux.com>
41 * \brief Data-structure to handle vertices in the software rasterizer.
43 * The software rasterizer now uses this format for vertices. Thus a
44 * 'RasterSetup' stage or other translation is required between the
45 * tnl module and the swrast rasterization functions. This serves to
46 * isolate the swrast module from the internals of the tnl module, and
47 * improve its usefulness as a fallback mechanism for hardware
50 * Full software drivers:
51 * - Register the rastersetup and triangle functions from
52 * utils/software_helper.
53 * - On statechange, update the rasterization pointers in that module.
55 * Rasterization hardware drivers:
56 * - Keep native rastersetup.
57 * - Implement native twoside,offset and unfilled triangle setup.
58 * - Implement a translator from native vertices to swrast vertices.
59 * - On partial fallback (mix of accelerated and unaccelerated
60 * prims), call a pass-through function which translates native
61 * vertices to SWvertices and calls the appropriate swrast function.
62 * - On total fallback (vertex format insufficient for state or all
63 * primitives unaccelerated), hook in swrast_setup instead.
67 GLfloat texcoord
[MAX_TEXTURE_UNITS
][4];
78 * \brief Contains data for either a horizontal line or a set of
79 * pixels that are passed through a pipeline of functions before being
82 * The sw_span structure describes the colors, Z, fogcoord, texcoords,
83 * etc for either a horizontal run or a set of independent pixels. We
84 * can either specify a base/step to indicate interpolated values, or
85 * fill in arrays of values. The interpMask and arrayMask bitfields
86 * indicate which are active.
88 * With this structure it's easy to hand-off span rasterization to
89 * subroutines instead of doing it all inline in the triangle functions
91 * It also cleans up the local variable namespace a great deal.
93 * It would be interesting to experiment with multiprocessor rasterization
94 * with this structure. The triangle rasterizer could simply emit a
95 * stream of these structures which would be consumed by one or more
96 * span-processing threads which could run in parallel.
100 /* Values for interpMask and arrayMask */
101 #define SPAN_RGBA 0x001
102 #define SPAN_SPEC 0x002
103 #define SPAN_INDEX 0x004
105 #define SPAN_FOG 0x010
106 #define SPAN_TEXTURE 0x020
107 #define SPAN_INT_TEXTURE 0x040
108 #define SPAN_LAMBDA 0x080
109 #define SPAN_COVERAGE 0x100
110 #define SPAN_FLAT 0x200 /* flat shading? */
111 #define SPAN_XY 0x400 /* arrayMask only - for xArray, yArray */
112 #define SPAN_MASK 0x800 /* arrayMask only */
118 /** Only need to process pixels between start <= i < end */
119 /** At this time, start is always zero. */
122 /** This flag indicates that mask[] array is effectively filled with ones */
125 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
129 * This bitmask (of SPAN_* flags) indicates which of the x/xStep
130 * variables are relevant.
134 #if CHAN_TYPE == GL_FLOAT
135 GLfloat red
, redStep
;
136 GLfloat green
, greenStep
;
137 GLfloat blue
, blueStep
;
138 GLfloat alpha
, alphaStep
;
139 GLfloat specRed
, specRedStep
;
140 GLfloat specGreen
, specGreenStep
;
141 GLfloat specBlue
, specBlueStep
;
142 #else /* CHAN_TYPE == GL_UNSIGNED_BYTE or GL_UNSIGNED SHORT */
143 GLfixed red
, redStep
;
144 GLfixed green
, greenStep
;
145 GLfixed blue
, blueStep
;
146 GLfixed alpha
, alphaStep
;
147 GLfixed specRed
, specRedStep
;
148 GLfixed specGreen
, specGreenStep
;
149 GLfixed specBlue
, specBlueStep
;
151 GLfixed index
, indexStep
;
153 GLfloat fog
, fogStep
;
154 GLfloat tex
[MAX_TEXTURE_UNITS
][4];
155 GLfloat texStepX
[MAX_TEXTURE_UNITS
][4];
156 GLfloat texStepY
[MAX_TEXTURE_UNITS
][4];
157 GLfixed intTex
[2], intTexStep
[2];
160 * This bitmask (of SPAN_* flags) indicates which of the fragment arrays
166 * Arrays of fragment values. These will either be computed from the
167 * x/xStep values above or filled in by glDraw/CopyPixels, etc.
170 GLchan rgb
[MAX_WIDTH
][3];
171 GLchan rgba
[MAX_WIDTH
][4];
172 GLuint index
[MAX_WIDTH
];
174 GLchan specArray
[MAX_WIDTH
][4];
175 GLint xArray
[MAX_WIDTH
]; /**< X/Y used for point/line rendering only */
176 GLint yArray
[MAX_WIDTH
]; /**< X/Y used for point/line rendering only */
177 GLdepth zArray
[MAX_WIDTH
];
178 GLfloat fogArray
[MAX_WIDTH
];
179 GLfloat texcoords
[MAX_TEXTURE_UNITS
][MAX_WIDTH
][4];
180 GLfloat lambda
[MAX_TEXTURE_UNITS
][MAX_WIDTH
];
181 GLfloat coverage
[MAX_WIDTH
];
183 /** This mask indicates if fragment is alive or culled */
184 GLubyte mask
[MAX_WIDTH
];
188 #define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK) \
190 S->primitive = (PRIMITIVE); \
191 S->interpMask = (INTERP_MASK); \
192 S->arrayMask = (ARRAY_MASK); \
199 struct swrast_device_driver
;
202 /* These are the public-access functions exported from swrast.
205 _swrast_alloc_buffers( GLframebuffer
*buffer
);
208 _swrast_CreateContext( GLcontext
*ctx
);
211 _swrast_DestroyContext( GLcontext
*ctx
);
213 /* Get a (non-const) reference to the device driver struct for swrast.
215 extern struct swrast_device_driver
*
216 _swrast_GetDeviceDriverReference( GLcontext
*ctx
);
219 _swrast_Bitmap( GLcontext
*ctx
,
221 GLsizei width
, GLsizei height
,
222 const struct gl_pixelstore_attrib
*unpack
,
223 const GLubyte
*bitmap
);
226 _swrast_CopyPixels( GLcontext
*ctx
,
227 GLint srcx
, GLint srcy
,
228 GLint destx
, GLint desty
,
229 GLsizei width
, GLsizei height
,
233 _swrast_DrawPixels( GLcontext
*ctx
,
235 GLsizei width
, GLsizei height
,
236 GLenum format
, GLenum type
,
237 const struct gl_pixelstore_attrib
*unpack
,
238 const GLvoid
*pixels
);
241 _swrast_ReadPixels( GLcontext
*ctx
,
242 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
243 GLenum format
, GLenum type
,
244 const struct gl_pixelstore_attrib
*unpack
,
248 _swrast_Clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
249 GLint x
, GLint y
, GLint width
, GLint height
);
252 _swrast_Accum( GLcontext
*ctx
, GLenum op
,
253 GLfloat value
, GLint xpos
, GLint ypos
,
254 GLint width
, GLint height
);
257 /* Reset the stipple counter
260 _swrast_ResetLineStipple( GLcontext
*ctx
);
262 /* These will always render the correct point/line/triangle for the
265 * For flatshaded primitives, the provoking vertex is the final one.
268 _swrast_Point( GLcontext
*ctx
, const SWvertex
*v
);
271 _swrast_Line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
274 _swrast_Triangle( GLcontext
*ctx
, const SWvertex
*v0
,
275 const SWvertex
*v1
, const SWvertex
*v2
);
278 _swrast_Quad( GLcontext
*ctx
,
279 const SWvertex
*v0
, const SWvertex
*v1
,
280 const SWvertex
*v2
, const SWvertex
*v3
);
283 _swrast_flush( GLcontext
*ctx
);
286 /* Tell the software rasterizer about core state changes.
289 _swrast_InvalidateState( GLcontext
*ctx
, GLuint new_state
);
291 /* Configure software rasterizer to match hardware rasterizer characteristics:
294 _swrast_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
);
297 _swrast_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
);
302 _swrast_print_vertex( GLcontext
*ctx
, const SWvertex
*v
);
306 * Imaging fallbacks (a better solution should be found, perhaps
307 * moving all the imaging fallback code to a new module)
310 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
311 GLenum internalFormat
,
312 GLint x
, GLint y
, GLsizei width
,
315 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
316 GLenum internalFormat
,
317 GLint x
, GLint y
, GLsizei width
);
319 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
320 GLint x
, GLint y
, GLsizei width
);
322 _swrast_CopyColorTable( GLcontext
*ctx
,
323 GLenum target
, GLenum internalformat
,
324 GLint x
, GLint y
, GLsizei width
);
328 * Texture fallbacks, Brian Paul. Could also live in a new module
329 * with the rest of the texture store fallbacks?
332 _swrast_copy_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
333 GLenum internalFormat
,
334 GLint x
, GLint y
, GLsizei width
, GLint border
);
337 _swrast_copy_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
338 GLenum internalFormat
,
339 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
344 _swrast_copy_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
345 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
348 _swrast_copy_texsubimage2d(GLcontext
*ctx
,
349 GLenum target
, GLint level
,
350 GLint xoffset
, GLint yoffset
,
351 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
354 _swrast_copy_texsubimage3d(GLcontext
*ctx
,
355 GLenum target
, GLint level
,
356 GLint xoffset
, GLint yoffset
, GLint zoffset
,
357 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
361 /* The driver interface for the software rasterizer. Unless otherwise
362 * noted, all functions are mandatory.
364 struct swrast_device_driver
{
366 void (*SetReadBuffer
)( GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
369 * Specifies the current buffer for span/pixel reading.
370 * colorBuffer will be one of:
371 * GL_FRONT_LEFT - this buffer always exists
372 * GL_BACK_LEFT - when double buffering
373 * GL_FRONT_RIGHT - when using stereo
374 * GL_BACK_RIGHT - when using stereo and double buffering
379 *** Functions for synchronizing access to the framebuffer:
382 void (*SpanRenderStart
)(GLcontext
*ctx
);
383 void (*SpanRenderFinish
)(GLcontext
*ctx
);
386 * Called before and after all rendering operations, including DrawPixels,
387 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
388 * These are a suitable place for grabbing/releasing hardware locks.
390 * NOTE: The swrast triangle/line/point routines *DO NOT* call
391 * these functions. Locking in that case must be organized by the
392 * driver by other mechanisms.
396 *** Functions for writing pixels to the frame buffer:
399 void (*WriteRGBASpan
)( const GLcontext
*ctx
,
400 GLuint n
, GLint x
, GLint y
,
401 CONST GLchan rgba
[][4], const GLubyte mask
[] );
402 void (*WriteRGBSpan
)( const GLcontext
*ctx
,
403 GLuint n
, GLint x
, GLint y
,
404 CONST GLchan rgb
[][3], const GLubyte mask
[] );
405 /* Write a horizontal run of RGBA or RGB pixels.
406 * If mask is NULL, draw all pixels.
407 * If mask is not null, only draw pixel [i] when mask [i] is true.
410 void (*WriteMonoRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
411 const GLchan color
[4], const GLubyte mask
[] );
412 /* Write a horizontal run of RGBA pixels all with the same color.
415 void (*WriteRGBAPixels
)( const GLcontext
*ctx
,
416 GLuint n
, const GLint x
[], const GLint y
[],
417 CONST GLchan rgba
[][4], const GLubyte mask
[] );
418 /* Write array of RGBA pixels at random locations.
421 void (*WriteMonoRGBAPixels
)( const GLcontext
*ctx
,
422 GLuint n
, const GLint x
[], const GLint y
[],
423 const GLchan color
[4], const GLubyte mask
[] );
424 /* Write an array of mono-RGBA pixels at random locations.
427 void (*WriteCI32Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
428 const GLuint index
[], const GLubyte mask
[] );
429 void (*WriteCI8Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
430 const GLubyte index
[], const GLubyte mask
[] );
431 /* Write a horizontal run of CI pixels. One function is for 32bpp
432 * indexes and the other for 8bpp pixels (the common case). You mus
433 * implement both for color index mode.
436 void (*WriteMonoCISpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
437 GLuint colorIndex
, const GLubyte mask
[] );
438 /* Write a horizontal run of color index pixels using the color index
439 * last specified by the Index() function.
442 void (*WriteCI32Pixels
)( const GLcontext
*ctx
,
443 GLuint n
, const GLint x
[], const GLint y
[],
444 const GLuint index
[], const GLubyte mask
[] );
446 * Write a random array of CI pixels.
449 void (*WriteMonoCIPixels
)( const GLcontext
*ctx
,
450 GLuint n
, const GLint x
[], const GLint y
[],
451 GLuint colorIndex
, const GLubyte mask
[] );
452 /* Write a random array of color index pixels using the color index
453 * last specified by the Index() function.
458 *** Functions to read pixels from frame buffer:
461 void (*ReadCI32Span
)( const GLcontext
*ctx
,
462 GLuint n
, GLint x
, GLint y
, GLuint index
[] );
463 /* Read a horizontal run of color index pixels.
466 void (*ReadRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
468 /* Read a horizontal run of RGBA pixels.
471 void (*ReadCI32Pixels
)( const GLcontext
*ctx
,
472 GLuint n
, const GLint x
[], const GLint y
[],
473 GLuint indx
[], const GLubyte mask
[] );
474 /* Read a random array of CI pixels.
477 void (*ReadRGBAPixels
)( const GLcontext
*ctx
,
478 GLuint n
, const GLint x
[], const GLint y
[],
479 GLchan rgba
[][4], const GLubyte mask
[] );
480 /* Read a random array of RGBA pixels.
486 *** For supporting hardware Z buffers:
487 *** Either ALL or NONE of these functions must be implemented!
488 *** NOTE that Each depth value is a 32-bit GLuint. If the depth
489 *** buffer is less than 32 bits deep then the extra upperbits are zero.
492 void (*WriteDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
493 const GLdepth depth
[], const GLubyte mask
[] );
494 /* Write a horizontal span of values into the depth buffer. Only write
495 * depth[i] value if mask[i] is nonzero.
498 void (*ReadDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
500 /* Read a horizontal span of values from the depth buffer.
504 void (*WriteDepthPixels
)( GLcontext
*ctx
, GLuint n
,
505 const GLint x
[], const GLint y
[],
506 const GLdepth depth
[], const GLubyte mask
[] );
507 /* Write an array of randomly positioned depth values into the
508 * depth buffer. Only write depth[i] value if mask[i] is nonzero.
511 void (*ReadDepthPixels
)( GLcontext
*ctx
, GLuint n
,
512 const GLint x
[], const GLint y
[],
514 /* Read an array of randomly positioned depth values from the depth buffer.
520 *** For supporting hardware stencil buffers:
521 *** Either ALL or NONE of these functions must be implemented!
524 void (*WriteStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
525 const GLstencil stencil
[], const GLubyte mask
[] );
526 /* Write a horizontal span of stencil values into the stencil buffer.
527 * If mask is NULL, write all stencil values.
528 * Else, only write stencil[i] if mask[i] is non-zero.
531 void (*ReadStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
532 GLstencil stencil
[] );
533 /* Read a horizontal span of stencil values from the stencil buffer.
536 void (*WriteStencilPixels
)( GLcontext
*ctx
, GLuint n
,
537 const GLint x
[], const GLint y
[],
538 const GLstencil stencil
[],
539 const GLubyte mask
[] );
540 /* Write an array of stencil values into the stencil buffer.
541 * If mask is NULL, write all stencil values.
542 * Else, only write stencil[i] if mask[i] is non-zero.
545 void (*ReadStencilPixels
)( GLcontext
*ctx
, GLuint n
,
546 const GLint x
[], const GLint y
[],
547 GLstencil stencil
[] );
548 /* Read an array of stencil values from the stencil buffer.