state.c revision f1d6b384415a083c358d3824e77f3d434f08bfcc
1/* $Id: state.c,v 1.52 2000/12/16 00:19:12 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  3.5
6 *
7 * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28/*
29 * This file initializes the immediate-mode dispatch table (which may
30 * be state-dependant) and manages internal Mesa state update.
31 */
32
33
34#ifdef PC_HEADER
35#include "all.h"
36#else
37#include "glheader.h"
38#include "accum.h"
39#include "alpha.h"
40#include "api_loopback.h"
41#include "attrib.h"
42#include "bitmap.h"
43#include "blend.h"
44#include "buffers.h"
45#include "clip.h"
46#include "colortab.h"
47#include "context.h"
48#include "convolve.h"
49#include "copypix.h"
50#include "depth.h"
51#include "dlist.h"
52#include "drawpix.h"
53#include "enable.h"
54#include "eval.h"
55#include "get.h"
56#include "feedback.h"
57#include "fog.h"
58#include "hint.h"
59#include "histogram.h"
60#include "light.h"
61#include "lines.h"
62#include "logic.h"
63#include "masking.h"
64#include "matrix.h"
65#include "mmath.h"
66#include "pixel.h"
67#include "pixeltex.h"
68#include "points.h"
69#include "polygon.h"
70#include "rastpos.h"
71#include "readpix.h"
72#include "scissor.h"
73#include "state.h"
74#include "stencil.h"
75#include "teximage.h"
76#include "texobj.h"
77#include "texstate.h"
78#include "texture.h"
79#include "mtypes.h"
80#include "varray.h"
81#include "winpos.h"
82
83#include "swrast/swrast.h"
84#include "math/m_matrix.h"
85#include "math/m_xform.h"
86#endif
87
88
89
90static int
91generic_noop(void)
92{
93#ifdef DEBUG
94   gl_problem(NULL, "undefined function dispatch");
95#endif
96   return 0;
97}
98
99
100/*
101 * Set all pointers in the given dispatch table to point to a
102 * generic no-op function.
103 */
104void
105_mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
106{
107   GLuint i;
108   void **dispatch = (void **) table;
109   for (i = 0; i < tableSize; i++) {
110      dispatch[i] = (void *) generic_noop;
111   }
112}
113
114
115/*
116 * Initialize the given dispatch table with pointers to Mesa's
117 * immediate-mode commands.
118 *
119 * Pointers to begin/end object commands and a few others
120 * are provided via the vtxfmt interface elsewhere.
121 */
122void
123_mesa_init_exec_table(struct _glapi_table *exec, GLuint tableSize)
124{
125   /* first initialize all dispatch slots to no-op */
126   _mesa_init_no_op_table(exec, tableSize);
127
128   _mesa_loopback_init_api_table( exec, GL_FALSE );
129
130   /* load the dispatch slots we understand */
131   exec->Accum = _mesa_Accum;
132   exec->AlphaFunc = _mesa_AlphaFunc;
133   exec->Bitmap = _mesa_Bitmap;
134   exec->BlendFunc = _mesa_BlendFunc;
135   exec->CallList = _mesa_CallList;
136   exec->CallLists = _mesa_CallLists;
137   exec->Clear = _mesa_Clear;
138   exec->ClearAccum = _mesa_ClearAccum;
139   exec->ClearColor = _mesa_ClearColor;
140   exec->ClearDepth = _mesa_ClearDepth;
141   exec->ClearIndex = _mesa_ClearIndex;
142   exec->ClearStencil = _mesa_ClearStencil;
143   exec->ClipPlane = _mesa_ClipPlane;
144   exec->ColorMask = _mesa_ColorMask;
145   exec->ColorMaterial = _mesa_ColorMaterial;
146   exec->CopyPixels = _mesa_CopyPixels;
147   exec->CullFace = _mesa_CullFace;
148   exec->DeleteLists = _mesa_DeleteLists;
149   exec->DepthFunc = _mesa_DepthFunc;
150   exec->DepthMask = _mesa_DepthMask;
151   exec->DepthRange = _mesa_DepthRange;
152   exec->Disable = _mesa_Disable;
153   exec->DrawBuffer = _mesa_DrawBuffer;
154   exec->DrawPixels = _mesa_DrawPixels;
155   exec->Enable = _mesa_Enable;
156   exec->EndList = _mesa_EndList;
157   exec->FeedbackBuffer = _mesa_FeedbackBuffer;
158   exec->Finish = _mesa_Finish;
159   exec->Flush = _mesa_Flush;
160   exec->FogCoordPointerEXT = _mesa_FogCoordPointerEXT;
161   exec->Fogf = _mesa_Fogf;
162   exec->Fogfv = _mesa_Fogfv;
163   exec->Fogi = _mesa_Fogi;
164   exec->Fogiv = _mesa_Fogiv;
165   exec->FrontFace = _mesa_FrontFace;
166   exec->Frustum = _mesa_Frustum;
167   exec->GenLists = _mesa_GenLists;
168   exec->GetBooleanv = _mesa_GetBooleanv;
169   exec->GetClipPlane = _mesa_GetClipPlane;
170   exec->GetDoublev = _mesa_GetDoublev;
171   exec->GetError = _mesa_GetError;
172   exec->GetFloatv = _mesa_GetFloatv;
173   exec->GetIntegerv = _mesa_GetIntegerv;
174   exec->GetLightfv = _mesa_GetLightfv;
175   exec->GetLightiv = _mesa_GetLightiv;
176   exec->GetMapdv = _mesa_GetMapdv;
177   exec->GetMapfv = _mesa_GetMapfv;
178   exec->GetMapiv = _mesa_GetMapiv;
179   exec->GetMaterialfv = _mesa_GetMaterialfv;
180   exec->GetMaterialiv = _mesa_GetMaterialiv;
181   exec->GetPixelMapfv = _mesa_GetPixelMapfv;
182   exec->GetPixelMapuiv = _mesa_GetPixelMapuiv;
183   exec->GetPixelMapusv = _mesa_GetPixelMapusv;
184   exec->GetPolygonStipple = _mesa_GetPolygonStipple;
185   exec->GetString = _mesa_GetString;
186   exec->GetTexEnvfv = _mesa_GetTexEnvfv;
187   exec->GetTexEnviv = _mesa_GetTexEnviv;
188   exec->GetTexGendv = _mesa_GetTexGendv;
189   exec->GetTexGenfv = _mesa_GetTexGenfv;
190   exec->GetTexGeniv = _mesa_GetTexGeniv;
191   exec->GetTexImage = _mesa_GetTexImage;
192   exec->GetTexLevelParameterfv = _mesa_GetTexLevelParameterfv;
193   exec->GetTexLevelParameteriv = _mesa_GetTexLevelParameteriv;
194   exec->GetTexParameterfv = _mesa_GetTexParameterfv;
195   exec->GetTexParameteriv = _mesa_GetTexParameteriv;
196   exec->Hint = _mesa_Hint;
197   exec->IndexMask = _mesa_IndexMask;
198   exec->InitNames = _mesa_InitNames;
199   exec->IsEnabled = _mesa_IsEnabled;
200   exec->IsList = _mesa_IsList;
201   exec->LightModelf = _mesa_LightModelf;
202   exec->LightModelfv = _mesa_LightModelfv;
203   exec->LightModeli = _mesa_LightModeli;
204   exec->LightModeliv = _mesa_LightModeliv;
205   exec->Lightf = _mesa_Lightf;
206   exec->Lightfv = _mesa_Lightfv;
207   exec->Lighti = _mesa_Lighti;
208   exec->Lightiv = _mesa_Lightiv;
209   exec->LineStipple = _mesa_LineStipple;
210   exec->LineWidth = _mesa_LineWidth;
211   exec->ListBase = _mesa_ListBase;
212   exec->LoadIdentity = _mesa_LoadIdentity;
213   exec->LoadMatrixd = _mesa_LoadMatrixd;
214   exec->LoadMatrixf = _mesa_LoadMatrixf;
215   exec->LoadName = _mesa_LoadName;
216   exec->LogicOp = _mesa_LogicOp;
217   exec->Map1d = _mesa_Map1d;
218   exec->Map1f = _mesa_Map1f;
219   exec->Map2d = _mesa_Map2d;
220   exec->Map2f = _mesa_Map2f;
221   exec->MapGrid1d = _mesa_MapGrid1d;
222   exec->MapGrid1f = _mesa_MapGrid1f;
223   exec->MapGrid2d = _mesa_MapGrid2d;
224   exec->MapGrid2f = _mesa_MapGrid2f;
225   exec->MatrixMode = _mesa_MatrixMode;
226   exec->MultMatrixd = _mesa_MultMatrixd;
227   exec->MultMatrixf = _mesa_MultMatrixf;
228   exec->NewList = _mesa_NewList;
229   exec->Ortho = _mesa_Ortho;
230   exec->PassThrough = _mesa_PassThrough;
231   exec->PixelMapfv = _mesa_PixelMapfv;
232   exec->PixelMapuiv = _mesa_PixelMapuiv;
233   exec->PixelMapusv = _mesa_PixelMapusv;
234   exec->PixelStoref = _mesa_PixelStoref;
235   exec->PixelStorei = _mesa_PixelStorei;
236   exec->PixelTransferf = _mesa_PixelTransferf;
237   exec->PixelTransferi = _mesa_PixelTransferi;
238   exec->PixelZoom = _mesa_PixelZoom;
239   exec->PointSize = _mesa_PointSize;
240   exec->PolygonMode = _mesa_PolygonMode;
241   exec->PolygonOffset = _mesa_PolygonOffset;
242   exec->PolygonStipple = _mesa_PolygonStipple;
243   exec->PopAttrib = _mesa_PopAttrib;
244   exec->PopMatrix = _mesa_PopMatrix;
245   exec->PopName = _mesa_PopName;
246   exec->PushAttrib = _mesa_PushAttrib;
247   exec->PushMatrix = _mesa_PushMatrix;
248   exec->PushName = _mesa_PushName;
249   exec->RasterPos2d = _mesa_RasterPos2d;
250   exec->RasterPos2dv = _mesa_RasterPos2dv;
251   exec->RasterPos2f = _mesa_RasterPos2f;
252   exec->RasterPos2fv = _mesa_RasterPos2fv;
253   exec->RasterPos2i = _mesa_RasterPos2i;
254   exec->RasterPos2iv = _mesa_RasterPos2iv;
255   exec->RasterPos2s = _mesa_RasterPos2s;
256   exec->RasterPos2sv = _mesa_RasterPos2sv;
257   exec->RasterPos3d = _mesa_RasterPos3d;
258   exec->RasterPos3dv = _mesa_RasterPos3dv;
259   exec->RasterPos3f = _mesa_RasterPos3f;
260   exec->RasterPos3fv = _mesa_RasterPos3fv;
261   exec->RasterPos3i = _mesa_RasterPos3i;
262   exec->RasterPos3iv = _mesa_RasterPos3iv;
263   exec->RasterPos3s = _mesa_RasterPos3s;
264   exec->RasterPos3sv = _mesa_RasterPos3sv;
265   exec->RasterPos4d = _mesa_RasterPos4d;
266   exec->RasterPos4dv = _mesa_RasterPos4dv;
267   exec->RasterPos4f = _mesa_RasterPos4f;
268   exec->RasterPos4fv = _mesa_RasterPos4fv;
269   exec->RasterPos4i = _mesa_RasterPos4i;
270   exec->RasterPos4iv = _mesa_RasterPos4iv;
271   exec->RasterPos4s = _mesa_RasterPos4s;
272   exec->RasterPos4sv = _mesa_RasterPos4sv;
273   exec->ReadBuffer = _mesa_ReadBuffer;
274   exec->ReadPixels = _mesa_ReadPixels;
275   exec->RenderMode = _mesa_RenderMode;
276   exec->Rotated = _mesa_Rotated;
277   exec->Rotatef = _mesa_Rotatef;
278   exec->Scaled = _mesa_Scaled;
279   exec->Scalef = _mesa_Scalef;
280   exec->Scissor = _mesa_Scissor;
281   exec->SecondaryColorPointerEXT = _mesa_SecondaryColorPointerEXT;
282   exec->SelectBuffer = _mesa_SelectBuffer;
283   exec->ShadeModel = _mesa_ShadeModel;
284   exec->StencilFunc = _mesa_StencilFunc;
285   exec->StencilMask = _mesa_StencilMask;
286   exec->StencilOp = _mesa_StencilOp;
287   exec->TexEnvf = _mesa_TexEnvf;
288   exec->TexEnvfv = _mesa_TexEnvfv;
289   exec->TexEnvi = _mesa_TexEnvi;
290   exec->TexEnviv = _mesa_TexEnviv;
291   exec->TexGend = _mesa_TexGend;
292   exec->TexGendv = _mesa_TexGendv;
293   exec->TexGenf = _mesa_TexGenf;
294   exec->TexGenfv = _mesa_TexGenfv;
295   exec->TexGeni = _mesa_TexGeni;
296   exec->TexGeniv = _mesa_TexGeniv;
297   exec->TexImage1D = _mesa_TexImage1D;
298   exec->TexImage2D = _mesa_TexImage2D;
299   exec->TexParameterf = _mesa_TexParameterf;
300   exec->TexParameterfv = _mesa_TexParameterfv;
301   exec->TexParameteri = _mesa_TexParameteri;
302   exec->TexParameteriv = _mesa_TexParameteriv;
303   exec->Translated = _mesa_Translated;
304   exec->Translatef = _mesa_Translatef;
305   exec->Viewport = _mesa_Viewport;
306
307   /* 1.1 */
308   exec->AreTexturesResident = _mesa_AreTexturesResident;
309   exec->BindTexture = _mesa_BindTexture;
310   exec->ColorPointer = _mesa_ColorPointer;
311   exec->CopyTexImage1D = _mesa_CopyTexImage1D;
312   exec->CopyTexImage2D = _mesa_CopyTexImage2D;
313   exec->CopyTexSubImage1D = _mesa_CopyTexSubImage1D;
314   exec->CopyTexSubImage2D = _mesa_CopyTexSubImage2D;
315   exec->DeleteTextures = _mesa_DeleteTextures;
316   exec->DisableClientState = _mesa_DisableClientState;
317   exec->EdgeFlagPointer = _mesa_EdgeFlagPointer;
318   exec->EnableClientState = _mesa_EnableClientState;
319   exec->GenTextures = _mesa_GenTextures;
320   exec->GetPointerv = _mesa_GetPointerv;
321   exec->IndexPointer = _mesa_IndexPointer;
322   exec->InterleavedArrays = _mesa_InterleavedArrays;
323   exec->IsTexture = _mesa_IsTexture;
324   exec->NormalPointer = _mesa_NormalPointer;
325   exec->PopClientAttrib = _mesa_PopClientAttrib;
326   exec->PrioritizeTextures = _mesa_PrioritizeTextures;
327   exec->PushClientAttrib = _mesa_PushClientAttrib;
328   exec->TexCoordPointer = _mesa_TexCoordPointer;
329   exec->TexSubImage1D = _mesa_TexSubImage1D;
330   exec->TexSubImage2D = _mesa_TexSubImage2D;
331   exec->VertexPointer = _mesa_VertexPointer;
332
333   /* 1.2 */
334   exec->CopyTexSubImage3D = _mesa_CopyTexSubImage3D;
335   exec->TexImage3D = _mesa_TexImage3D;
336   exec->TexSubImage3D = _mesa_TexSubImage3D;
337
338   /* OpenGL 1.2  GL_ARB_imaging */
339   exec->BlendColor = _mesa_BlendColor;
340   exec->BlendEquation = _mesa_BlendEquation;
341   exec->ColorSubTable = _mesa_ColorSubTable;
342   exec->ColorTable = _mesa_ColorTable;
343   exec->ColorTableParameterfv = _mesa_ColorTableParameterfv;
344   exec->ColorTableParameteriv = _mesa_ColorTableParameteriv;
345   exec->ConvolutionFilter1D = _mesa_ConvolutionFilter1D;
346   exec->ConvolutionFilter2D = _mesa_ConvolutionFilter2D;
347   exec->ConvolutionParameterf = _mesa_ConvolutionParameterf;
348   exec->ConvolutionParameterfv = _mesa_ConvolutionParameterfv;
349   exec->ConvolutionParameteri = _mesa_ConvolutionParameteri;
350   exec->ConvolutionParameteriv = _mesa_ConvolutionParameteriv;
351   exec->CopyColorSubTable = _mesa_CopyColorSubTable;
352   exec->CopyColorTable = _mesa_CopyColorTable;
353   exec->CopyConvolutionFilter1D = _mesa_CopyConvolutionFilter1D;
354   exec->CopyConvolutionFilter2D = _mesa_CopyConvolutionFilter2D;
355   exec->GetColorTable = _mesa_GetColorTable;
356   exec->GetColorTableParameterfv = _mesa_GetColorTableParameterfv;
357   exec->GetColorTableParameteriv = _mesa_GetColorTableParameteriv;
358   exec->GetConvolutionFilter = _mesa_GetConvolutionFilter;
359   exec->GetConvolutionParameterfv = _mesa_GetConvolutionParameterfv;
360   exec->GetConvolutionParameteriv = _mesa_GetConvolutionParameteriv;
361   exec->GetHistogram = _mesa_GetHistogram;
362   exec->GetHistogramParameterfv = _mesa_GetHistogramParameterfv;
363   exec->GetHistogramParameteriv = _mesa_GetHistogramParameteriv;
364   exec->GetMinmax = _mesa_GetMinmax;
365   exec->GetMinmaxParameterfv = _mesa_GetMinmaxParameterfv;
366   exec->GetMinmaxParameteriv = _mesa_GetMinmaxParameteriv;
367   exec->GetSeparableFilter = _mesa_GetSeparableFilter;
368   exec->Histogram = _mesa_Histogram;
369   exec->Minmax = _mesa_Minmax;
370   exec->ResetHistogram = _mesa_ResetHistogram;
371   exec->ResetMinmax = _mesa_ResetMinmax;
372   exec->SeparableFilter2D = _mesa_SeparableFilter2D;
373
374   /* 2. GL_EXT_blend_color */
375#if 0
376   exec->BlendColorEXT = _mesa_BlendColorEXT;
377#endif
378
379   /* 3. GL_EXT_polygon_offset */
380   exec->PolygonOffsetEXT = _mesa_PolygonOffsetEXT;
381
382   /* 6. GL_EXT_texture3d */
383#if 0
384   exec->CopyTexSubImage3DEXT = _mesa_CopyTexSubImage3D;
385   exec->TexImage3DEXT = _mesa_TexImage3DEXT;
386   exec->TexSubImage3DEXT = _mesa_TexSubImage3D;
387#endif
388
389   /* 11. GL_EXT_histogram */
390   exec->GetHistogramEXT = _mesa_GetHistogram;
391   exec->GetHistogramParameterfvEXT = _mesa_GetHistogramParameterfv;
392   exec->GetHistogramParameterivEXT = _mesa_GetHistogramParameteriv;
393   exec->GetMinmaxEXT = _mesa_GetMinmax;
394   exec->GetMinmaxParameterfvEXT = _mesa_GetMinmaxParameterfv;
395   exec->GetMinmaxParameterivEXT = _mesa_GetMinmaxParameteriv;
396
397   /* ?. GL_SGIX_pixel_texture */
398   exec->PixelTexGenSGIX = _mesa_PixelTexGenSGIX;
399
400   /* 15. GL_SGIS_pixel_texture */
401   exec->PixelTexGenParameteriSGIS = _mesa_PixelTexGenParameteriSGIS;
402   exec->PixelTexGenParameterivSGIS = _mesa_PixelTexGenParameterivSGIS;
403   exec->PixelTexGenParameterfSGIS = _mesa_PixelTexGenParameterfSGIS;
404   exec->PixelTexGenParameterfvSGIS = _mesa_PixelTexGenParameterfvSGIS;
405   exec->GetPixelTexGenParameterivSGIS = _mesa_GetPixelTexGenParameterivSGIS;
406   exec->GetPixelTexGenParameterfvSGIS = _mesa_GetPixelTexGenParameterfvSGIS;
407
408   /* 30. GL_EXT_vertex_array */
409   exec->ColorPointerEXT = _mesa_ColorPointerEXT;
410   exec->EdgeFlagPointerEXT = _mesa_EdgeFlagPointerEXT;
411   exec->IndexPointerEXT = _mesa_IndexPointerEXT;
412   exec->NormalPointerEXT = _mesa_NormalPointerEXT;
413   exec->TexCoordPointerEXT = _mesa_TexCoordPointerEXT;
414   exec->VertexPointerEXT = _mesa_VertexPointerEXT;
415
416   /* 37. GL_EXT_blend_minmax */
417#if 0
418   exec->BlendEquationEXT = _mesa_BlendEquationEXT;
419#endif
420
421   /* 54. GL_EXT_point_parameters */
422   exec->PointParameterfEXT = _mesa_PointParameterfEXT;
423   exec->PointParameterfvEXT = _mesa_PointParameterfvEXT;
424
425   /* 77. GL_PGI_misc_hints */
426   exec->HintPGI = _mesa_HintPGI;
427
428   /* 78. GL_EXT_paletted_texture */
429#if 0
430   exec->ColorTableEXT = _mesa_ColorTableEXT;
431   exec->ColorSubTableEXT = _mesa_ColorSubTableEXT;
432#endif
433   exec->GetColorTableEXT = _mesa_GetColorTable;
434   exec->GetColorTableParameterfvEXT = _mesa_GetColorTableParameterfv;
435   exec->GetColorTableParameterivEXT = _mesa_GetColorTableParameteriv;
436
437   /* 97. GL_EXT_compiled_vertex_array */
438   exec->LockArraysEXT = _mesa_LockArraysEXT;
439   exec->UnlockArraysEXT = _mesa_UnlockArraysEXT;
440
441   /* 173. GL_INGR_blend_func_separate */
442   exec->BlendFuncSeparateEXT = _mesa_BlendFuncSeparateEXT;
443
444   /* 196. GL_MESA_resize_buffers */
445   exec->ResizeBuffersMESA = _mesa_ResizeBuffersMESA;
446
447   /* 197. GL_MESA_window_pos */
448   exec->WindowPos2dMESA = _mesa_WindowPos2dMESA;
449   exec->WindowPos2dvMESA = _mesa_WindowPos2dvMESA;
450   exec->WindowPos2fMESA = _mesa_WindowPos2fMESA;
451   exec->WindowPos2fvMESA = _mesa_WindowPos2fvMESA;
452   exec->WindowPos2iMESA = _mesa_WindowPos2iMESA;
453   exec->WindowPos2ivMESA = _mesa_WindowPos2ivMESA;
454   exec->WindowPos2sMESA = _mesa_WindowPos2sMESA;
455   exec->WindowPos2svMESA = _mesa_WindowPos2svMESA;
456   exec->WindowPos3dMESA = _mesa_WindowPos3dMESA;
457   exec->WindowPos3dvMESA = _mesa_WindowPos3dvMESA;
458   exec->WindowPos3fMESA = _mesa_WindowPos3fMESA;
459   exec->WindowPos3fvMESA = _mesa_WindowPos3fvMESA;
460   exec->WindowPos3iMESA = _mesa_WindowPos3iMESA;
461   exec->WindowPos3ivMESA = _mesa_WindowPos3ivMESA;
462   exec->WindowPos3sMESA = _mesa_WindowPos3sMESA;
463   exec->WindowPos3svMESA = _mesa_WindowPos3svMESA;
464   exec->WindowPos4dMESA = _mesa_WindowPos4dMESA;
465   exec->WindowPos4dvMESA = _mesa_WindowPos4dvMESA;
466   exec->WindowPos4fMESA = _mesa_WindowPos4fMESA;
467   exec->WindowPos4fvMESA = _mesa_WindowPos4fvMESA;
468   exec->WindowPos4iMESA = _mesa_WindowPos4iMESA;
469   exec->WindowPos4ivMESA = _mesa_WindowPos4ivMESA;
470   exec->WindowPos4sMESA = _mesa_WindowPos4sMESA;
471   exec->WindowPos4svMESA = _mesa_WindowPos4svMESA;
472
473   /* ARB 1. GL_ARB_multitexture */
474   exec->ActiveTextureARB = _mesa_ActiveTextureARB;
475   exec->ClientActiveTextureARB = _mesa_ClientActiveTextureARB;
476
477   /* ARB 3. GL_ARB_transpose_matrix */
478   exec->LoadTransposeMatrixdARB = _mesa_LoadTransposeMatrixdARB;
479   exec->LoadTransposeMatrixfARB = _mesa_LoadTransposeMatrixfARB;
480   exec->MultTransposeMatrixdARB = _mesa_MultTransposeMatrixdARB;
481   exec->MultTransposeMatrixfARB = _mesa_MultTransposeMatrixfARB;
482
483   /* ARB 12. GL_ARB_texture_compression */
484   exec->CompressedTexImage3DARB = _mesa_CompressedTexImage3DARB;
485   exec->CompressedTexImage2DARB = _mesa_CompressedTexImage2DARB;
486   exec->CompressedTexImage1DARB = _mesa_CompressedTexImage1DARB;
487   exec->CompressedTexSubImage3DARB = _mesa_CompressedTexSubImage3DARB;
488   exec->CompressedTexSubImage2DARB = _mesa_CompressedTexSubImage2DARB;
489   exec->CompressedTexSubImage1DARB = _mesa_CompressedTexSubImage1DARB;
490   exec->GetCompressedTexImageARB = _mesa_GetCompressedTexImageARB;
491
492}
493
494
495
496/**********************************************************************/
497/*****                   State update logic                       *****/
498/**********************************************************************/
499
500
501static void
502update_polygon( GLcontext *ctx )
503{
504   ctx->_TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK;
505
506   /* Setup CullBits bitmask */
507   if (ctx->Polygon.CullFlag) {
508      switch(ctx->Polygon.CullFaceMode) {
509      case GL_BACK:
510	 ctx->Polygon._CullBits = 1;
511	 break;
512      case GL_FRONT:
513	 ctx->Polygon._CullBits = 2;
514	 break;
515      default:
516      case GL_FRONT_AND_BACK:
517	 ctx->Polygon._CullBits = 0;
518	 ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
519	 break;
520      }
521   }
522   else {
523      ctx->Polygon._CullBits = 3;
524   }
525
526   /* Any Polygon offsets enabled? */
527   ctx->Polygon._OffsetAny = GL_FALSE;
528   ctx->_TriangleCaps &= ~DD_TRI_OFFSET;
529
530   if (ctx->Polygon.OffsetPoint ||
531       ctx->Polygon.OffsetLine ||
532       ctx->Polygon.OffsetFill) {
533      ctx->_TriangleCaps |= DD_TRI_OFFSET;
534      ctx->Polygon._OffsetAny = GL_TRUE;
535   }
536}
537
538static void
539calculate_model_project_matrix( GLcontext *ctx )
540{
541   if (!ctx->_NeedEyeCoords) {
542      _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix,
543			       &ctx->ProjectionMatrix,
544			       &ctx->ModelView );
545
546      _math_matrix_analyse( &ctx->_ModelProjectMatrix );
547   }
548}
549
550static void
551update_modelview_scale( GLcontext *ctx )
552{
553   ctx->_ModelViewInvScale = 1.0F;
554   if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
555			       MAT_FLAG_GENERAL_SCALE |
556			       MAT_FLAG_GENERAL_3D |
557			       MAT_FLAG_GENERAL) ) {
558      const GLfloat *m = ctx->ModelView.inv;
559      GLfloat f = m[2] * m[2] + m[6] * m[6] + m[10] * m[10];
560      if (f < 1e-12) f = 1.0;
561      if (ctx->_NeedEyeCoords)
562	 ctx->_ModelViewInvScale = 1.0/GL_SQRT(f);
563      else
564	 ctx->_ModelViewInvScale = GL_SQRT(f);
565   }
566}
567
568
569/* Bring uptodate any state that relies on _NeedEyeCoords.
570 */
571static void
572update_tnl_spaces( GLcontext *ctx, GLuint oldneedeyecoords )
573{
574   /* Check if the truth-value interpretations of the bitfields have
575    * changed:
576    */
577   if ((oldneedeyecoords == 0) != (ctx->_NeedEyeCoords == 0)) {
578      /* Recalculate all state that depends on _NeedEyeCoords.
579       */
580      update_modelview_scale(ctx);
581      calculate_model_project_matrix(ctx);
582      gl_compute_light_positions( ctx );
583
584      if (ctx->Driver.LightingSpaceChange)
585	 ctx->Driver.LightingSpaceChange( ctx );
586   }
587   else {
588      GLuint new_state = ctx->NewState;
589
590      /* Recalculate that same state if and only if it has been
591       * invalidated by other statechanges.
592       */
593      if (new_state & _NEW_MODELVIEW)
594	 update_modelview_scale(ctx);
595
596      if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
597	 calculate_model_project_matrix(ctx);
598
599      if (new_state & (_NEW_LIGHT|_NEW_MODELVIEW))
600	 gl_compute_light_positions( ctx );
601   }
602}
603
604
605static void
606update_drawbuffer( GLcontext *ctx )
607{
608   ctx->DrawBuffer->_Xmin = 0;
609   ctx->DrawBuffer->_Ymin = 0;
610   ctx->DrawBuffer->_Xmax = ctx->DrawBuffer->Width;
611   ctx->DrawBuffer->_Ymax = ctx->DrawBuffer->Height;
612   if (ctx->Scissor.Enabled) {
613      if (ctx->Scissor.X > ctx->DrawBuffer->_Xmin) {
614	 ctx->DrawBuffer->_Xmin = ctx->Scissor.X;
615      }
616      if (ctx->Scissor.Y > ctx->DrawBuffer->_Ymin) {
617	 ctx->DrawBuffer->_Ymin = ctx->Scissor.Y;
618      }
619      if (ctx->Scissor.X + ctx->Scissor.Width < ctx->DrawBuffer->_Xmax) {
620	 ctx->DrawBuffer->_Xmax = ctx->Scissor.X + ctx->Scissor.Width;
621      }
622      if (ctx->Scissor.Y + ctx->Scissor.Height < ctx->DrawBuffer->_Ymax) {
623	 ctx->DrawBuffer->_Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
624      }
625   }
626}
627
628
629/* NOTE: This routine references Tranform attribute values to compute
630 * userclip positions in clip space, but is only called on
631 * _NEW_PROJECTION.  The _mesa_ClipPlane() function keeps these values
632 * uptodate across changes to the Transform attributes.
633 */
634static void
635update_projection( GLcontext *ctx )
636{
637   _math_matrix_analyse( &ctx->ProjectionMatrix );
638
639   /* Recompute clip plane positions in clipspace.  This is also done
640    * in _mesa_ClipPlane().
641    */
642   if (ctx->Transform._AnyClip) {
643      GLuint p;
644      for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
645	 if (ctx->Transform.ClipEnabled[p]) {
646	    gl_transform_vector( ctx->Transform._ClipUserPlane[p],
647				 ctx->Transform.EyeUserPlane[p],
648				 ctx->ProjectionMatrix.inv );
649	 }
650      }
651   }
652}
653
654
655
656/*
657 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
658 * pixel transfer operations are enabled.
659 */
660static void
661update_image_transfer_state(GLcontext *ctx)
662{
663   GLuint mask = 0;
664
665   if (ctx->Pixel.RedScale   != 1.0F || ctx->Pixel.RedBias   != 0.0F ||
666       ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
667       ctx->Pixel.BlueScale  != 1.0F || ctx->Pixel.BlueBias  != 0.0F ||
668       ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
669      mask |= IMAGE_SCALE_BIAS_BIT;
670
671   if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
672      mask |= IMAGE_SHIFT_OFFSET_BIT;
673
674   if (ctx->Pixel.MapColorFlag)
675      mask |= IMAGE_MAP_COLOR_BIT;
676
677   if (ctx->Pixel.ColorTableEnabled)
678      mask |= IMAGE_COLOR_TABLE_BIT;
679
680   if (ctx->Pixel.Convolution1DEnabled ||
681       ctx->Pixel.Convolution2DEnabled ||
682       ctx->Pixel.Separable2DEnabled) {
683      mask |= IMAGE_CONVOLUTION_BIT;
684      if (ctx->Pixel.PostConvolutionScale[0] != 1.0F ||
685          ctx->Pixel.PostConvolutionScale[1] != 1.0F ||
686          ctx->Pixel.PostConvolutionScale[2] != 1.0F ||
687          ctx->Pixel.PostConvolutionScale[3] != 1.0F ||
688          ctx->Pixel.PostConvolutionBias[0] != 0.0F ||
689          ctx->Pixel.PostConvolutionBias[1] != 0.0F ||
690          ctx->Pixel.PostConvolutionBias[2] != 0.0F ||
691          ctx->Pixel.PostConvolutionBias[3] != 0.0F) {
692         mask |= IMAGE_POST_CONVOLUTION_SCALE_BIAS;
693      }
694   }
695
696   if (ctx->Pixel.PostConvolutionColorTableEnabled)
697      mask |= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT;
698
699   if (ctx->ColorMatrix.type != MATRIX_IDENTITY ||
700       ctx->Pixel.PostColorMatrixScale[0] != 1.0F ||
701       ctx->Pixel.PostColorMatrixBias[0]  != 0.0F ||
702       ctx->Pixel.PostColorMatrixScale[1] != 1.0F ||
703       ctx->Pixel.PostColorMatrixBias[1]  != 0.0F ||
704       ctx->Pixel.PostColorMatrixScale[2] != 1.0F ||
705       ctx->Pixel.PostColorMatrixBias[2]  != 0.0F ||
706       ctx->Pixel.PostColorMatrixScale[3] != 1.0F ||
707       ctx->Pixel.PostColorMatrixBias[3]  != 0.0F)
708      mask |= IMAGE_COLOR_MATRIX_BIT;
709
710   if (ctx->Pixel.PostColorMatrixColorTableEnabled)
711      mask |= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT;
712
713   if (ctx->Pixel.HistogramEnabled)
714      mask |= IMAGE_HISTOGRAM_BIT;
715
716   if (ctx->Pixel.MinMaxEnabled)
717      mask |= IMAGE_MIN_MAX_BIT;
718
719   ctx->_ImageTransferState = mask;
720}
721
722
723/*
724 * If ctx->NewState is non-zero then this function MUST be called before
725 * rendering any primitive.  Basically, function pointers and miscellaneous
726 * flags are updated to reflect the current state of the state machine.
727 *
728 * Special care is taken with the derived value _NeedEyeCoords.  These
729 * is a bitflag which is updated with information from a number of
730 * attribute groups (MODELVIEW, LIGHT, TEXTURE).  A lot of derived
731 * state references this value, and must be treated with care to
732 * ensure that updates are done correctly.  All state dependent on
733 * _NeedEyeCoords is calculated from within _mesa_update_tnl_spaces(),
734 * and from nowhere else.
735 */
736void gl_update_state( GLcontext *ctx )
737{
738   GLuint new_state = ctx->NewState;
739   GLuint oldneedeyecoords = ctx->_NeedEyeCoords;
740
741   if (MESA_VERBOSE & VERBOSE_STATE)
742      gl_print_state("", new_state);
743
744   if (new_state & _NEW_MODELVIEW)
745      _math_matrix_analyse( &ctx->ModelView );
746
747   if (new_state & _NEW_PROJECTION)
748      update_projection( ctx );
749
750   if (new_state & _NEW_TEXTURE_MATRIX)
751      _mesa_update_texture_matrices( ctx );
752
753   if (new_state & _NEW_COLOR_MATRIX)
754      _math_matrix_analyse( &ctx->ColorMatrix );
755
756   /* References ColorMatrix.type (derived above).
757    */
758   if (new_state & (_NEW_PIXEL|_NEW_COLOR_MATRIX))
759      update_image_transfer_state(ctx);
760
761   /* Contributes to NeedEyeCoords, NeedNormals.
762    */
763   if (new_state & _NEW_TEXTURE)
764      _mesa_update_texture_state( ctx );
765
766   if (new_state & (_NEW_BUFFERS|_NEW_SCISSOR))
767      update_drawbuffer( ctx );
768
769   if (new_state & _NEW_POLYGON)
770      update_polygon( ctx );
771
772   /* Contributes to NeedEyeCoords, NeedNormals.
773    */
774   if (new_state & _NEW_LIGHT)
775      gl_update_lighting( ctx );
776
777   /* We can light in object space if the modelview matrix preserves
778    * lengths and relative angles.
779    */
780   if (new_state & (_NEW_MODELVIEW|_NEW_LIGHT)) {
781      ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT_MODELVIEW;
782      if (ctx->Light.Enabled &&
783	  !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
784	    ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW;
785   }
786
787   /* point attenuation requires eye coords */
788   if (new_state & _NEW_POINT) {
789      if (ctx->Point._Attenuated) {
790         ctx->_NeedEyeCoords |= NEED_EYE_POINT_ATTEN;
791      }
792   }
793
794   /* ctx->_NeedEyeCoords and ctx->_NeedEyeNormals are now uptodate.
795    *
796    * If the truth value of either has changed, update for the new
797    * lighting space and recompute the positions of lights and the
798    * normal transform.
799    *
800    * If the lighting space hasn't changed, may still need to recompute
801    * light positions & normal transforms for other reasons.
802    */
803   if (new_state & (_NEW_MODELVIEW |
804		    _NEW_PROJECTION |
805		    _TNL_NEW_NORMAL_TRANSFORM |
806		    _NEW_LIGHT |
807		    _TNL_NEW_NEED_EYE_COORDS))
808      update_tnl_spaces( ctx, oldneedeyecoords );
809
810   /*
811    * Here the driver sets up all the ctx->Driver function pointers
812    * to it's specific, private functions, and performs any
813    * internal state management necessary, including invalidating
814    * state of active modules.
815    */
816   ctx->Driver.UpdateState(ctx);
817   ctx->NewState = 0;
818}
819