swrast.h revision 894844a8d956a0ee5f95836331dc318f49fdb845
1/* 2 * Mesa 3-D graphics library 3 * Version: 6.1 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 144/* Reset the stipple counter 145 */ 146extern void 147_swrast_ResetLineStipple( GLcontext *ctx ); 148 149/* These will always render the correct point/line/triangle for the 150 * current state. 151 * 152 * For flatshaded primitives, the provoking vertex is the final one. 153 */ 154extern void 155_swrast_Point( GLcontext *ctx, const SWvertex *v ); 156 157extern void 158_swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ); 159 160extern void 161_swrast_Triangle( GLcontext *ctx, const SWvertex *v0, 162 const SWvertex *v1, const SWvertex *v2 ); 163 164extern void 165_swrast_Quad( GLcontext *ctx, 166 const SWvertex *v0, const SWvertex *v1, 167 const SWvertex *v2, const SWvertex *v3); 168 169extern void 170_swrast_flush( GLcontext *ctx ); 171 172extern void 173_swrast_render_primitive( GLcontext *ctx, GLenum mode ); 174 175extern void 176_swrast_render_start( GLcontext *ctx ); 177 178extern void 179_swrast_render_finish( GLcontext *ctx ); 180 181/* Tell the software rasterizer about core state changes. 182 */ 183extern void 184_swrast_InvalidateState( GLcontext *ctx, GLuint new_state ); 185 186/* Configure software rasterizer to match hardware rasterizer characteristics: 187 */ 188extern void 189_swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ); 190 191extern void 192_swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ); 193 194/* Debug: 195 */ 196extern void 197_swrast_print_vertex( GLcontext *ctx, const SWvertex *v ); 198 199 200extern GLvoid * 201_swrast_validate_pbo_access(const struct gl_pixelstore_attrib *pack, 202 GLsizei width, GLsizei height, GLsizei depth, 203 GLenum format, GLenum type, GLvoid *ptr); 204 205/* 206 * Imaging fallbacks (a better solution should be found, perhaps 207 * moving all the imaging fallback code to a new module) 208 */ 209extern void 210_swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, 211 GLenum internalFormat, 212 GLint x, GLint y, GLsizei width, 213 GLsizei height); 214extern void 215_swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, 216 GLenum internalFormat, 217 GLint x, GLint y, GLsizei width); 218extern void 219_swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start, 220 GLint x, GLint y, GLsizei width); 221extern void 222_swrast_CopyColorTable( GLcontext *ctx, 223 GLenum target, GLenum internalformat, 224 GLint x, GLint y, GLsizei width); 225 226 227/* 228 * Texture fallbacks. Could also live in a new module 229 * with the rest of the texture store fallbacks? 230 */ 231extern void 232_swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level, 233 GLenum internalFormat, 234 GLint x, GLint y, GLsizei width, GLint border); 235 236extern void 237_swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level, 238 GLenum internalFormat, 239 GLint x, GLint y, GLsizei width, GLsizei height, 240 GLint border); 241 242 243extern void 244_swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, 245 GLint xoffset, GLint x, GLint y, GLsizei width); 246 247extern void 248_swrast_copy_texsubimage2d(GLcontext *ctx, 249 GLenum target, GLint level, 250 GLint xoffset, GLint yoffset, 251 GLint x, GLint y, GLsizei width, GLsizei height); 252 253extern void 254_swrast_copy_texsubimage3d(GLcontext *ctx, 255 GLenum target, GLint level, 256 GLint xoffset, GLint yoffset, GLint zoffset, 257 GLint x, GLint y, GLsizei width, GLsizei height); 258 259 260/* The driver interface for the software rasterizer. 261 * Unless otherwise noted, all functions are mandatory. 262 */ 263struct swrast_device_driver { 264 265 void (*SetBuffer)(GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit); 266 /* 267 * Specifies the current color buffer for span/pixel writing/reading. 268 * buffer indicates which window to write to / read from. Normally, 269 * this'll be the buffer currently bound to the context, but it doesn't 270 * have to be! 271 * bufferBit indicates which color buffer, exactly one of: 272 * DD_FRONT_LEFT_BIT - this buffer always exists 273 * DD_BACK_LEFT_BIT - when double buffering 274 * DD_FRONT_RIGHT_BIT - when using stereo 275 * DD_BACK_RIGHT_BIT - when using stereo and double buffering 276 * DD_AUXn_BIT - if aux buffers are implemented 277 */ 278 279 280 /*** 281 *** Functions for synchronizing access to the framebuffer: 282 ***/ 283 284 void (*SpanRenderStart)(GLcontext *ctx); 285 void (*SpanRenderFinish)(GLcontext *ctx); 286 /* OPTIONAL. 287 * 288 * Called before and after all rendering operations, including DrawPixels, 289 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands. 290 * These are a suitable place for grabbing/releasing hardware locks. 291 * 292 * NOTE: The swrast triangle/line/point routines *DO NOT* call 293 * these functions. Locking in that case must be organized by the 294 * driver by other mechanisms. 295 */ 296 297 /*** 298 *** Functions for writing pixels to the frame buffer: 299 ***/ 300 301 void (*WriteRGBASpan)( const GLcontext *ctx, 302 GLuint n, GLint x, GLint y, 303 CONST GLchan rgba[][4], const GLubyte mask[] ); 304 void (*WriteRGBSpan)( const GLcontext *ctx, 305 GLuint n, GLint x, GLint y, 306 CONST GLchan rgb[][3], const GLubyte mask[] ); 307 /* Write a horizontal run of RGBA or RGB pixels. 308 * If mask is NULL, draw all pixels. 309 * If mask is not null, only draw pixel [i] when mask [i] is true. 310 */ 311 312 void (*WriteMonoRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 313 const GLchan color[4], const GLubyte mask[] ); 314 /* Write a horizontal run of RGBA pixels all with the same color. 315 * If mask is NULL, draw all pixels. 316 * If mask is not null, only draw pixel [i] when mask [i] is true. 317 */ 318 319 void (*WriteRGBAPixels)( const GLcontext *ctx, 320 GLuint n, const GLint x[], const GLint y[], 321 CONST GLchan rgba[][4], const GLubyte mask[] ); 322 /* Write array of RGBA pixels at random locations. 323 */ 324 325 void (*WriteMonoRGBAPixels)( const GLcontext *ctx, 326 GLuint n, const GLint x[], const GLint y[], 327 const GLchan color[4], const GLubyte mask[] ); 328 /* Write an array of mono-RGBA pixels at random locations. 329 */ 330 331 void (*WriteCI32Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 332 const GLuint index[], const GLubyte mask[] ); 333 void (*WriteCI8Span)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 334 const GLubyte index[], const GLubyte mask[] ); 335 /* Write a horizontal run of CI pixels. One function is for 32bpp 336 * indexes and the other for 8bpp pixels (the common case). You mus 337 * implement both for color index mode. 338 * If mask is NULL, draw all pixels. 339 * If mask is not null, only draw pixel [i] when mask [i] is true. 340 */ 341 342 void (*WriteMonoCISpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 343 GLuint colorIndex, const GLubyte mask[] ); 344 /* Write a horizontal run of color index pixels using the color index 345 * last specified by the Index() function. 346 * If mask is NULL, draw all pixels. 347 * If mask is not null, only draw pixel [i] when mask [i] is true. 348 */ 349 350 void (*WriteCI32Pixels)( const GLcontext *ctx, 351 GLuint n, const GLint x[], const GLint y[], 352 const GLuint index[], const GLubyte mask[] ); 353 /* 354 * Write a random array of CI pixels. 355 */ 356 357 void (*WriteMonoCIPixels)( const GLcontext *ctx, 358 GLuint n, const GLint x[], const GLint y[], 359 GLuint colorIndex, const GLubyte mask[] ); 360 /* Write a random array of color index pixels using the color index 361 * last specified by the Index() function. 362 */ 363 364 365 /*** 366 *** Functions to read pixels from frame buffer: 367 ***/ 368 369 void (*ReadCI32Span)( const GLcontext *ctx, 370 GLuint n, GLint x, GLint y, GLuint index[] ); 371 /* Read a horizontal run of color index pixels. 372 */ 373 374 void (*ReadRGBASpan)( const GLcontext *ctx, GLuint n, GLint x, GLint y, 375 GLchan rgba[][4] ); 376 /* Read a horizontal run of RGBA pixels. 377 */ 378 379 void (*ReadCI32Pixels)( const GLcontext *ctx, 380 GLuint n, const GLint x[], const GLint y[], 381 GLuint indx[], const GLubyte mask[] ); 382 /* Read a random array of CI pixels. 383 */ 384 385 void (*ReadRGBAPixels)( const GLcontext *ctx, 386 GLuint n, const GLint x[], const GLint y[], 387 GLchan rgba[][4], const GLubyte mask[] ); 388 /* Read a random array of RGBA pixels. 389 */ 390 391 392 393 /*** 394 *** For supporting hardware Z buffers: 395 *** Either ALL or NONE of these functions must be implemented! 396 *** NOTE that Each depth value is a 32-bit GLuint. If the depth 397 *** buffer is less than 32 bits deep then the extra upperbits are zero. 398 ***/ 399 400 void (*WriteDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 401 const GLdepth depth[], const GLubyte mask[] ); 402 /* Write a horizontal span of values into the depth buffer. Only write 403 * depth[i] value if mask[i] is nonzero. 404 */ 405 406 void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 407 GLdepth depth[] ); 408 /* Read a horizontal span of values from the depth buffer. 409 */ 410 411 412 void (*WriteDepthPixels)( GLcontext *ctx, GLuint n, 413 const GLint x[], const GLint y[], 414 const GLdepth depth[], const GLubyte mask[] ); 415 /* Write an array of randomly positioned depth values into the 416 * depth buffer. Only write depth[i] value if mask[i] is nonzero. 417 */ 418 419 void (*ReadDepthPixels)( GLcontext *ctx, GLuint n, 420 const GLint x[], const GLint y[], 421 GLdepth depth[] ); 422 /* Read an array of randomly positioned depth values from the depth buffer. 423 */ 424 425 426 427 /*** 428 *** For supporting hardware stencil buffers: 429 *** Either ALL or NONE of these functions must be implemented! 430 ***/ 431 432 void (*WriteStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 433 const GLstencil stencil[], const GLubyte mask[] ); 434 /* Write a horizontal span of stencil values into the stencil buffer. 435 * If mask is NULL, write all stencil values. 436 * Else, only write stencil[i] if mask[i] is non-zero. 437 */ 438 439 void (*ReadStencilSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, 440 GLstencil stencil[] ); 441 /* Read a horizontal span of stencil values from the stencil buffer. 442 */ 443 444 void (*WriteStencilPixels)( GLcontext *ctx, GLuint n, 445 const GLint x[], const GLint y[], 446 const GLstencil stencil[], 447 const GLubyte mask[] ); 448 /* Write an array of stencil values into the stencil buffer. 449 * If mask is NULL, write all stencil values. 450 * Else, only write stencil[i] if mask[i] is non-zero. 451 */ 452 453 void (*ReadStencilPixels)( GLcontext *ctx, GLuint n, 454 const GLint x[], const GLint y[], 455 GLstencil stencil[] ); 456 /* Read an array of stencil values from the stencil buffer. 457 */ 458}; 459 460 461 462#endif 463