Rev 55 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
55 | pj | 1 | /* $Id: vtxfmt.c,v 1.1 2003-02-28 11:42:07 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 4.1 |
||
6 | * |
||
7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||
8 | * |
||
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: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
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. |
||
25 | * |
||
26 | * Authors: |
||
27 | * Keith Whitwell <keith@tungstengraphics.com> |
||
28 | * Gareth Hughes |
||
29 | */ |
||
30 | |||
31 | #include "glheader.h" |
||
32 | #include "api_loopback.h" |
||
33 | #include "context.h" |
||
34 | #include "imports.h" |
||
35 | #include "mtypes.h" |
||
36 | #include "state.h" |
||
37 | #include "vtxfmt.h" |
||
38 | |||
39 | |||
40 | /* The neutral vertex format. This wraps all tnl module functions, |
||
41 | * verifying that the currently-installed module is valid and then |
||
42 | * installing the function pointers in a lazy fashion. It records the |
||
43 | * function pointers that have been swapped out, which allows a fast |
||
44 | * restoration of the neutral module in almost all cases -- a typical |
||
45 | * app might only require 4-6 functions to be modified from the neutral |
||
46 | * baseline, and only restoring these is certainly preferable to doing |
||
47 | * the entire module's 60 or so function pointers. |
||
48 | */ |
||
49 | |||
50 | #define PRE_LOOPBACK( FUNC ) \ |
||
51 | { \ |
||
52 | GET_CURRENT_CONTEXT(ctx); \ |
||
53 | struct gl_tnl_module *tnl = &(ctx->TnlModule); \ |
||
54 | \ |
||
55 | ASSERT( tnl->Current ); \ |
||
56 | ASSERT( tnl->SwapCount < NUM_VERTEX_FORMAT_ENTRIES ); \ |
||
57 | \ |
||
58 | /* Save the swapped function's dispatch entry so it can be */ \ |
||
59 | /* restored later. */ \ |
||
60 | tnl->Swapped[tnl->SwapCount][0] = (void *)&(ctx->Exec->FUNC); \ |
||
61 | tnl->Swapped[tnl->SwapCount][1] = (void *)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 | ctx->Exec->FUNC = tnl->Current->FUNC; \ |
||
69 | } |
||
70 | |||
71 | #define TAG(x) neutral_##x |
||
72 | #include "vtxfmt_tmp.h" |
||
73 | |||
74 | |||
75 | |||
76 | static void install_vtxfmt( struct _glapi_table *tab, GLvertexformat *vfmt ) |
||
77 | { |
||
78 | tab->ArrayElement = vfmt->ArrayElement; |
||
79 | tab->Color3f = vfmt->Color3f; |
||
80 | tab->Color3fv = vfmt->Color3fv; |
||
81 | tab->Color3ub = vfmt->Color3ub; |
||
82 | tab->Color3ubv = vfmt->Color3ubv; |
||
83 | tab->Color4f = vfmt->Color4f; |
||
84 | tab->Color4fv = vfmt->Color4fv; |
||
85 | tab->Color4ub = vfmt->Color4ub; |
||
86 | tab->Color4ubv = vfmt->Color4ubv; |
||
87 | tab->EdgeFlag = vfmt->EdgeFlag; |
||
88 | tab->EdgeFlagv = vfmt->EdgeFlagv; |
||
89 | tab->EvalCoord1f = vfmt->EvalCoord1f; |
||
90 | tab->EvalCoord1fv = vfmt->EvalCoord1fv; |
||
91 | tab->EvalCoord2f = vfmt->EvalCoord2f; |
||
92 | tab->EvalCoord2fv = vfmt->EvalCoord2fv; |
||
93 | tab->EvalPoint1 = vfmt->EvalPoint1; |
||
94 | tab->EvalPoint2 = vfmt->EvalPoint2; |
||
95 | tab->FogCoordfEXT = vfmt->FogCoordfEXT; |
||
96 | tab->FogCoordfvEXT = vfmt->FogCoordfvEXT; |
||
97 | tab->Indexi = vfmt->Indexi; |
||
98 | tab->Indexiv = vfmt->Indexiv; |
||
99 | tab->Materialfv = vfmt->Materialfv; |
||
100 | tab->MultiTexCoord1fARB = vfmt->MultiTexCoord1fARB; |
||
101 | tab->MultiTexCoord1fvARB = vfmt->MultiTexCoord1fvARB; |
||
102 | tab->MultiTexCoord2fARB = vfmt->MultiTexCoord2fARB; |
||
103 | tab->MultiTexCoord2fvARB = vfmt->MultiTexCoord2fvARB; |
||
104 | tab->MultiTexCoord3fARB = vfmt->MultiTexCoord3fARB; |
||
105 | tab->MultiTexCoord3fvARB = vfmt->MultiTexCoord3fvARB; |
||
106 | tab->MultiTexCoord4fARB = vfmt->MultiTexCoord4fARB; |
||
107 | tab->MultiTexCoord4fvARB = vfmt->MultiTexCoord4fvARB; |
||
108 | tab->Normal3f = vfmt->Normal3f; |
||
109 | tab->Normal3fv = vfmt->Normal3fv; |
||
110 | tab->SecondaryColor3fEXT = vfmt->SecondaryColor3fEXT; |
||
111 | tab->SecondaryColor3fvEXT = vfmt->SecondaryColor3fvEXT; |
||
112 | tab->SecondaryColor3ubEXT = vfmt->SecondaryColor3ubEXT; |
||
113 | tab->SecondaryColor3ubvEXT = vfmt->SecondaryColor3ubvEXT; |
||
114 | tab->TexCoord1f = vfmt->TexCoord1f; |
||
115 | tab->TexCoord1fv = vfmt->TexCoord1fv; |
||
116 | tab->TexCoord2f = vfmt->TexCoord2f; |
||
117 | tab->TexCoord2fv = vfmt->TexCoord2fv; |
||
118 | tab->TexCoord3f = vfmt->TexCoord3f; |
||
119 | tab->TexCoord3fv = vfmt->TexCoord3fv; |
||
120 | tab->TexCoord4f = vfmt->TexCoord4f; |
||
121 | tab->TexCoord4fv = vfmt->TexCoord4fv; |
||
122 | tab->Vertex2f = vfmt->Vertex2f; |
||
123 | tab->Vertex2fv = vfmt->Vertex2fv; |
||
124 | tab->Vertex3f = vfmt->Vertex3f; |
||
125 | tab->Vertex3fv = vfmt->Vertex3fv; |
||
126 | tab->Vertex4f = vfmt->Vertex4f; |
||
127 | tab->Vertex4fv = vfmt->Vertex4fv; |
||
128 | tab->CallList = vfmt->CallList; |
||
129 | tab->Begin = vfmt->Begin; |
||
130 | tab->End = vfmt->End; |
||
131 | tab->VertexAttrib4fNV = vfmt->VertexAttrib4fNV; |
||
132 | tab->Rectf = vfmt->Rectf; |
||
133 | tab->DrawArrays = vfmt->DrawArrays; |
||
134 | tab->DrawElements = vfmt->DrawElements; |
||
135 | tab->DrawRangeElements = vfmt->DrawRangeElements; |
||
136 | tab->EvalMesh1 = vfmt->EvalMesh1; |
||
137 | tab->EvalMesh2 = vfmt->EvalMesh2; |
||
138 | assert(tab->EvalMesh2); |
||
139 | } |
||
140 | |||
141 | |||
142 | void _mesa_init_exec_vtxfmt( GLcontext *ctx ) |
||
143 | { |
||
144 | install_vtxfmt( ctx->Exec, &neutral_vtxfmt ); |
||
145 | ctx->TnlModule.SwapCount = 0; |
||
146 | } |
||
147 | |||
148 | |||
149 | void _mesa_install_exec_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt ) |
||
150 | { |
||
151 | ctx->TnlModule.Current = vfmt; |
||
152 | _mesa_restore_exec_vtxfmt( ctx ); |
||
153 | if ( ctx->ExecPrefersFloat != vfmt->prefer_float_colors ) |
||
154 | _mesa_loopback_prefer_float( ctx->Exec, vfmt->prefer_float_colors ); |
||
155 | } |
||
156 | |||
157 | void _mesa_install_save_vtxfmt( GLcontext *ctx, GLvertexformat *vfmt ) |
||
158 | { |
||
159 | install_vtxfmt( ctx->Save, vfmt ); |
||
160 | if ( ctx->SavePrefersFloat != vfmt->prefer_float_colors ) |
||
161 | _mesa_loopback_prefer_float( ctx->Save, vfmt->prefer_float_colors ); |
||
162 | } |
||
163 | |||
164 | |||
165 | void _mesa_restore_exec_vtxfmt( GLcontext *ctx ) |
||
166 | { |
||
167 | struct gl_tnl_module *tnl = &(ctx->TnlModule); |
||
168 | GLuint i; |
||
169 | |||
170 | /* Restore the neutral tnl module wrapper. |
||
171 | */ |
||
172 | for ( i = 0 ; i < tnl->SwapCount ; i++ ) { |
||
173 | *(void **)tnl->Swapped[i][0] = tnl->Swapped[i][1]; |
||
174 | } |
||
175 | |||
176 | tnl->SwapCount = 0; |
||
177 | } |