-/* $Id: dd.h,v 1.56 2001/03/07 00:21:32 brianp Exp $ */
+/* $Id: dd.h,v 1.57 2001/03/11 18:49:11 gareth Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.5
- *
+ *
* Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
*
* Look below in the dd_function_table struct definition for descriptions
* of each device driver function.
- *
+ *
* More function pointers may be added as required.
*
*
typedef void (*quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
GLuint v3, GLuint v4 );
-typedef void (*render_func)( GLcontext *ctx, GLuint start, GLuint count,
+typedef void (*render_func)( GLcontext *ctx, GLuint start, GLuint count,
GLuint flags );
typedef void (*interp_func)( GLcontext *ctx,
GLint x, GLint y, GLint width, GLint height );
/* Clear the color/depth/stencil/accum buffer(s).
* 'mask' is a bitmask of the DD_*_BIT values defined above that indicates
- * which buffers need to be cleared.
+ * which buffers need to be cleared.
* If 'all' is true then the clear the whole buffer, else clear only the
* region defined by (x,y,width,height).
* This function must obey the glColorMask, glIndexMask and glStencilMask
GLstencil stencil[] );
/* Read an array of stencil values from the stencil buffer.
*/
-
+
/***
*** For hardware accumulation buffer:
* width, height, border and internalFormat information.
* The driver should use a fallback routine from texstore.c if needed.
*/
-
+
void (*CopyTexImage1D)( GLcontext *ctx, GLenum target, GLint level,
GLenum internalFormat, GLint x, GLint y,
GLsizei width, GLint border );
* should free anything attached to the DriverData pointers.
*/
- GLboolean (*IsTextureResident)( GLcontext *ctx,
+ GLboolean (*IsTextureResident)( GLcontext *ctx,
struct gl_texture_object *t );
/* Called by glAreTextureResident().
*/
void (*StencilFunc)(GLcontext *ctx, GLenum func, GLint ref, GLuint mask);
void (*StencilMask)(GLcontext *ctx, GLuint mask);
void (*StencilOp)(GLcontext *ctx, GLenum fail, GLenum zfail, GLenum zpass);
- void (*TexGen)(GLcontext *ctx, GLenum coord, GLenum pname,
+ void (*TexGen)(GLcontext *ctx, GLenum coord, GLenum pname,
const GLfloat *params);
void (*TexEnv)(GLcontext *ctx, GLenum target, GLenum pname,
const GLfloat *param);
***
*** Called by the corresponding OpenGL functions.
***/
- void (*VertexPointer)(GLcontext *ctx, GLint size, GLenum type,
+ void (*VertexPointer)(GLcontext *ctx, GLint size, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*NormalPointer)(GLcontext *ctx, GLenum type,
+ void (*NormalPointer)(GLcontext *ctx, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*ColorPointer)(GLcontext *ctx, GLint size, GLenum type,
+ void (*ColorPointer)(GLcontext *ctx, GLint size, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*FogCoordPointer)(GLcontext *ctx, GLenum type,
+ void (*FogCoordPointer)(GLcontext *ctx, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*IndexPointer)(GLcontext *ctx, GLenum type,
+ void (*IndexPointer)(GLcontext *ctx, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*SecondaryColorPointer)(GLcontext *ctx, GLint size, GLenum type,
+ void (*SecondaryColorPointer)(GLcontext *ctx, GLint size, GLenum type,
GLsizei stride, const GLvoid *ptr);
- void (*TexCoordPointer)(GLcontext *ctx, GLint size, GLenum type,
+ void (*TexCoordPointer)(GLcontext *ctx, GLint size, GLenum type,
GLsizei stride, const GLvoid *ptr);
void (*EdgeFlagPointer)(GLcontext *ctx, GLsizei stride, const GLvoid *ptr);
void (*ResetLineStipple)( GLcontext *ctx );
/* Reset the hardware's line stipple counter.
*/
-
- void (*BuildProjectedVertices)( GLcontext *ctx,
+
+ void (*BuildProjectedVertices)( GLcontext *ctx,
GLuint start, GLuint end,
GLuint new_inputs);
/* This function is called whenever new vertices are required for
* the vertex which need to be updated, if only a partial repair of
* the vertex is required.
*
- * This function is called only from _tnl_render_stage in tnl/t_render.c.
+ * This function is called only from _tnl_render_stage in tnl/t_render.c.
*/
* when this function is called. This function will be called
* after the first pass, and passes will be made until the function
* returns GL_FALSE. If no function is registered, only one pass
- * is made.
- *
+ * is made.
+ *
* This function will be first invoked with passno == 1.
*/
/***
*** Support for multiple t&l engines
***/
+
+ GLuint NeedValidate;
+ /* Bitmask of state changes that require the current tnl module to be
+ * validated, using ValidateTnlModule() below.
+ */
+
+ void (*ValidateTnlModule)( GLcontext *ctx, GLuint new_state );
+ /* Validate the current tnl module. This is called directly after
+ * UpdateState() when a state change that has occured matches the
+ * NeedValidate bitmask above. This ensures all computed values are
+ * up to date, thus allowing the driver to decide if the current tnl
+ * module needs to be swapped out.
+ *
+ * This must be non-NULL if a driver installs a custom tnl module and
+ * sets the NeedValidate bitmask, but may be NULL otherwise.
+ */
+
+
#define PRIM_OUTSIDE_BEGIN_END GL_POLYGON+1
#define PRIM_INSIDE_UNKNOWN_PRIM GL_POLYGON+2
#define PRIM_UNKNOWN GL_POLYGON+3
-
+
GLuint CurrentExecPrimitive;
/* Set by the driver-supplied t&l engine. Set to
- * PRIM_OUTSIDE_BEGIN_END when outside begin/end.
+ * PRIM_OUTSIDE_BEGIN_END when outside begin/end.
*/
GLuint CurrentSavePrimitive;
* the additional values defined above.
*/
-
#define FLUSH_STORED_VERTICES 0x1
#define FLUSH_UPDATE_CURRENT 0x2
/* Set by the driver-supplied t&l engine whenever vertices are
* buffered between begin/end objects or ctx->Current is not uptodate.
*
- * The FlushVertices() call below may be used to resolve
- * these conditions.
+ * The FlushVertices() call below may be used to resolve
+ * these conditions.
*/
void (*FlushVertices)( GLcontext *ctx, GLuint flags );
- /* If inside begin/end, ASSERT(0).
- * Otherwise,
+ /* If inside begin/end, ASSERT(0).
+ * Otherwise,
* if (flags & FLUSH_STORED_VERTICES) flushes any buffered vertices,
- * if (flags & FLUSH_UPDATE_CURRENT) updates ctx->Current
+ * if (flags & FLUSH_UPDATE_CURRENT) updates ctx->Current
* and ctx->Light.Material
*
* Note that the default t&l engine never clears the
void (*LightingSpaceChange)( GLcontext *ctx );
/* Notify driver that the special derived value _NeedEyeCoords has
- * changed.
+ * changed.
*/
void (*NewList)( GLcontext *ctx, GLuint list, GLenum mode );
* Called by glCallList(s), but not recursively.
*/
- void (*MakeCurrent)( GLcontext *ctx, GLframebuffer *drawBuffer,
+ void (*MakeCurrent)( GLcontext *ctx, GLframebuffer *drawBuffer,
GLframebuffer *readBuffer );
/* Let the t&l component know when the context becomes current.
*/
void (*FogCoordfvEXT)( const GLfloat * );
void (*Indexi)( GLint );
void (*Indexiv)( const GLint * );
- void (*Materialfv)( GLenum face, GLenum pname, const GLfloat * ); /* NOTE */
+ void (*Materialfv)( GLenum face, GLenum pname, const GLfloat * ); /* NOTE */
void (*MultiTexCoord1fARB)( GLenum, GLfloat );
void (*MultiTexCoord1fvARB)( GLenum, const GLfloat * );
void (*MultiTexCoord2fARB)( GLenum, GLfloat, GLfloat );
void (*End)( void );
/* Drivers present a reduced set of the functions possible in
* begin/end objects. Core mesa provides translation stubs for the
- * remaining functions to map down to these entrypoints.
+ * remaining functions to map down to these entrypoints.
*
* These are the initial values to be installed into dispatch by
* mesa. If the t&l driver wants to modify the dispatch table
*
* If the driver wants to hook in entrypoints other than those
* listed above, it must restore them to their original values in
- * the disable() callback, below.
+ * the disable() callback, below.
*/
void (*Rectf)( GLfloat, GLfloat, GLfloat, GLfloat );
- /*
+ /*
*/
-
void (*DrawArrays)( GLenum mode, GLint start, GLsizei count );
- void (*DrawElements)( GLenum mode, GLsizei count, GLenum type,
+ void (*DrawElements)( GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices );
- void (*DrawRangeElements)(GLenum mode, GLuint start,
- GLuint end, GLsizei count,
- GLenum type, const GLvoid *indices);
+ void (*DrawRangeElements)( GLenum mode, GLuint start,
+ GLuint end, GLsizei count,
+ GLenum type, const GLvoid *indices );
/* These may or may not belong here. Heuristic: If an array is
* enabled, the installed vertex format should support that array and
* it's current size natively.
* provide partial t&l acceleration.
*
* Mesa will provide a set of helper functions to do eval within
- * accelerated vertex formats, eventually...
+ * accelerated vertex formats, eventually...
*/
GLboolean prefer_float_colors;
/* Should core try to send colors to glColor4f or glColor4chan,
- * where it has a choice?
+ * where it has a choice?
*/
-
-
} GLvertexformat;
-#endif
-
+#endif /* DD_INCLUDED */
+/* $Id: vtxfmt.c,v 1.2 2001/03/11 18:49:11 gareth Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.5
+ *
+ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Author:
+ * Keith Whitwell <keithw@valinux.com>
+ * Gareth Hughes <gareth@valinux.com>
+ */
+
#include "glheader.h"
#include "api_loopback.h"
+#include "context.h"
#include "mtypes.h"
#include "vtxfmt.h"
+/* The neutral vertex format. This wraps all tnl module functions,
+ * verifying that the currently-installed module is valid and then
+ * installing the function pointers in a lazy fashion. It records the
+ * function pointers that have been swapped out, which allows a fast
+ * restoration of the neutral module in almost all cases -- a typical
+ * app might only require 4-6 functions to be modified from the neutral
+ * baseline, and only restoring these is certainly preferable to doing
+ * the entire module's 60 or so function pointers.
+ */
+
+#define PRE_LOOPBACK( FUNC ) \
+{ \
+ GET_CURRENT_CONTEXT(ctx); \
+ struct gl_tnl_module *tnl = &(ctx->TnlModule); \
+ const GLuint new_state = ctx->NewState; \
+ \
+ if ( new_state ) \
+ _mesa_update_state( ctx ); \
+ \
+ /* Validate the current tnl module. \
+ */ \
+ if ( new_state & ctx->Driver.NeedValidate ) \
+ ctx->Driver.ValidateTnlModule( ctx, new_state ); \
+ \
+ ASSERT( tnl->Current ); \
+ ASSERT( tnl->SwapCount < NUM_VERTEX_FORMAT_ENTRIES ); \
+ \
+ /* Save the swapped function's dispatch entry so it can be \
+ * restored later. \
+ */ \
+ tnl->Swapped[tnl->SwapCount][0] = (void *)&(ctx->Exec->FUNC); \
+ tnl->Swapped[tnl->SwapCount][1] = (void *)TAG(FUNC); \
+ tnl->SwapCount++; \
+ \
+ if ( 0 ) \
+ fprintf( stderr, " swapping gl" #FUNC"...\n" ); \
+ \
+ /* Install the tnl function pointer. \
+ */ \
+ ctx->Exec->FUNC = tnl->Current->FUNC; \
+}
+
+#define TAG(x) neutral_##x
+#include "vtxfmt_tmp.h"
+
+
static void install_vtxfmt( struct _glapi_table *tab, GLvertexformat *vfmt )
{
tab->Vertex4fv = vfmt->Vertex4fv;
tab->Begin = vfmt->Begin;
tab->End = vfmt->End;
-
+
/* tab->NewList = vfmt->NewList; */
tab->CallList = vfmt->CallList;
void _mesa_install_exec_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt )
{
- install_vtxfmt( ctx->Exec, vfmt );
+ ctx->TnlModule.Current = vfmt;
+ install_vtxfmt( ctx->Exec, &neutral_vtxfmt );
if (ctx->ExecPrefersFloat != vfmt->prefer_float_colors)
_mesa_loopback_prefer_float( ctx->Exec, vfmt->prefer_float_colors );
}
-
void _mesa_install_save_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt )
{
install_vtxfmt( ctx->Save, vfmt );
_mesa_loopback_prefer_float( ctx->Save, vfmt->prefer_float_colors );
}
+void _mesa_restore_exec_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt )
+{
+ struct gl_tnl_module *tnl = &(ctx->TnlModule);
+ GLuint i;
+
+ tnl->Current = vfmt;
+
+ /* Restore the neutral tnl module wrapper.
+ */
+ for ( i = 0 ; i < tnl->SwapCount ; i++ ) {
+ *(void **)tnl->Swapped[i][0] = tnl->Swapped[i][1];
+ }
+
+ tnl->SwapCount = 0;
+}