9a20370888c0d5d3857c5627e1a878061f5b8332
1 /* $Id: swrast.h,v 1.18 2002/01/28 03:42:28 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.
27 * Keith Whitwell <keithw@valinux.com>
36 /* The software rasterizer now uses this format for vertices. Thus a
37 * 'RasterSetup' stage or other translation is required between the
38 * tnl module and the swrast rasterization functions. This serves to
39 * isolate the swrast module from the internals of the tnl module, and
40 * improve its usefulness as a fallback mechanism for hardware
43 * Full software drivers:
44 * - Register the rastersetup and triangle functions from
45 * utils/software_helper.
46 * - On statechange, update the rasterization pointers in that module.
48 * Rasterization hardware drivers:
49 * - Keep native rastersetup.
50 * - Implement native twoside,offset and unfilled triangle setup.
51 * - Implement a translator from native vertices to swrast vertices.
52 * - On partial fallback (mix of accelerated and unaccelerated
53 * prims), call a pass-through function which translates native
54 * vertices to SWvertices and calls the appropriate swrast function.
55 * - On total fallback (vertex format insufficient for state or all
56 * primitives unaccelerated), hook in swrast_setup instead.
60 GLfloat texcoord
[MAX_TEXTURE_UNITS
][4];
70 * The sw_span structure is used by the triangle template code in
71 * s_tritemp.h. It describes how colors, Z, texcoords, etc are to be
72 * interpolated across each scanline of triangle.
73 * With this structure it's easy to hand-off span rasterization to a
74 * subroutine instead of doing it all inline like we used to do.
75 * It also cleans up the local variable namespace a great deal.
77 * It would be interesting to experiment with multiprocessor rasterization
78 * with this structure. The triangle rasterizer could simply emit a
79 * stream of these structures which would be consumed by one or more
80 * span-processing threads which could run in parallel.
84 /* When the sw_span struct is initialized, these flags indicates
85 * which values are needed for rendering the triangle.
87 #define SPAN_RGBA 0x001
88 #define SPAN_SPEC 0x002
89 #define SPAN_INDEX 0x004
91 #define SPAN_FOG 0x010
92 #define SPAN_TEXTURE 0x020
93 #define SPAN_INT_TEXTURE 0x040
94 #define SPAN_LAMBDA 0x080
95 #define SPAN_COVERAGE 0x100
96 #define SPAN_FLAT 0x200 /* flat shading? */
102 /* only need to process pixels between start <= i < end */
105 /* This flag indicates that only a part of the span is visible */
108 /* This bitmask (bitwise-or of SPAN_* flags) indicates which of the
109 * x/xStep variables are relevant.
113 #if CHAN_TYPE == GL_FLOAT
114 GLfloat red
, redStep
;
115 GLfloat green
, greenStep
;
116 GLfloat blue
, blueStep
;
117 GLfloat alpha
, alphaStep
;
118 GLfloat specRed
, specRedStep
;
119 GLfloat specGreen
, specGreenStep
;
120 GLfloat specBlue
, specBlueStep
;
121 #else /* CHAN_TYPE == */
122 GLfixed red
, redStep
;
123 GLfixed green
, greenStep
;
124 GLfixed blue
, blueStep
;
125 GLfixed alpha
, alphaStep
;
126 GLfixed specRed
, specRedStep
;
127 GLfixed specGreen
, specGreenStep
;
128 GLfixed specBlue
, specBlueStep
;
130 GLfixed index
, indexStep
;
132 GLfloat fog
, fogStep
;
133 GLfloat tex
[MAX_TEXTURE_UNITS
][4], texStep
[MAX_TEXTURE_UNITS
][4];
134 GLfixed intTex
[2], intTexStep
[2];
135 /* Needed for texture lambda (LOD) computation */
136 GLfloat rho
[MAX_TEXTURE_UNITS
];
137 GLfloat texWidth
[MAX_TEXTURE_UNITS
], texHeight
[MAX_TEXTURE_UNITS
];
139 /* This bitmask (bitwise-or of SPAN_* flags) indicates which of the
140 * fragment arrays are relevant.
145 * Arrays of fragment values. These will either be computed from the
146 * x/xStep values above or loadd from glDrawPixels, etc.
149 GLchan rgb
[MAX_WIDTH
][3];
150 GLchan rgba
[MAX_WIDTH
][4];
151 GLuint index
[MAX_WIDTH
];
153 GLchan specArray
[MAX_WIDTH
][4];
154 GLdepth zArray
[MAX_WIDTH
];
155 GLfloat fogArray
[MAX_WIDTH
];
156 /* Texture (s,t,r). 4th component only used for pixel texture */
157 GLfloat texcoords
[MAX_TEXTURE_UNITS
][MAX_WIDTH
][4];
158 GLfloat lambda
[MAX_TEXTURE_UNITS
][MAX_WIDTH
];
159 GLfloat coverage
[MAX_WIDTH
];
161 /* This mask indicates if fragment is alive or culled */
162 GLubyte mask
[MAX_WIDTH
];
166 #define INIT_SPAN(S) \
170 S.start = S.end = 0; \
175 struct swrast_device_driver
;
178 /* These are the public-access functions exported from swrast.
181 _swrast_alloc_buffers( GLcontext
*ctx
);
184 _swrast_CreateContext( GLcontext
*ctx
);
187 _swrast_DestroyContext( GLcontext
*ctx
);
189 /* Get a (non-const) reference to the device driver struct for swrast.
191 extern struct swrast_device_driver
*
192 _swrast_GetDeviceDriverReference( GLcontext
*ctx
);
195 _swrast_Bitmap( GLcontext
*ctx
,
197 GLsizei width
, GLsizei height
,
198 const struct gl_pixelstore_attrib
*unpack
,
199 const GLubyte
*bitmap
);
202 _swrast_CopyPixels( GLcontext
*ctx
,
203 GLint srcx
, GLint srcy
,
204 GLint destx
, GLint desty
,
205 GLsizei width
, GLsizei height
,
209 _swrast_DrawPixels( GLcontext
*ctx
,
211 GLsizei width
, GLsizei height
,
212 GLenum format
, GLenum type
,
213 const struct gl_pixelstore_attrib
*unpack
,
214 const GLvoid
*pixels
);
217 _swrast_ReadPixels( GLcontext
*ctx
,
218 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
219 GLenum format
, GLenum type
,
220 const struct gl_pixelstore_attrib
*unpack
,
224 _swrast_Clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
225 GLint x
, GLint y
, GLint width
, GLint height
);
228 _swrast_Accum( GLcontext
*ctx
, GLenum op
,
229 GLfloat value
, GLint xpos
, GLint ypos
,
230 GLint width
, GLint height
);
233 /* Reset the stipple counter
236 _swrast_ResetLineStipple( GLcontext
*ctx
);
238 /* These will always render the correct point/line/triangle for the
241 * For flatshaded primitives, the provoking vertex is the final one.
244 _swrast_Point( GLcontext
*ctx
, const SWvertex
*v
);
247 _swrast_Line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
250 _swrast_Triangle( GLcontext
*ctx
, const SWvertex
*v0
,
251 const SWvertex
*v1
, const SWvertex
*v2
);
254 _swrast_Quad( GLcontext
*ctx
,
255 const SWvertex
*v0
, const SWvertex
*v1
,
256 const SWvertex
*v2
, const SWvertex
*v3
);
259 _swrast_flush( GLcontext
*ctx
);
262 /* Tell the software rasterizer about core state changes.
265 _swrast_InvalidateState( GLcontext
*ctx
, GLuint new_state
);
267 /* Configure software rasterizer to match hardware rasterizer characteristics:
270 _swrast_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
);
273 _swrast_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
);
278 _swrast_print_vertex( GLcontext
*ctx
, const SWvertex
*v
);
282 * Imaging fallbacks (a better solution should be found, perhaps
283 * moving all the imaging fallback code to a new module)
286 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
287 GLenum internalFormat
,
288 GLint x
, GLint y
, GLsizei width
,
291 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
292 GLenum internalFormat
,
293 GLint x
, GLint y
, GLsizei width
);
295 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
296 GLint x
, GLint y
, GLsizei width
);
298 _swrast_CopyColorTable( GLcontext
*ctx
,
299 GLenum target
, GLenum internalformat
,
300 GLint x
, GLint y
, GLsizei width
);
304 * Texture fallbacks, Brian Paul. Could also live in a new module
305 * with the rest of the texture store fallbacks?
308 _swrast_copy_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
309 GLenum internalFormat
,
310 GLint x
, GLint y
, GLsizei width
, GLint border
);
313 _swrast_copy_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
314 GLenum internalFormat
,
315 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
320 _swrast_copy_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
321 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
324 _swrast_copy_texsubimage2d(GLcontext
*ctx
,
325 GLenum target
, GLint level
,
326 GLint xoffset
, GLint yoffset
,
327 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
330 _swrast_copy_texsubimage3d(GLcontext
*ctx
,
331 GLenum target
, GLint level
,
332 GLint xoffset
, GLint yoffset
, GLint zoffset
,
333 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
337 /* The driver interface for the software rasterizer. Unless otherwise
338 * noted, all functions are mandatory.
340 struct swrast_device_driver
{
342 void (*SetReadBuffer
)( GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
345 * Specifies the current buffer for span/pixel reading.
346 * colorBuffer will be one of:
347 * GL_FRONT_LEFT - this buffer always exists
348 * GL_BACK_LEFT - when double buffering
349 * GL_FRONT_RIGHT - when using stereo
350 * GL_BACK_RIGHT - when using stereo and double buffering
355 *** Functions for synchronizing access to the framebuffer:
358 void (*SpanRenderStart
)(GLcontext
*ctx
);
359 void (*SpanRenderFinish
)(GLcontext
*ctx
);
362 * Called before and after all rendering operations, including DrawPixels,
363 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
364 * These are a suitable place for grabbing/releasing hardware locks.
366 * NOTE: The swrast triangle/line/point routines *DO NOT* call
367 * these functions. Locking in that case must be organized by the
368 * driver by other mechanisms.
372 *** Functions for writing pixels to the frame buffer:
375 void (*WriteRGBASpan
)( const GLcontext
*ctx
,
376 GLuint n
, GLint x
, GLint y
,
377 CONST GLchan rgba
[][4], const GLubyte mask
[] );
378 void (*WriteRGBSpan
)( const GLcontext
*ctx
,
379 GLuint n
, GLint x
, GLint y
,
380 CONST GLchan rgb
[][3], const GLubyte mask
[] );
381 /* Write a horizontal run of RGBA or RGB pixels.
382 * If mask is NULL, draw all pixels.
383 * If mask is not null, only draw pixel [i] when mask [i] is true.
386 void (*WriteMonoRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
387 const GLchan color
[4], const GLubyte mask
[] );
388 /* Write a horizontal run of RGBA pixels all with the same color.
391 void (*WriteRGBAPixels
)( const GLcontext
*ctx
,
392 GLuint n
, const GLint x
[], const GLint y
[],
393 CONST GLchan rgba
[][4], const GLubyte mask
[] );
394 /* Write array of RGBA pixels at random locations.
397 void (*WriteMonoRGBAPixels
)( const GLcontext
*ctx
,
398 GLuint n
, const GLint x
[], const GLint y
[],
399 const GLchan color
[4], const GLubyte mask
[] );
400 /* Write an array of mono-RGBA pixels at random locations.
403 void (*WriteCI32Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
404 const GLuint index
[], const GLubyte mask
[] );
405 void (*WriteCI8Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
406 const GLubyte index
[], const GLubyte mask
[] );
407 /* Write a horizontal run of CI pixels. One function is for 32bpp
408 * indexes and the other for 8bpp pixels (the common case). You mus
409 * implement both for color index mode.
412 void (*WriteMonoCISpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
413 GLuint colorIndex
, const GLubyte mask
[] );
414 /* Write a horizontal run of color index pixels using the color index
415 * last specified by the Index() function.
418 void (*WriteCI32Pixels
)( const GLcontext
*ctx
,
419 GLuint n
, const GLint x
[], const GLint y
[],
420 const GLuint index
[], const GLubyte mask
[] );
422 * Write a random array of CI pixels.
425 void (*WriteMonoCIPixels
)( const GLcontext
*ctx
,
426 GLuint n
, const GLint x
[], const GLint y
[],
427 GLuint colorIndex
, const GLubyte mask
[] );
428 /* Write a random array of color index pixels using the color index
429 * last specified by the Index() function.
434 *** Functions to read pixels from frame buffer:
437 void (*ReadCI32Span
)( const GLcontext
*ctx
,
438 GLuint n
, GLint x
, GLint y
, GLuint index
[] );
439 /* Read a horizontal run of color index pixels.
442 void (*ReadRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
444 /* Read a horizontal run of RGBA pixels.
447 void (*ReadCI32Pixels
)( const GLcontext
*ctx
,
448 GLuint n
, const GLint x
[], const GLint y
[],
449 GLuint indx
[], const GLubyte mask
[] );
450 /* Read a random array of CI pixels.
453 void (*ReadRGBAPixels
)( const GLcontext
*ctx
,
454 GLuint n
, const GLint x
[], const GLint y
[],
455 GLchan rgba
[][4], const GLubyte mask
[] );
456 /* Read a random array of RGBA pixels.
462 *** For supporting hardware Z buffers:
463 *** Either ALL or NONE of these functions must be implemented!
464 *** NOTE that Each depth value is a 32-bit GLuint. If the depth
465 *** buffer is less than 32 bits deep then the extra upperbits are zero.
468 void (*WriteDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
469 const GLdepth depth
[], const GLubyte mask
[] );
470 /* Write a horizontal span of values into the depth buffer. Only write
471 * depth[i] value if mask[i] is nonzero.
474 void (*ReadDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
476 /* Read a horizontal span of values from the depth buffer.
480 void (*WriteDepthPixels
)( GLcontext
*ctx
, GLuint n
,
481 const GLint x
[], const GLint y
[],
482 const GLdepth depth
[], const GLubyte mask
[] );
483 /* Write an array of randomly positioned depth values into the
484 * depth buffer. Only write depth[i] value if mask[i] is nonzero.
487 void (*ReadDepthPixels
)( GLcontext
*ctx
, GLuint n
,
488 const GLint x
[], const GLint y
[],
490 /* Read an array of randomly positioned depth values from the depth buffer.
496 *** For supporting hardware stencil buffers:
497 *** Either ALL or NONE of these functions must be implemented!
500 void (*WriteStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
501 const GLstencil stencil
[], const GLubyte mask
[] );
502 /* Write a horizontal span of stencil values into the stencil buffer.
503 * If mask is NULL, write all stencil values.
504 * Else, only write stencil[i] if mask[i] is non-zero.
507 void (*ReadStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
508 GLstencil stencil
[] );
509 /* Read a horizontal span of stencil values from the stencil buffer.
512 void (*WriteStencilPixels
)( GLcontext
*ctx
, GLuint n
,
513 const GLint x
[], const GLint y
[],
514 const GLstencil stencil
[],
515 const GLubyte mask
[] );
516 /* Write an array of stencil values into the stencil buffer.
517 * If mask is NULL, write all stencil values.
518 * Else, only write stencil[i] if mask[i] is non-zero.
521 void (*ReadStencilPixels
)( GLcontext
*ctx
, GLuint n
,
522 const GLint x
[], const GLint y
[],
523 GLstencil stencil
[] );
524 /* Read an array of stencil values from the stencil buffer.