swrast.h revision 53f82c5aadbb15585754bfacf3237093eccdb2ce
1/* 2 * Mesa 3-D graphics library 3 * Version: 6.3 4 * 5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 */ 25 26/** 27 * \file swrast/swrast.h 28 * \brief Public interface to the software rasterization functions. 29 * \author Keith Whitwell <keith@tungstengraphics.com> 30 */ 31 32#ifndef SWRAST_H 33#define SWRAST_H 34 35#include "mtypes.h" 36 37/** 38 * \struct SWvertex 39 * \brief Data-structure to handle vertices in the software rasterizer. 40 * 41 * The software rasterizer now uses this format for vertices. Thus a 42 * 'RasterSetup' stage or other translation is required between the 43 * tnl module and the swrast rasterization functions. This serves to 44 * isolate the swrast module from the internals of the tnl module, and 45 * improve its usefulness as a fallback mechanism for hardware 46 * drivers. 47 * 48 * Full software drivers: 49 * - Register the rastersetup and triangle functions from 50 * utils/software_helper. 51 * - On statechange, update the rasterization pointers in that module. 52 * 53 * Rasterization hardware drivers: 54 * - Keep native rastersetup. 55 * - Implement native twoside,offset and unfilled triangle setup. 56 * - Implement a translator from native vertices to swrast vertices. 57 * - On partial fallback (mix of accelerated and unaccelerated 58 * prims), call a pass-through function which translates native 59 * vertices to SWvertices and calls the appropriate swrast function. 60 * - On total fallback (vertex format insufficient for state or all 61 * primitives unaccelerated), hook in swrast_setup instead. 62 */ 63typedef struct { 64 /** win[0], win[1] are the screen-coords of SWvertex. win[2] is the 65 * z-coord. what is win[3]? */ 66 GLfloat win[4]; 67 GLfloat texcoord[MAX_TEXTURE_COORD_UNITS][4]; 68 GLchan color[4]; 69 GLchan specular[4]; 70 GLfloat fog; 71 GLfloat index; 72 GLfloat pointSize; 73} SWvertex; 74 75 76struct swrast_device_driver; 77 78 79/* These are the public-access functions exported from swrast. 80 */ 81extern void 82_swrast_alloc_buffers( GLframebuffer *buffer ); 83 84extern void 85_swrast_use_read_buffer( GLcontext *ctx ); 86 87extern void 88_swrast_use_draw_buffer( GLcontext *ctx ); 89 90extern GLboolean 91_swrast_CreateContext( GLcontext *ctx ); 92 93extern void 94_swrast_DestroyContext( GLcontext *ctx ); 95 96/* Get a (non-const) reference to the device driver struct for swrast. 97 */ 98extern struct swrast_device_driver * 99_swrast_GetDeviceDriverReference( GLcontext *ctx ); 100 101extern void 102_swrast_Bitmap( GLcontext *ctx, 103 GLint px, GLint py, 104 GLsizei width, GLsizei height, 105 const struct gl_pixelstore_attrib *unpack, 106 const GLubyte *bitmap ); 107 108extern void 109_swrast_CopyPixels( GLcontext *ctx, 110 GLint srcx, GLint srcy, 111 GLint destx, GLint desty, 112 GLsizei width, GLsizei height, 113 GLenum type ); 114 115extern void 116_swrast_DrawPixels( GLcontext *ctx, 117 GLint x, GLint y, 118 GLsizei width, GLsizei height, 119 GLenum format, GLenum type, 120 const struct gl_pixelstore_attrib *unpack, 121 const GLvoid *pixels ); 122 123extern void 124_swrast_ReadPixels( GLcontext *ctx, 125 GLint x, GLint y, GLsizei width, GLsizei height, 126 GLenum format, GLenum type, 127 const struct gl_pixelstore_attrib *unpack, 128 GLvoid *pixels ); 129 130extern void 131_swrast_Clear( GLcontext *ctx, GLbitfield mask, GLboolean all, 132 GLint x, GLint y, GLint width, GLint height ); 133 134extern void 135_swrast_Accum( GLcontext *ctx, GLenum op, 136 GLfloat value, GLint xpos, GLint ypos, 137 GLint width, GLint height ); 138 139 140extern void 141_swrast_DrawBuffer( GLcontext *ctx, GLenum mode ); 142 143 144extern void 145_swrast_DrawBuffers( GLcontext *ctx, GLsizei n, const GLenum *buffers ); 146 147 148/* Reset the stipple counter 149 */ 150extern void 151_swrast_ResetLineStipple( GLcontext *ctx ); 152 153/* These will always render the correct point/line/triangle for the 154 * current state. 155 * 156 * For flatshaded primitives, the provoking vertex is the final one. 157 */ 158extern void 159_swrast_Point( GLcontext *ctx, const SWvertex *v ); 160 161extern void 162_swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ); 163 164extern void 165_swrast_Triangle( GLcontext *ctx, const SWvertex *v0, 166 const SWvertex *v1, const SWvertex *v2 ); 167 168extern void 169_swrast_Quad( GLcontext *ctx, 170 const SWvertex *v0, const SWvertex *v1, 171 const SWvertex *v2, const SWvertex *v3); 172 173extern void 174_swrast_flush( GLcontext *ctx ); 175 176extern void 177_swrast_render_primitive( GLcontext *ctx, GLenum mode ); 178 179extern void 180_swrast_render_start( GLcontext *ctx ); 181 182extern void 183_swrast_render_finish( GLcontext *ctx ); 184 185/* Tell the software rasterizer about core state changes. 186 */ 187extern void 188_swrast_InvalidateState( GLcontext *ctx, GLuint new_state ); 189 190/* Configure software rasterizer to match hardware rasterizer characteristics: 191 */ 192extern void 193_swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ); 194 195extern void 196_swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ); 197 198/* Debug: 199 */ 200extern void 201_swrast_print_vertex( GLcontext *ctx, const SWvertex *v ); 202 203 204extern GLvoid * 205_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack, 206 GLsizei width, GLsizei height, GLsizei depth, 207 GLenum format, GLenum type, GLvoid *ptr); 208 209/* 210 * Imaging fallbacks (a better solution should be found, perhaps 211 * moving all the imaging fallback code to a new module) 212 */ 213extern void 214_swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, 215 GLenum internalFormat, 216 GLint x, GLint y, GLsizei width, 217 GLsizei height); 218extern void 219_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, 220 GLenum internalFormat, 221 GLint x, GLint y, GLsizei width); 222extern void 223_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start, 224 GLint x, GLint y, GLsizei width); 225extern void 226_swrast_CopyColorTable( GLcontext *ctx, 227 GLenum target, GLenum internalformat, 228 GLint x, GLint y, GLsizei width); 229 230 231/* 232 * Texture fallbacks. Could also live in a new module 233 * with the rest of the texture store fallbacks? 234 */ 235extern void 236_swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level, 237 GLenum internalFormat, 238 GLint x, GLint y, GLsizei width, GLint border); 239 240extern void 241_swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level, 242 GLenum internalFormat, 243 GLint x, GLint y, GLsizei width, GLsizei height, 244 GLint border); 245 246 247extern void 248_swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 249 GLint xoffset, GLint x, GLint y, GLsizei width); 250 251extern void 252_swrast_copy_texsubimage2d(GLcontext *ctx, 253 GLenum target, GLint level, 254 GLint xoffset, GLint yoffset, 255 GLint x, GLint y, GLsizei width, GLsizei height); 256 257extern void 258_swrast_copy_texsubimage3d(GLcontext *ctx, 259 GLenum target, GLint level, 260 GLint xoffset, GLint yoffset, GLint zoffset, 261 GLint x, GLint y, GLsizei width, GLsizei height); 262 263 264/* The driver interface for the software rasterizer. 265 * Unless otherwise noted, all functions are mandatory. 266 */ 267struct swrast_device_driver { 268 269 void (*SetBuffer)(GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit); 270 /* 271 * Specifies the current color buffer for span/pixel writing/reading. 272 * buffer indicates which window to write to / read from. Normally, 273 * this'll be the buffer currently bound to the context, but it doesn't 274 * have to be! 275 * bufferBit indicates which color buffer, exactly one of: 276 * DD_FRONT_LEFT_BIT - this buffer always exists 277 * DD_BACK_LEFT_BIT - when double buffering 278 * DD_FRONT_RIGHT_BIT - when using stereo 279 * DD_BACK_RIGHT_BIT - when using stereo and double buffering 280 * DD_AUXn_BIT - if aux buffers are implemented 281 */ 282 283 284 /*** 285 *** Functions for synchronizing access to the framebuffer: 286 ***/ 287 288 void (*SpanRenderStart)(GLcontext *ctx); 289 void (*SpanRenderFinish)(GLcontext *ctx); 290 /* OPTIONAL. 291 * 292 * Called before and after all rendering operations, including DrawPixels, 293 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands. 294 * These are a suitable place for grabbing/releasing hardware locks. 295 * 296 * NOTE: The swrast triangle/line/point routines *DO NOT* call 297 * these functions. Locking in that case must be organized by the 298 * driver by other mechanisms. 299 */ 300 301 /*** 302 *** Functions for writing pixels to the frame buffer: 303 ***/ 304 305 void (*WriteRGBASpan)( const GLcontext *ctx, 306 GLuint n, GLint x, GLint y, 307 CONST GLchan rgba[][4], const GLubyte mask[] ); 308 void (*WriteRGBSpan)( const GLcontext *ctx, 309 GLuint n, GLint x, GLint y, 310 CONST GLchan rgb[][3], const GLubyte mask[] ); 311 /* Write a horizontal run of RGBA or RGB pixels. 312 * If mask is NULL, draw all pixels. 313 * If mask is not null, only draw pixel [i] when mask [i] is true. 314 */ 315 316 void (*WriteMonoRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 317 const GLchan color[4], const GLubyte mask[] ); 318 /* Write a horizontal run of RGBA pixels all with the same color. 319 * If mask is NULL, draw all pixels. 320 * If mask is not null, only draw pixel [i] when mask [i] is true. 321 */ 322 323 void (*WriteRGBAPixels)( const GLcontext *ctx, 324 GLuint n, const GLint x[], const GLint y[], 325 CONST GLchan rgba[][4], const GLubyte mask[] ); 326 /* Write array of RGBA pixels at random locations. 327 */ 328 329 void (*WriteMonoRGBAPixels)( const GLcontext *ctx, 330 GLuint n, const GLint x[], const GLint y[], 331 const GLchan color[4], const GLubyte mask[] ); 332 /* Write an array of mono-RGBA pixels at random locations. 333 */ 334 335 void (*WriteCI32Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 336 const GLuint index[], const GLubyte mask[] ); 337 void (*WriteCI8Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 338 const GLubyte index[], const GLubyte mask[] ); 339 /* Write a horizontal run of CI pixels. One function is for 32bpp 340 * indexes and the other for 8bpp pixels (the common case). You mus 341 * implement both for color index mode. 342 * If mask is NULL, draw all pixels. 343 * If mask is not null, only draw pixel [i] when mask [i] is true. 344 */ 345 346 void (*WriteMonoCISpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 347 GLuint colorIndex, const GLubyte mask[] ); 348 /* Write a horizontal run of color index pixels using the color index 349 * last specified by the Index() function. 350 * If mask is NULL, draw all pixels. 351 * If mask is not null, only draw pixel [i] when mask [i] is true. 352 */ 353 354 void (*WriteCI32Pixels)( const GLcontext *ctx, 355 GLuint n, const GLint x[], const GLint y[], 356 const GLuint index[], const GLubyte mask[] ); 357 /* 358 * Write a random array of CI pixels. 359 */ 360 361 void (*WriteMonoCIPixels)( const GLcontext *ctx, 362 GLuint n, const GLint x[], const GLint y[], 363 GLuint colorIndex, const GLubyte mask[] ); 364 /* Write a random array of color index pixels using the color index 365 * last specified by the Index() function. 366 */ 367 368 369 /*** 370 *** Functions to read pixels from frame buffer: 371 ***/ 372 373 void (*ReadCI32Span)( const GLcontext *ctx, 374 GLuint n, GLint x, GLint y, GLuint index[] ); 375 /* Read a horizontal run of color index pixels. 376 */ 377 378 void (*ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 379 GLchan rgba[][4] ); 380 /* Read a horizontal run of RGBA pixels. 381 */ 382 383 void (*ReadCI32Pixels)( const GLcontext *ctx, 384 GLuint n, const GLint x[], const GLint y[], 385 GLuint indx[], const GLubyte mask[] ); 386 /* Read a random array of CI pixels. 387 */ 388 389 void (*ReadRGBAPixels)( const GLcontext *ctx, 390 GLuint n, const GLint x[], const GLint y[], 391 GLchan rgba[][4], const GLubyte mask[] ); 392 /* Read a random array of RGBA pixels. 393 */ 394 395 396 397 /*** 398 *** For supporting hardware Z buffers: 399 *** Either ALL or NONE of these functions must be implemented! 400 *** NOTE that Each depth value is a 32-bit GLuint. If the depth 401 *** buffer is less than 32 bits deep then the extra upperbits are zero. 402 ***/ 403 404 void (*WriteDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 405 const GLdepth depth[], const GLubyte mask[] ); 406 /* Write a horizontal span of values into the depth buffer. Only write 407 * depth[i] value if mask[i] is nonzero. 408 */ 409 410 void (*WriteMonoDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 411 const GLdepth depth, const GLubyte mask[] ); 412 /* Write a horizontal run of depth values. 413 * If mask is NULL, draw all pixels. 414 * If mask is not null, only draw pixel [i] when mask [i] is true. 415 */ 416 417 void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 418 GLdepth depth[] ); 419 /* Read a horizontal span of values from the depth buffer. 420 */ 421 422 423 void (*WriteDepthPixels)( GLcontext *ctx, GLuint n, 424 const GLint x[], const GLint y[], 425 const GLdepth depth[], const GLubyte mask[] ); 426 /* Write an array of randomly positioned depth values into the 427 * depth buffer. Only write depth[i] value if mask[i] is nonzero. 428 */ 429 430 void (*ReadDepthPixels)( GLcontext *ctx, GLuint n, 431 const GLint x[], const GLint y[], 432 GLdepth depth[] ); 433 /* Read an array of randomly positioned depth values from the depth buffer. 434 */ 435 436 437 438 /*** 439 *** For supporting hardware stencil buffers: 440 *** Either ALL or NONE of these functions must be implemented! 441 ***/ 442 443 void (*WriteStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 444 const GLstencil stencil[], const GLubyte mask[] ); 445 /* Write a horizontal span of stencil values into the stencil buffer. 446 * If mask is NULL, write all stencil values. 447 * Else, only write stencil[i] if mask[i] is non-zero. 448 */ 449 450 void (*ReadStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 451 GLstencil stencil[] ); 452 /* Read a horizontal span of stencil values from the stencil buffer. 453 */ 454 455 void (*WriteStencilPixels)( GLcontext *ctx, GLuint n, 456 const GLint x[], const GLint y[], 457 const GLstencil stencil[], 458 const GLubyte mask[] ); 459 /* Write an array of stencil values into the stencil buffer. 460 * If mask is NULL, write all stencil values. 461 * Else, only write stencil[i] if mask[i] is non-zero. 462 */ 463 464 void (*ReadStencilPixels)( GLcontext *ctx, GLuint n, 465 const GLint x[], const GLint y[], 466 GLstencil stencil[] ); 467 /* Read an array of stencil values from the stencil buffer. 468 */ 469}; 470 471 472 473#endif 474