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