1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keithw@vmware.com> Gareth Hughes
26 */
27
28 #include "glheader.h"
29 #include "api_arrayelt.h"
30 #include "context.h"
31 #include "imports.h"
32 #include "mtypes.h"
33 #include "vtxfmt.h"
34 #include "eval.h"
35 #include "dlist.h"
36 #include "main/dispatch.h"
37 #include "vbo/vbo_context.h"
38
39
40 /**
41 * Copy the functions found in the GLvertexformat object into the
42 * dispatch table.
43 */
44 static void
install_vtxfmt(struct gl_context * ctx,struct _glapi_table * tab,const GLvertexformat * vfmt)45 install_vtxfmt(struct gl_context *ctx, struct _glapi_table *tab,
46 const GLvertexformat *vfmt)
47 {
48 assert(ctx->Version > 0);
49
50 if (ctx->API != API_OPENGL_CORE && ctx->API != API_OPENGLES2) {
51 SET_Color4f(tab, vfmt->Color4f);
52 }
53
54 if (ctx->API == API_OPENGL_COMPAT) {
55 _mesa_install_arrayelt_vtxfmt(tab, vfmt);
56 SET_Color3f(tab, vfmt->Color3f);
57 SET_Color3fv(tab, vfmt->Color3fv);
58 SET_Color4fv(tab, vfmt->Color4fv);
59 SET_EdgeFlag(tab, vfmt->EdgeFlag);
60 }
61
62 if (ctx->API == API_OPENGL_COMPAT) {
63 _mesa_install_eval_vtxfmt(tab, vfmt);
64 }
65
66 if (ctx->API != API_OPENGL_CORE && ctx->API != API_OPENGLES2) {
67 SET_Materialfv(tab, vfmt->Materialfv);
68 SET_MultiTexCoord4fARB(tab, vfmt->MultiTexCoord4fARB);
69 SET_Normal3f(tab, vfmt->Normal3f);
70 }
71
72 if (ctx->API == API_OPENGL_COMPAT) {
73 SET_FogCoordfEXT(tab, vfmt->FogCoordfEXT);
74 SET_FogCoordfvEXT(tab, vfmt->FogCoordfvEXT);
75 SET_Indexf(tab, vfmt->Indexf);
76 SET_Indexfv(tab, vfmt->Indexfv);
77 SET_MultiTexCoord1fARB(tab, vfmt->MultiTexCoord1fARB);
78 SET_MultiTexCoord1fvARB(tab, vfmt->MultiTexCoord1fvARB);
79 SET_MultiTexCoord2fARB(tab, vfmt->MultiTexCoord2fARB);
80 SET_MultiTexCoord2fvARB(tab, vfmt->MultiTexCoord2fvARB);
81 SET_MultiTexCoord3fARB(tab, vfmt->MultiTexCoord3fARB);
82 SET_MultiTexCoord3fvARB(tab, vfmt->MultiTexCoord3fvARB);
83 SET_MultiTexCoord4fvARB(tab, vfmt->MultiTexCoord4fvARB);
84 SET_Normal3fv(tab, vfmt->Normal3fv);
85 }
86
87 if (ctx->API == API_OPENGL_COMPAT) {
88 SET_SecondaryColor3fEXT(tab, vfmt->SecondaryColor3fEXT);
89 SET_SecondaryColor3fvEXT(tab, vfmt->SecondaryColor3fvEXT);
90 SET_TexCoord1f(tab, vfmt->TexCoord1f);
91 SET_TexCoord1fv(tab, vfmt->TexCoord1fv);
92 SET_TexCoord2f(tab, vfmt->TexCoord2f);
93 SET_TexCoord2fv(tab, vfmt->TexCoord2fv);
94 SET_TexCoord3f(tab, vfmt->TexCoord3f);
95 SET_TexCoord3fv(tab, vfmt->TexCoord3fv);
96 SET_TexCoord4f(tab, vfmt->TexCoord4f);
97 SET_TexCoord4fv(tab, vfmt->TexCoord4fv);
98 SET_Vertex2f(tab, vfmt->Vertex2f);
99 SET_Vertex2fv(tab, vfmt->Vertex2fv);
100 SET_Vertex3f(tab, vfmt->Vertex3f);
101 SET_Vertex3fv(tab, vfmt->Vertex3fv);
102 SET_Vertex4f(tab, vfmt->Vertex4f);
103 SET_Vertex4fv(tab, vfmt->Vertex4fv);
104 }
105
106 if (ctx->API == API_OPENGL_COMPAT) {
107 _mesa_install_dlist_vtxfmt(tab, vfmt); /* glCallList / glCallLists */
108
109 SET_Begin(tab, vfmt->Begin);
110 SET_End(tab, vfmt->End);
111 SET_PrimitiveRestartNV(tab, vfmt->PrimitiveRestartNV);
112 }
113
114 /* Originally for GL_NV_vertex_program, this is also used by dlist.c */
115 if (ctx->API == API_OPENGL_COMPAT) {
116 SET_VertexAttrib1fNV(tab, vfmt->VertexAttrib1fNV);
117 SET_VertexAttrib1fvNV(tab, vfmt->VertexAttrib1fvNV);
118 SET_VertexAttrib2fNV(tab, vfmt->VertexAttrib2fNV);
119 SET_VertexAttrib2fvNV(tab, vfmt->VertexAttrib2fvNV);
120 SET_VertexAttrib3fNV(tab, vfmt->VertexAttrib3fNV);
121 SET_VertexAttrib3fvNV(tab, vfmt->VertexAttrib3fvNV);
122 SET_VertexAttrib4fNV(tab, vfmt->VertexAttrib4fNV);
123 SET_VertexAttrib4fvNV(tab, vfmt->VertexAttrib4fvNV);
124 }
125
126 if (ctx->API != API_OPENGLES) {
127 SET_VertexAttrib1fARB(tab, vfmt->VertexAttrib1fARB);
128 SET_VertexAttrib1fvARB(tab, vfmt->VertexAttrib1fvARB);
129 SET_VertexAttrib2fARB(tab, vfmt->VertexAttrib2fARB);
130 SET_VertexAttrib2fvARB(tab, vfmt->VertexAttrib2fvARB);
131 SET_VertexAttrib3fARB(tab, vfmt->VertexAttrib3fARB);
132 SET_VertexAttrib3fvARB(tab, vfmt->VertexAttrib3fvARB);
133 SET_VertexAttrib4fARB(tab, vfmt->VertexAttrib4fARB);
134 SET_VertexAttrib4fvARB(tab, vfmt->VertexAttrib4fvARB);
135 }
136
137 /* GL_EXT_gpu_shader4 / OpenGL 3.0 */
138 if (_mesa_is_desktop_gl(ctx)) {
139 SET_VertexAttribI1iEXT(tab, vfmt->VertexAttribI1i);
140 SET_VertexAttribI2iEXT(tab, vfmt->VertexAttribI2i);
141 SET_VertexAttribI3iEXT(tab, vfmt->VertexAttribI3i);
142 SET_VertexAttribI2ivEXT(tab, vfmt->VertexAttribI2iv);
143 SET_VertexAttribI3ivEXT(tab, vfmt->VertexAttribI3iv);
144
145 SET_VertexAttribI1uiEXT(tab, vfmt->VertexAttribI1ui);
146 SET_VertexAttribI2uiEXT(tab, vfmt->VertexAttribI2ui);
147 SET_VertexAttribI3uiEXT(tab, vfmt->VertexAttribI3ui);
148 SET_VertexAttribI2uivEXT(tab, vfmt->VertexAttribI2uiv);
149 SET_VertexAttribI3uivEXT(tab, vfmt->VertexAttribI3uiv);
150 }
151
152 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx)) {
153 SET_VertexAttribI4iEXT(tab, vfmt->VertexAttribI4i);
154 SET_VertexAttribI4ivEXT(tab, vfmt->VertexAttribI4iv);
155 SET_VertexAttribI4uiEXT(tab, vfmt->VertexAttribI4ui);
156 SET_VertexAttribI4uivEXT(tab, vfmt->VertexAttribI4uiv);
157 }
158
159 if (ctx->API == API_OPENGL_COMPAT) {
160 /* GL_ARB_vertex_type_10_10_10_2_rev / GL 3.3 */
161 SET_VertexP2ui(tab, vfmt->VertexP2ui);
162 SET_VertexP2uiv(tab, vfmt->VertexP2uiv);
163 SET_VertexP3ui(tab, vfmt->VertexP3ui);
164 SET_VertexP3uiv(tab, vfmt->VertexP3uiv);
165 SET_VertexP4ui(tab, vfmt->VertexP4ui);
166 SET_VertexP4uiv(tab, vfmt->VertexP4uiv);
167
168 SET_TexCoordP1ui(tab, vfmt->TexCoordP1ui);
169 SET_TexCoordP1uiv(tab, vfmt->TexCoordP1uiv);
170 SET_TexCoordP2ui(tab, vfmt->TexCoordP2ui);
171 SET_TexCoordP2uiv(tab, vfmt->TexCoordP2uiv);
172 SET_TexCoordP3ui(tab, vfmt->TexCoordP3ui);
173 SET_TexCoordP3uiv(tab, vfmt->TexCoordP3uiv);
174 SET_TexCoordP4ui(tab, vfmt->TexCoordP4ui);
175 SET_TexCoordP4uiv(tab, vfmt->TexCoordP4uiv);
176
177 SET_MultiTexCoordP1ui(tab, vfmt->MultiTexCoordP1ui);
178 SET_MultiTexCoordP2ui(tab, vfmt->MultiTexCoordP2ui);
179 SET_MultiTexCoordP3ui(tab, vfmt->MultiTexCoordP3ui);
180 SET_MultiTexCoordP4ui(tab, vfmt->MultiTexCoordP4ui);
181 SET_MultiTexCoordP1uiv(tab, vfmt->MultiTexCoordP1uiv);
182 SET_MultiTexCoordP2uiv(tab, vfmt->MultiTexCoordP2uiv);
183 SET_MultiTexCoordP3uiv(tab, vfmt->MultiTexCoordP3uiv);
184 SET_MultiTexCoordP4uiv(tab, vfmt->MultiTexCoordP4uiv);
185
186 SET_NormalP3ui(tab, vfmt->NormalP3ui);
187 SET_NormalP3uiv(tab, vfmt->NormalP3uiv);
188
189 SET_ColorP3ui(tab, vfmt->ColorP3ui);
190 SET_ColorP4ui(tab, vfmt->ColorP4ui);
191 SET_ColorP3uiv(tab, vfmt->ColorP3uiv);
192 SET_ColorP4uiv(tab, vfmt->ColorP4uiv);
193
194 SET_SecondaryColorP3ui(tab, vfmt->SecondaryColorP3ui);
195 SET_SecondaryColorP3uiv(tab, vfmt->SecondaryColorP3uiv);
196 }
197
198 if (_mesa_is_desktop_gl(ctx)) {
199 SET_VertexAttribP1ui(tab, vfmt->VertexAttribP1ui);
200 SET_VertexAttribP2ui(tab, vfmt->VertexAttribP2ui);
201 SET_VertexAttribP3ui(tab, vfmt->VertexAttribP3ui);
202 SET_VertexAttribP4ui(tab, vfmt->VertexAttribP4ui);
203
204 SET_VertexAttribP1uiv(tab, vfmt->VertexAttribP1uiv);
205 SET_VertexAttribP2uiv(tab, vfmt->VertexAttribP2uiv);
206 SET_VertexAttribP3uiv(tab, vfmt->VertexAttribP3uiv);
207 SET_VertexAttribP4uiv(tab, vfmt->VertexAttribP4uiv);
208 }
209
210 if (ctx->API == API_OPENGL_CORE) {
211 SET_VertexAttribL1d(tab, vfmt->VertexAttribL1d);
212 SET_VertexAttribL2d(tab, vfmt->VertexAttribL2d);
213 SET_VertexAttribL3d(tab, vfmt->VertexAttribL3d);
214 SET_VertexAttribL4d(tab, vfmt->VertexAttribL4d);
215
216 SET_VertexAttribL1dv(tab, vfmt->VertexAttribL1dv);
217 SET_VertexAttribL2dv(tab, vfmt->VertexAttribL2dv);
218 SET_VertexAttribL3dv(tab, vfmt->VertexAttribL3dv);
219 SET_VertexAttribL4dv(tab, vfmt->VertexAttribL4dv);
220
221 /* GL_ARB_bindless_texture */
222 SET_VertexAttribL1ui64ARB(tab, vfmt->VertexAttribL1ui64ARB);
223 SET_VertexAttribL1ui64vARB(tab, vfmt->VertexAttribL1ui64vARB);
224 }
225 }
226
227
228 /**
229 * Install per-vertex functions into the API dispatch table for execution.
230 */
231 void
_mesa_install_exec_vtxfmt(struct gl_context * ctx,const GLvertexformat * vfmt)232 _mesa_install_exec_vtxfmt(struct gl_context *ctx, const GLvertexformat *vfmt)
233 {
234 install_vtxfmt(ctx, ctx->Exec, vfmt);
235 if (ctx->BeginEnd)
236 install_vtxfmt(ctx, ctx->BeginEnd, vfmt);
237 }
238
239
240 /**
241 * Install per-vertex functions into the API dispatch table for display
242 * list compilation.
243 */
244 void
_mesa_install_save_vtxfmt(struct gl_context * ctx,const GLvertexformat * vfmt)245 _mesa_install_save_vtxfmt(struct gl_context *ctx, const GLvertexformat *vfmt)
246 {
247 if (_mesa_is_desktop_gl(ctx))
248 install_vtxfmt(ctx, ctx->Save, vfmt);
249 }
250
251
252 /**
253 * Install VBO vtxfmt functions.
254 *
255 * This function depends on ctx->Version.
256 */
257 void
_mesa_initialize_vbo_vtxfmt(struct gl_context * ctx)258 _mesa_initialize_vbo_vtxfmt(struct gl_context *ctx)
259 {
260 struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
261 _mesa_install_exec_vtxfmt(ctx, &exec->vtxfmt);
262 if (ctx->API == API_OPENGL_COMPAT) {
263 _mesa_install_save_vtxfmt(ctx, &ctx->ListState.ListVtxfmt);
264 }
265 }
266
267