| 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 |
* Authors: |
| 25 |
* Keith Whitwell <[email protected]> |
| 26 |
* Gareth Hughes |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "glheader.h" |
| 30 |
#include "api_loopback.h" |
| 31 |
#include "context.h" |
| 32 |
#include "imports.h" |
| 33 |
#include "mtypes.h" |
| 34 |
#include "state.h" |
| 35 |
#include "vtxfmt.h" |
| 36 |
|
| 37 |
|
| 38 |
/* The neutral vertex format. This wraps all tnl module functions, |
| 39 |
* verifying that the currently-installed module is valid and then |
| 40 |
* installing the function pointers in a lazy fashion. It records the |
| 41 |
* function pointers that have been swapped out, which allows a fast |
| 42 |
* restoration of the neutral module in almost all cases -- a typical |
| 43 |
* app might only require 4-6 functions to be modified from the neutral |
| 44 |
* baseline, and only restoring these is certainly preferable to doing |
| 45 |
* the entire module's 60 or so function pointers. |
| 46 |
*/ |
| 47 |
|
| 48 |
#define PRE_LOOPBACK( FUNC ) \ |
| 49 |
{ \ |
| 50 |
GET_CURRENT_CONTEXT(ctx); \ |
| 51 |
struct gl_tnl_module * const tnl = &(ctx->TnlModule); \ |
| 52 |
const int tmp_offset = _gloffset_ ## FUNC ; \ |
| 53 |
\ |
| 54 |
ASSERT( tnl->Current ); \ |
| 55 |
ASSERT( tnl->SwapCount < NUM_VERTEX_FORMAT_ENTRIES ); \ |
| 56 |
ASSERT( tmp_offset >= 0 ); \ |
| 57 |
\ |
| 58 |
/* Save the swapped function's dispatch entry so it can be */ \ |
| 59 |
/* restored later. */ \ |
| 60 |
tnl->Swapped[tnl->SwapCount].location = & (((_glapi_proc *)ctx->Exec)[tmp_offset]); \ |
| 61 |
tnl->Swapped[tnl->SwapCount].function = (_glapi_proc)TAG(FUNC); \ |
| 62 |
tnl->SwapCount++; \ |
| 63 |
\ |
| 64 |
if ( 0 ) \ |
| 65 |
_mesa_debug(ctx, " swapping gl" #FUNC"...\n" ); \ |
| 66 |
\ |
| 67 |
/* Install the tnl function pointer. */ \ |
| 68 |
SET_ ## FUNC(ctx->Exec, tnl->Current->FUNC); \ |
| 69 |
} |
| 70 |
|
| 71 |
#define TAG(x) neutral_##x |
| 72 |
#include "vtxfmt_tmp.h" |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
static void |
| 77 |
install_vtxfmt( struct _glapi_table *tab, const GLvertexformat *vfmt ) |
| 78 |
{ |
| 79 |
SET_ArrayElement(tab, vfmt->ArrayElement); |
| 80 |
SET_Color3f(tab, vfmt->Color3f); |
| 81 |
SET_Color3fv(tab, vfmt->Color3fv); |
| 82 |
SET_Color4f(tab, vfmt->Color4f); |
| 83 |
SET_Color4fv(tab, vfmt->Color4fv); |
| 84 |
SET_EdgeFlag(tab, vfmt->EdgeFlag); |
| 85 |
SET_EdgeFlagv(tab, vfmt->EdgeFlagv); |
| 86 |
SET_EvalCoord1f(tab, vfmt->EvalCoord1f); |
| 87 |
SET_EvalCoord1fv(tab, vfmt->EvalCoord1fv); |
| 88 |
SET_EvalCoord2f(tab, vfmt->EvalCoord2f); |
| 89 |
SET_EvalCoord2fv(tab, vfmt->EvalCoord2fv); |
| 90 |
SET_EvalPoint1(tab, vfmt->EvalPoint1); |
| 91 |
SET_EvalPoint2(tab, vfmt->EvalPoint2); |
| 92 |
SET_FogCoordfEXT(tab, vfmt->FogCoordfEXT); |
| 93 |
SET_FogCoordfvEXT(tab, vfmt->FogCoordfvEXT); |
| 94 |
SET_Indexf(tab, vfmt->Indexf); |
| 95 |
SET_Indexfv(tab, vfmt->Indexfv); |
| 96 |
SET_Materialfv(tab, vfmt->Materialfv); |
| 97 |
SET_MultiTexCoord1fARB(tab, vfmt->MultiTexCoord1fARB); |
| 98 |
SET_MultiTexCoord1fvARB(tab, vfmt->MultiTexCoord1fvARB); |
| 99 |
SET_MultiTexCoord2fARB(tab, vfmt->MultiTexCoord2fARB); |
| 100 |
SET_MultiTexCoord2fvARB(tab, vfmt->MultiTexCoord2fvARB); |
| 101 |
SET_MultiTexCoord3fARB(tab, vfmt->MultiTexCoord3fARB); |
| 102 |
SET_MultiTexCoord3fvARB(tab, vfmt->MultiTexCoord3fvARB); |
| 103 |
SET_MultiTexCoord4fARB(tab, vfmt->MultiTexCoord4fARB); |
| 104 |
SET_MultiTexCoord4fvARB(tab, vfmt->MultiTexCoord4fvARB); |
| 105 |
SET_Normal3f(tab, vfmt->Normal3f); |
| 106 |
SET_Normal3fv(tab, vfmt->Normal3fv); |
| 107 |
SET_SecondaryColor3fEXT(tab, vfmt->SecondaryColor3fEXT); |
| 108 |
SET_SecondaryColor3fvEXT(tab, vfmt->SecondaryColor3fvEXT); |
| 109 |
SET_TexCoord1f(tab, vfmt->TexCoord1f); |
| 110 |
SET_TexCoord1fv(tab, vfmt->TexCoord1fv); |
| 111 |
SET_TexCoord2f(tab, vfmt->TexCoord2f); |
| 112 |
SET_TexCoord2fv(tab, vfmt->TexCoord2fv); |
| 113 |
SET_TexCoord3f(tab, vfmt->TexCoord3f); |
| 114 |
SET_TexCoord3fv(tab, vfmt->TexCoord3fv); |
| 115 |
SET_TexCoord4f(tab, vfmt->TexCoord4f); |
| 116 |
SET_TexCoord4fv(tab, vfmt->TexCoord4fv); |
| 117 |
SET_Vertex2f(tab, vfmt->Vertex2f); |
| 118 |
SET_Vertex2fv(tab, vfmt->Vertex2fv); |
| 119 |
SET_Vertex3f(tab, vfmt->Vertex3f); |
| 120 |
SET_Vertex3fv(tab, vfmt->Vertex3fv); |
| 121 |
SET_Vertex4f(tab, vfmt->Vertex4f); |
| 122 |
SET_Vertex4fv(tab, vfmt->Vertex4fv); |
| 123 |
SET_CallList(tab, vfmt->CallList); |
| 124 |
SET_CallLists(tab, vfmt->CallLists); |
| 125 |
SET_Begin(tab, vfmt->Begin); |
| 126 |
SET_End(tab, vfmt->End); |
| 127 |
SET_VertexAttrib1fNV(tab, vfmt->VertexAttrib1fNV); |
| 128 |
SET_VertexAttrib1fvNV(tab, vfmt->VertexAttrib1fvNV); |
| 129 |
SET_VertexAttrib2fNV(tab, vfmt->VertexAttrib2fNV); |
| 130 |
SET_VertexAttrib2fvNV(tab, vfmt->VertexAttrib2fvNV); |
| 131 |
SET_VertexAttrib3fNV(tab, vfmt->VertexAttrib3fNV); |
| 132 |
SET_VertexAttrib3fvNV(tab, vfmt->VertexAttrib3fvNV); |
| 133 |
SET_VertexAttrib4fNV(tab, vfmt->VertexAttrib4fNV); |
| 134 |
SET_VertexAttrib4fvNV(tab, vfmt->VertexAttrib4fvNV); |
| 135 |
SET_VertexAttrib1fARB(tab, vfmt->VertexAttrib1fARB); |
| 136 |
SET_VertexAttrib1fvARB(tab, vfmt->VertexAttrib1fvARB); |
| 137 |
SET_VertexAttrib2fARB(tab, vfmt->VertexAttrib2fARB); |
| 138 |
SET_VertexAttrib2fvARB(tab, vfmt->VertexAttrib2fvARB); |
| 139 |
SET_VertexAttrib3fARB(tab, vfmt->VertexAttrib3fARB); |
| 140 |
SET_VertexAttrib3fvARB(tab, vfmt->VertexAttrib3fvARB); |
| 141 |
SET_VertexAttrib4fARB(tab, vfmt->VertexAttrib4fARB); |
| 142 |
SET_VertexAttrib4fvARB(tab, vfmt->VertexAttrib4fvARB); |
| 143 |
SET_Rectf(tab, vfmt->Rectf); |
| 144 |
SET_DrawArrays(tab, vfmt->DrawArrays); |
| 145 |
SET_DrawElements(tab, vfmt->DrawElements); |
| 146 |
SET_DrawRangeElements(tab, vfmt->DrawRangeElements); |
| 147 |
SET_EvalMesh1(tab, vfmt->EvalMesh1); |
| 148 |
SET_EvalMesh2(tab, vfmt->EvalMesh2); |
| 149 |
ASSERT(tab->EvalMesh2); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
void _mesa_init_exec_vtxfmt( GLcontext *ctx ) |
| 154 |
{ |
| 155 |
install_vtxfmt( ctx->Exec, &neutral_vtxfmt ); |
| 156 |
ctx->TnlModule.SwapCount = 0; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
void _mesa_install_exec_vtxfmt( GLcontext *ctx, const GLvertexformat *vfmt ) |
| 161 |
{ |
| 162 |
ctx->TnlModule.Current = vfmt; |
| 163 |
_mesa_restore_exec_vtxfmt( ctx ); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
void _mesa_install_save_vtxfmt( GLcontext *ctx, const GLvertexformat *vfmt ) |
| 168 |
{ |
| 169 |
install_vtxfmt( ctx->Save, vfmt ); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
void _mesa_restore_exec_vtxfmt( GLcontext *ctx ) |
| 174 |
{ |
| 175 |
struct gl_tnl_module *tnl = &(ctx->TnlModule); |
| 176 |
GLuint i; |
| 177 |
|
| 178 |
/* Restore the neutral tnl module wrapper. |
| 179 |
*/ |
| 180 |
for ( i = 0 ; i < tnl->SwapCount ; i++ ) { |
| 181 |
*(tnl->Swapped[i].location) = tnl->Swapped[i].function; |
| 182 |
} |
| 183 |
|
| 184 |
tnl->SwapCount = 0; |
| 185 |
} |