1 /* $Id: swrast.h,v 1.12 2001/03/19 02:25:36 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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>
37 /* The software rasterizer now uses this format for vertices. Thus a
38 * 'RasterSetup' stage or other translation is required between the
39 * tnl module and the swrast rasterization functions. This serves to
40 * isolate the swrast module from the internals of the tnl module, and
41 * improve its usefulness as a fallback mechanism for hardware
44 * Full software drivers:
45 * - Register the rastersetup and triangle functions from
46 * utils/software_helper.
47 * - On statechange, update the rasterization pointers in that module.
49 * Rasterization hardware drivers:
50 * - Keep native rastersetup.
51 * - Implement native twoside,offset and unfilled triangle setup.
52 * - Implement a translator from native vertices to swrast vertices.
53 * - On partial fallback (mix of accelerated and unaccelerated
54 * prims), call a pass-through function which translates native
55 * vertices to SWvertices and calls the appropriate swrast function.
56 * - On total fallback (vertex format insufficient for state or all
57 * primitives unaccelerated), hook in swrast_setup instead.
61 GLfloat texcoord
[MAX_TEXTURE_UNITS
][4];
70 struct swrast_device_driver
;
73 /* These are the public-access functions exported from swrast.
76 _swrast_alloc_buffers( GLcontext
*ctx
);
79 _swrast_CreateContext( GLcontext
*ctx
);
82 _swrast_DestroyContext( GLcontext
*ctx
);
84 /* Get a (non-const) reference to the device driver struct for swrast.
86 extern struct swrast_device_driver
*
87 _swrast_GetDeviceDriverReference( GLcontext
*ctx
);
90 _swrast_Bitmap( GLcontext
*ctx
,
92 GLsizei width
, GLsizei height
,
93 const struct gl_pixelstore_attrib
*unpack
,
94 const GLubyte
*bitmap
);
97 _swrast_CopyPixels( GLcontext
*ctx
,
98 GLint srcx
, GLint srcy
,
99 GLint destx
, GLint desty
,
100 GLsizei width
, GLsizei height
,
104 _swrast_DrawPixels( GLcontext
*ctx
,
106 GLsizei width
, GLsizei height
,
107 GLenum format
, GLenum type
,
108 const struct gl_pixelstore_attrib
*unpack
,
109 const GLvoid
*pixels
);
112 _swrast_ReadPixels( GLcontext
*ctx
,
113 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
114 GLenum format
, GLenum type
,
115 const struct gl_pixelstore_attrib
*unpack
,
119 _swrast_Clear( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
120 GLint x
, GLint y
, GLint width
, GLint height
);
123 _swrast_Accum( GLcontext
*ctx
, GLenum op
,
124 GLfloat value
, GLint xpos
, GLint ypos
,
125 GLint width
, GLint height
);
128 /* Reset the stipple counter
131 _swrast_ResetLineStipple( GLcontext
*ctx
);
133 /* These will always render the correct point/line/triangle for the
136 * For flatshaded primitives, the provoking vertex is the final one.
139 _swrast_Point( GLcontext
*ctx
, const SWvertex
*v
);
142 _swrast_Line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
145 _swrast_Triangle( GLcontext
*ctx
, const SWvertex
*v0
,
146 const SWvertex
*v1
, const SWvertex
*v2
);
149 _swrast_Quad( GLcontext
*ctx
,
150 const SWvertex
*v0
, const SWvertex
*v1
,
151 const SWvertex
*v2
, const SWvertex
*v3
);
154 _swrast_flush( GLcontext
*ctx
);
157 /* Tell the software rasterizer about core state changes.
160 _swrast_InvalidateState( GLcontext
*ctx
, GLuint new_state
);
162 /* Configure software rasterizer to match hardware rasterizer characteristics:
165 _swrast_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
);
168 _swrast_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
);
173 _swrast_print_vertex( GLcontext
*ctx
, const SWvertex
*v
);
177 * Imaging fallbacks (a better solution should be found, perhaps
178 * moving all the imaging fallback code to a new module)
181 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
182 GLenum internalFormat
,
183 GLint x
, GLint y
, GLsizei width
,
186 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
187 GLenum internalFormat
,
188 GLint x
, GLint y
, GLsizei width
);
190 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
191 GLint x
, GLint y
, GLsizei width
);
193 _swrast_CopyColorTable( GLcontext
*ctx
,
194 GLenum target
, GLenum internalformat
,
195 GLint x
, GLint y
, GLsizei width
);
199 * Texture fallbacks, Brian Paul. Could also live in a new module
200 * with the rest of the texture store fallbacks?
203 _swrast_copy_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
204 GLenum internalFormat
,
205 GLint x
, GLint y
, GLsizei width
, GLint border
);
208 _swrast_copy_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
209 GLenum internalFormat
,
210 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
215 _swrast_copy_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
216 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
219 _swrast_copy_texsubimage2d(GLcontext
*ctx
,
220 GLenum target
, GLint level
,
221 GLint xoffset
, GLint yoffset
,
222 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
225 _swrast_copy_texsubimage3d(GLcontext
*ctx
,
226 GLenum target
, GLint level
,
227 GLint xoffset
, GLint yoffset
, GLint zoffset
,
228 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
232 /* The driver interface for the software rasterizer. Unless otherwise
233 * noted, all functions are mandatory.
235 struct swrast_device_driver
{
237 void (*SetReadBuffer
)( GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
240 * Specifies the current buffer for span/pixel reading.
241 * colorBuffer will be one of:
242 * GL_FRONT_LEFT - this buffer always exists
243 * GL_BACK_LEFT - when double buffering
244 * GL_FRONT_RIGHT - when using stereo
245 * GL_BACK_RIGHT - when using stereo and double buffering
250 *** Functions for synchronizing access to the framebuffer:
253 void (*SpanRenderStart
)(GLcontext
*ctx
);
254 void (*SpanRenderFinish
)(GLcontext
*ctx
);
257 * Called before and after all rendering operations, including DrawPixels,
258 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
259 * These are a suitable place for grabbing/releasing hardware locks.
261 * NOTE: The swrast triangle/line/point routines *DO NOT* call
262 * these functions. Locking in that case must be organized by the
263 * driver by other mechanisms.
267 *** Functions for writing pixels to the frame buffer:
270 void (*WriteRGBASpan
)( const GLcontext
*ctx
,
271 GLuint n
, GLint x
, GLint y
,
272 CONST GLchan rgba
[][4], const GLubyte mask
[] );
273 void (*WriteRGBSpan
)( const GLcontext
*ctx
,
274 GLuint n
, GLint x
, GLint y
,
275 CONST GLchan rgb
[][3], const GLubyte mask
[] );
276 /* Write a horizontal run of RGBA or RGB pixels.
277 * If mask is NULL, draw all pixels.
278 * If mask is not null, only draw pixel [i] when mask [i] is true.
281 void (*WriteMonoRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
282 const GLchan color
[4], const GLubyte mask
[] );
283 /* Write a horizontal run of RGBA pixels all with the same color.
286 void (*WriteRGBAPixels
)( const GLcontext
*ctx
,
287 GLuint n
, const GLint x
[], const GLint y
[],
288 CONST GLchan rgba
[][4], const GLubyte mask
[] );
289 /* Write array of RGBA pixels at random locations.
292 void (*WriteMonoRGBAPixels
)( const GLcontext
*ctx
,
293 GLuint n
, const GLint x
[], const GLint y
[],
294 const GLchan color
[4], const GLubyte mask
[] );
295 /* Write an array of mono-RGBA pixels at random locations.
298 void (*WriteCI32Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
299 const GLuint index
[], const GLubyte mask
[] );
300 void (*WriteCI8Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
301 const GLubyte index
[], const GLubyte mask
[] );
302 /* Write a horizontal run of CI pixels. One function is for 32bpp
303 * indexes and the other for 8bpp pixels (the common case). You mus
304 * implement both for color index mode.
307 void (*WriteMonoCISpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
308 GLuint colorIndex
, const GLubyte mask
[] );
309 /* Write a horizontal run of color index pixels using the color index
310 * last specified by the Index() function.
313 void (*WriteCI32Pixels
)( const GLcontext
*ctx
,
314 GLuint n
, const GLint x
[], const GLint y
[],
315 const GLuint index
[], const GLubyte mask
[] );
317 * Write a random array of CI pixels.
320 void (*WriteMonoCIPixels
)( const GLcontext
*ctx
,
321 GLuint n
, const GLint x
[], const GLint y
[],
322 GLuint colorIndex
, const GLubyte mask
[] );
323 /* Write a random array of color index pixels using the color index
324 * last specified by the Index() function.
329 *** Functions to read pixels from frame buffer:
332 void (*ReadCI32Span
)( const GLcontext
*ctx
,
333 GLuint n
, GLint x
, GLint y
, GLuint index
[] );
334 /* Read a horizontal run of color index pixels.
337 void (*ReadRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
339 /* Read a horizontal run of RGBA pixels.
342 void (*ReadCI32Pixels
)( const GLcontext
*ctx
,
343 GLuint n
, const GLint x
[], const GLint y
[],
344 GLuint indx
[], const GLubyte mask
[] );
345 /* Read a random array of CI pixels.
348 void (*ReadRGBAPixels
)( const GLcontext
*ctx
,
349 GLuint n
, const GLint x
[], const GLint y
[],
350 GLchan rgba
[][4], const GLubyte mask
[] );
351 /* Read a random array of RGBA pixels.
357 *** For supporting hardware Z buffers:
358 *** Either ALL or NONE of these functions must be implemented!
359 *** NOTE that Each depth value is a 32-bit GLuint. If the depth
360 *** buffer is less than 32 bits deep then the extra upperbits are zero.
363 void (*WriteDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
364 const GLdepth depth
[], const GLubyte mask
[] );
365 /* Write a horizontal span of values into the depth buffer. Only write
366 * depth[i] value if mask[i] is nonzero.
369 void (*ReadDepthSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
371 /* Read a horizontal span of values from the depth buffer.
375 void (*WriteDepthPixels
)( GLcontext
*ctx
, GLuint n
,
376 const GLint x
[], const GLint y
[],
377 const GLdepth depth
[], const GLubyte mask
[] );
378 /* Write an array of randomly positioned depth values into the
379 * depth buffer. Only write depth[i] value if mask[i] is nonzero.
382 void (*ReadDepthPixels
)( GLcontext
*ctx
, GLuint n
,
383 const GLint x
[], const GLint y
[],
385 /* Read an array of randomly positioned depth values from the depth buffer.
391 *** For supporting hardware stencil buffers:
392 *** Either ALL or NONE of these functions must be implemented!
395 void (*WriteStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
396 const GLstencil stencil
[], const GLubyte mask
[] );
397 /* Write a horizontal span of stencil values into the stencil buffer.
398 * If mask is NULL, write all stencil values.
399 * Else, only write stencil[i] if mask[i] is non-zero.
402 void (*ReadStencilSpan
)( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
403 GLstencil stencil
[] );
404 /* Read a horizontal span of stencil values from the stencil buffer.
407 void (*WriteStencilPixels
)( GLcontext
*ctx
, GLuint n
,
408 const GLint x
[], const GLint y
[],
409 const GLstencil stencil
[],
410 const GLubyte mask
[] );
411 /* Write an array of stencil values into the stencil buffer.
412 * If mask is NULL, write all stencil values.
413 * Else, only write stencil[i] if mask[i] is non-zero.
416 void (*ReadStencilPixels
)( GLcontext
*ctx
, GLuint n
,
417 const GLint x
[], const GLint y
[],
418 GLstencil stencil
[] );
419 /* Read an array of stencil values from the stencil buffer.