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