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