2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 * Keith Whitwell <keith@tungstengraphics.com>
30 #include "api_loopback.h"
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.
48 #define PRE_LOOPBACK( FUNC ) \
50 GET_CURRENT_CONTEXT(ctx); \
51 struct gl_tnl_module *tnl = &(ctx->TnlModule); \
52 typedef void (*func_ptr_t)(void); \
54 ASSERT( tnl->Current ); \
55 ASSERT( tnl->SwapCount < NUM_VERTEX_FORMAT_ENTRIES ); \
57 /* Save the swapped function's dispatch entry so it can be */ \
58 /* restored later. */ \
59 tnl->Swapped[tnl->SwapCount][0] = (void *)&(ctx->Exec->FUNC); \
60 *(func_ptr_t *)(tnl->Swapped[tnl->SwapCount]+1) = (func_ptr_t)TAG(FUNC); \
64 _mesa_debug(ctx, " swapping gl" #FUNC"...\n" ); \
66 /* Install the tnl function pointer. */ \
67 ctx->Exec->FUNC = tnl->Current->FUNC; \
70 #define TAG(x) neutral_##x
71 #include "vtxfmt_tmp.h"
76 install_vtxfmt( struct _glapi_table
*tab
, const GLvertexformat
*vfmt
)
78 tab
->ArrayElement
= vfmt
->ArrayElement
;
79 tab
->Color3f
= vfmt
->Color3f
;
80 tab
->Color3fv
= vfmt
->Color3fv
;
81 tab
->Color4f
= vfmt
->Color4f
;
82 tab
->Color4fv
= vfmt
->Color4fv
;
83 tab
->EdgeFlag
= vfmt
->EdgeFlag
;
84 tab
->EdgeFlagv
= vfmt
->EdgeFlagv
;
85 tab
->EvalCoord1f
= vfmt
->EvalCoord1f
;
86 tab
->EvalCoord1fv
= vfmt
->EvalCoord1fv
;
87 tab
->EvalCoord2f
= vfmt
->EvalCoord2f
;
88 tab
->EvalCoord2fv
= vfmt
->EvalCoord2fv
;
89 tab
->EvalPoint1
= vfmt
->EvalPoint1
;
90 tab
->EvalPoint2
= vfmt
->EvalPoint2
;
91 tab
->FogCoordfEXT
= vfmt
->FogCoordfEXT
;
92 tab
->FogCoordfvEXT
= vfmt
->FogCoordfvEXT
;
93 tab
->Indexf
= vfmt
->Indexf
;
94 tab
->Indexfv
= vfmt
->Indexfv
;
95 tab
->Materialfv
= vfmt
->Materialfv
;
96 tab
->MultiTexCoord1fARB
= vfmt
->MultiTexCoord1fARB
;
97 tab
->MultiTexCoord1fvARB
= vfmt
->MultiTexCoord1fvARB
;
98 tab
->MultiTexCoord2fARB
= vfmt
->MultiTexCoord2fARB
;
99 tab
->MultiTexCoord2fvARB
= vfmt
->MultiTexCoord2fvARB
;
100 tab
->MultiTexCoord3fARB
= vfmt
->MultiTexCoord3fARB
;
101 tab
->MultiTexCoord3fvARB
= vfmt
->MultiTexCoord3fvARB
;
102 tab
->MultiTexCoord4fARB
= vfmt
->MultiTexCoord4fARB
;
103 tab
->MultiTexCoord4fvARB
= vfmt
->MultiTexCoord4fvARB
;
104 tab
->Normal3f
= vfmt
->Normal3f
;
105 tab
->Normal3fv
= vfmt
->Normal3fv
;
106 tab
->SecondaryColor3fEXT
= vfmt
->SecondaryColor3fEXT
;
107 tab
->SecondaryColor3fvEXT
= vfmt
->SecondaryColor3fvEXT
;
108 tab
->TexCoord1f
= vfmt
->TexCoord1f
;
109 tab
->TexCoord1fv
= vfmt
->TexCoord1fv
;
110 tab
->TexCoord2f
= vfmt
->TexCoord2f
;
111 tab
->TexCoord2fv
= vfmt
->TexCoord2fv
;
112 tab
->TexCoord3f
= vfmt
->TexCoord3f
;
113 tab
->TexCoord3fv
= vfmt
->TexCoord3fv
;
114 tab
->TexCoord4f
= vfmt
->TexCoord4f
;
115 tab
->TexCoord4fv
= vfmt
->TexCoord4fv
;
116 tab
->Vertex2f
= vfmt
->Vertex2f
;
117 tab
->Vertex2fv
= vfmt
->Vertex2fv
;
118 tab
->Vertex3f
= vfmt
->Vertex3f
;
119 tab
->Vertex3fv
= vfmt
->Vertex3fv
;
120 tab
->Vertex4f
= vfmt
->Vertex4f
;
121 tab
->Vertex4fv
= vfmt
->Vertex4fv
;
122 tab
->CallList
= vfmt
->CallList
;
123 tab
->CallLists
= vfmt
->CallLists
;
124 tab
->Begin
= vfmt
->Begin
;
125 tab
->End
= vfmt
->End
;
126 tab
->VertexAttrib1fNV
= vfmt
->VertexAttrib1fNV
;
127 tab
->VertexAttrib1fvNV
= vfmt
->VertexAttrib1fvNV
;
128 tab
->VertexAttrib2fNV
= vfmt
->VertexAttrib2fNV
;
129 tab
->VertexAttrib2fvNV
= vfmt
->VertexAttrib2fvNV
;
130 tab
->VertexAttrib3fNV
= vfmt
->VertexAttrib3fNV
;
131 tab
->VertexAttrib3fvNV
= vfmt
->VertexAttrib3fvNV
;
132 tab
->VertexAttrib4fNV
= vfmt
->VertexAttrib4fNV
;
133 tab
->VertexAttrib4fvNV
= vfmt
->VertexAttrib4fvNV
;
134 tab
->VertexAttrib1fARB
= vfmt
->VertexAttrib1fARB
;
135 tab
->VertexAttrib1fvARB
= vfmt
->VertexAttrib1fvARB
;
136 tab
->VertexAttrib2fARB
= vfmt
->VertexAttrib2fARB
;
137 tab
->VertexAttrib2fvARB
= vfmt
->VertexAttrib2fvARB
;
138 tab
->VertexAttrib3fARB
= vfmt
->VertexAttrib3fARB
;
139 tab
->VertexAttrib3fvARB
= vfmt
->VertexAttrib3fvARB
;
140 tab
->VertexAttrib4fARB
= vfmt
->VertexAttrib4fARB
;
141 tab
->VertexAttrib4fvARB
= vfmt
->VertexAttrib4fvARB
;
142 tab
->Rectf
= vfmt
->Rectf
;
143 tab
->DrawArrays
= vfmt
->DrawArrays
;
144 tab
->DrawElements
= vfmt
->DrawElements
;
145 tab
->DrawRangeElements
= vfmt
->DrawRangeElements
;
146 tab
->EvalMesh1
= vfmt
->EvalMesh1
;
147 tab
->EvalMesh2
= vfmt
->EvalMesh2
;
148 ASSERT(tab
->EvalMesh2
);
152 void _mesa_init_exec_vtxfmt( GLcontext
*ctx
)
154 install_vtxfmt( ctx
->Exec
, &neutral_vtxfmt
);
155 ctx
->TnlModule
.SwapCount
= 0;
159 void _mesa_install_exec_vtxfmt( GLcontext
*ctx
, const GLvertexformat
*vfmt
)
161 ctx
->TnlModule
.Current
= vfmt
;
162 _mesa_restore_exec_vtxfmt( ctx
);
166 void _mesa_install_save_vtxfmt( GLcontext
*ctx
, const GLvertexformat
*vfmt
)
168 install_vtxfmt( ctx
->Save
, vfmt
);
172 void _mesa_restore_exec_vtxfmt( GLcontext
*ctx
)
174 struct gl_tnl_module
*tnl
= &(ctx
->TnlModule
);
177 /* Restore the neutral tnl module wrapper.
179 for ( i
= 0 ; i
< tnl
->SwapCount
; i
++ ) {
180 *(void **)tnl
->Swapped
[i
][0] = tnl
->Swapped
[i
][1];