Support for floating point color representation in tnl module.
[mesa.git] / src / mesa / swrast / swrast.h
1 /* $Id: swrast.h,v 1.12 2001/03/19 02:25:36 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #ifndef SWRAST_H
31 #define SWRAST_H
32
33 #include "mtypes.h"
34
35
36
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
42 * drivers.
43 *
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.
48 *
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.
58 */
59 typedef struct {
60 GLfloat win[4];
61 GLfloat texcoord[MAX_TEXTURE_UNITS][4];
62 GLchan color[4];
63 GLchan specular[4];
64 GLfloat fog;
65 GLuint index;
66 GLfloat pointSize;
67 } SWvertex;
68
69
70 struct swrast_device_driver;
71
72
73 /* These are the public-access functions exported from swrast.
74 */
75 extern void
76 _swrast_alloc_buffers( GLcontext *ctx );
77
78 extern GLboolean
79 _swrast_CreateContext( GLcontext *ctx );
80
81 extern void
82 _swrast_DestroyContext( GLcontext *ctx );
83
84 /* Get a (non-const) reference to the device driver struct for swrast.
85 */
86 extern struct swrast_device_driver *
87 _swrast_GetDeviceDriverReference( GLcontext *ctx );
88
89 extern void
90 _swrast_Bitmap( GLcontext *ctx,
91 GLint px, GLint py,
92 GLsizei width, GLsizei height,
93 const struct gl_pixelstore_attrib *unpack,
94 const GLubyte *bitmap );
95
96 extern void
97 _swrast_CopyPixels( GLcontext *ctx,
98 GLint srcx, GLint srcy,
99 GLint destx, GLint desty,
100 GLsizei width, GLsizei height,
101 GLenum type );
102
103 extern void
104 _swrast_DrawPixels( GLcontext *ctx,
105 GLint x, GLint y,
106 GLsizei width, GLsizei height,
107 GLenum format, GLenum type,
108 const struct gl_pixelstore_attrib *unpack,
109 const GLvoid *pixels );
110
111 extern void
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,
116 GLvoid *pixels );
117
118 extern void
119 _swrast_Clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
120 GLint x, GLint y, GLint width, GLint height );
121
122 extern void
123 _swrast_Accum( GLcontext *ctx, GLenum op,
124 GLfloat value, GLint xpos, GLint ypos,
125 GLint width, GLint height );
126
127
128 /* Reset the stipple counter
129 */
130 extern void
131 _swrast_ResetLineStipple( GLcontext *ctx );
132
133 /* These will always render the correct point/line/triangle for the
134 * current state.
135 *
136 * For flatshaded primitives, the provoking vertex is the final one.
137 */
138 extern void
139 _swrast_Point( GLcontext *ctx, const SWvertex *v );
140
141 extern void
142 _swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 );
143
144 extern void
145 _swrast_Triangle( GLcontext *ctx, const SWvertex *v0,
146 const SWvertex *v1, const SWvertex *v2 );
147
148 extern void
149 _swrast_Quad( GLcontext *ctx,
150 const SWvertex *v0, const SWvertex *v1,
151 const SWvertex *v2, const SWvertex *v3);
152
153 extern void
154 _swrast_flush( GLcontext *ctx );
155
156
157 /* Tell the software rasterizer about core state changes.
158 */
159 extern void
160 _swrast_InvalidateState( GLcontext *ctx, GLuint new_state );
161
162 /* Configure software rasterizer to match hardware rasterizer characteristics:
163 */
164 extern void
165 _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value );
166
167 extern void
168 _swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value );
169
170 /* Debug:
171 */
172 extern void
173 _swrast_print_vertex( GLcontext *ctx, const SWvertex *v );
174
175
176 /*
177 * Imaging fallbacks (a better solution should be found, perhaps
178 * moving all the imaging fallback code to a new module)
179 */
180 void
181 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
182 GLenum internalFormat,
183 GLint x, GLint y, GLsizei width,
184 GLsizei height);
185 void
186 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
187 GLenum internalFormat,
188 GLint x, GLint y, GLsizei width);
189 void
190 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
191 GLint x, GLint y, GLsizei width);
192 void
193 _swrast_CopyColorTable( GLcontext *ctx,
194 GLenum target, GLenum internalformat,
195 GLint x, GLint y, GLsizei width);
196
197
198 /*
199 * Texture fallbacks, Brian Paul. Could also live in a new module
200 * with the rest of the texture store fallbacks?
201 */
202 extern void
203 _swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level,
204 GLenum internalFormat,
205 GLint x, GLint y, GLsizei width, GLint border);
206
207 extern void
208 _swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level,
209 GLenum internalFormat,
210 GLint x, GLint y, GLsizei width, GLsizei height,
211 GLint border);
212
213
214 extern void
215 _swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
216 GLint xoffset, GLint x, GLint y, GLsizei width);
217
218 extern void
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);
223
224 extern void
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);
229
230
231
232 /* The driver interface for the software rasterizer. Unless otherwise
233 * noted, all functions are mandatory.
234 */
235 struct swrast_device_driver {
236
237 void (*SetReadBuffer)( GLcontext *ctx, GLframebuffer *colorBuffer,
238 GLenum buffer );
239 /*
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
246 */
247
248
249 /***
250 *** Functions for synchronizing access to the framebuffer:
251 ***/
252
253 void (*SpanRenderStart)(GLcontext *ctx);
254 void (*SpanRenderFinish)(GLcontext *ctx);
255 /* OPTIONAL.
256 *
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.
260 *
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.
264 */
265
266 /***
267 *** Functions for writing pixels to the frame buffer:
268 ***/
269
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.
279 */
280
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.
284 */
285
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.
290 */
291
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.
296 */
297
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.
305 */
306
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.
311 */
312
313 void (*WriteCI32Pixels)( const GLcontext *ctx,
314 GLuint n, const GLint x[], const GLint y[],
315 const GLuint index[], const GLubyte mask[] );
316 /*
317 * Write a random array of CI pixels.
318 */
319
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.
325 */
326
327
328 /***
329 *** Functions to read pixels from frame buffer:
330 ***/
331
332 void (*ReadCI32Span)( const GLcontext *ctx,
333 GLuint n, GLint x, GLint y, GLuint index[] );
334 /* Read a horizontal run of color index pixels.
335 */
336
337 void (*ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
338 GLchan rgba[][4] );
339 /* Read a horizontal run of RGBA pixels.
340 */
341
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.
346 */
347
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.
352 */
353
354
355
356 /***
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.
361 ***/
362
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.
367 */
368
369 void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
370 GLdepth depth[] );
371 /* Read a horizontal span of values from the depth buffer.
372 */
373
374
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.
380 */
381
382 void (*ReadDepthPixels)( GLcontext *ctx, GLuint n,
383 const GLint x[], const GLint y[],
384 GLdepth depth[] );
385 /* Read an array of randomly positioned depth values from the depth buffer.
386 */
387
388
389
390 /***
391 *** For supporting hardware stencil buffers:
392 *** Either ALL or NONE of these functions must be implemented!
393 ***/
394
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.
400 */
401
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.
405 */
406
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.
414 */
415
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.
420 */
421 };
422
423
424
425 #endif