swrast.h revision 2ef866d1fc0a5cc5ef8543d65744dfd4da4dbbaf
1/* $Id: swrast.h,v 1.15 2002/01/21 18:12:34 brianp Exp $ */ 2 3/* 4 * Mesa 3-D graphics library 5 * Version: 4.1 6 * 7 * Copyright (C) 1999-2002 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/* 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 41 * drivers. 42 * 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. 47 * 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. 57 */ 58typedef struct { 59 GLfloat win[4]; 60 GLfloat texcoord[MAX_TEXTURE_UNITS][4]; 61 GLchan color[4]; 62 GLchan specular[4]; 63 GLfloat fog; 64 GLuint index; 65 GLfloat pointSize; 66} SWvertex; 67 68 69/* 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. 76 * 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. 81 */ 82 83 84/* When the sw_span struct is initialized, these flags indicates 85 * which values are needed for rendering the triangle. 86 */ 87#define SPAN_RGBA 0x001 88#define SPAN_SPEC 0x002 89#define SPAN_INDEX 0x004 90#define SPAN_Z 0x008 91#define SPAN_FOG 0x010 92#define SPAN_TEXTURE 0x020 93#define SPAN_INT_TEXTURE 0x040 94#define SPAN_LAMBDA 0x080 95#define SPAN_FLAT 0x100 /* flat shading? */ 96 97 98struct sw_span { 99 GLint x, y; 100 101 /* only need to process pixels between start <= i < end */ 102 GLuint start, end; 103 104 /* This flag indicates that only a part of the span is visible */ 105 GLboolean writeAll; 106 107 GLuint activeMask; /* OR of the SPAN_* flags */ 108 109#if CHAN_TYPE == GL_FLOAT 110 GLfloat red, redStep; 111 GLfloat green, greenStep; 112 GLfloat blue, blueStep; 113 GLfloat alpha, alphaStep; 114 GLfloat specRed, specRedStep; 115 GLfloat specGreen, specGreenStep; 116 GLfloat specBlue, specBlueStep; 117#else /* CHAN_TYPE == */ 118 GLfixed red, redStep; 119 GLfixed green, greenStep; 120 GLfixed blue, blueStep; 121 GLfixed alpha, alphaStep; 122 GLfixed specRed, specRedStep; 123 GLfixed specGreen, specGreenStep; 124 GLfixed specBlue, specBlueStep; 125#endif 126 GLfixed index, indexStep; 127 GLfixed z, zStep; 128 GLfloat fog, fogStep; 129 GLfloat tex[MAX_TEXTURE_UNITS][4], texStep[MAX_TEXTURE_UNITS][4]; 130 GLfixed intTex[2], intTexStep[2]; 131 /* Needed for texture lambda (LOD) computation */ 132 GLfloat rho[MAX_TEXTURE_UNITS]; 133 GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS]; 134 135 /** 136 * Arrays of fragment values. These will either be computed from the 137 * x/xStep values above or loadd from glDrawPixels, etc. 138 */ 139 GLdepth depth[MAX_WIDTH]; 140 union { 141 GLchan rgb[MAX_WIDTH][3]; 142 GLchan rgba[MAX_WIDTH][4]; 143 GLuint index[MAX_WIDTH]; 144 } color; 145 GLchan specular[MAX_WIDTH][4]; 146 GLint itexcoords[MAX_WIDTH][2]; /* Integer texture (s, t) */ 147 /* Texture (s,t,r). 4th component only used for pixel texture */ 148 GLfloat texcoords[MAX_TEXTURE_UNITS][MAX_WIDTH][4]; 149 GLfloat lambda[MAX_TEXTURE_UNITS][MAX_WIDTH]; 150 GLfloat coverage[MAX_WIDTH]; 151 GLubyte mask[MAX_WIDTH]; 152 153#ifdef DEBUG 154 GLboolean filledDepth, filledMask, filledAlpha; 155 GLboolean filledColor, filledSpecular; 156 GLboolean filledLambda[MAX_TEXTURE_UNITS], filledTex[MAX_TEXTURE_UNITS]; 157 GLboolean testedDepth, testedAlpha; 158#endif 159}; 160 161 162#ifdef DEBUG 163#define SW_SPAN_SET_FLAG(flag) {ASSERT((flag) == GL_FALSE);(flag) = GL_TRUE;} 164#define SW_SPAN_RESET(span) { \ 165 (span).filledDepth = (span).filledMask = (span).filledAlpha \ 166 = (span).filledColor = (span).filledSpecular \ 167 = (span).testedDepth = (span).testedAlpha = GL_FALSE; \ 168 MEMSET((span).filledTex, GL_FALSE, \ 169 MAX_TEXTURE_UNITS*sizeof(GLboolean)); \ 170 MEMSET((span).filledLambda, GL_FALSE, \ 171 MAX_TEXTURE_UNITS*sizeof(GLboolean)); \ 172 (span).start = 0; (span).writeAll = GL_TRUE;} 173#else 174#define SW_SPAN_SET_FLAG(flag) ; 175#define SW_SPAN_RESET(span) {(span).start = 0;(span).writeAll = GL_TRUE;} 176#endif 177 178struct swrast_device_driver; 179 180 181/* These are the public-access functions exported from swrast. 182 */ 183extern void 184_swrast_alloc_buffers( GLcontext *ctx ); 185 186extern GLboolean 187_swrast_CreateContext( GLcontext *ctx ); 188 189extern void 190_swrast_DestroyContext( GLcontext *ctx ); 191 192/* Get a (non-const) reference to the device driver struct for swrast. 193 */ 194extern struct swrast_device_driver * 195_swrast_GetDeviceDriverReference( GLcontext *ctx ); 196 197extern void 198_swrast_Bitmap( GLcontext *ctx, 199 GLint px, GLint py, 200 GLsizei width, GLsizei height, 201 const struct gl_pixelstore_attrib *unpack, 202 const GLubyte *bitmap ); 203 204extern void 205_swrast_CopyPixels( GLcontext *ctx, 206 GLint srcx, GLint srcy, 207 GLint destx, GLint desty, 208 GLsizei width, GLsizei height, 209 GLenum type ); 210 211extern void 212_swrast_DrawPixels( GLcontext *ctx, 213 GLint x, GLint y, 214 GLsizei width, GLsizei height, 215 GLenum format, GLenum type, 216 const struct gl_pixelstore_attrib *unpack, 217 const GLvoid *pixels ); 218 219extern void 220_swrast_ReadPixels( GLcontext *ctx, 221 GLint x, GLint y, GLsizei width, GLsizei height, 222 GLenum format, GLenum type, 223 const struct gl_pixelstore_attrib *unpack, 224 GLvoid *pixels ); 225 226extern void 227_swrast_Clear( GLcontext *ctx, GLbitfield mask, GLboolean all, 228 GLint x, GLint y, GLint width, GLint height ); 229 230extern void 231_swrast_Accum( GLcontext *ctx, GLenum op, 232 GLfloat value, GLint xpos, GLint ypos, 233 GLint width, GLint height ); 234 235 236/* Reset the stipple counter 237 */ 238extern void 239_swrast_ResetLineStipple( GLcontext *ctx ); 240 241/* These will always render the correct point/line/triangle for the 242 * current state. 243 * 244 * For flatshaded primitives, the provoking vertex is the final one. 245 */ 246extern void 247_swrast_Point( GLcontext *ctx, const SWvertex *v ); 248 249extern void 250_swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ); 251 252extern void 253_swrast_Triangle( GLcontext *ctx, const SWvertex *v0, 254 const SWvertex *v1, const SWvertex *v2 ); 255 256extern void 257_swrast_Quad( GLcontext *ctx, 258 const SWvertex *v0, const SWvertex *v1, 259 const SWvertex *v2, const SWvertex *v3); 260 261extern void 262_swrast_flush( GLcontext *ctx ); 263 264 265/* Tell the software rasterizer about core state changes. 266 */ 267extern void 268_swrast_InvalidateState( GLcontext *ctx, GLuint new_state ); 269 270/* Configure software rasterizer to match hardware rasterizer characteristics: 271 */ 272extern void 273_swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ); 274 275extern void 276_swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ); 277 278/* Debug: 279 */ 280extern void 281_swrast_print_vertex( GLcontext *ctx, const SWvertex *v ); 282 283 284/* 285 * Imaging fallbacks (a better solution should be found, perhaps 286 * moving all the imaging fallback code to a new module) 287 */ 288void 289_swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, 290 GLenum internalFormat, 291 GLint x, GLint y, GLsizei width, 292 GLsizei height); 293void 294_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, 295 GLenum internalFormat, 296 GLint x, GLint y, GLsizei width); 297void 298_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start, 299 GLint x, GLint y, GLsizei width); 300void 301_swrast_CopyColorTable( GLcontext *ctx, 302 GLenum target, GLenum internalformat, 303 GLint x, GLint y, GLsizei width); 304 305 306/* 307 * Texture fallbacks, Brian Paul. Could also live in a new module 308 * with the rest of the texture store fallbacks? 309 */ 310extern void 311_swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level, 312 GLenum internalFormat, 313 GLint x, GLint y, GLsizei width, GLint border); 314 315extern void 316_swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level, 317 GLenum internalFormat, 318 GLint x, GLint y, GLsizei width, GLsizei height, 319 GLint border); 320 321 322extern void 323_swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 324 GLint xoffset, GLint x, GLint y, GLsizei width); 325 326extern void 327_swrast_copy_texsubimage2d(GLcontext *ctx, 328 GLenum target, GLint level, 329 GLint xoffset, GLint yoffset, 330 GLint x, GLint y, GLsizei width, GLsizei height); 331 332extern void 333_swrast_copy_texsubimage3d(GLcontext *ctx, 334 GLenum target, GLint level, 335 GLint xoffset, GLint yoffset, GLint zoffset, 336 GLint x, GLint y, GLsizei width, GLsizei height); 337 338 339 340/* The driver interface for the software rasterizer. Unless otherwise 341 * noted, all functions are mandatory. 342 */ 343struct swrast_device_driver { 344 345 void (*SetReadBuffer)( GLcontext *ctx, GLframebuffer *colorBuffer, 346 GLenum buffer ); 347 /* 348 * Specifies the current buffer for span/pixel reading. 349 * colorBuffer will be one of: 350 * GL_FRONT_LEFT - this buffer always exists 351 * GL_BACK_LEFT - when double buffering 352 * GL_FRONT_RIGHT - when using stereo 353 * GL_BACK_RIGHT - when using stereo and double buffering 354 */ 355 356 357 /*** 358 *** Functions for synchronizing access to the framebuffer: 359 ***/ 360 361 void (*SpanRenderStart)(GLcontext *ctx); 362 void (*SpanRenderFinish)(GLcontext *ctx); 363 /* OPTIONAL. 364 * 365 * Called before and after all rendering operations, including DrawPixels, 366 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands. 367 * These are a suitable place for grabbing/releasing hardware locks. 368 * 369 * NOTE: The swrast triangle/line/point routines *DO NOT* call 370 * these functions. Locking in that case must be organized by the 371 * driver by other mechanisms. 372 */ 373 374 /*** 375 *** Functions for writing pixels to the frame buffer: 376 ***/ 377 378 void (*WriteRGBASpan)( const GLcontext *ctx, 379 GLuint n, GLint x, GLint y, 380 CONST GLchan rgba[][4], const GLubyte mask[] ); 381 void (*WriteRGBSpan)( const GLcontext *ctx, 382 GLuint n, GLint x, GLint y, 383 CONST GLchan rgb[][3], const GLubyte mask[] ); 384 /* Write a horizontal run of RGBA or RGB pixels. 385 * If mask is NULL, draw all pixels. 386 * If mask is not null, only draw pixel [i] when mask [i] is true. 387 */ 388 389 void (*WriteMonoRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 390 const GLchan color[4], const GLubyte mask[] ); 391 /* Write a horizontal run of RGBA pixels all with the same color. 392 */ 393 394 void (*WriteRGBAPixels)( const GLcontext *ctx, 395 GLuint n, const GLint x[], const GLint y[], 396 CONST GLchan rgba[][4], const GLubyte mask[] ); 397 /* Write array of RGBA pixels at random locations. 398 */ 399 400 void (*WriteMonoRGBAPixels)( const GLcontext *ctx, 401 GLuint n, const GLint x[], const GLint y[], 402 const GLchan color[4], const GLubyte mask[] ); 403 /* Write an array of mono-RGBA pixels at random locations. 404 */ 405 406 void (*WriteCI32Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 407 const GLuint index[], const GLubyte mask[] ); 408 void (*WriteCI8Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 409 const GLubyte index[], const GLubyte mask[] ); 410 /* Write a horizontal run of CI pixels. One function is for 32bpp 411 * indexes and the other for 8bpp pixels (the common case). You mus 412 * implement both for color index mode. 413 */ 414 415 void (*WriteMonoCISpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 416 GLuint colorIndex, const GLubyte mask[] ); 417 /* Write a horizontal run of color index pixels using the color index 418 * last specified by the Index() function. 419 */ 420 421 void (*WriteCI32Pixels)( const GLcontext *ctx, 422 GLuint n, const GLint x[], const GLint y[], 423 const GLuint index[], const GLubyte mask[] ); 424 /* 425 * Write a random array of CI pixels. 426 */ 427 428 void (*WriteMonoCIPixels)( const GLcontext *ctx, 429 GLuint n, const GLint x[], const GLint y[], 430 GLuint colorIndex, const GLubyte mask[] ); 431 /* Write a random array of color index pixels using the color index 432 * last specified by the Index() function. 433 */ 434 435 436 /*** 437 *** Functions to read pixels from frame buffer: 438 ***/ 439 440 void (*ReadCI32Span)( const GLcontext *ctx, 441 GLuint n, GLint x, GLint y, GLuint index[] ); 442 /* Read a horizontal run of color index pixels. 443 */ 444 445 void (*ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 446 GLchan rgba[][4] ); 447 /* Read a horizontal run of RGBA pixels. 448 */ 449 450 void (*ReadCI32Pixels)( const GLcontext *ctx, 451 GLuint n, const GLint x[], const GLint y[], 452 GLuint indx[], const GLubyte mask[] ); 453 /* Read a random array of CI pixels. 454 */ 455 456 void (*ReadRGBAPixels)( const GLcontext *ctx, 457 GLuint n, const GLint x[], const GLint y[], 458 GLchan rgba[][4], const GLubyte mask[] ); 459 /* Read a random array of RGBA pixels. 460 */ 461 462 463 464 /*** 465 *** For supporting hardware Z buffers: 466 *** Either ALL or NONE of these functions must be implemented! 467 *** NOTE that Each depth value is a 32-bit GLuint. If the depth 468 *** buffer is less than 32 bits deep then the extra upperbits are zero. 469 ***/ 470 471 void (*WriteDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 472 const GLdepth depth[], const GLubyte mask[] ); 473 /* Write a horizontal span of values into the depth buffer. Only write 474 * depth[i] value if mask[i] is nonzero. 475 */ 476 477 void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 478 GLdepth depth[] ); 479 /* Read a horizontal span of values from the depth buffer. 480 */ 481 482 483 void (*WriteDepthPixels)( GLcontext *ctx, GLuint n, 484 const GLint x[], const GLint y[], 485 const GLdepth depth[], const GLubyte mask[] ); 486 /* Write an array of randomly positioned depth values into the 487 * depth buffer. Only write depth[i] value if mask[i] is nonzero. 488 */ 489 490 void (*ReadDepthPixels)( GLcontext *ctx, GLuint n, 491 const GLint x[], const GLint y[], 492 GLdepth depth[] ); 493 /* Read an array of randomly positioned depth values from the depth buffer. 494 */ 495 496 497 498 /*** 499 *** For supporting hardware stencil buffers: 500 *** Either ALL or NONE of these functions must be implemented! 501 ***/ 502 503 void (*WriteStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 504 const GLstencil stencil[], const GLubyte mask[] ); 505 /* Write a horizontal span of stencil values into the stencil buffer. 506 * If mask is NULL, write all stencil values. 507 * Else, only write stencil[i] if mask[i] is non-zero. 508 */ 509 510 void (*ReadStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 511 GLstencil stencil[] ); 512 /* Read a horizontal span of stencil values from the stencil buffer. 513 */ 514 515 void (*WriteStencilPixels)( GLcontext *ctx, GLuint n, 516 const GLint x[], const GLint y[], 517 const GLstencil stencil[], 518 const GLubyte mask[] ); 519 /* Write an array of stencil values into the stencil buffer. 520 * If mask is NULL, write all stencil values. 521 * Else, only write stencil[i] if mask[i] is non-zero. 522 */ 523 524 void (*ReadStencilPixels)( GLcontext *ctx, GLuint n, 525 const GLint x[], const GLint y[], 526 GLstencil stencil[] ); 527 /* Read an array of stencil values from the stencil buffer. 528 */ 529}; 530 531 532 533#endif 534