API dispath updates
[mesa.git] / src / mesa / main / state.c
1 /* $Id: state.c,v 1.70 2001/11/18 22:48:13 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
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
27
28 /*
29 * This file manages recalculation of derived values in the
30 * __GLcontext.
31 */
32
33
34 #ifdef PC_HEADER
35 #include "all.h"
36 #else
37 #include "glheader.h"
38 #include "accum.h"
39 #include "api_loopback.h"
40 #include "attrib.h"
41 #include "blend.h"
42 #include "buffers.h"
43 #include "clip.h"
44 #include "colortab.h"
45 #include "context.h"
46 #include "convolve.h"
47 #include "depth.h"
48 #include "dlist.h"
49 #include "drawpix.h"
50 #include "enable.h"
51 #include "eval.h"
52 #include "get.h"
53 #include "feedback.h"
54 #include "fog.h"
55 #include "hint.h"
56 #include "histogram.h"
57 #include "light.h"
58 #include "lines.h"
59 #include "matrix.h"
60 #include "mmath.h"
61 #include "pixel.h"
62 #include "points.h"
63 #include "polygon.h"
64 #include "rastpos.h"
65 #include "state.h"
66 #include "stencil.h"
67 #include "teximage.h"
68 #include "texobj.h"
69 #include "texstate.h"
70 #include "mtypes.h"
71 #include "varray.h"
72
73 #include "math/m_matrix.h"
74 #include "math/m_xform.h"
75 #endif
76
77
78 static int
79 generic_noop(void)
80 {
81 #ifdef DEBUG
82 _mesa_problem(NULL, "undefined function dispatch");
83 #endif
84 return 0;
85 }
86
87
88 /*
89 * Set all pointers in the given dispatch table to point to a
90 * generic no-op function.
91 */
92 void
93 _mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
94 {
95 GLuint i;
96 void **dispatch = (void **) table;
97 for (i = 0; i < tableSize; i++) {
98 dispatch[i] = (void *) generic_noop;
99 }
100 }
101
102
103
104 /*
105 * Initialize the given dispatch table with pointers to Mesa's
106 * immediate-mode commands.
107 *
108 * Pointers to begin/end object commands and a few others
109 * are provided via the vtxfmt interface elsewhere.
110 */
111 void
112 _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
113 {
114 /* first initialize all dispatch slots to no-op */
115 _mesa_init_no_op_table(exec, tableSize);
116
117 _mesa_loopback_init_api_table( exec, GL_TRUE );
118
119 /* load the dispatch slots we understand */
120 exec->Accum = _mesa_Accum;
121 exec->AlphaFunc = _mesa_AlphaFunc;
122 exec->Bitmap = _mesa_Bitmap;
123 exec->BlendFunc = _mesa_BlendFunc;
124 exec->CallList = _mesa_CallList;
125 exec->CallLists = _mesa_CallLists;
126 exec->Clear = _mesa_Clear;
127 exec->ClearAccum = _mesa_ClearAccum;
128 exec->ClearColor = _mesa_ClearColor;
129 exec->ClearDepth = _mesa_ClearDepth;
130 exec->ClearIndex = _mesa_ClearIndex;
131 exec->ClearStencil = _mesa_ClearStencil;
132 exec->ClipPlane = _mesa_ClipPlane;
133 exec->ColorMask = _mesa_ColorMask;
134 exec->ColorMaterial = _mesa_ColorMaterial;
135 exec->CopyPixels = _mesa_CopyPixels;
136 exec->CullFace = _mesa_CullFace;
137 exec->DeleteLists = _mesa_DeleteLists;
138 exec->DepthFunc = _mesa_DepthFunc;
139 exec->DepthMask = _mesa_DepthMask;
140 exec->DepthRange = _mesa_DepthRange;
141 exec->Disable = _mesa_Disable;
142 exec->DrawBuffer = _mesa_DrawBuffer;
143 exec->DrawPixels = _mesa_DrawPixels;
144 exec->Enable = _mesa_Enable;
145 exec->EndList = _mesa_EndList;
146 exec->FeedbackBuffer = _mesa_FeedbackBuffer;
147 exec->Finish = _mesa_Finish;
148 exec->Flush = _mesa_Flush;
149 exec->FogCoordPointerEXT = _mesa_FogCoordPointerEXT;
150 exec->Fogf = _mesa_Fogf;
151 exec->Fogfv = _mesa_Fogfv;
152 exec->Fogi = _mesa_Fogi;
153 exec->Fogiv = _mesa_Fogiv;
154 exec->FrontFace = _mesa_FrontFace;
155 exec->Frustum = _mesa_Frustum;
156 exec->GenLists = _mesa_GenLists;
157 exec->GetBooleanv = _mesa_GetBooleanv;
158 exec->GetClipPlane = _mesa_GetClipPlane;
159 exec->GetDoublev = _mesa_GetDoublev;
160 exec->GetError = _mesa_GetError;
161 exec->GetFloatv = _mesa_GetFloatv;
162 exec->GetIntegerv = _mesa_GetIntegerv;
163 exec->GetLightfv = _mesa_GetLightfv;
164 exec->GetLightiv = _mesa_GetLightiv;
165 exec->GetMapdv = _mesa_GetMapdv;
166 exec->GetMapfv = _mesa_GetMapfv;
167 exec->GetMapiv = _mesa_GetMapiv;
168 exec->GetMaterialfv = _mesa_GetMaterialfv;
169 exec->GetMaterialiv = _mesa_GetMaterialiv;
170 exec->GetPixelMapfv = _mesa_GetPixelMapfv;
171 exec->GetPixelMapuiv = _mesa_GetPixelMapuiv;
172 exec->GetPixelMapusv = _mesa_GetPixelMapusv;
173 exec->GetPolygonStipple = _mesa_GetPolygonStipple;
174 exec->GetString = _mesa_GetString;
175 exec->GetTexEnvfv = _mesa_GetTexEnvfv;
176 exec->GetTexEnviv = _mesa_GetTexEnviv;
177 exec->GetTexGendv = _mesa_GetTexGendv;
178 exec->GetTexGenfv = _mesa_GetTexGenfv;
179 exec->GetTexGeniv = _mesa_GetTexGeniv;
180 exec->GetTexImage = _mesa_GetTexImage;
181 exec->GetTexLevelParameterfv = _mesa_GetTexLevelParameterfv;
182 exec->GetTexLevelParameteriv = _mesa_GetTexLevelParameteriv;
183 exec->GetTexParameterfv = _mesa_GetTexParameterfv;
184 exec->GetTexParameteriv = _mesa_GetTexParameteriv;
185 exec->Hint = _mesa_Hint;
186 exec->IndexMask = _mesa_IndexMask;
187 exec->InitNames = _mesa_InitNames;
188 exec->IsEnabled = _mesa_IsEnabled;
189 exec->IsList = _mesa_IsList;
190 exec->LightModelf = _mesa_LightModelf;
191 exec->LightModelfv = _mesa_LightModelfv;
192 exec->LightModeli = _mesa_LightModeli;
193 exec->LightModeliv = _mesa_LightModeliv;
194 exec->Lightf = _mesa_Lightf;
195 exec->Lightfv = _mesa_Lightfv;
196 exec->Lighti = _mesa_Lighti;
197 exec->Lightiv = _mesa_Lightiv;
198 exec->LineStipple = _mesa_LineStipple;
199 exec->LineWidth = _mesa_LineWidth;
200 exec->ListBase = _mesa_ListBase;
201 exec->LoadIdentity = _mesa_LoadIdentity;
202 exec->LoadMatrixd = _mesa_LoadMatrixd;
203 exec->LoadMatrixf = _mesa_LoadMatrixf;
204 exec->LoadName = _mesa_LoadName;
205 exec->LogicOp = _mesa_LogicOp;
206 exec->Map1d = _mesa_Map1d;
207 exec->Map1f = _mesa_Map1f;
208 exec->Map2d = _mesa_Map2d;
209 exec->Map2f = _mesa_Map2f;
210 exec->MapGrid1d = _mesa_MapGrid1d;
211 exec->MapGrid1f = _mesa_MapGrid1f;
212 exec->MapGrid2d = _mesa_MapGrid2d;
213 exec->MapGrid2f = _mesa_MapGrid2f;
214 exec->MatrixMode = _mesa_MatrixMode;
215 exec->MultMatrixd = _mesa_MultMatrixd;
216 exec->MultMatrixf = _mesa_MultMatrixf;
217 exec->NewList = _mesa_NewList;
218 exec->Ortho = _mesa_Ortho;
219 exec->PassThrough = _mesa_PassThrough;
220 exec->PixelMapfv = _mesa_PixelMapfv;
221 exec->PixelMapuiv = _mesa_PixelMapuiv;
222 exec->PixelMapusv = _mesa_PixelMapusv;
223 exec->PixelStoref = _mesa_PixelStoref;
224 exec->PixelStorei = _mesa_PixelStorei;
225 exec->PixelTransferf = _mesa_PixelTransferf;
226 exec->PixelTransferi = _mesa_PixelTransferi;
227 exec->PixelZoom = _mesa_PixelZoom;
228 exec->PointSize = _mesa_PointSize;
229 exec->PolygonMode = _mesa_PolygonMode;
230 exec->PolygonOffset = _mesa_PolygonOffset;
231 exec->PolygonStipple = _mesa_PolygonStipple;
232 exec->PopAttrib = _mesa_PopAttrib;
233 exec->PopMatrix = _mesa_PopMatrix;
234 exec->PopName = _mesa_PopName;
235 exec->PushAttrib = _mesa_PushAttrib;
236 exec->PushMatrix = _mesa_PushMatrix;
237 exec->PushName = _mesa_PushName;
238 exec->RasterPos2d = _mesa_RasterPos2d;
239 exec->RasterPos2dv = _mesa_RasterPos2dv;
240 exec->RasterPos2f = _mesa_RasterPos2f;
241 exec->RasterPos2fv = _mesa_RasterPos2fv;
242 exec->RasterPos2i = _mesa_RasterPos2i;
243 exec->RasterPos2iv = _mesa_RasterPos2iv;
244 exec->RasterPos2s = _mesa_RasterPos2s;
245 exec->RasterPos2sv = _mesa_RasterPos2sv;
246 exec->RasterPos3d = _mesa_RasterPos3d;
247 exec->RasterPos3dv = _mesa_RasterPos3dv;
248 exec->RasterPos3f = _mesa_RasterPos3f;
249 exec->RasterPos3fv = _mesa_RasterPos3fv;
250 exec->RasterPos3i = _mesa_RasterPos3i;
251 exec->RasterPos3iv = _mesa_RasterPos3iv;
252 exec->RasterPos3s = _mesa_RasterPos3s;
253 exec->RasterPos3sv = _mesa_RasterPos3sv;
254 exec->RasterPos4d = _mesa_RasterPos4d;
255 exec->RasterPos4dv = _mesa_RasterPos4dv;
256 exec->RasterPos4f = _mesa_RasterPos4f;
257 exec->RasterPos4fv = _mesa_RasterPos4fv;
258 exec->RasterPos4i = _mesa_RasterPos4i;
259 exec->RasterPos4iv = _mesa_RasterPos4iv;
260 exec->RasterPos4s = _mesa_RasterPos4s;
261 exec->RasterPos4sv = _mesa_RasterPos4sv;
262 exec->ReadBuffer = _mesa_ReadBuffer;
263 exec->ReadPixels = _mesa_ReadPixels;
264 exec->RenderMode = _mesa_RenderMode;
265 exec->Rotated = _mesa_Rotated;
266 exec->Rotatef = _mesa_Rotatef;
267 exec->Scaled = _mesa_Scaled;
268 exec->Scalef = _mesa_Scalef;
269 exec->Scissor = _mesa_Scissor;
270 exec->SecondaryColorPointerEXT = _mesa_SecondaryColorPointerEXT;
271 exec->SelectBuffer = _mesa_SelectBuffer;
272 exec->ShadeModel = _mesa_ShadeModel;
273 exec->StencilFunc = _mesa_StencilFunc;
274 exec->StencilMask = _mesa_StencilMask;
275 exec->StencilOp = _mesa_StencilOp;
276 exec->TexEnvf = _mesa_TexEnvf;
277 exec->TexEnvfv = _mesa_TexEnvfv;
278 exec->TexEnvi = _mesa_TexEnvi;
279 exec->TexEnviv = _mesa_TexEnviv;
280 exec->TexGend = _mesa_TexGend;
281 exec->TexGendv = _mesa_TexGendv;
282 exec->TexGenf = _mesa_TexGenf;
283 exec->TexGenfv = _mesa_TexGenfv;
284 exec->TexGeni = _mesa_TexGeni;
285 exec->TexGeniv = _mesa_TexGeniv;
286 exec->TexImage1D = _mesa_TexImage1D;
287 exec->TexImage2D = _mesa_TexImage2D;
288 exec->TexParameterf = _mesa_TexParameterf;
289 exec->TexParameterfv = _mesa_TexParameterfv;
290 exec->TexParameteri = _mesa_TexParameteri;
291 exec->TexParameteriv = _mesa_TexParameteriv;
292 exec->Translated = _mesa_Translated;
293 exec->Translatef = _mesa_Translatef;
294 exec->Viewport = _mesa_Viewport;
295
296 /* 1.1 */
297 exec->AreTexturesResident = _mesa_AreTexturesResident;
298 exec->BindTexture = _mesa_BindTexture;
299 exec->ColorPointer = _mesa_ColorPointer;
300 exec->CopyTexImage1D = _mesa_CopyTexImage1D;
301 exec->CopyTexImage2D = _mesa_CopyTexImage2D;
302 exec->CopyTexSubImage1D = _mesa_CopyTexSubImage1D;
303 exec->CopyTexSubImage2D = _mesa_CopyTexSubImage2D;
304 exec->DeleteTextures = _mesa_DeleteTextures;
305 exec->DisableClientState = _mesa_DisableClientState;
306 exec->EdgeFlagPointer = _mesa_EdgeFlagPointer;
307 exec->EnableClientState = _mesa_EnableClientState;
308 exec->GenTextures = _mesa_GenTextures;
309 exec->GetPointerv = _mesa_GetPointerv;
310 exec->IndexPointer = _mesa_IndexPointer;
311 exec->InterleavedArrays = _mesa_InterleavedArrays;
312 exec->IsTexture = _mesa_IsTexture;
313 exec->NormalPointer = _mesa_NormalPointer;
314 exec->PopClientAttrib = _mesa_PopClientAttrib;
315 exec->PrioritizeTextures = _mesa_PrioritizeTextures;
316 exec->PushClientAttrib = _mesa_PushClientAttrib;
317 exec->TexCoordPointer = _mesa_TexCoordPointer;
318 exec->TexSubImage1D = _mesa_TexSubImage1D;
319 exec->TexSubImage2D = _mesa_TexSubImage2D;
320 exec->VertexPointer = _mesa_VertexPointer;
321
322 /* 1.2 */
323 exec->CopyTexSubImage3D = _mesa_CopyTexSubImage3D;
324 exec->TexImage3D = _mesa_TexImage3D;
325 exec->TexSubImage3D = _mesa_TexSubImage3D;
326
327 /* OpenGL 1.2 GL_ARB_imaging */
328 exec->BlendColor = _mesa_BlendColor;
329 exec->BlendEquation = _mesa_BlendEquation;
330 exec->ColorSubTable = _mesa_ColorSubTable;
331 exec->ColorTable = _mesa_ColorTable;
332 exec->ColorTableParameterfv = _mesa_ColorTableParameterfv;
333 exec->ColorTableParameteriv = _mesa_ColorTableParameteriv;
334 exec->ConvolutionFilter1D = _mesa_ConvolutionFilter1D;
335 exec->ConvolutionFilter2D = _mesa_ConvolutionFilter2D;
336 exec->ConvolutionParameterf = _mesa_ConvolutionParameterf;
337 exec->ConvolutionParameterfv = _mesa_ConvolutionParameterfv;
338 exec->ConvolutionParameteri = _mesa_ConvolutionParameteri;
339 exec->ConvolutionParameteriv = _mesa_ConvolutionParameteriv;
340 exec->CopyColorSubTable = _mesa_CopyColorSubTable;
341 exec->CopyColorTable = _mesa_CopyColorTable;
342 exec->CopyConvolutionFilter1D = _mesa_CopyConvolutionFilter1D;
343 exec->CopyConvolutionFilter2D = _mesa_CopyConvolutionFilter2D;
344 exec->GetColorTable = _mesa_GetColorTable;
345 exec->GetColorTableParameterfv = _mesa_GetColorTableParameterfv;
346 exec->GetColorTableParameteriv = _mesa_GetColorTableParameteriv;
347 exec->GetConvolutionFilter = _mesa_GetConvolutionFilter;
348 exec->GetConvolutionParameterfv = _mesa_GetConvolutionParameterfv;
349 exec->GetConvolutionParameteriv = _mesa_GetConvolutionParameteriv;
350 exec->GetHistogram = _mesa_GetHistogram;
351 exec->GetHistogramParameterfv = _mesa_GetHistogramParameterfv;
352 exec->GetHistogramParameteriv = _mesa_GetHistogramParameteriv;
353 exec->GetMinmax = _mesa_GetMinmax;
354 exec->GetMinmaxParameterfv = _mesa_GetMinmaxParameterfv;
355 exec->GetMinmaxParameteriv = _mesa_GetMinmaxParameteriv;
356 exec->GetSeparableFilter = _mesa_GetSeparableFilter;
357 exec->Histogram = _mesa_Histogram;
358 exec->Minmax = _mesa_Minmax;
359 exec->ResetHistogram = _mesa_ResetHistogram;
360 exec->ResetMinmax = _mesa_ResetMinmax;
361 exec->SeparableFilter2D = _mesa_SeparableFilter2D;
362
363 /* 2. GL_EXT_blend_color */
364 #if 0
365 exec->BlendColorEXT = _mesa_BlendColorEXT;
366 #endif
367
368 /* 3. GL_EXT_polygon_offset */
369 exec->PolygonOffsetEXT = _mesa_PolygonOffsetEXT;
370
371 /* 6. GL_EXT_texture3d */
372 #if 0
373 exec->CopyTexSubImage3DEXT = _mesa_CopyTexSubImage3D;
374 exec->TexImage3DEXT = _mesa_TexImage3DEXT;
375 exec->TexSubImage3DEXT = _mesa_TexSubImage3D;
376 #endif
377
378 /* 11. GL_EXT_histogram */
379 exec->GetHistogramEXT = _mesa_GetHistogram;
380 exec->GetHistogramParameterfvEXT = _mesa_GetHistogramParameterfv;
381 exec->GetHistogramParameterivEXT = _mesa_GetHistogramParameteriv;
382 exec->GetMinmaxEXT = _mesa_GetMinmax;
383 exec->GetMinmaxParameterfvEXT = _mesa_GetMinmaxParameterfv;
384 exec->GetMinmaxParameterivEXT = _mesa_GetMinmaxParameteriv;
385
386 /* ?. GL_SGIX_pixel_texture */
387 exec->PixelTexGenSGIX = _mesa_PixelTexGenSGIX;
388
389 /* 15. GL_SGIS_pixel_texture */
390 exec->PixelTexGenParameteriSGIS = _mesa_PixelTexGenParameteriSGIS;
391 exec->PixelTexGenParameterivSGIS = _mesa_PixelTexGenParameterivSGIS;
392 exec->PixelTexGenParameterfSGIS = _mesa_PixelTexGenParameterfSGIS;
393 exec->PixelTexGenParameterfvSGIS = _mesa_PixelTexGenParameterfvSGIS;
394 exec->GetPixelTexGenParameterivSGIS = _mesa_GetPixelTexGenParameterivSGIS;
395 exec->GetPixelTexGenParameterfvSGIS = _mesa_GetPixelTexGenParameterfvSGIS;
396
397 /* 30. GL_EXT_vertex_array */
398 exec->ColorPointerEXT = _mesa_ColorPointerEXT;
399 exec->EdgeFlagPointerEXT = _mesa_EdgeFlagPointerEXT;
400 exec->IndexPointerEXT = _mesa_IndexPointerEXT;
401 exec->NormalPointerEXT = _mesa_NormalPointerEXT;
402 exec->TexCoordPointerEXT = _mesa_TexCoordPointerEXT;
403 exec->VertexPointerEXT = _mesa_VertexPointerEXT;
404
405 /* 37. GL_EXT_blend_minmax */
406 #if 0
407 exec->BlendEquationEXT = _mesa_BlendEquationEXT;
408 #endif
409
410 /* 54. GL_EXT_point_parameters */
411 exec->PointParameterfARB = _mesa_PointParameterfEXT;
412 exec->PointParameterfvARB = _mesa_PointParameterfvEXT;
413
414 /* 78. GL_EXT_paletted_texture */
415 #if 0
416 exec->ColorTableEXT = _mesa_ColorTableEXT;
417 exec->ColorSubTableEXT = _mesa_ColorSubTableEXT;
418 #endif
419 exec->GetColorTableEXT = _mesa_GetColorTable;
420 exec->GetColorTableParameterfvEXT = _mesa_GetColorTableParameterfv;
421 exec->GetColorTableParameterivEXT = _mesa_GetColorTableParameteriv;
422
423 /* 97. GL_EXT_compiled_vertex_array */
424 exec->LockArraysEXT = _mesa_LockArraysEXT;
425 exec->UnlockArraysEXT = _mesa_UnlockArraysEXT;
426
427 /* 173. GL_INGR_blend_func_separate */
428 exec->BlendFuncSeparateEXT = _mesa_BlendFuncSeparateEXT;
429
430 /* 196. GL_MESA_resize_buffers */
431 exec->ResizeBuffersMESA = _mesa_ResizeBuffersMESA;
432
433 /* 197. GL_MESA_window_pos */
434 exec->WindowPos2dMESA = _mesa_WindowPos2dMESA;
435 exec->WindowPos2dvMESA = _mesa_WindowPos2dvMESA;
436 exec->WindowPos2fMESA = _mesa_WindowPos2fMESA;
437 exec->WindowPos2fvMESA = _mesa_WindowPos2fvMESA;
438 exec->WindowPos2iMESA = _mesa_WindowPos2iMESA;
439 exec->WindowPos2ivMESA = _mesa_WindowPos2ivMESA;
440 exec->WindowPos2sMESA = _mesa_WindowPos2sMESA;
441 exec->WindowPos2svMESA = _mesa_WindowPos2svMESA;
442 exec->WindowPos3dMESA = _mesa_WindowPos3dMESA;
443 exec->WindowPos3dvMESA = _mesa_WindowPos3dvMESA;
444 exec->WindowPos3fMESA = _mesa_WindowPos3fMESA;
445 exec->WindowPos3fvMESA = _mesa_WindowPos3fvMESA;
446 exec->WindowPos3iMESA = _mesa_WindowPos3iMESA;
447 exec->WindowPos3ivMESA = _mesa_WindowPos3ivMESA;
448 exec->WindowPos3sMESA = _mesa_WindowPos3sMESA;
449 exec->WindowPos3svMESA = _mesa_WindowPos3svMESA;
450 exec->WindowPos4dMESA = _mesa_WindowPos4dMESA;
451 exec->WindowPos4dvMESA = _mesa_WindowPos4dvMESA;
452 exec->WindowPos4fMESA = _mesa_WindowPos4fMESA;
453 exec->WindowPos4fvMESA = _mesa_WindowPos4fvMESA;
454 exec->WindowPos4iMESA = _mesa_WindowPos4iMESA;
455 exec->WindowPos4ivMESA = _mesa_WindowPos4ivMESA;
456 exec->WindowPos4sMESA = _mesa_WindowPos4sMESA;
457 exec->WindowPos4svMESA = _mesa_WindowPos4svMESA;
458
459 /* ARB 1. GL_ARB_multitexture */
460 exec->ActiveTexture = _mesa_ActiveTextureARB;
461 exec->ClientActiveTexture = _mesa_ClientActiveTextureARB;
462
463 /* ARB 3. GL_ARB_transpose_matrix */
464 exec->LoadTransposeMatrixd = _mesa_LoadTransposeMatrixdARB;
465 exec->LoadTransposeMatrixf = _mesa_LoadTransposeMatrixfARB;
466 exec->MultTransposeMatrixd = _mesa_MultTransposeMatrixdARB;
467 exec->MultTransposeMatrixf = _mesa_MultTransposeMatrixfARB;
468
469 /* ARB 5. GL_ARB_multisample */
470 exec->SampleCoverage = _mesa_SampleCoverageARB;
471
472 /* ARB 12. GL_ARB_texture_compression */
473 exec->CompressedTexImage3D = _mesa_CompressedTexImage3DARB;
474 exec->CompressedTexImage2D = _mesa_CompressedTexImage2DARB;
475 exec->CompressedTexImage1D = _mesa_CompressedTexImage1DARB;
476 exec->CompressedTexSubImage3D = _mesa_CompressedTexSubImage3DARB;
477 exec->CompressedTexSubImage2D = _mesa_CompressedTexSubImage2DARB;
478 exec->CompressedTexSubImage1D = _mesa_CompressedTexSubImage1DARB;
479 exec->GetCompressedTexImage = _mesa_GetCompressedTexImageARB;
480
481 }
482
483
484
485 /**********************************************************************/
486 /***** State update logic *****/
487 /**********************************************************************/
488
489
490 static void
491 update_polygon( GLcontext *ctx )
492 {
493 ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
494
495 if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
496 ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
497
498 /* Any Polygon offsets enabled? */
499 ctx->Polygon._OffsetAny = GL_FALSE;
500 ctx->_TriangleCaps &= ~DD_TRI_OFFSET;
501
502 if (ctx->Polygon.OffsetPoint ||
503 ctx->Polygon.OffsetLine ||
504 ctx->Polygon.OffsetFill) {
505 ctx->_TriangleCaps |= DD_TRI_OFFSET;
506 ctx->Polygon._OffsetAny = GL_TRUE;
507 }
508 }
509
510 static void
511 calculate_model_project_matrix( GLcontext *ctx )
512 {
513 if (!ctx->_NeedEyeCoords) {
514 _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix,
515 &ctx->ProjectionMatrix,
516 &ctx->ModelView );
517
518 _math_matrix_analyse( &ctx->_ModelProjectMatrix );
519 }
520 }
521
522 static void
523 update_modelview_scale( GLcontext *ctx )
524 {
525 ctx->_ModelViewInvScale = 1.0F;
526 if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
527 MAT_FLAG_GENERAL_SCALE |
528 MAT_FLAG_GENERAL_3D |
529 MAT_FLAG_GENERAL) ) {
530 const GLfloat *m = ctx->ModelView.inv;
531 GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
532 if (f < 1e-12) f = 1.0;
533 if (ctx->_NeedEyeCoords)
534 ctx->_ModelViewInvScale = (GLfloat) (1.0/GL_SQRT(f));
535 else
536 ctx->_ModelViewInvScale = (GLfloat) GL_SQRT(f);
537 }
538 }
539
540
541 /* Bring uptodate any state that relies on _NeedEyeCoords.
542 */
543 static void
544 update_tnl_spaces( GLcontext *ctx, GLuint oldneedeyecoords )
545 {
546 /* Check if the truth-value interpretations of the bitfields have
547 * changed:
548 */
549 if ((oldneedeyecoords == 0) != (ctx->_NeedEyeCoords == 0)) {
550 /* Recalculate all state that depends on _NeedEyeCoords.
551 */
552 update_modelview_scale(ctx);
553 calculate_model_project_matrix(ctx);
554 _mesa_compute_light_positions( ctx );
555
556 if (ctx->Driver.LightingSpaceChange)
557 ctx->Driver.LightingSpaceChange( ctx );
558 }
559 else {
560 GLuint new_state = ctx->NewState;
561
562 /* Recalculate that same state only if it has been invalidated
563 * by other statechanges.
564 */
565 if (new_state & _NEW_MODELVIEW)
566 update_modelview_scale(ctx);
567
568 if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
569 calculate_model_project_matrix(ctx);
570
571 if (new_state & (_NEW_LIGHT|_NEW_MODELVIEW))
572 _mesa_compute_light_positions( ctx );
573 }
574 }
575
576
577 static void
578 update_drawbuffer( GLcontext *ctx )
579 {
580 ctx->DrawBuffer->_Xmin = 0;
581 ctx->DrawBuffer->_Ymin = 0;
582 ctx->DrawBuffer->_Xmax = ctx->DrawBuffer->Width;
583 ctx->DrawBuffer->_Ymax = ctx->DrawBuffer->Height;
584 if (ctx->Scissor.Enabled) {
585 if (ctx->Scissor.X > ctx->DrawBuffer->_Xmin) {
586 ctx->DrawBuffer->_Xmin = ctx->Scissor.X;
587 }
588 if (ctx->Scissor.Y > ctx->DrawBuffer->_Ymin) {
589 ctx->DrawBuffer->_Ymin = ctx->Scissor.Y;
590 }
591 if (ctx->Scissor.X + ctx->Scissor.Width < ctx->DrawBuffer->_Xmax) {
592 ctx->DrawBuffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width;
593 }
594 if (ctx->Scissor.Y + ctx->Scissor.Height < ctx->DrawBuffer->_Ymax) {
595 ctx->DrawBuffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
596 }
597 }
598 }
599
600
601 /* NOTE: This routine references Tranform attribute values to compute
602 * userclip positions in clip space, but is only called on
603 * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values
604 * uptodate across changes to the Transform attributes.
605 */
606 static void
607 update_projection( GLcontext *ctx )
608 {
609 _math_matrix_analyse( &ctx->ProjectionMatrix );
610
611 /* Recompute clip plane positions in clipspace. This is also done
612 * in _mesa_ClipPlane().
613 */
614 if (ctx->Transform._AnyClip) {
615 GLuint p;
616 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
617 if (ctx->Transform.ClipEnabled[p]) {
618 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
619 ctx->Transform.EyeUserPlane[p],
620 ctx->ProjectionMatrix.inv );
621 }
622 }
623 }
624 }
625
626
627 /*
628 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
629 * pixel transfer operations are enabled.
630 */
631 static void
632 update_image_transfer_state(GLcontext *ctx)
633 {
634 GLuint mask = 0;
635
636 if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
637 ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
638 ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
639 ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
640 mask |= IMAGE_SCALE_BIAS_BIT;
641
642 if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
643 mask |= IMAGE_SHIFT_OFFSET_BIT;
644
645 if (ctx->Pixel.MapColorFlag)
646 mask |= IMAGE_MAP_COLOR_BIT;
647
648 if (ctx->Pixel.ColorTableEnabled)
649 mask |= IMAGE_COLOR_TABLE_BIT;
650
651 if (ctx->Pixel.Convolution1DEnabled ||
652 ctx->Pixel.Convolution2DEnabled ||
653 ctx->Pixel.Separable2DEnabled) {
654 mask |= IMAGE_CONVOLUTION_BIT;
655 if (ctx->Pixel.PostConvolutionScale[0] != 1.0F ||
656 ctx->Pixel.PostConvolutionScale[1] != 1.0F ||
657 ctx->Pixel.PostConvolutionScale[2] != 1.0F ||
658 ctx->Pixel.PostConvolutionScale[3] != 1.0F ||
659 ctx->Pixel.PostConvolutionBias[0] != 0.0F ||
660 ctx->Pixel.PostConvolutionBias[1] != 0.0F ||
661 ctx->Pixel.PostConvolutionBias[2] != 0.0F ||
662 ctx->Pixel.PostConvolutionBias[3] != 0.0F) {
663 mask |= IMAGE_POST_CONVOLUTION_SCALE_BIAS;
664 }
665 }
666
667 if (ctx->Pixel.PostConvolutionColorTableEnabled)
668 mask |= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT;
669
670 if (ctx->ColorMatrix.type != MATRIX_IDENTITY ||
671 ctx->Pixel.PostColorMatrixScale[0] != 1.0F ||
672 ctx->Pixel.PostColorMatrixBias[0] != 0.0F ||
673 ctx->Pixel.PostColorMatrixScale[1] != 1.0F ||
674 ctx->Pixel.PostColorMatrixBias[1] != 0.0F ||
675 ctx->Pixel.PostColorMatrixScale[2] != 1.0F ||
676 ctx->Pixel.PostColorMatrixBias[2] != 0.0F ||
677 ctx->Pixel.PostColorMatrixScale[3] != 1.0F ||
678 ctx->Pixel.PostColorMatrixBias[3] != 0.0F)
679 mask |= IMAGE_COLOR_MATRIX_BIT;
680
681 if (ctx->Pixel.PostColorMatrixColorTableEnabled)
682 mask |= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT;
683
684 if (ctx->Pixel.HistogramEnabled)
685 mask |= IMAGE_HISTOGRAM_BIT;
686
687 if (ctx->Pixel.MinMaxEnabled)
688 mask |= IMAGE_MIN_MAX_BIT;
689
690 ctx->_ImageTransferState = mask;
691 }
692
693
694
695
696 /* Note: This routine refers to derived texture attribute values to
697 * compute the ENABLE_TEXMAT flags, but is only called on
698 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
699 * flags are updated by _mesa_update_textures(), below.
700 *
701 * If both TEXTURE and TEXTURE_MATRIX change at once, these values
702 * will be computed twice.
703 */
704 static void
705 update_texture_matrices( GLcontext *ctx )
706 {
707 GLuint i;
708
709 ctx->Texture._TexMatEnabled = 0;
710
711 for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
712 if (ctx->TextureMatrix[i].flags & MAT_DIRTY) {
713 _math_matrix_analyse( &ctx->TextureMatrix[i] );
714
715 if (ctx->Driver.TextureMatrix)
716 ctx->Driver.TextureMatrix( ctx, i, &ctx->TextureMatrix[i] );
717
718 if (ctx->Texture.Unit[i]._ReallyEnabled &&
719 ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
720 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
721 }
722 }
723 }
724
725
726 /* Note: This routine refers to derived texture matrix values to
727 * compute the ENABLE_TEXMAT flags, but is only called on
728 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
729 * flags are updated by _mesa_update_texture_matrices, above.
730 *
731 * If both TEXTURE and TEXTURE_MATRIX change at once, these values
732 * will be computed twice.
733 */
734 static void
735 update_texture_state( GLcontext *ctx )
736 {
737 GLuint i;
738
739 ctx->Texture._ReallyEnabled = 0;
740 ctx->Texture._GenFlags = 0;
741 ctx->_NeedNormals &= ~NEED_NORMALS_TEXGEN;
742 ctx->_NeedEyeCoords &= ~NEED_EYE_TEXGEN;
743 ctx->Texture._TexMatEnabled = 0;
744 ctx->Texture._TexGenEnabled = 0;
745
746 /* Update texture unit state.
747 */
748 for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
749 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
750
751 texUnit->_ReallyEnabled = 0;
752 texUnit->_GenFlags = 0;
753
754 if (!texUnit->Enabled)
755 continue;
756
757 /* Find the texture of highest dimensionality that is enabled
758 * and complete. We'll use it for texturing.
759 */
760 if (texUnit->Enabled & TEXTURE0_CUBE) {
761 struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
762 if (!texObj->Complete) {
763 _mesa_test_texobj_completeness(ctx, texObj);
764 }
765 if (texObj->Complete) {
766 texUnit->_ReallyEnabled = TEXTURE0_CUBE;
767 texUnit->_Current = texObj;
768 }
769 }
770
771 if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_3D)) {
772 struct gl_texture_object *texObj = texUnit->Current3D;
773 if (!texObj->Complete) {
774 _mesa_test_texobj_completeness(ctx, texObj);
775 }
776 if (texObj->Complete) {
777 texUnit->_ReallyEnabled = TEXTURE0_3D;
778 texUnit->_Current = texObj;
779 }
780 }
781
782 if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_2D)) {
783 struct gl_texture_object *texObj = texUnit->Current2D;
784 if (!texObj->Complete) {
785 _mesa_test_texobj_completeness(ctx, texObj);
786 }
787 if (texObj->Complete) {
788 texUnit->_ReallyEnabled = TEXTURE0_2D;
789 texUnit->_Current = texObj;
790 }
791 }
792
793 if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE0_1D)) {
794 struct gl_texture_object *texObj = texUnit->Current1D;
795 if (!texObj->Complete) {
796 _mesa_test_texobj_completeness(ctx, texObj);
797 }
798 if (texObj->Complete) {
799 texUnit->_ReallyEnabled = TEXTURE0_1D;
800 texUnit->_Current = texObj;
801 }
802 }
803
804 if (!texUnit->_ReallyEnabled) {
805 texUnit->_Current = NULL;
806 continue;
807 }
808
809 {
810 GLuint flag = texUnit->_ReallyEnabled << (i * 4);
811 ctx->Texture._ReallyEnabled |= flag;
812 }
813
814 if (texUnit->TexGenEnabled) {
815 if (texUnit->TexGenEnabled & S_BIT) {
816 texUnit->_GenFlags |= texUnit->_GenBitS;
817 }
818 if (texUnit->TexGenEnabled & T_BIT) {
819 texUnit->_GenFlags |= texUnit->_GenBitT;
820 }
821 if (texUnit->TexGenEnabled & Q_BIT) {
822 texUnit->_GenFlags |= texUnit->_GenBitQ;
823 }
824 if (texUnit->TexGenEnabled & R_BIT) {
825 texUnit->_GenFlags |= texUnit->_GenBitR;
826 }
827
828 ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(i);
829 ctx->Texture._GenFlags |= texUnit->_GenFlags;
830 }
831
832 if (ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
833 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
834 }
835
836 if (ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS) {
837 ctx->_NeedNormals |= NEED_NORMALS_TEXGEN;
838 ctx->_NeedEyeCoords |= NEED_EYE_TEXGEN;
839 }
840
841 if (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) {
842 ctx->_NeedEyeCoords |= NEED_EYE_TEXGEN;
843 }
844 }
845
846
847 /*
848 * If ctx->NewState is non-zero then this function MUST be called before
849 * rendering any primitive. Basically, function pointers and miscellaneous
850 * flags are updated to reflect the current state of the state machine.
851 *
852 * The above constraint is now maintained largely by the two Exec
853 * dispatch tables, which trigger the appropriate flush on transition
854 * between State and Geometry modes.
855 *
856 * Special care is taken with the derived value _NeedEyeCoords. This
857 * is a bitflag which is updated with information from a number of
858 * attribute groups (MODELVIEW, LIGHT, TEXTURE). A lot of derived
859 * state references this value, and must be treated with care to
860 * ensure that updates are done correctly. All state dependent on
861 * _NeedEyeCoords is calculated from within _mesa_update_tnl_spaces(),
862 * and from nowhere else.
863 */
864 void _mesa_update_state( GLcontext *ctx )
865 {
866 const GLuint new_state = ctx->NewState;
867 const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
868
869 if (MESA_VERBOSE & VERBOSE_STATE)
870 _mesa_print_state("", new_state);
871
872 if (new_state & _NEW_MODELVIEW)
873 _math_matrix_analyse( &ctx->ModelView );
874
875 if (new_state & _NEW_PROJECTION)
876 update_projection( ctx );
877
878 if (new_state & _NEW_TEXTURE_MATRIX)
879 update_texture_matrices( ctx );
880
881 if (new_state & _NEW_COLOR_MATRIX)
882 _math_matrix_analyse( &ctx->ColorMatrix );
883
884 /* References ColorMatrix.type (derived above).
885 */
886 if (new_state & _IMAGE_NEW_TRANSFER_STATE)
887 update_image_transfer_state(ctx);
888
889 /* Contributes to NeedEyeCoords, NeedNormals.
890 */
891 if (new_state & _NEW_TEXTURE)
892 update_texture_state( ctx );
893
894 if (new_state & (_NEW_BUFFERS|_NEW_SCISSOR))
895 update_drawbuffer( ctx );
896
897 if (new_state & _NEW_POLYGON)
898 update_polygon( ctx );
899
900 /* Contributes to NeedEyeCoords, NeedNormals.
901 */
902 if (new_state & _NEW_LIGHT)
903 _mesa_update_lighting( ctx );
904
905 /* We can light in object space if the modelview matrix preserves
906 * lengths and relative angles.
907 */
908 if (new_state & (_NEW_MODELVIEW|_NEW_LIGHT)) {
909 ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT_MODELVIEW;
910 if (ctx->Light.Enabled &&
911 !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
912 ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW;
913 }
914
915
916 /* ctx->_NeedEyeCoords is now uptodate.
917 *
918 * If the truth value of this variable has changed, update for the
919 * new lighting space and recompute the positions of lights and the
920 * normal transform.
921 *
922 * If the lighting space hasn't changed, may still need to recompute
923 * light positions & normal transforms for other reasons.
924 */
925 if (new_state & (_NEW_MODELVIEW |
926 _NEW_PROJECTION |
927 _NEW_LIGHT |
928 _MESA_NEW_NEED_EYE_COORDS))
929 update_tnl_spaces( ctx, oldneedeyecoords );
930
931 /*
932 * Here the driver sets up all the ctx->Driver function pointers
933 * to it's specific, private functions, and performs any
934 * internal state management necessary, including invalidating
935 * state of active modules.
936 *
937 * Set ctx->NewState to zero to avoid recursion if
938 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
939 */
940 ctx->NewState = 0;
941 ctx->Driver.UpdateState(ctx, new_state);
942 ctx->Array.NewState = 0;
943
944 /* At this point we can do some assertions to be sure the required
945 * device driver function pointers are all initialized.
946 */
947 ASSERT(ctx->Driver.GetString);
948 ASSERT(ctx->Driver.UpdateState);
949 ASSERT(ctx->Driver.Clear);
950 ASSERT(ctx->Driver.SetDrawBuffer);
951 ASSERT(ctx->Driver.GetBufferSize);
952 if (ctx->Visual.accumRedBits > 0) {
953 ASSERT(ctx->Driver.Accum);
954 }
955 ASSERT(ctx->Driver.DrawPixels);
956 ASSERT(ctx->Driver.ReadPixels);
957 ASSERT(ctx->Driver.CopyPixels);
958 ASSERT(ctx->Driver.Bitmap);
959 ASSERT(ctx->Driver.ResizeBuffersMESA);
960 ASSERT(ctx->Driver.TexImage1D);
961 ASSERT(ctx->Driver.TexImage2D);
962 ASSERT(ctx->Driver.TexImage3D);
963 ASSERT(ctx->Driver.TexSubImage1D);
964 ASSERT(ctx->Driver.TexSubImage2D);
965 ASSERT(ctx->Driver.TexSubImage3D);
966 ASSERT(ctx->Driver.CopyTexImage1D);
967 ASSERT(ctx->Driver.CopyTexImage2D);
968 ASSERT(ctx->Driver.CopyTexSubImage1D);
969 ASSERT(ctx->Driver.CopyTexSubImage2D);
970 ASSERT(ctx->Driver.CopyTexSubImage3D);
971 if (ctx->Extensions.ARB_texture_compression) {
972 ASSERT(ctx->Driver.BaseCompressedTexFormat);
973 ASSERT(ctx->Driver.CompressedTextureSize);
974 ASSERT(ctx->Driver.GetCompressedTexImage);
975 #if 0 /* HW drivers need these, but not SW rasterizers */
976 ASSERT(ctx->Driver.CompressedTexImage1D);
977 ASSERT(ctx->Driver.CompressedTexImage2D);
978 ASSERT(ctx->Driver.CompressedTexImage3D);
979 ASSERT(ctx->Driver.CompressedTexSubImage1D);
980 ASSERT(ctx->Driver.CompressedTexSubImage2D);
981 ASSERT(ctx->Driver.CompressedTexSubImage3D);
982 #endif
983 }
984 }