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