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