1 /* $Id: dd.h,v 1.3 1999/09/30 11:18:21 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
36 struct gl_pixelstore_attrib
;
41 struct gl_pipeline_stage
;
44 /* THIS FILE ONLY INCLUDED BY types.h !!!!! */
48 * Device Driver (DD) interface
51 * All device driver functions are accessed through pointers in the
52 * dd_function_table struct (defined below) which is stored in the GLcontext
53 * struct. Since the device driver is strictly accessed trough a table of
54 * function pointers we can:
55 * 1. switch between a number of different device drivers at runtime.
56 * 2. use optimized functions dependant on current rendering state or
57 * frame buffer configuration.
59 * The function pointers in the dd_function_table struct are divided into
60 * two groups: mandatory and optional.
61 * Mandatory functions have to be implemented by every device driver.
62 * Optional functions may or may not be implemented by the device driver.
63 * The optional functions provide ways to take advantage of special hardware
64 * or optimized algorithms.
66 * The function pointers in the dd_function_table struct are first
67 * initialized in the "MakeCurrent" function. The "MakeCurrent" function
68 * is a little different in each device driver. See the X/Mesa, GLX, or
69 * OS/Mesa drivers for examples.
71 * Later, Mesa may call the dd_function_table's UpdateState() function.
72 * This function should initialize the dd_function_table's pointers again.
73 * The UpdateState() function is called whenever the core (GL) rendering
74 * state is changed in a way which may effect rasterization. For example,
75 * the TriangleFunc() pointer may have to point to different functions
76 * depending on whether smooth or flat shading is enabled.
78 * Note that the first argument to every device driver function is a
79 * GLcontext *. In turn, the GLcontext->DriverCtx pointer points to
80 * the driver-specific context struct. See the X/Mesa or OS/Mesa interface
83 * For more information about writing a device driver see the ddsample.c
84 * file and other device drivers (xmesa[123].c, osmesa.c, etc) for examples.
87 * Look below in the dd_function_table struct definition for descriptions
88 * of each device driver function.
91 * In the future more function pointers may be added for glReadPixels
97 * RGBA = red/green/blue/alpha
98 * CI = color index (color mapped mode)
99 * mono = all pixels have the same color or index
101 * The write_ functions all take an array of mask flags which indicate
102 * whether or not the pixel should be written. One special case exists
103 * in the write_color_span function: if the mask array is NULL, then
104 * draw all pixels. This is an optimization used for glDrawPixels().
107 * X coordinates start at 0 at the left and increase to the right
108 * Y coordinates start at 0 at the bottom and increase upward
115 /* Used by the GetParameteri device driver function */
116 #define DD_HAVE_HARDWARE_FOG 3
123 * Device Driver function table.
125 struct dd_function_table
{
127 /**********************************************************************
128 *** Mandatory functions: these functions must be implemented by ***
129 *** every device driver. ***
130 **********************************************************************/
132 const char * (*RendererString
)(void);
134 * Return a string which uniquely identifies this device driver.
135 * The string should contain no whitespace. Examples: "X11" "OffScreen"
136 * "MSWindows" "SVGA".
137 * NOTE: This function will be obsolete in favor of GetString in the future!
140 void (*UpdateState
)( GLcontext
*ctx
);
142 * UpdateState() is called whenver Mesa thinks the device driver should
143 * update its state and/or the other pointers (such as PointsFunc,
144 * LineFunc, or TriangleFunc).
147 void (*ClearIndex
)( GLcontext
*ctx
, GLuint index
);
149 * Called whenever glClearIndex() is called. Set the index for clearing
153 void (*ClearColor
)( GLcontext
*ctx
, GLubyte red
, GLubyte green
,
154 GLubyte blue
, GLubyte alpha
);
156 * Called whenever glClearColor() is called. Set the color for clearing
160 GLbitfield (*Clear
)( GLcontext
*ctx
, GLbitfield mask
, GLboolean all
,
161 GLint x
, GLint y
, GLint width
, GLint height
);
162 /* Clear the color/depth/stencil/accum buffer(s).
163 * 'mask' indicates which buffers need to be cleared. Return a bitmask
164 * indicating which buffers weren't cleared by the driver function.
165 * If 'all' is true then the clear the whole buffer, else clear the
166 * region defined by (x,y,width,height).
169 void (*Index
)( GLcontext
*ctx
, GLuint index
);
171 * Sets current color index for drawing flat-shaded primitives.
174 void (*Color
)( GLcontext
*ctx
,
175 GLubyte red
, GLubyte green
, GLubyte glue
, GLubyte alpha
);
177 * Sets current color for drawing flat-shaded primitives.
180 GLboolean (*SetBuffer
)( GLcontext
*ctx
, GLenum buffer
);
182 * Selects the color buffer(s) for reading and writing.
183 * The following values must be accepted when applicable:
184 * GL_FRONT_LEFT - this buffer always exists
185 * GL_BACK_LEFT - when double buffering
186 * GL_FRONT_RIGHT - when using stereo
187 * GL_BACK_RIGHT - when using stereo and double buffering
188 * The folowing values may optionally be accepted. Return GL_TRUE
189 * if accepted, GL_FALSE if not accepted. In practice, only drivers
190 * which can write to multiple color buffers at once should accept
192 * GL_FRONT - write to front left and front right if it exists
193 * GL_BACK - write to back left and back right if it exists
194 * GL_LEFT - write to front left and back left if it exists
195 * GL_RIGHT - write to right left and back right if they exist
196 * GL_FRONT_AND_BACK - write to all four buffers if they exist
197 * GL_NONE - disable buffer write in device driver.
200 void (*GetBufferSize
)( GLcontext
*ctx
,
201 GLuint
*width
, GLuint
*height
);
203 * Returns the width and height of the current color buffer.
208 *** Functions for writing pixels to the frame buffer:
211 void (*WriteRGBASpan
)( const GLcontext
*ctx
,
212 GLuint n
, GLint x
, GLint y
,
213 CONST GLubyte rgba
[][4], const GLubyte mask
[] );
214 void (*WriteRGBSpan
)( const GLcontext
*ctx
,
215 GLuint n
, GLint x
, GLint y
,
216 CONST GLubyte rgb
[][3], const GLubyte mask
[] );
217 /* Write a horizontal run of RGB[A] pixels. The later version is only
218 * used to accelerate GL_RGB, GL_UNSIGNED_BYTE glDrawPixels() calls.
221 void (*WriteMonoRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
222 const GLubyte mask
[] );
223 /* Write a horizontal run of mono-RGBA pixels.
226 void (*WriteRGBAPixels
)( const GLcontext
*ctx
,
227 GLuint n
, const GLint x
[], const GLint y
[],
228 CONST GLubyte rgba
[][4], const GLubyte mask
[] );
229 /* Write array of RGBA pixels at random locations.
232 void (*WriteMonoRGBAPixels
)( const GLcontext
*ctx
,
233 GLuint n
, const GLint x
[], const GLint y
[],
234 const GLubyte mask
[] );
235 /* Write an array of mono-RGBA pixels at random locations.
238 void (*WriteCI32Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
239 const GLuint index
[], const GLubyte mask
[] );
240 void (*WriteCI8Span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
241 const GLubyte index
[], const GLubyte mask
[] );
242 /* Write a horizontal run of CI pixels. 32 or 8bpp.
245 void (*WriteMonoCISpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
246 const GLubyte mask
[] );
247 /* Write a horizontal run of mono-CI pixels.
250 void (*WriteCI32Pixels
)( const GLcontext
*ctx
,
251 GLuint n
, const GLint x
[], const GLint y
[],
252 const GLuint index
[], const GLubyte mask
[] );
254 * Write a random array of CI pixels.
257 void (*WriteMonoCIPixels
)( const GLcontext
*ctx
,
258 GLuint n
, const GLint x
[], const GLint y
[],
259 const GLubyte mask
[] );
261 * Write a random array of mono-CI pixels.
266 *** Functions to read pixels from frame buffer:
269 void (*ReadCI32Span
)( const GLcontext
*ctx
,
270 GLuint n
, GLint x
, GLint y
, GLuint index
[] );
271 /* Read a horizontal run of color index pixels.
274 void (*ReadRGBASpan
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
276 /* Read a horizontal run of RGBA pixels.
279 void (*ReadCI32Pixels
)( const GLcontext
*ctx
,
280 GLuint n
, const GLint x
[], const GLint y
[],
281 GLuint indx
[], const GLubyte mask
[] );
282 /* Read a random array of CI pixels.
285 void (*ReadRGBAPixels
)( const GLcontext
*ctx
,
286 GLuint n
, const GLint x
[], const GLint y
[],
287 GLubyte rgba
[][4], const GLubyte mask
[] );
288 /* Read a random array of RGBA pixels.
292 /**********************************************************************
293 *** Optional functions: these functions may or may not be ***
294 *** implemented by the device driver. If the device driver ***
295 *** doesn't implement them it should never touch these pointers ***
296 *** since Mesa will either set them to NULL or point them at a ***
297 *** fall-back function. ***
298 **********************************************************************/
300 const char * (*ExtensionString
)( GLcontext
*ctx
);
301 /* Return a space-separated list of extensions for this driver.
302 * NOTE: This function will be obsolete in favor of GetString in the future!
305 const GLubyte
* (*GetString
)( GLcontext
*ctx
, GLenum name
);
306 /* Return a string as needed by glGetString().
307 * NOTE: This will replace the ExtensionString and RendererString
308 * functions in the future!
311 void (*Finish
)( GLcontext
*ctx
);
313 * Called whenever glFinish() is called.
316 void (*Flush
)( GLcontext
*ctx
);
318 * Called whenever glFlush() is called.
321 GLboolean (*IndexMask
)( GLcontext
*ctx
, GLuint mask
);
323 * Implements glIndexMask() if possible, else return GL_FALSE.
326 GLboolean (*ColorMask
)( GLcontext
*ctx
,
327 GLboolean rmask
, GLboolean gmask
,
328 GLboolean bmask
, GLboolean amask
);
330 * Implements glColorMask() if possible, else return GL_FALSE.
333 GLboolean (*LogicOp
)( GLcontext
*ctx
, GLenum op
);
335 * Implements glLogicOp() if possible, else return GL_FALSE.
338 void (*Dither
)( GLcontext
*ctx
, GLboolean enable
);
340 * Enable/disable dithering.
341 * NOTE: This function will be removed in the future in favor
342 * of the "Enable" driver function.
345 void (*Error
)( GLcontext
*ctx
);
347 * Called whenever an error is generated. ctx->ErrorValue contains
351 void (*NearFar
)( GLcontext
*ctx
, GLfloat nearVal
, GLfloat farVal
);
353 * Called from glFrustum and glOrtho to tell device driver the
354 * near and far clipping plane Z values. The 3Dfx driver, for example,
358 GLint (*GetParameteri
)( const GLcontext
*ctx
, GLint param
);
359 /* Query the device driver to get an integer parameter.
360 * Current parameters:
361 * DD_MAX_TEXTURE_SIZE return maximum texture size
363 * DD_MAX_TEXTURES number of texture sets/stages, usually 1
365 * DD_HAVE_HARDWARE_FOG the driver should return 1 (0 otherwise)
366 * when the hardware support per fragment
367 * fog for free (like the Voodoo Graphics)
368 * so the Mesa core will start to ever use
374 *** For supporting hardware Z buffers:
377 void (*AllocDepthBuffer
)( GLcontext
*ctx
);
379 * Called when the depth buffer must be allocated or possibly resized.
382 GLuint (*DepthTestSpan
)( GLcontext
*ctx
,
383 GLuint n
, GLint x
, GLint y
, const GLdepth z
[],
385 void (*DepthTestPixels
)( GLcontext
*ctx
,
386 GLuint n
, const GLint x
[], const GLint y
[],
387 const GLdepth z
[], GLubyte mask
[] );
389 * Apply the depth buffer test to an span/array of pixels and return
390 * an updated pixel mask. This function is not used when accelerated
391 * point, line, polygon functions are used.
394 void (*ReadDepthSpanFloat
)( GLcontext
*ctx
,
395 GLuint n
, GLint x
, GLint y
, GLfloat depth
[]);
396 void (*ReadDepthSpanInt
)( GLcontext
*ctx
,
397 GLuint n
, GLint x
, GLint y
, GLdepth depth
[] );
399 * Return depth values as integers for glReadPixels.
400 * Floats should be returned in the range [0,1].
401 * Ints (GLdepth) values should be in the range [0,MAXDEPTH].
406 *** Accelerated point, line, polygon, glDrawPixels and glBitmap functions:
409 points_func PointsFunc
;
411 triangle_func TriangleFunc
;
416 GLboolean (*DrawPixels
)( GLcontext
*ctx
,
417 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
418 GLenum format
, GLenum type
,
419 const struct gl_pixelstore_attrib
*unpack
,
420 const GLvoid
*pixels
);
421 /* Device driver hook for optimized glDrawPixels. 'unpack' describes how
422 * to unpack the source image data.
425 GLboolean (*Bitmap
)( GLcontext
*ctx
,
426 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
427 const struct gl_pixelstore_attrib
*unpack
,
428 const GLubyte
*bitmap
);
429 /* Device driver hook for optimized glBitmap. 'unpack' describes how
430 * to unpack the source image data.
433 void (*RenderStart
)( GLcontext
*ctx
);
434 void (*RenderFinish
)( GLcontext
*ctx
);
435 /* KW: These replace Begin and End, and have more relaxed semantics.
436 * They are called prior-to and after one or more vb flush, and are
437 * thus decoupled from the gl_begin/gl_end pairs, which are possibly
438 * more frequent. If a begin/end pair covers >1 vertex buffer, these
439 * are called at most once for the pair. (a bit broken at present)
442 void (*RasterSetup
)( struct vertex_buffer
*VB
, GLuint start
, GLuint end
);
443 /* This function, if not NULL, is called whenever new window coordinates
444 * are put in the vertex buffer. The vertices in question are those n
445 * such that start <= n < end.
446 * The device driver can convert the window coords to its own specialized
447 * format. The 3Dfx driver uses this.
449 * Note: Deprecated in favour of RegisterPipelineStages, below.
453 render_func
*RenderVBClippedTab
;
454 render_func
*RenderVBCulledTab
;
455 render_func
*RenderVBRawTab
;
456 /* These function tables allow the device driver to rasterize an
457 * entire begin/end group of primitives at once. See the
458 * gl_render_vb() function in vbrender.c for more details.
462 void (*ReducedPrimitiveChange
)( GLcontext
*ctx
, GLenum primitive
);
463 /* If registered, this will be called when rendering transitions between
464 * points, lines and triangles. It is not called on transitions between
465 * primtives such as GL_TRIANGLES and GL_TRIANGLE_STRIPS, or between
466 * triangles and quads or triangles and polygons.
470 /* Holds a list of the reasons why we might normally want to call
471 * render_triangle, but which are in fact implemented by the
472 * driver. The FX driver sets this to DD_TRI_CULL, and will soon
473 * implement DD_TRI_OFFSET.
477 GLboolean (*MultipassFunc
)( struct vertex_buffer
*VB
, GLuint passno
);
478 /* Driver may request additional render passes by returning GL_TRUE
479 * when this function is called. This function will be called
480 * after the first pass, and passes will be made until the function
481 * returns GL_FALSE. If no function is registered, only one pass
484 * This function will be first invoked with passno == 1.
488 *** Texture mapping functions:
491 void (*TexEnv
)( GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
);
493 * Called whenever glTexEnv*() is called.
494 * Pname will be one of GL_TEXTURE_ENV_MODE or GL_TEXTURE_ENV_COLOR.
495 * If pname is GL_TEXTURE_ENV_MODE then param will be one
496 * of GL_MODULATE, GL_BLEND, GL_DECAL, or GL_REPLACE.
499 void (*TexImage
)( GLcontext
*ctx
, GLenum target
,
500 struct gl_texture_object
*tObj
, GLint level
,
501 GLint internalFormat
,
502 const struct gl_texture_image
*image
);
504 * Called whenever a texture object's image is changed.
505 * texObject is the number of the texture object being changed.
506 * level indicates the mipmap level.
507 * internalFormat is the format in which the texture is to be stored.
508 * image is a pointer to a gl_texture_image struct which contains
509 * the actual image data.
512 void (*TexSubImage
)( GLcontext
*ctx
, GLenum target
,
513 struct gl_texture_object
*tObj
, GLint level
,
514 GLint xoffset
, GLint yoffset
,
515 GLsizei width
, GLsizei height
,
516 GLint internalFormat
,
517 const struct gl_texture_image
*image
);
519 * Called from glTexSubImage() to define a sub-region of a texture.
522 void (*TexParameter
)( GLcontext
*ctx
, GLenum target
,
523 struct gl_texture_object
*tObj
,
524 GLenum pname
, const GLfloat
*params
);
526 * Called whenever glTexParameter*() is called.
527 * target is GL_TEXTURE_1D or GL_TEXTURE_2D
528 * texObject is the texture object to modify
529 * pname is one of GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER,
530 * GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, or GL_TEXTURE_BORDER_COLOR.
531 * params is dependant on pname. See man glTexParameter.
534 void (*BindTexture
)( GLcontext
*ctx
, GLenum target
,
535 struct gl_texture_object
*tObj
);
537 * Called whenever glBindTexture() is called. This specifies which
538 * texture is to be the current one. No dirty flags will be set.
541 void (*DeleteTexture
)( GLcontext
*ctx
, struct gl_texture_object
*tObj
);
543 * Called when a texture object is about to be deallocated. Driver
544 * should free anything attached to the DriverData pointers.
547 void (*UpdateTexturePalette
)( GLcontext
*ctx
,
548 struct gl_texture_object
*tObj
);
550 * Called when the texture's color lookup table is changed.
551 * If tObj is NULL then the shared texture palette ctx->Texture.Palette
555 void (*UseGlobalTexturePalette
)( GLcontext
*ctx
, GLboolean state
);
557 * Called via glEnable/Disable(GL_SHARED_TEXTURE_PALETTE_EXT)
560 void (*ActiveTexture
)( GLcontext
*ctx
, GLuint texUnitNumber
);
562 * Called by glActiveTextureARB to set current texture unit.
566 GLboolean (*IsTextureResident
)( GLcontext
*ctx
,
567 struct gl_texture_object
*t
);
569 * Allows the driver to implement the AreTexturesResident tests without
570 * knowing about Mesa's internal hash tables for textures.
573 void (*PrioritizeTexture
)( GLcontext
*ctx
,
574 struct gl_texture_object
*t
,
577 * Notify driver of priority change for a texture.
587 void (*RegisterVB
)( struct vertex_buffer
*VB
);
588 void (*UnregisterVB
)( struct vertex_buffer
*VB
);
589 /* Do any processing (eg allocate memory) required to set up a new
594 void (*ResetVB
)( struct vertex_buffer
*VB
);
595 void (*ResetCvaVB
)( struct vertex_buffer
*VB
, GLuint stages
);
596 /* Do any reset operations necessary to the driver data associated
597 * with these vertex buffers.
600 GLuint RenderVectorFlags
;
601 /* What do the render tables require of the vectors they deal
605 GLuint (*RegisterPipelineStages
)( struct gl_pipeline_stage
*out
,
606 const struct gl_pipeline_stage
*in
,
608 /* Register new pipeline stages, or modify existing ones. See also
609 * the OptimizePipeline() functions.
613 GLboolean (*BuildPrecalcPipeline
)( GLcontext
*ctx
);
614 GLboolean (*BuildEltPipeline
)( GLcontext
*ctx
);
615 /* Perform the full pipeline build, or return false.
619 void (*OptimizePrecalcPipeline
)( GLcontext
*ctx
, struct gl_pipeline
*pipe
);
620 void (*OptimizeImmediatePipeline
)( GLcontext
*ctx
, struct gl_pipeline
*pipe
);
621 /* Check to see if a fast path exists for this combination of stages
622 * in the precalc and immediate (elt) pipelines.
627 * State-changing functions (drawing functions are above)
629 * These functions are called by their corresponding OpenGL API functions.
630 * They're ALSO called by the gl_PopAttrib() function!!!
631 * May add more functions like these to the device driver in the future.
632 * This should reduce the amount of state checking that
633 * the driver's UpdateState() function must do.
635 void (*AlphaFunc
)(GLcontext
*ctx
, GLenum func
, GLclampf ref
);
636 void (*BlendEquation
)(GLcontext
*ctx
, GLenum mode
);
637 void (*BlendFunc
)(GLcontext
*ctx
, GLenum sfactor
, GLenum dfactor
);
638 void (*BlendFuncSeparate
)( GLcontext
*ctx
, GLenum sfactorRGB
,
639 GLenum dfactorRGB
, GLenum sfactorA
,
641 void (*ClearDepth
)(GLcontext
*ctx
, GLclampd d
);
642 void (*CullFace
)(GLcontext
*ctx
, GLenum mode
);
643 void (*FrontFace
)(GLcontext
*ctx
, GLenum mode
);
644 void (*DepthFunc
)(GLcontext
*ctx
, GLenum func
);
645 void (*DepthMask
)(GLcontext
*ctx
, GLboolean flag
);
646 void (*DepthRange
)(GLcontext
*ctx
, GLclampd nearval
, GLclampd farval
);
647 void (*Enable
)(GLcontext
* ctx
, GLenum cap
, GLboolean state
);
648 void (*Fogfv
)(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
);
649 void (*Hint
)(GLcontext
*ctx
, GLenum target
, GLenum mode
);
650 void (*Lightfv
)(GLcontext
*ctx
, GLenum light
,
651 GLenum pname
, const GLfloat
*params
, GLint nparams
);
652 void (*LightModelfv
)(GLcontext
*ctx
, GLenum pname
, const GLfloat
*params
);
653 void (*PolygonMode
)(GLcontext
*ctx
, GLenum face
, GLenum mode
);
654 void (*Scissor
)(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
);
655 void (*ShadeModel
)(GLcontext
*ctx
, GLenum mode
);
656 void (*ClearStencil
)(GLcontext
*ctx
, GLint s
);
657 void (*StencilFunc
)(GLcontext
*ctx
, GLenum func
, GLint ref
, GLuint mask
);
658 void (*StencilMask
)(GLcontext
*ctx
, GLuint mask
);
659 void (*StencilOp
)(GLcontext
*ctx
, GLenum fail
, GLenum zfail
, GLenum zpass
);
660 void (*Viewport
)(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
);