Implemented GL_EXT_depth_bounds_test.
[mesa.git] / src / mesa / main / state.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 /*
27 * /brief This file manages recalculation of derived values in the
28 * __GLcontext. Also, this is where we initialize the API dispatch table.
29 */
30
31
32 #include "glheader.h"
33 #include "accum.h"
34 #include "api_loopback.h"
35 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
36 #include "arbprogram.h"
37 #endif
38 #include "attrib.h"
39 #include "blend.h"
40 #if FEATURE_ARB_vertex_buffer_object
41 #include "bufferobj.h"
42 #endif
43 #include "buffers.h"
44 #include "clip.h"
45 #include "colortab.h"
46 #include "context.h"
47 #include "convolve.h"
48 #include "depth.h"
49 #include "dlist.h"
50 #include "drawpix.h"
51 #include "enable.h"
52 #include "eval.h"
53 #include "get.h"
54 #include "feedback.h"
55 #include "fog.h"
56 #include "hint.h"
57 #include "histogram.h"
58 #include "imports.h"
59 #include "light.h"
60 #include "lines.h"
61 #include "matrix.h"
62 #include "pixel.h"
63 #include "points.h"
64 #include "polygon.h"
65 #include "rastpos.h"
66 #include "state.h"
67 #include "stencil.h"
68 #include "teximage.h"
69 #include "texobj.h"
70 #include "texstate.h"
71 #include "mtypes.h"
72 #include "varray.h"
73 #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
74 #include "nvprogram.h"
75 #endif
76 #if FEATURE_NV_fragment_program
77 #include "nvfragprog.h"
78 #endif
79
80 #include "math/m_matrix.h"
81 #include "math/m_xform.h"
82
83
84 static int
85 generic_noop(void)
86 {
87 #ifdef DEBUG
88 _mesa_problem(NULL, "User called no-op dispatch function");
89 #endif
90 return 0;
91 }
92
93
94 /*
95 * Set all pointers in the given dispatch table to point to a
96 * generic no-op function.
97 */
98 void
99 _mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
100 {
101 GLuint i;
102 void **dispatch = (void **) table;
103 for (i = 0; i < tableSize; i++) {
104 dispatch[i] = (void *) generic_noop;
105 }
106 }
107
108
109
110 /*
111 * Initialize the given dispatch table with pointers to Mesa's
112 * immediate-mode commands.
113 *
114 * Pointers to begin/end object commands and a few others
115 * are provided via the vtxfmt interface elsewhere.
116 */
117 void
118 _mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
119 {
120 /* first initialize all dispatch slots to no-op */
121 _mesa_init_no_op_table(exec, tableSize);
122
123 _mesa_loopback_init_api_table( exec, GL_TRUE );
124
125 /* load the dispatch slots we understand */
126 exec->Accum = _mesa_Accum;
127 exec->AlphaFunc = _mesa_AlphaFunc;
128 exec->Bitmap = _mesa_Bitmap;
129 exec->BlendFunc = _mesa_BlendFunc;
130 exec->CallList = _mesa_CallList;
131 exec->CallLists = _mesa_CallLists;
132 exec->Clear = _mesa_Clear;
133 exec->ClearAccum = _mesa_ClearAccum;
134 exec->ClearColor = _mesa_ClearColor;
135 exec->ClearDepth = _mesa_ClearDepth;
136 exec->ClearIndex = _mesa_ClearIndex;
137 exec->ClearStencil = _mesa_ClearStencil;
138 exec->ClipPlane = _mesa_ClipPlane;
139 exec->ColorMask = _mesa_ColorMask;
140 exec->ColorMaterial = _mesa_ColorMaterial;
141 exec->CopyPixels = _mesa_CopyPixels;
142 exec->CullFace = _mesa_CullFace;
143 exec->DeleteLists = _mesa_DeleteLists;
144 exec->DepthFunc = _mesa_DepthFunc;
145 exec->DepthMask = _mesa_DepthMask;
146 exec->DepthRange = _mesa_DepthRange;
147 exec->Disable = _mesa_Disable;
148 exec->DrawBuffer = _mesa_DrawBuffer;
149 exec->DrawPixels = _mesa_DrawPixels;
150 exec->Enable = _mesa_Enable;
151 exec->EndList = _mesa_EndList;
152 exec->FeedbackBuffer = _mesa_FeedbackBuffer;
153 exec->Finish = _mesa_Finish;
154 exec->Flush = _mesa_Flush;
155 exec->FogCoordPointerEXT = _mesa_FogCoordPointerEXT;
156 exec->Fogf = _mesa_Fogf;
157 exec->Fogfv = _mesa_Fogfv;
158 exec->Fogi = _mesa_Fogi;
159 exec->Fogiv = _mesa_Fogiv;
160 exec->FrontFace = _mesa_FrontFace;
161 exec->Frustum = _mesa_Frustum;
162 exec->GenLists = _mesa_GenLists;
163 exec->GetBooleanv = _mesa_GetBooleanv;
164 exec->GetClipPlane = _mesa_GetClipPlane;
165 exec->GetDoublev = _mesa_GetDoublev;
166 exec->GetError = _mesa_GetError;
167 exec->GetFloatv = _mesa_GetFloatv;
168 exec->GetIntegerv = _mesa_GetIntegerv;
169 exec->GetLightfv = _mesa_GetLightfv;
170 exec->GetLightiv = _mesa_GetLightiv;
171 exec->GetMapdv = _mesa_GetMapdv;
172 exec->GetMapfv = _mesa_GetMapfv;
173 exec->GetMapiv = _mesa_GetMapiv;
174 exec->GetMaterialfv = _mesa_GetMaterialfv;
175 exec->GetMaterialiv = _mesa_GetMaterialiv;
176 exec->GetPixelMapfv = _mesa_GetPixelMapfv;
177 exec->GetPixelMapuiv = _mesa_GetPixelMapuiv;
178 exec->GetPixelMapusv = _mesa_GetPixelMapusv;
179 exec->GetPolygonStipple = _mesa_GetPolygonStipple;
180 exec->GetString = _mesa_GetString;
181 exec->GetTexEnvfv = _mesa_GetTexEnvfv;
182 exec->GetTexEnviv = _mesa_GetTexEnviv;
183 exec->GetTexGendv = _mesa_GetTexGendv;
184 exec->GetTexGenfv = _mesa_GetTexGenfv;
185 exec->GetTexGeniv = _mesa_GetTexGeniv;
186 exec->GetTexImage = _mesa_GetTexImage;
187 exec->GetTexLevelParameterfv = _mesa_GetTexLevelParameterfv;
188 exec->GetTexLevelParameteriv = _mesa_GetTexLevelParameteriv;
189 exec->GetTexParameterfv = _mesa_GetTexParameterfv;
190 exec->GetTexParameteriv = _mesa_GetTexParameteriv;
191 exec->Hint = _mesa_Hint;
192 exec->IndexMask = _mesa_IndexMask;
193 exec->InitNames = _mesa_InitNames;
194 exec->IsEnabled = _mesa_IsEnabled;
195 exec->IsList = _mesa_IsList;
196 exec->LightModelf = _mesa_LightModelf;
197 exec->LightModelfv = _mesa_LightModelfv;
198 exec->LightModeli = _mesa_LightModeli;
199 exec->LightModeliv = _mesa_LightModeliv;
200 exec->Lightf = _mesa_Lightf;
201 exec->Lightfv = _mesa_Lightfv;
202 exec->Lighti = _mesa_Lighti;
203 exec->Lightiv = _mesa_Lightiv;
204 exec->LineStipple = _mesa_LineStipple;
205 exec->LineWidth = _mesa_LineWidth;
206 exec->ListBase = _mesa_ListBase;
207 exec->LoadIdentity = _mesa_LoadIdentity;
208 exec->LoadMatrixd = _mesa_LoadMatrixd;
209 exec->LoadMatrixf = _mesa_LoadMatrixf;
210 exec->LoadName = _mesa_LoadName;
211 exec->LogicOp = _mesa_LogicOp;
212 exec->Map1d = _mesa_Map1d;
213 exec->Map1f = _mesa_Map1f;
214 exec->Map2d = _mesa_Map2d;
215 exec->Map2f = _mesa_Map2f;
216 exec->MapGrid1d = _mesa_MapGrid1d;
217 exec->MapGrid1f = _mesa_MapGrid1f;
218 exec->MapGrid2d = _mesa_MapGrid2d;
219 exec->MapGrid2f = _mesa_MapGrid2f;
220 exec->MatrixMode = _mesa_MatrixMode;
221 exec->MultMatrixd = _mesa_MultMatrixd;
222 exec->MultMatrixf = _mesa_MultMatrixf;
223 exec->NewList = _mesa_NewList;
224 exec->Ortho = _mesa_Ortho;
225 exec->PassThrough = _mesa_PassThrough;
226 exec->PixelMapfv = _mesa_PixelMapfv;
227 exec->PixelMapuiv = _mesa_PixelMapuiv;
228 exec->PixelMapusv = _mesa_PixelMapusv;
229 exec->PixelStoref = _mesa_PixelStoref;
230 exec->PixelStorei = _mesa_PixelStorei;
231 exec->PixelTransferf = _mesa_PixelTransferf;
232 exec->PixelTransferi = _mesa_PixelTransferi;
233 exec->PixelZoom = _mesa_PixelZoom;
234 exec->PointSize = _mesa_PointSize;
235 exec->PolygonMode = _mesa_PolygonMode;
236 exec->PolygonOffset = _mesa_PolygonOffset;
237 exec->PolygonStipple = _mesa_PolygonStipple;
238 exec->PopAttrib = _mesa_PopAttrib;
239 exec->PopMatrix = _mesa_PopMatrix;
240 exec->PopName = _mesa_PopName;
241 exec->PushAttrib = _mesa_PushAttrib;
242 exec->PushMatrix = _mesa_PushMatrix;
243 exec->PushName = _mesa_PushName;
244 exec->RasterPos2d = _mesa_RasterPos2d;
245 exec->RasterPos2dv = _mesa_RasterPos2dv;
246 exec->RasterPos2f = _mesa_RasterPos2f;
247 exec->RasterPos2fv = _mesa_RasterPos2fv;
248 exec->RasterPos2i = _mesa_RasterPos2i;
249 exec->RasterPos2iv = _mesa_RasterPos2iv;
250 exec->RasterPos2s = _mesa_RasterPos2s;
251 exec->RasterPos2sv = _mesa_RasterPos2sv;
252 exec->RasterPos3d = _mesa_RasterPos3d;
253 exec->RasterPos3dv = _mesa_RasterPos3dv;
254 exec->RasterPos3f = _mesa_RasterPos3f;
255 exec->RasterPos3fv = _mesa_RasterPos3fv;
256 exec->RasterPos3i = _mesa_RasterPos3i;
257 exec->RasterPos3iv = _mesa_RasterPos3iv;
258 exec->RasterPos3s = _mesa_RasterPos3s;
259 exec->RasterPos3sv = _mesa_RasterPos3sv;
260 exec->RasterPos4d = _mesa_RasterPos4d;
261 exec->RasterPos4dv = _mesa_RasterPos4dv;
262 exec->RasterPos4f = _mesa_RasterPos4f;
263 exec->RasterPos4fv = _mesa_RasterPos4fv;
264 exec->RasterPos4i = _mesa_RasterPos4i;
265 exec->RasterPos4iv = _mesa_RasterPos4iv;
266 exec->RasterPos4s = _mesa_RasterPos4s;
267 exec->RasterPos4sv = _mesa_RasterPos4sv;
268 exec->ReadBuffer = _mesa_ReadBuffer;
269 exec->ReadPixels = _mesa_ReadPixels;
270 exec->RenderMode = _mesa_RenderMode;
271 exec->Rotated = _mesa_Rotated;
272 exec->Rotatef = _mesa_Rotatef;
273 exec->Scaled = _mesa_Scaled;
274 exec->Scalef = _mesa_Scalef;
275 exec->Scissor = _mesa_Scissor;
276 exec->SecondaryColorPointerEXT = _mesa_SecondaryColorPointerEXT;
277 exec->SelectBuffer = _mesa_SelectBuffer;
278 exec->ShadeModel = _mesa_ShadeModel;
279 exec->StencilFunc = _mesa_StencilFunc;
280 exec->StencilMask = _mesa_StencilMask;
281 exec->StencilOp = _mesa_StencilOp;
282 exec->TexEnvf = _mesa_TexEnvf;
283 exec->TexEnvfv = _mesa_TexEnvfv;
284 exec->TexEnvi = _mesa_TexEnvi;
285 exec->TexEnviv = _mesa_TexEnviv;
286 exec->TexGend = _mesa_TexGend;
287 exec->TexGendv = _mesa_TexGendv;
288 exec->TexGenf = _mesa_TexGenf;
289 exec->TexGenfv = _mesa_TexGenfv;
290 exec->TexGeni = _mesa_TexGeni;
291 exec->TexGeniv = _mesa_TexGeniv;
292 exec->TexImage1D = _mesa_TexImage1D;
293 exec->TexImage2D = _mesa_TexImage2D;
294 exec->TexParameterf = _mesa_TexParameterf;
295 exec->TexParameterfv = _mesa_TexParameterfv;
296 exec->TexParameteri = _mesa_TexParameteri;
297 exec->TexParameteriv = _mesa_TexParameteriv;
298 exec->Translated = _mesa_Translated;
299 exec->Translatef = _mesa_Translatef;
300 exec->Viewport = _mesa_Viewport;
301
302 /* 1.1 */
303 exec->AreTexturesResident = _mesa_AreTexturesResident;
304 exec->AreTexturesResidentEXT = _mesa_AreTexturesResident;
305 exec->BindTexture = _mesa_BindTexture;
306 exec->ColorPointer = _mesa_ColorPointer;
307 exec->CopyTexImage1D = _mesa_CopyTexImage1D;
308 exec->CopyTexImage2D = _mesa_CopyTexImage2D;
309 exec->CopyTexSubImage1D = _mesa_CopyTexSubImage1D;
310 exec->CopyTexSubImage2D = _mesa_CopyTexSubImage2D;
311 exec->DeleteTextures = _mesa_DeleteTextures;
312 exec->DisableClientState = _mesa_DisableClientState;
313 exec->EdgeFlagPointer = _mesa_EdgeFlagPointer;
314 exec->EnableClientState = _mesa_EnableClientState;
315 exec->GenTextures = _mesa_GenTextures;
316 exec->GenTexturesEXT = _mesa_GenTextures;
317 exec->GetPointerv = _mesa_GetPointerv;
318 exec->IndexPointer = _mesa_IndexPointer;
319 exec->InterleavedArrays = _mesa_InterleavedArrays;
320 exec->IsTexture = _mesa_IsTexture;
321 exec->IsTextureEXT = _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->GetColorTableEXT = _mesa_GetColorTable;
355 exec->GetColorTableParameterfv = _mesa_GetColorTableParameterfv;
356 exec->GetColorTableParameterfvEXT = _mesa_GetColorTableParameterfv;
357 exec->GetColorTableParameteriv = _mesa_GetColorTableParameteriv;
358 exec->GetColorTableParameterivEXT = _mesa_GetColorTableParameteriv;
359 exec->GetConvolutionFilter = _mesa_GetConvolutionFilter;
360 exec->GetConvolutionFilterEXT = _mesa_GetConvolutionFilter;
361 exec->GetConvolutionParameterfv = _mesa_GetConvolutionParameterfv;
362 exec->GetConvolutionParameterfvEXT = _mesa_GetConvolutionParameterfv;
363 exec->GetConvolutionParameteriv = _mesa_GetConvolutionParameteriv;
364 exec->GetConvolutionParameterivEXT = _mesa_GetConvolutionParameteriv;
365 exec->GetHistogram = _mesa_GetHistogram;
366 exec->GetHistogramEXT = _mesa_GetHistogram;
367 exec->GetHistogramParameterfv = _mesa_GetHistogramParameterfv;
368 exec->GetHistogramParameterfvEXT = _mesa_GetHistogramParameterfv;
369 exec->GetHistogramParameteriv = _mesa_GetHistogramParameteriv;
370 exec->GetHistogramParameterivEXT = _mesa_GetHistogramParameteriv;
371 exec->GetMinmax = _mesa_GetMinmax;
372 exec->GetMinmaxEXT = _mesa_GetMinmax;
373 exec->GetMinmaxParameterfv = _mesa_GetMinmaxParameterfv;
374 exec->GetMinmaxParameterfvEXT = _mesa_GetMinmaxParameterfv;
375 exec->GetMinmaxParameteriv = _mesa_GetMinmaxParameteriv;
376 exec->GetMinmaxParameterivEXT = _mesa_GetMinmaxParameteriv;
377 exec->GetSeparableFilter = _mesa_GetSeparableFilter;
378 exec->GetSeparableFilterEXT = _mesa_GetSeparableFilter;
379 exec->Histogram = _mesa_Histogram;
380 exec->Minmax = _mesa_Minmax;
381 exec->ResetHistogram = _mesa_ResetHistogram;
382 exec->ResetMinmax = _mesa_ResetMinmax;
383 exec->SeparableFilter2D = _mesa_SeparableFilter2D;
384
385 /* 2. GL_EXT_blend_color */
386 #if 0
387 exec->BlendColorEXT = _mesa_BlendColorEXT;
388 #endif
389
390 /* 3. GL_EXT_polygon_offset */
391 exec->PolygonOffsetEXT = _mesa_PolygonOffsetEXT;
392
393 /* 6. GL_EXT_texture3d */
394 #if 0
395 exec->CopyTexSubImage3DEXT = _mesa_CopyTexSubImage3D;
396 exec->TexImage3DEXT = _mesa_TexImage3DEXT;
397 exec->TexSubImage3DEXT = _mesa_TexSubImage3D;
398 #endif
399
400 /* 11. GL_EXT_histogram */
401 exec->GetHistogramEXT = _mesa_GetHistogram;
402 exec->GetHistogramParameterfvEXT = _mesa_GetHistogramParameterfv;
403 exec->GetHistogramParameterivEXT = _mesa_GetHistogramParameteriv;
404 exec->GetMinmaxEXT = _mesa_GetMinmax;
405 exec->GetMinmaxParameterfvEXT = _mesa_GetMinmaxParameterfv;
406 exec->GetMinmaxParameterivEXT = _mesa_GetMinmaxParameteriv;
407
408 /* ?. GL_SGIX_pixel_texture */
409 exec->PixelTexGenSGIX = _mesa_PixelTexGenSGIX;
410
411 /* 15. GL_SGIS_pixel_texture */
412 exec->PixelTexGenParameteriSGIS = _mesa_PixelTexGenParameteriSGIS;
413 exec->PixelTexGenParameterivSGIS = _mesa_PixelTexGenParameterivSGIS;
414 exec->PixelTexGenParameterfSGIS = _mesa_PixelTexGenParameterfSGIS;
415 exec->PixelTexGenParameterfvSGIS = _mesa_PixelTexGenParameterfvSGIS;
416 exec->GetPixelTexGenParameterivSGIS = _mesa_GetPixelTexGenParameterivSGIS;
417 exec->GetPixelTexGenParameterfvSGIS = _mesa_GetPixelTexGenParameterfvSGIS;
418
419 /* 30. GL_EXT_vertex_array */
420 exec->ColorPointerEXT = _mesa_ColorPointerEXT;
421 exec->EdgeFlagPointerEXT = _mesa_EdgeFlagPointerEXT;
422 exec->IndexPointerEXT = _mesa_IndexPointerEXT;
423 exec->NormalPointerEXT = _mesa_NormalPointerEXT;
424 exec->TexCoordPointerEXT = _mesa_TexCoordPointerEXT;
425 exec->VertexPointerEXT = _mesa_VertexPointerEXT;
426
427 /* 37. GL_EXT_blend_minmax */
428 #if 0
429 exec->BlendEquationEXT = _mesa_BlendEquationEXT;
430 #endif
431
432 /* 54. GL_EXT_point_parameters */
433 exec->PointParameterfEXT = _mesa_PointParameterfEXT;
434 exec->PointParameterfvEXT = _mesa_PointParameterfvEXT;
435
436 /* 78. GL_EXT_paletted_texture */
437 #if 0
438 exec->ColorTableEXT = _mesa_ColorTableEXT;
439 exec->ColorSubTableEXT = _mesa_ColorSubTableEXT;
440 #endif
441 exec->GetColorTableEXT = _mesa_GetColorTable;
442 exec->GetColorTableParameterfvEXT = _mesa_GetColorTableParameterfv;
443 exec->GetColorTableParameterivEXT = _mesa_GetColorTableParameteriv;
444
445 /* 97. GL_EXT_compiled_vertex_array */
446 exec->LockArraysEXT = _mesa_LockArraysEXT;
447 exec->UnlockArraysEXT = _mesa_UnlockArraysEXT;
448
449 /* 148. GL_EXT_multi_draw_arrays */
450 exec->MultiDrawArraysEXT = _mesa_MultiDrawArraysEXT;
451 exec->MultiDrawElementsEXT = _mesa_MultiDrawElementsEXT;
452
453 /* 173. GL_INGR_blend_func_separate */
454 exec->BlendFuncSeparateEXT = _mesa_BlendFuncSeparateEXT;
455
456 /* 196. GL_MESA_resize_buffers */
457 exec->ResizeBuffersMESA = _mesa_ResizeBuffersMESA;
458
459 /* 197. GL_MESA_window_pos */
460 exec->WindowPos2dMESA = _mesa_WindowPos2dMESA;
461 exec->WindowPos2dvMESA = _mesa_WindowPos2dvMESA;
462 exec->WindowPos2fMESA = _mesa_WindowPos2fMESA;
463 exec->WindowPos2fvMESA = _mesa_WindowPos2fvMESA;
464 exec->WindowPos2iMESA = _mesa_WindowPos2iMESA;
465 exec->WindowPos2ivMESA = _mesa_WindowPos2ivMESA;
466 exec->WindowPos2sMESA = _mesa_WindowPos2sMESA;
467 exec->WindowPos2svMESA = _mesa_WindowPos2svMESA;
468 exec->WindowPos3dMESA = _mesa_WindowPos3dMESA;
469 exec->WindowPos3dvMESA = _mesa_WindowPos3dvMESA;
470 exec->WindowPos3fMESA = _mesa_WindowPos3fMESA;
471 exec->WindowPos3fvMESA = _mesa_WindowPos3fvMESA;
472 exec->WindowPos3iMESA = _mesa_WindowPos3iMESA;
473 exec->WindowPos3ivMESA = _mesa_WindowPos3ivMESA;
474 exec->WindowPos3sMESA = _mesa_WindowPos3sMESA;
475 exec->WindowPos3svMESA = _mesa_WindowPos3svMESA;
476 exec->WindowPos4dMESA = _mesa_WindowPos4dMESA;
477 exec->WindowPos4dvMESA = _mesa_WindowPos4dvMESA;
478 exec->WindowPos4fMESA = _mesa_WindowPos4fMESA;
479 exec->WindowPos4fvMESA = _mesa_WindowPos4fvMESA;
480 exec->WindowPos4iMESA = _mesa_WindowPos4iMESA;
481 exec->WindowPos4ivMESA = _mesa_WindowPos4ivMESA;
482 exec->WindowPos4sMESA = _mesa_WindowPos4sMESA;
483 exec->WindowPos4svMESA = _mesa_WindowPos4svMESA;
484
485 /* 233. GL_NV_vertex_program */
486 #if FEATURE_NV_vertex_program
487 exec->BindProgramNV = _mesa_BindProgramNV;
488 exec->DeleteProgramsNV = _mesa_DeleteProgramsNV;
489 exec->ExecuteProgramNV = _mesa_ExecuteProgramNV;
490 exec->GenProgramsNV = _mesa_GenProgramsNV;
491 exec->AreProgramsResidentNV = _mesa_AreProgramsResidentNV;
492 exec->RequestResidentProgramsNV = _mesa_RequestResidentProgramsNV;
493 exec->GetProgramParameterfvNV = _mesa_GetProgramParameterfvNV;
494 exec->GetProgramParameterdvNV = _mesa_GetProgramParameterdvNV;
495 exec->GetProgramivNV = _mesa_GetProgramivNV;
496 exec->GetProgramStringNV = _mesa_GetProgramStringNV;
497 exec->GetTrackMatrixivNV = _mesa_GetTrackMatrixivNV;
498 exec->GetVertexAttribdvNV = _mesa_GetVertexAttribdvNV;
499 exec->GetVertexAttribfvNV = _mesa_GetVertexAttribfvNV;
500 exec->GetVertexAttribivNV = _mesa_GetVertexAttribivNV;
501 exec->GetVertexAttribPointervNV = _mesa_GetVertexAttribPointervNV;
502 exec->IsProgramNV = _mesa_IsProgramNV;
503 exec->LoadProgramNV = _mesa_LoadProgramNV;
504 exec->ProgramParameter4dNV = _mesa_ProgramParameter4dNV;
505 exec->ProgramParameter4dvNV = _mesa_ProgramParameter4dvNV;
506 exec->ProgramParameter4fNV = _mesa_ProgramParameter4fNV;
507 exec->ProgramParameter4fvNV = _mesa_ProgramParameter4fvNV;
508 exec->ProgramParameters4dvNV = _mesa_ProgramParameters4dvNV;
509 exec->ProgramParameters4fvNV = _mesa_ProgramParameters4fvNV;
510 exec->TrackMatrixNV = _mesa_TrackMatrixNV;
511 exec->VertexAttribPointerNV = _mesa_VertexAttribPointerNV;
512 #endif
513
514 /* 282. GL_NV_fragment_program */
515 #if FEATURE_NV_fragment_program
516 exec->ProgramNamedParameter4fNV = _mesa_ProgramNamedParameter4fNV;
517 exec->ProgramNamedParameter4dNV = _mesa_ProgramNamedParameter4dNV;
518 exec->ProgramNamedParameter4fvNV = _mesa_ProgramNamedParameter4fvNV;
519 exec->ProgramNamedParameter4dvNV = _mesa_ProgramNamedParameter4dvNV;
520 exec->GetProgramNamedParameterfvNV = _mesa_GetProgramNamedParameterfvNV;
521 exec->GetProgramNamedParameterdvNV = _mesa_GetProgramNamedParameterdvNV;
522 exec->ProgramLocalParameter4dARB = _mesa_ProgramLocalParameter4dARB;
523 exec->ProgramLocalParameter4dvARB = _mesa_ProgramLocalParameter4dvARB;
524 exec->ProgramLocalParameter4fARB = _mesa_ProgramLocalParameter4fARB;
525 exec->ProgramLocalParameter4fvARB = _mesa_ProgramLocalParameter4fvARB;
526 exec->GetProgramLocalParameterdvARB = _mesa_GetProgramLocalParameterdvARB;
527 exec->GetProgramLocalParameterfvARB = _mesa_GetProgramLocalParameterfvARB;
528 #endif
529
530 /* 262. GL_NV_point_sprite */
531 exec->PointParameteriNV = _mesa_PointParameteriNV;
532 exec->PointParameterivNV = _mesa_PointParameterivNV;
533
534 /* 268. GL_EXT_stencil_two_side */
535 exec->ActiveStencilFaceEXT = _mesa_ActiveStencilFaceEXT;
536
537 /* ???. GL_EXT_depth_bounds_test */
538 exec->DepthBoundsEXT = _mesa_DepthBoundsEXT;
539
540 /* ARB 1. GL_ARB_multitexture */
541 exec->ActiveTextureARB = _mesa_ActiveTextureARB;
542 exec->ClientActiveTextureARB = _mesa_ClientActiveTextureARB;
543
544 /* ARB 3. GL_ARB_transpose_matrix */
545 exec->LoadTransposeMatrixdARB = _mesa_LoadTransposeMatrixdARB;
546 exec->LoadTransposeMatrixfARB = _mesa_LoadTransposeMatrixfARB;
547 exec->MultTransposeMatrixdARB = _mesa_MultTransposeMatrixdARB;
548 exec->MultTransposeMatrixfARB = _mesa_MultTransposeMatrixfARB;
549
550 /* ARB 5. GL_ARB_multisample */
551 exec->SampleCoverageARB = _mesa_SampleCoverageARB;
552
553 /* ARB 12. GL_ARB_texture_compression */
554 exec->CompressedTexImage3DARB = _mesa_CompressedTexImage3DARB;
555 exec->CompressedTexImage2DARB = _mesa_CompressedTexImage2DARB;
556 exec->CompressedTexImage1DARB = _mesa_CompressedTexImage1DARB;
557 exec->CompressedTexSubImage3DARB = _mesa_CompressedTexSubImage3DARB;
558 exec->CompressedTexSubImage2DARB = _mesa_CompressedTexSubImage2DARB;
559 exec->CompressedTexSubImage1DARB = _mesa_CompressedTexSubImage1DARB;
560 exec->GetCompressedTexImageARB = _mesa_GetCompressedTexImageARB;
561
562 /* ARB 14. GL_ARB_point_parameters */
563 /* reuse EXT_point_parameters functions */
564
565 /* ARB 26. GL_ARB_vertex_program */
566 /* ARB 27. GL_ARB_fragment_program */
567 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
568 /* glVertexAttrib1sARB aliases glVertexAttrib1sNV */
569 /* glVertexAttrib1fARB aliases glVertexAttrib1fNV */
570 /* glVertexAttrib1dARB aliases glVertexAttrib1dNV */
571 /* glVertexAttrib2sARB aliases glVertexAttrib2sNV */
572 /* glVertexAttrib2fARB aliases glVertexAttrib2fNV */
573 /* glVertexAttrib2dARB aliases glVertexAttrib2dNV */
574 /* glVertexAttrib3sARB aliases glVertexAttrib3sNV */
575 /* glVertexAttrib3fARB aliases glVertexAttrib3fNV */
576 /* glVertexAttrib3dARB aliases glVertexAttrib3dNV */
577 /* glVertexAttrib4sARB aliases glVertexAttrib4sNV */
578 /* glVertexAttrib4fARB aliases glVertexAttrib4fNV */
579 /* glVertexAttrib4dARB aliases glVertexAttrib4dNV */
580 /* glVertexAttrib4NubARB aliases glVertexAttrib4NubNV */
581 /* glVertexAttrib1svARB aliases glVertexAttrib1svNV */
582 /* glVertexAttrib1fvARB aliases glVertexAttrib1fvNV */
583 /* glVertexAttrib1dvARB aliases glVertexAttrib1dvNV */
584 /* glVertexAttrib2svARB aliases glVertexAttrib2svNV */
585 /* glVertexAttrib2fvARB aliases glVertexAttrib2fvNV */
586 /* glVertexAttrib2dvARB aliases glVertexAttrib2dvNV */
587 /* glVertexAttrib3svARB aliases glVertexAttrib3svNV */
588 /* glVertexAttrib3fvARB aliases glVertexAttrib3fvNV */
589 /* glVertexAttrib3dvARB aliases glVertexAttrib3dvNV */
590 /* glVertexAttrib4svARB aliases glVertexAttrib4svNV */
591 /* glVertexAttrib4fvARB aliases glVertexAttrib4fvNV */
592 /* glVertexAttrib4dvARB aliases glVertexAttrib4dvNV */
593 /* glVertexAttrib4NubvARB aliases glVertexAttrib4NubvNV */
594 exec->VertexAttrib4bvARB = _mesa_VertexAttrib4bvARB;
595 exec->VertexAttrib4ivARB = _mesa_VertexAttrib4ivARB;
596 exec->VertexAttrib4ubvARB = _mesa_VertexAttrib4ubvARB;
597 exec->VertexAttrib4usvARB = _mesa_VertexAttrib4usvARB;
598 exec->VertexAttrib4uivARB = _mesa_VertexAttrib4uivARB;
599 exec->VertexAttrib4NbvARB = _mesa_VertexAttrib4NbvARB;
600 exec->VertexAttrib4NsvARB = _mesa_VertexAttrib4NsvARB;
601 exec->VertexAttrib4NivARB = _mesa_VertexAttrib4NivARB;
602 exec->VertexAttrib4NusvARB = _mesa_VertexAttrib4NusvARB;
603 exec->VertexAttrib4NuivARB = _mesa_VertexAttrib4NuivARB;
604 exec->VertexAttribPointerARB = _mesa_VertexAttribPointerARB;
605 exec->EnableVertexAttribArrayARB = _mesa_EnableVertexAttribArrayARB;
606 exec->DisableVertexAttribArrayARB = _mesa_DisableVertexAttribArrayARB;
607 exec->ProgramStringARB = _mesa_ProgramStringARB;
608 /* glBindProgramARB aliases glBindProgramNV */
609 /* glDeleteProgramsARB aliases glDeleteProgramsNV */
610 /* glGenProgramsARB aliases glGenProgramsNV */
611 /* glIsProgramARB aliases glIsProgramNV */
612 /* glGetVertexAttribdvARB aliases glGetVertexAttribdvNV */
613 /* glGetVertexAttribfvARB aliases glGetVertexAttribfvNV */
614 /* glGetVertexAttribivARB aliases glGetVertexAttribivNV */
615 /* glGetVertexAttribPointervARB aliases glGetVertexAttribPointervNV */
616 exec->ProgramEnvParameter4dARB = _mesa_ProgramEnvParameter4dARB;
617 exec->ProgramEnvParameter4dvARB = _mesa_ProgramEnvParameter4dvARB;
618 exec->ProgramEnvParameter4fARB = _mesa_ProgramEnvParameter4fARB;
619 exec->ProgramEnvParameter4fvARB = _mesa_ProgramEnvParameter4fvARB;
620 exec->ProgramLocalParameter4dARB = _mesa_ProgramLocalParameter4dARB;
621 exec->ProgramLocalParameter4dvARB = _mesa_ProgramLocalParameter4dvARB;
622 exec->ProgramLocalParameter4fARB = _mesa_ProgramLocalParameter4fARB;
623 exec->ProgramLocalParameter4fvARB = _mesa_ProgramLocalParameter4fvARB;
624 exec->GetProgramEnvParameterdvARB = _mesa_GetProgramEnvParameterdvARB;
625 exec->GetProgramEnvParameterfvARB = _mesa_GetProgramEnvParameterfvARB;
626 exec->GetProgramLocalParameterdvARB = _mesa_GetProgramLocalParameterdvARB;
627 exec->GetProgramLocalParameterfvARB = _mesa_GetProgramLocalParameterfvARB;
628 exec->GetProgramivARB = _mesa_GetProgramivARB;
629 exec->GetProgramStringARB = _mesa_GetProgramStringARB;
630 #endif
631
632 /* ARB 28. GL_ARB_vertex_buffer_object */
633 #if FEATURE_ARB_vertex_buffer_object
634 exec->BindBufferARB = _mesa_BindBufferARB;
635 exec->BufferDataARB = _mesa_BufferDataARB;
636 exec->BufferSubDataARB = _mesa_BufferSubDataARB;
637 exec->DeleteBuffersARB = _mesa_DeleteBuffersARB;
638 exec->GenBuffersARB = _mesa_GenBuffersARB;
639 exec->GetBufferParameterivARB = _mesa_GetBufferParameterivARB;
640 exec->GetBufferPointervARB = _mesa_GetBufferPointervARB;
641 exec->GetBufferSubDataARB = _mesa_GetBufferSubDataARB;
642 exec->IsBufferARB = _mesa_IsBufferARB;
643 exec->MapBufferARB = _mesa_MapBufferARB;
644 exec->UnmapBufferARB = _mesa_UnmapBufferARB;
645 #endif
646 }
647
648
649
650 /**********************************************************************/
651 /***** State update logic *****/
652 /**********************************************************************/
653
654
655 /*
656 * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
657 * in ctx->_TriangleCaps if needed.
658 */
659 static void
660 update_polygon( GLcontext *ctx )
661 {
662 ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
663
664 if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
665 ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
666
667 /* Any Polygon offsets enabled? */
668 if (ctx->Polygon.OffsetPoint ||
669 ctx->Polygon.OffsetLine ||
670 ctx->Polygon.OffsetFill) {
671 ctx->_TriangleCaps |= DD_TRI_OFFSET;
672 }
673 }
674
675 static void
676 calculate_model_project_matrix( GLcontext *ctx )
677 {
678 _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix,
679 ctx->ProjectionMatrixStack.Top,
680 ctx->ModelviewMatrixStack.Top );
681
682 _math_matrix_analyse( &ctx->_ModelProjectMatrix );
683 }
684
685 static void
686 update_modelview_scale( GLcontext *ctx )
687 {
688 ctx->_ModelViewInvScale = 1.0F;
689 if (ctx->ModelviewMatrixStack.Top->flags & (MAT_FLAG_UNIFORM_SCALE |
690 MAT_FLAG_GENERAL_SCALE |
691 MAT_FLAG_GENERAL_3D |
692 MAT_FLAG_GENERAL) ) {
693 const GLfloat *m = ctx->ModelviewMatrixStack.Top->inv;
694 GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
695 if (f < 1e-12) f = 1.0;
696 if (ctx->_NeedEyeCoords)
697 ctx->_ModelViewInvScale = 1.0F / SQRTF(f);
698 else
699 ctx->_ModelViewInvScale = SQRTF(f);
700 }
701 }
702
703
704 /* Bring uptodate any state that relies on _NeedEyeCoords.
705 */
706 static void
707 update_tnl_spaces( GLcontext *ctx, GLuint oldneedeyecoords )
708 {
709 /* Check if the truth-value interpretations of the bitfields have
710 * changed:
711 */
712 if ((oldneedeyecoords == 0) != (ctx->_NeedEyeCoords == 0)) {
713 /* Recalculate all state that depends on _NeedEyeCoords.
714 */
715 update_modelview_scale(ctx);
716 _mesa_compute_light_positions( ctx );
717
718 if (ctx->Driver.LightingSpaceChange)
719 ctx->Driver.LightingSpaceChange( ctx );
720 }
721 else {
722 GLuint new_state = ctx->NewState;
723
724 /* Recalculate that same state only if it has been invalidated
725 * by other statechanges.
726 */
727 if (new_state & _NEW_MODELVIEW)
728 update_modelview_scale(ctx);
729
730 if (new_state & (_NEW_LIGHT|_NEW_MODELVIEW))
731 _mesa_compute_light_positions( ctx );
732 }
733 }
734
735
736 static void
737 update_drawbuffer( GLcontext *ctx )
738 {
739 ctx->DrawBuffer->_Xmin = 0;
740 ctx->DrawBuffer->_Ymin = 0;
741 ctx->DrawBuffer->_Xmax = ctx->DrawBuffer->Width;
742 ctx->DrawBuffer->_Ymax = ctx->DrawBuffer->Height;
743 if (ctx->Scissor.Enabled) {
744 if (ctx->Scissor.X > ctx->DrawBuffer->_Xmin) {
745 ctx->DrawBuffer->_Xmin = ctx->Scissor.X;
746 }
747 if (ctx->Scissor.Y > ctx->DrawBuffer->_Ymin) {
748 ctx->DrawBuffer->_Ymin = ctx->Scissor.Y;
749 }
750 if (ctx->Scissor.X + ctx->Scissor.Width < ctx->DrawBuffer->_Xmax) {
751 ctx->DrawBuffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width;
752 }
753 if (ctx->Scissor.Y + ctx->Scissor.Height < ctx->DrawBuffer->_Ymax) {
754 ctx->DrawBuffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
755 }
756 }
757 }
758
759
760 /* NOTE: This routine references Tranform attribute values to compute
761 * userclip positions in clip space, but is only called on
762 * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values
763 * up to date across changes to the Transform attributes.
764 */
765 static void
766 update_projection( GLcontext *ctx )
767 {
768 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
769
770 /* Recompute clip plane positions in clipspace. This is also done
771 * in _mesa_ClipPlane().
772 */
773 if (ctx->Transform.ClipPlanesEnabled) {
774 GLuint p;
775 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
776 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
777 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
778 ctx->Transform.EyeUserPlane[p],
779 ctx->ProjectionMatrixStack.Top->inv );
780 }
781 }
782 }
783 }
784
785
786 /*
787 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
788 * pixel transfer operations are enabled.
789 */
790 static void
791 update_image_transfer_state(GLcontext *ctx)
792 {
793 GLuint mask = 0;
794
795 if (ctx->Pixel.RedScale != 1.0F || ctx->Pixel.RedBias != 0.0F ||
796 ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
797 ctx->Pixel.BlueScale != 1.0F || ctx->Pixel.BlueBias != 0.0F ||
798 ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
799 mask |= IMAGE_SCALE_BIAS_BIT;
800
801 if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
802 mask |= IMAGE_SHIFT_OFFSET_BIT;
803
804 if (ctx->Pixel.MapColorFlag)
805 mask |= IMAGE_MAP_COLOR_BIT;
806
807 if (ctx->Pixel.ColorTableEnabled)
808 mask |= IMAGE_COLOR_TABLE_BIT;
809
810 if (ctx->Pixel.Convolution1DEnabled ||
811 ctx->Pixel.Convolution2DEnabled ||
812 ctx->Pixel.Separable2DEnabled) {
813 mask |= IMAGE_CONVOLUTION_BIT;
814 if (ctx->Pixel.PostConvolutionScale[0] != 1.0F ||
815 ctx->Pixel.PostConvolutionScale[1] != 1.0F ||
816 ctx->Pixel.PostConvolutionScale[2] != 1.0F ||
817 ctx->Pixel.PostConvolutionScale[3] != 1.0F ||
818 ctx->Pixel.PostConvolutionBias[0] != 0.0F ||
819 ctx->Pixel.PostConvolutionBias[1] != 0.0F ||
820 ctx->Pixel.PostConvolutionBias[2] != 0.0F ||
821 ctx->Pixel.PostConvolutionBias[3] != 0.0F) {
822 mask |= IMAGE_POST_CONVOLUTION_SCALE_BIAS;
823 }
824 }
825
826 if (ctx->Pixel.PostConvolutionColorTableEnabled)
827 mask |= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT;
828
829 if (ctx->ColorMatrixStack.Top->type != MATRIX_IDENTITY ||
830 ctx->Pixel.PostColorMatrixScale[0] != 1.0F ||
831 ctx->Pixel.PostColorMatrixBias[0] != 0.0F ||
832 ctx->Pixel.PostColorMatrixScale[1] != 1.0F ||
833 ctx->Pixel.PostColorMatrixBias[1] != 0.0F ||
834 ctx->Pixel.PostColorMatrixScale[2] != 1.0F ||
835 ctx->Pixel.PostColorMatrixBias[2] != 0.0F ||
836 ctx->Pixel.PostColorMatrixScale[3] != 1.0F ||
837 ctx->Pixel.PostColorMatrixBias[3] != 0.0F)
838 mask |= IMAGE_COLOR_MATRIX_BIT;
839
840 if (ctx->Pixel.PostColorMatrixColorTableEnabled)
841 mask |= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT;
842
843 if (ctx->Pixel.HistogramEnabled)
844 mask |= IMAGE_HISTOGRAM_BIT;
845
846 if (ctx->Pixel.MinMaxEnabled)
847 mask |= IMAGE_MIN_MAX_BIT;
848
849 ctx->_ImageTransferState = mask;
850 }
851
852
853
854
855 /* Note: This routine refers to derived texture attribute values to
856 * compute the ENABLE_TEXMAT flags, but is only called on
857 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
858 * flags are updated by _mesa_update_textures(), below.
859 *
860 * If both TEXTURE and TEXTURE_MATRIX change at once, these values
861 * will be computed twice.
862 */
863 static void
864 update_texture_matrices( GLcontext *ctx )
865 {
866 GLuint i;
867
868 ctx->Texture._TexMatEnabled = 0;
869
870 for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
871 if (ctx->TextureMatrixStack[i].Top->flags & MAT_DIRTY) {
872 _math_matrix_analyse( ctx->TextureMatrixStack[i].Top );
873
874 if (ctx->Texture.Unit[i]._ReallyEnabled &&
875 ctx->TextureMatrixStack[i].Top->type != MATRIX_IDENTITY)
876 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
877
878 if (ctx->Driver.TextureMatrix)
879 ctx->Driver.TextureMatrix( ctx, i, ctx->TextureMatrixStack[i].Top);
880 }
881 }
882 }
883
884
885 /* Note: This routine refers to derived texture matrix values to
886 * compute the ENABLE_TEXMAT flags, but is only called on
887 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
888 * flags are updated by _mesa_update_texture_matrices, above.
889 *
890 * If both TEXTURE and TEXTURE_MATRIX change at once, these values
891 * will be computed twice.
892 */
893 static void
894 update_texture_state( GLcontext *ctx )
895 {
896 GLuint unit;
897
898 ctx->Texture._EnabledUnits = 0;
899 ctx->Texture._GenFlags = 0;
900 ctx->_NeedNormals &= ~NEED_NORMALS_TEXGEN;
901 ctx->_NeedEyeCoords &= ~NEED_EYE_TEXGEN;
902 ctx->Texture._TexMatEnabled = 0;
903 ctx->Texture._TexGenEnabled = 0;
904
905 /* Update texture unit state.
906 */
907 for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
908 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
909 GLuint enableBits;
910
911 texUnit->_ReallyEnabled = 0;
912 texUnit->_GenFlags = 0;
913
914 /* Get the bitmask of texture enables */
915 if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
916 enableBits = ctx->FragmentProgram.Current->TexturesUsed[unit];
917 }
918 else {
919 if (!texUnit->Enabled)
920 continue;
921 enableBits = texUnit->Enabled;
922 }
923
924 /* Look for the highest-priority texture target that's enabled and
925 * complete. That's the one we'll use for texturing. If we're using
926 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
927 */
928 if (enableBits & TEXTURE_CUBE_BIT) {
929 struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
930 if (!texObj->Complete) {
931 _mesa_test_texobj_completeness(ctx, texObj);
932 }
933 if (texObj->Complete) {
934 texUnit->_ReallyEnabled = TEXTURE_CUBE_BIT;
935 texUnit->_Current = texObj;
936 }
937 }
938
939 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_3D_BIT)) {
940 struct gl_texture_object *texObj = texUnit->Current3D;
941 if (!texObj->Complete) {
942 _mesa_test_texobj_completeness(ctx, texObj);
943 }
944 if (texObj->Complete) {
945 texUnit->_ReallyEnabled = TEXTURE_3D_BIT;
946 texUnit->_Current = texObj;
947 }
948 }
949
950 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_RECT_BIT)) {
951 struct gl_texture_object *texObj = texUnit->CurrentRect;
952 if (!texObj->Complete) {
953 _mesa_test_texobj_completeness(ctx, texObj);
954 }
955 if (texObj->Complete) {
956 texUnit->_ReallyEnabled = TEXTURE_RECT_BIT;
957 texUnit->_Current = texObj;
958 }
959 }
960
961 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_2D_BIT)) {
962 struct gl_texture_object *texObj = texUnit->Current2D;
963 if (!texObj->Complete) {
964 _mesa_test_texobj_completeness(ctx, texObj);
965 }
966 if (texObj->Complete) {
967 texUnit->_ReallyEnabled = TEXTURE_2D_BIT;
968 texUnit->_Current = texObj;
969 }
970 }
971
972 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_1D_BIT)) {
973 struct gl_texture_object *texObj = texUnit->Current1D;
974 if (!texObj->Complete) {
975 _mesa_test_texobj_completeness(ctx, texObj);
976 }
977 if (texObj->Complete) {
978 texUnit->_ReallyEnabled = TEXTURE_1D_BIT;
979 texUnit->_Current = texObj;
980 }
981 }
982
983 if (!texUnit->_ReallyEnabled) {
984 texUnit->_Current = NULL;
985 continue;
986 }
987
988 if (texUnit->_ReallyEnabled)
989 ctx->Texture._EnabledUnits |= (1 << unit);
990
991 if (texUnit->TexGenEnabled) {
992 if (texUnit->TexGenEnabled & S_BIT) {
993 texUnit->_GenFlags |= texUnit->_GenBitS;
994 }
995 if (texUnit->TexGenEnabled & T_BIT) {
996 texUnit->_GenFlags |= texUnit->_GenBitT;
997 }
998 if (texUnit->TexGenEnabled & Q_BIT) {
999 texUnit->_GenFlags |= texUnit->_GenBitQ;
1000 }
1001 if (texUnit->TexGenEnabled & R_BIT) {
1002 texUnit->_GenFlags |= texUnit->_GenBitR;
1003 }
1004
1005 ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
1006 ctx->Texture._GenFlags |= texUnit->_GenFlags;
1007 }
1008
1009 if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
1010 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
1011 }
1012
1013 if (ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS) {
1014 ctx->_NeedNormals |= NEED_NORMALS_TEXGEN;
1015 ctx->_NeedEyeCoords |= NEED_EYE_TEXGEN;
1016 }
1017
1018 if (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD) {
1019 ctx->_NeedEyeCoords |= NEED_EYE_TEXGEN;
1020 }
1021
1022 ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
1023 /* Fragment programs may need texture coordinates but not the
1024 * corresponding texture images.
1025 */
1026 if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
1027 ctx->Texture._EnabledCoordUnits |=
1028 (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0);
1029 }
1030 }
1031
1032
1033 /*
1034 * Update items which depend on vertex/fragment programs.
1035 */
1036 static void
1037 update_program( GLcontext *ctx )
1038 {
1039 if (ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current) {
1040 if (ctx->FragmentProgram.Current->InputsRead & (1 << FRAG_ATTRIB_COL1))
1041 ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
1042 }
1043 }
1044
1045
1046 /*
1047 * If ctx->NewState is non-zero then this function MUST be called before
1048 * rendering any primitive. Basically, function pointers and miscellaneous
1049 * flags are updated to reflect the current state of the state machine.
1050 *
1051 * The above constraint is now maintained largely by the two Exec
1052 * dispatch tables, which trigger the appropriate flush on transition
1053 * between State and Geometry modes.
1054 *
1055 * Special care is taken with the derived value _NeedEyeCoords. This
1056 * is a bitflag which is updated with information from a number of
1057 * attribute groups (MODELVIEW, LIGHT, TEXTURE). A lot of derived
1058 * state references this value, and must be treated with care to
1059 * ensure that updates are done correctly. All state dependent on
1060 * _NeedEyeCoords is calculated from within _mesa_update_tnl_spaces(),
1061 * and from nowhere else.
1062 */
1063 void _mesa_update_state( GLcontext *ctx )
1064 {
1065 const GLuint new_state = ctx->NewState;
1066 const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
1067
1068 if (MESA_VERBOSE & VERBOSE_STATE)
1069 _mesa_print_state("_mesa_update_state", new_state);
1070
1071 if (new_state & _NEW_MODELVIEW)
1072 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
1073
1074 if (new_state & _NEW_PROJECTION)
1075 update_projection( ctx );
1076
1077 if (new_state & _NEW_TEXTURE_MATRIX)
1078 update_texture_matrices( ctx );
1079
1080 if (new_state & _NEW_COLOR_MATRIX)
1081 _math_matrix_analyse( ctx->ColorMatrixStack.Top );
1082
1083 /* References ColorMatrix.type (derived above).
1084 */
1085 if (new_state & _IMAGE_NEW_TRANSFER_STATE)
1086 update_image_transfer_state(ctx);
1087
1088 /* Contributes to NeedEyeCoords, NeedNormals.
1089 */
1090 if (new_state & _NEW_TEXTURE)
1091 update_texture_state( ctx );
1092
1093 if (new_state & (_NEW_BUFFERS|_NEW_SCISSOR))
1094 update_drawbuffer( ctx );
1095
1096 if (new_state & _NEW_POLYGON)
1097 update_polygon( ctx );
1098
1099 /* Contributes to NeedEyeCoords, NeedNormals.
1100 */
1101 if (new_state & _NEW_LIGHT)
1102 _mesa_update_lighting( ctx );
1103
1104 /* We can light in object space if the modelview matrix preserves
1105 * lengths and relative angles.
1106 */
1107 if (new_state & (_NEW_MODELVIEW|_NEW_LIGHT)) {
1108 ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT_MODELVIEW;
1109 if (ctx->Light.Enabled &&
1110 !TEST_MAT_FLAGS( ctx->ModelviewMatrixStack.Top, MAT_FLAGS_LENGTH_PRESERVING))
1111 ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW;
1112 }
1113
1114 if (new_state & _NEW_PROGRAM)
1115 update_program( ctx );
1116
1117 #if 0
1118 /* XXX this is a bit of a hack. We should be checking elsewhere if
1119 * vertex program mode is enabled. We set _NeedEyeCoords to zero to
1120 * ensure that the combined modelview/projection matrix is computed
1121 * in calculate_model_project_matrix().
1122 */
1123 if (ctx->VertexProgram.Enabled)
1124 ctx->_NeedEyeCoords = 0;
1125 /* KW: it's now always computed.
1126 */
1127 #endif
1128
1129 /* Keep ModelviewProject uptodate always to allow tnl
1130 * implementations that go model->clip even when eye is required.
1131 */
1132 if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
1133 calculate_model_project_matrix(ctx);
1134
1135 /* ctx->_NeedEyeCoords is now uptodate.
1136 *
1137 * If the truth value of this variable has changed, update for the
1138 * new lighting space and recompute the positions of lights and the
1139 * normal transform.
1140 *
1141 * If the lighting space hasn't changed, may still need to recompute
1142 * light positions & normal transforms for other reasons.
1143 */
1144 if (new_state & (_NEW_MODELVIEW |
1145 _NEW_LIGHT |
1146 _MESA_NEW_NEED_EYE_COORDS))
1147 update_tnl_spaces( ctx, oldneedeyecoords );
1148
1149 /*
1150 * Here the driver sets up all the ctx->Driver function pointers
1151 * to it's specific, private functions, and performs any
1152 * internal state management necessary, including invalidating
1153 * state of active modules.
1154 *
1155 * Set ctx->NewState to zero to avoid recursion if
1156 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
1157 */
1158 ctx->NewState = 0;
1159 ctx->Driver.UpdateState(ctx, new_state);
1160 ctx->Array.NewState = 0;
1161
1162 /* At this point we can do some assertions to be sure the required
1163 * device driver function pointers are all initialized.
1164 */
1165 ASSERT(ctx->Driver.GetString);
1166 ASSERT(ctx->Driver.UpdateState);
1167 ASSERT(ctx->Driver.Clear);
1168 ASSERT(ctx->Driver.GetBufferSize);
1169 if (ctx->Visual.accumRedBits > 0) {
1170 ASSERT(ctx->Driver.Accum);
1171 }
1172 ASSERT(ctx->Driver.DrawPixels);
1173 ASSERT(ctx->Driver.ReadPixels);
1174 ASSERT(ctx->Driver.CopyPixels);
1175 ASSERT(ctx->Driver.Bitmap);
1176 ASSERT(ctx->Driver.ResizeBuffers);
1177 ASSERT(ctx->Driver.TexImage1D);
1178 ASSERT(ctx->Driver.TexImage2D);
1179 ASSERT(ctx->Driver.TexImage3D);
1180 ASSERT(ctx->Driver.TexSubImage1D);
1181 ASSERT(ctx->Driver.TexSubImage2D);
1182 ASSERT(ctx->Driver.TexSubImage3D);
1183 ASSERT(ctx->Driver.CopyTexImage1D);
1184 ASSERT(ctx->Driver.CopyTexImage2D);
1185 ASSERT(ctx->Driver.CopyTexSubImage1D);
1186 ASSERT(ctx->Driver.CopyTexSubImage2D);
1187 ASSERT(ctx->Driver.CopyTexSubImage3D);
1188 if (ctx->Extensions.ARB_texture_compression) {
1189 #if 0 /* HW drivers need these, but not SW rasterizers */
1190 ASSERT(ctx->Driver.CompressedTexImage1D);
1191 ASSERT(ctx->Driver.CompressedTexImage2D);
1192 ASSERT(ctx->Driver.CompressedTexImage3D);
1193 ASSERT(ctx->Driver.CompressedTexSubImage1D);
1194 ASSERT(ctx->Driver.CompressedTexSubImage2D);
1195 ASSERT(ctx->Driver.CompressedTexSubImage3D);
1196 #endif
1197 }
1198 }
1199
1200 /* Is this helpful?
1201 */
1202 void
1203 _mesa_allow_light_in_model( GLcontext *ctx, GLboolean flag )
1204 {
1205 if (flag)
1206 ctx->_NeedEyeCoords &= ~NEED_EYE_DRIVER;
1207 else
1208 ctx->_NeedEyeCoords |= NEED_EYE_DRIVER;
1209
1210 ctx->NewState |= _NEW_POINT; /* one of the bits from
1211 * _MESA_NEW_NEED_EYE_COORDS.
1212 */
1213 }