state.c revision fe5d67d95f3a5fc84c5421d409a6464642aaf2cb
1/* $Id: state.c,v 1.34 2000/10/27 16:44:41 keithw 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 "attrib.h"
41#include "bitmap.h"
42#include "blend.h"
43#include "buffers.h"
44#include "clip.h"
45#include "colortab.h"
46#include "context.h"
47#include "convolve.h"
48#include "copypix.h"
49#include "cva.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 "imaging.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 "pipeline.h"
67#include "pixel.h"
68#include "pixeltex.h"
69#include "points.h"
70#include "polygon.h"
71#include "quads.h"
72#include "rastpos.h"
73#include "readpix.h"
74#include "rect.h"
75#include "scissor.h"
76#include "shade.h"
77#include "state.h"
78#include "stencil.h"
79#include "teximage.h"
80#include "texobj.h"
81#include "texstate.h"
82#include "texture.h"
83#include "triangle.h"
84#include "types.h"
85#include "varray.h"
86#include "vbfill.h"
87#include "vbrender.h"
88#include "winpos.h"
89#endif
90
91
92
93static int
94generic_noop(void)
95{
96#ifdef DEBUG
97   gl_problem(NULL, "undefined function dispatch");
98#endif
99   return 0;
100}
101
102
103/*
104 * Set all pointers in the given dispatch table to point to a
105 * generic no-op function.
106 */
107void
108_mesa_init_no_op_table(struct _glapi_table *table, GLuint tableSize)
109{
110   GLuint i;
111   void **dispatch = (void **) table;
112   for (i = 0; i < tableSize; i++) {
113      dispatch[i] = (void *) generic_noop;
114   }
115}
116
117
118/*
119 * Initialize the given dispatch table with pointers to Mesa's
120 * immediate-mode commands.
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   /* load the dispatch slots we understand */
129   exec->Accum = _mesa_Accum;
130   exec->AlphaFunc = _mesa_AlphaFunc;
131   exec->Begin = _mesa_Begin;
132   exec->Bitmap = _mesa_Bitmap;
133   exec->BlendFunc = _mesa_BlendFunc;
134   exec->CallList = _mesa_CallList;
135   exec->CallLists = _mesa_CallLists;
136   exec->Clear = _mesa_Clear;
137   exec->ClearAccum = _mesa_ClearAccum;
138   exec->ClearColor = _mesa_ClearColor;
139   exec->ClearDepth = _mesa_ClearDepth;
140   exec->ClearIndex = _mesa_ClearIndex;
141   exec->ClearStencil = _mesa_ClearStencil;
142   exec->ClipPlane = _mesa_ClipPlane;
143   exec->Color3b = _mesa_Color3b;
144   exec->Color3bv = _mesa_Color3bv;
145   exec->Color3d = _mesa_Color3d;
146   exec->Color3dv = _mesa_Color3dv;
147   exec->Color3f = _mesa_Color3f;
148   exec->Color3fv = _mesa_Color3fv;
149   exec->Color3i = _mesa_Color3i;
150   exec->Color3iv = _mesa_Color3iv;
151   exec->Color3s = _mesa_Color3s;
152   exec->Color3sv = _mesa_Color3sv;
153   exec->Color3ub = _mesa_Color3ub;
154   exec->Color3ubv = _mesa_Color3ubv;
155   exec->Color3ui = _mesa_Color3ui;
156   exec->Color3uiv = _mesa_Color3uiv;
157   exec->Color3us = _mesa_Color3us;
158   exec->Color3usv = _mesa_Color3usv;
159   exec->Color4b = _mesa_Color4b;
160   exec->Color4bv = _mesa_Color4bv;
161   exec->Color4d = _mesa_Color4d;
162   exec->Color4dv = _mesa_Color4dv;
163   exec->Color4f = _mesa_Color4f;
164   exec->Color4fv = _mesa_Color4fv;
165   exec->Color4i = _mesa_Color4i;
166   exec->Color4iv = _mesa_Color4iv;
167   exec->Color4s = _mesa_Color4s;
168   exec->Color4sv = _mesa_Color4sv;
169   exec->Color4ub = _mesa_Color4ub;
170   exec->Color4ubv = _mesa_Color4ubv;
171   exec->Color4ui = _mesa_Color4ui;
172   exec->Color4uiv = _mesa_Color4uiv;
173   exec->Color4us = _mesa_Color4us;
174   exec->Color4usv = _mesa_Color4usv;
175   exec->ColorMask = _mesa_ColorMask;
176   exec->ColorMaterial = _mesa_ColorMaterial;
177   exec->CopyPixels = _mesa_CopyPixels;
178   exec->CullFace = _mesa_CullFace;
179   exec->DeleteLists = _mesa_DeleteLists;
180   exec->DepthFunc = _mesa_DepthFunc;
181   exec->DepthMask = _mesa_DepthMask;
182   exec->DepthRange = _mesa_DepthRange;
183   exec->Disable = _mesa_Disable;
184   exec->DrawBuffer = _mesa_DrawBuffer;
185   exec->DrawPixels = _mesa_DrawPixels;
186   exec->EdgeFlag = _mesa_EdgeFlag;
187   exec->EdgeFlagv = _mesa_EdgeFlagv;
188   exec->Enable = _mesa_Enable;
189   exec->End = _mesa_End;
190   exec->EndList = _mesa_EndList;
191   exec->EvalCoord1d = _mesa_EvalCoord1d;
192   exec->EvalCoord1dv = _mesa_EvalCoord1dv;
193   exec->EvalCoord1f = _mesa_EvalCoord1f;
194   exec->EvalCoord1fv = _mesa_EvalCoord1fv;
195   exec->EvalCoord2d = _mesa_EvalCoord2d;
196   exec->EvalCoord2dv = _mesa_EvalCoord2dv;
197   exec->EvalCoord2f = _mesa_EvalCoord2f;
198   exec->EvalCoord2fv = _mesa_EvalCoord2fv;
199   exec->EvalMesh1 = _mesa_EvalMesh1;
200   exec->EvalMesh2 = _mesa_EvalMesh2;
201   exec->EvalPoint1 = _mesa_EvalPoint1;
202   exec->EvalPoint2 = _mesa_EvalPoint2;
203   exec->FeedbackBuffer = _mesa_FeedbackBuffer;
204   exec->Finish = _mesa_Finish;
205   exec->Flush = _mesa_Flush;
206
207   exec->FogCoordfEXT = _mesa_FogCoordfEXT;
208   exec->FogCoordfvEXT = _mesa_FogCoordfvEXT;
209   exec->FogCoorddEXT = _mesa_FogCoorddEXT;
210   exec->FogCoorddvEXT = _mesa_FogCoorddvEXT;
211   exec->FogCoordPointerEXT = _mesa_FogCoordPointerEXT;
212
213   exec->Fogf = _mesa_Fogf;
214   exec->Fogfv = _mesa_Fogfv;
215   exec->Fogi = _mesa_Fogi;
216   exec->Fogiv = _mesa_Fogiv;
217   exec->FrontFace = _mesa_FrontFace;
218   exec->Frustum = _mesa_Frustum;
219   exec->GenLists = _mesa_GenLists;
220   exec->GetBooleanv = _mesa_GetBooleanv;
221   exec->GetClipPlane = _mesa_GetClipPlane;
222   exec->GetDoublev = _mesa_GetDoublev;
223   exec->GetError = _mesa_GetError;
224   exec->GetFloatv = _mesa_GetFloatv;
225   exec->GetIntegerv = _mesa_GetIntegerv;
226   exec->GetLightfv = _mesa_GetLightfv;
227   exec->GetLightiv = _mesa_GetLightiv;
228   exec->GetMapdv = _mesa_GetMapdv;
229   exec->GetMapfv = _mesa_GetMapfv;
230   exec->GetMapiv = _mesa_GetMapiv;
231   exec->GetMaterialfv = _mesa_GetMaterialfv;
232   exec->GetMaterialiv = _mesa_GetMaterialiv;
233   exec->GetPixelMapfv = _mesa_GetPixelMapfv;
234   exec->GetPixelMapuiv = _mesa_GetPixelMapuiv;
235   exec->GetPixelMapusv = _mesa_GetPixelMapusv;
236   exec->GetPolygonStipple = _mesa_GetPolygonStipple;
237   exec->GetString = _mesa_GetString;
238   exec->GetTexEnvfv = _mesa_GetTexEnvfv;
239   exec->GetTexEnviv = _mesa_GetTexEnviv;
240   exec->GetTexGendv = _mesa_GetTexGendv;
241   exec->GetTexGenfv = _mesa_GetTexGenfv;
242   exec->GetTexGeniv = _mesa_GetTexGeniv;
243   exec->GetTexImage = _mesa_GetTexImage;
244   exec->GetTexLevelParameterfv = _mesa_GetTexLevelParameterfv;
245   exec->GetTexLevelParameteriv = _mesa_GetTexLevelParameteriv;
246   exec->GetTexParameterfv = _mesa_GetTexParameterfv;
247   exec->GetTexParameteriv = _mesa_GetTexParameteriv;
248   exec->Hint = _mesa_Hint;
249   exec->IndexMask = _mesa_IndexMask;
250   exec->Indexd = _mesa_Indexd;
251   exec->Indexdv = _mesa_Indexdv;
252   exec->Indexf = _mesa_Indexf;
253   exec->Indexfv = _mesa_Indexfv;
254   exec->Indexi = _mesa_Indexi;
255   exec->Indexiv = _mesa_Indexiv;
256   exec->Indexs = _mesa_Indexs;
257   exec->Indexsv = _mesa_Indexsv;
258   exec->InitNames = _mesa_InitNames;
259   exec->IsEnabled = _mesa_IsEnabled;
260   exec->IsList = _mesa_IsList;
261   exec->LightModelf = _mesa_LightModelf;
262   exec->LightModelfv = _mesa_LightModelfv;
263   exec->LightModeli = _mesa_LightModeli;
264   exec->LightModeliv = _mesa_LightModeliv;
265   exec->Lightf = _mesa_Lightf;
266   exec->Lightfv = _mesa_Lightfv;
267   exec->Lighti = _mesa_Lighti;
268   exec->Lightiv = _mesa_Lightiv;
269   exec->LineStipple = _mesa_LineStipple;
270   exec->LineWidth = _mesa_LineWidth;
271   exec->ListBase = _mesa_ListBase;
272   exec->LoadIdentity = _mesa_LoadIdentity;
273   exec->LoadMatrixd = _mesa_LoadMatrixd;
274   exec->LoadMatrixf = _mesa_LoadMatrixf;
275   exec->LoadName = _mesa_LoadName;
276   exec->LogicOp = _mesa_LogicOp;
277   exec->Map1d = _mesa_Map1d;
278   exec->Map1f = _mesa_Map1f;
279   exec->Map2d = _mesa_Map2d;
280   exec->Map2f = _mesa_Map2f;
281   exec->MapGrid1d = _mesa_MapGrid1d;
282   exec->MapGrid1f = _mesa_MapGrid1f;
283   exec->MapGrid2d = _mesa_MapGrid2d;
284   exec->MapGrid2f = _mesa_MapGrid2f;
285   exec->Materialf = _mesa_Materialf;
286   exec->Materialfv = _mesa_Materialfv;
287   exec->Materiali = _mesa_Materiali;
288   exec->Materialiv = _mesa_Materialiv;
289   exec->MatrixMode = _mesa_MatrixMode;
290   exec->MultMatrixd = _mesa_MultMatrixd;
291   exec->MultMatrixf = _mesa_MultMatrixf;
292   exec->NewList = _mesa_NewList;
293   exec->Normal3b = _mesa_Normal3b;
294   exec->Normal3bv = _mesa_Normal3bv;
295   exec->Normal3d = _mesa_Normal3d;
296   exec->Normal3dv = _mesa_Normal3dv;
297   exec->Normal3f = _mesa_Normal3f;
298   exec->Normal3fv = _mesa_Normal3fv;
299   exec->Normal3i = _mesa_Normal3i;
300   exec->Normal3iv = _mesa_Normal3iv;
301   exec->Normal3s = _mesa_Normal3s;
302   exec->Normal3sv = _mesa_Normal3sv;
303   exec->Ortho = _mesa_Ortho;
304   exec->PassThrough = _mesa_PassThrough;
305   exec->PixelMapfv = _mesa_PixelMapfv;
306   exec->PixelMapuiv = _mesa_PixelMapuiv;
307   exec->PixelMapusv = _mesa_PixelMapusv;
308   exec->PixelStoref = _mesa_PixelStoref;
309   exec->PixelStorei = _mesa_PixelStorei;
310   exec->PixelTransferf = _mesa_PixelTransferf;
311   exec->PixelTransferi = _mesa_PixelTransferi;
312   exec->PixelZoom = _mesa_PixelZoom;
313   exec->PointSize = _mesa_PointSize;
314   exec->PolygonMode = _mesa_PolygonMode;
315   exec->PolygonOffset = _mesa_PolygonOffset;
316   exec->PolygonStipple = _mesa_PolygonStipple;
317   exec->PopAttrib = _mesa_PopAttrib;
318   exec->PopMatrix = _mesa_PopMatrix;
319   exec->PopName = _mesa_PopName;
320   exec->PushAttrib = _mesa_PushAttrib;
321   exec->PushMatrix = _mesa_PushMatrix;
322   exec->PushName = _mesa_PushName;
323   exec->RasterPos2d = _mesa_RasterPos2d;
324   exec->RasterPos2dv = _mesa_RasterPos2dv;
325   exec->RasterPos2f = _mesa_RasterPos2f;
326   exec->RasterPos2fv = _mesa_RasterPos2fv;
327   exec->RasterPos2i = _mesa_RasterPos2i;
328   exec->RasterPos2iv = _mesa_RasterPos2iv;
329   exec->RasterPos2s = _mesa_RasterPos2s;
330   exec->RasterPos2sv = _mesa_RasterPos2sv;
331   exec->RasterPos3d = _mesa_RasterPos3d;
332   exec->RasterPos3dv = _mesa_RasterPos3dv;
333   exec->RasterPos3f = _mesa_RasterPos3f;
334   exec->RasterPos3fv = _mesa_RasterPos3fv;
335   exec->RasterPos3i = _mesa_RasterPos3i;
336   exec->RasterPos3iv = _mesa_RasterPos3iv;
337   exec->RasterPos3s = _mesa_RasterPos3s;
338   exec->RasterPos3sv = _mesa_RasterPos3sv;
339   exec->RasterPos4d = _mesa_RasterPos4d;
340   exec->RasterPos4dv = _mesa_RasterPos4dv;
341   exec->RasterPos4f = _mesa_RasterPos4f;
342   exec->RasterPos4fv = _mesa_RasterPos4fv;
343   exec->RasterPos4i = _mesa_RasterPos4i;
344   exec->RasterPos4iv = _mesa_RasterPos4iv;
345   exec->RasterPos4s = _mesa_RasterPos4s;
346   exec->RasterPos4sv = _mesa_RasterPos4sv;
347   exec->ReadBuffer = _mesa_ReadBuffer;
348   exec->ReadPixels = _mesa_ReadPixels;
349   exec->Rectd = _mesa_Rectd;
350   exec->Rectdv = _mesa_Rectdv;
351   exec->Rectf = _mesa_Rectf;
352   exec->Rectfv = _mesa_Rectfv;
353   exec->Recti = _mesa_Recti;
354   exec->Rectiv = _mesa_Rectiv;
355   exec->Rects = _mesa_Rects;
356   exec->Rectsv = _mesa_Rectsv;
357   exec->RenderMode = _mesa_RenderMode;
358   exec->Rotated = _mesa_Rotated;
359   exec->Rotatef = _mesa_Rotatef;
360   exec->Scaled = _mesa_Scaled;
361   exec->Scalef = _mesa_Scalef;
362   exec->Scissor = _mesa_Scissor;
363
364#if 0
365   exec->SecondaryColor3fEXT = _mesa_SecondaryColor3bEXT;
366   exec->SecondaryColor3fvEXT = _mesa_SecondaryColor3bvEXT;
367   exec->SecondaryColor3dEXT = _mesa_SecondaryColor3sEXT;
368   exec->SecondaryColordvEXT = _mesa_SecondaryColor3svEXT;
369   exec->SecondaryColor3fEXT = _mesa_SecondaryColor3iEXT;
370   exec->SecondaryColor3fvEXT = _mesa_SecondaryColor3ivEXT;
371   exec->SecondaryColor3dEXT = _mesa_SecondaryColor3fEXT;
372   exec->SecondaryColordvEXT = _mesa_SecondaryColor3fvEXT;
373   exec->SecondaryColor3fEXT = _mesa_SecondaryColor3dEXT;
374   exec->SecondaryColor3fvEXT = _mesa_SecondaryColor3dvEXT;
375   exec->SecondaryColor3dEXT = _mesa_SecondaryColor3ubEXT;
376   exec->SecondaryColordvEXT = _mesa_SecondaryColor3ubvEXT;
377   exec->SecondaryColor3fEXT = _mesa_SecondaryColor3usEXT;
378   exec->SecondaryColor3fvEXT = _mesa_SecondaryColor3usvEXT;
379   exec->SecondaryColor3dEXT = _mesa_SecondaryColor3uiEXT;
380   exec->SecondaryColordvEXT = _mesa_SecondaryColor3uivEXT;
381   exec->SecondaryColorPointerEXT = _mesa_SecondaryColorPointerEXT;
382#endif
383
384   exec->SelectBuffer = _mesa_SelectBuffer;
385   exec->ShadeModel = _mesa_ShadeModel;
386   exec->StencilFunc = _mesa_StencilFunc;
387   exec->StencilMask = _mesa_StencilMask;
388   exec->StencilOp = _mesa_StencilOp;
389   exec->TexCoord1d = _mesa_TexCoord1d;
390   exec->TexCoord1dv = _mesa_TexCoord1dv;
391   exec->TexCoord1f = _mesa_TexCoord1f;
392   exec->TexCoord1fv = _mesa_TexCoord1fv;
393   exec->TexCoord1i = _mesa_TexCoord1i;
394   exec->TexCoord1iv = _mesa_TexCoord1iv;
395   exec->TexCoord1s = _mesa_TexCoord1s;
396   exec->TexCoord1sv = _mesa_TexCoord1sv;
397   exec->TexCoord2d = _mesa_TexCoord2d;
398   exec->TexCoord2dv = _mesa_TexCoord2dv;
399   exec->TexCoord2f = _mesa_TexCoord2f;
400   exec->TexCoord2fv = _mesa_TexCoord2fv;
401   exec->TexCoord2i = _mesa_TexCoord2i;
402   exec->TexCoord2iv = _mesa_TexCoord2iv;
403   exec->TexCoord2s = _mesa_TexCoord2s;
404   exec->TexCoord2sv = _mesa_TexCoord2sv;
405   exec->TexCoord3d = _mesa_TexCoord3d;
406   exec->TexCoord3dv = _mesa_TexCoord3dv;
407   exec->TexCoord3f = _mesa_TexCoord3f;
408   exec->TexCoord3fv = _mesa_TexCoord3fv;
409   exec->TexCoord3i = _mesa_TexCoord3i;
410   exec->TexCoord3iv = _mesa_TexCoord3iv;
411   exec->TexCoord3s = _mesa_TexCoord3s;
412   exec->TexCoord3sv = _mesa_TexCoord3sv;
413   exec->TexCoord4d = _mesa_TexCoord4d;
414   exec->TexCoord4dv = _mesa_TexCoord4dv;
415   exec->TexCoord4f = _mesa_TexCoord4f;
416   exec->TexCoord4fv = _mesa_TexCoord4fv;
417   exec->TexCoord4i = _mesa_TexCoord4i;
418   exec->TexCoord4iv = _mesa_TexCoord4iv;
419   exec->TexCoord4s = _mesa_TexCoord4s;
420   exec->TexCoord4sv = _mesa_TexCoord4sv;
421   exec->TexEnvf = _mesa_TexEnvf;
422   exec->TexEnvfv = _mesa_TexEnvfv;
423   exec->TexEnvi = _mesa_TexEnvi;
424   exec->TexEnviv = _mesa_TexEnviv;
425   exec->TexGend = _mesa_TexGend;
426   exec->TexGendv = _mesa_TexGendv;
427   exec->TexGenf = _mesa_TexGenf;
428   exec->TexGenfv = _mesa_TexGenfv;
429   exec->TexGeni = _mesa_TexGeni;
430   exec->TexGeniv = _mesa_TexGeniv;
431   exec->TexImage1D = _mesa_TexImage1D;
432   exec->TexImage2D = _mesa_TexImage2D;
433   exec->TexParameterf = _mesa_TexParameterf;
434   exec->TexParameterfv = _mesa_TexParameterfv;
435   exec->TexParameteri = _mesa_TexParameteri;
436   exec->TexParameteriv = _mesa_TexParameteriv;
437   exec->Translated = _mesa_Translated;
438   exec->Translatef = _mesa_Translatef;
439   exec->Vertex2d = _mesa_Vertex2d;
440   exec->Vertex2dv = _mesa_Vertex2dv;
441   exec->Vertex2f = _mesa_Vertex2f;
442   exec->Vertex2fv = _mesa_Vertex2fv;
443   exec->Vertex2i = _mesa_Vertex2i;
444   exec->Vertex2iv = _mesa_Vertex2iv;
445   exec->Vertex2s = _mesa_Vertex2s;
446   exec->Vertex2sv = _mesa_Vertex2sv;
447   exec->Vertex3d = _mesa_Vertex3d;
448   exec->Vertex3dv = _mesa_Vertex3dv;
449   exec->Vertex3f = _mesa_Vertex3f;
450   exec->Vertex3fv = _mesa_Vertex3fv;
451   exec->Vertex3i = _mesa_Vertex3i;
452   exec->Vertex3iv = _mesa_Vertex3iv;
453   exec->Vertex3s = _mesa_Vertex3s;
454   exec->Vertex3sv = _mesa_Vertex3sv;
455   exec->Vertex4d = _mesa_Vertex4d;
456   exec->Vertex4dv = _mesa_Vertex4dv;
457   exec->Vertex4f = _mesa_Vertex4f;
458   exec->Vertex4fv = _mesa_Vertex4fv;
459   exec->Vertex4i = _mesa_Vertex4i;
460   exec->Vertex4iv = _mesa_Vertex4iv;
461   exec->Vertex4s = _mesa_Vertex4s;
462   exec->Vertex4sv = _mesa_Vertex4sv;
463   exec->Viewport = _mesa_Viewport;
464
465   /* 1.1 */
466   exec->AreTexturesResident = _mesa_AreTexturesResident;
467   exec->ArrayElement = _mesa_ArrayElement;
468   exec->BindTexture = _mesa_BindTexture;
469   exec->ColorPointer = _mesa_ColorPointer;
470   exec->CopyTexImage1D = _mesa_CopyTexImage1D;
471   exec->CopyTexImage2D = _mesa_CopyTexImage2D;
472   exec->CopyTexSubImage1D = _mesa_CopyTexSubImage1D;
473   exec->CopyTexSubImage2D = _mesa_CopyTexSubImage2D;
474   exec->DeleteTextures = _mesa_DeleteTextures;
475   exec->DisableClientState = _mesa_DisableClientState;
476   exec->DrawArrays = _mesa_DrawArrays;
477   exec->DrawElements = _mesa_DrawElements;
478   exec->EdgeFlagPointer = _mesa_EdgeFlagPointer;
479   exec->EnableClientState = _mesa_EnableClientState;
480   exec->GenTextures = _mesa_GenTextures;
481   exec->GetPointerv = _mesa_GetPointerv;
482   exec->IndexPointer = _mesa_IndexPointer;
483   exec->Indexub = _mesa_Indexub;
484   exec->Indexubv = _mesa_Indexubv;
485   exec->InterleavedArrays = _mesa_InterleavedArrays;
486   exec->IsTexture = _mesa_IsTexture;
487   exec->NormalPointer = _mesa_NormalPointer;
488   exec->PopClientAttrib = _mesa_PopClientAttrib;
489   exec->PrioritizeTextures = _mesa_PrioritizeTextures;
490   exec->PushClientAttrib = _mesa_PushClientAttrib;
491   exec->TexCoordPointer = _mesa_TexCoordPointer;
492   exec->TexSubImage1D = _mesa_TexSubImage1D;
493   exec->TexSubImage2D = _mesa_TexSubImage2D;
494   exec->VertexPointer = _mesa_VertexPointer;
495
496   /* 1.2 */
497   exec->CopyTexSubImage3D = _mesa_CopyTexSubImage3D;
498   exec->DrawRangeElements = _mesa_DrawRangeElements;
499   exec->TexImage3D = _mesa_TexImage3D;
500   exec->TexSubImage3D = _mesa_TexSubImage3D;
501
502   /* OpenGL 1.2  GL_ARB_imaging */
503   exec->BlendColor = _mesa_BlendColor;
504   exec->BlendEquation = _mesa_BlendEquation;
505   exec->ColorSubTable = _mesa_ColorSubTable;
506   exec->ColorTable = _mesa_ColorTable;
507   exec->ColorTableParameterfv = _mesa_ColorTableParameterfv;
508   exec->ColorTableParameteriv = _mesa_ColorTableParameteriv;
509   exec->ConvolutionFilter1D = _mesa_ConvolutionFilter1D;
510   exec->ConvolutionFilter2D = _mesa_ConvolutionFilter2D;
511   exec->ConvolutionParameterf = _mesa_ConvolutionParameterf;
512   exec->ConvolutionParameterfv = _mesa_ConvolutionParameterfv;
513   exec->ConvolutionParameteri = _mesa_ConvolutionParameteri;
514   exec->ConvolutionParameteriv = _mesa_ConvolutionParameteriv;
515   exec->CopyColorSubTable = _mesa_CopyColorSubTable;
516   exec->CopyColorTable = _mesa_CopyColorTable;
517   exec->CopyConvolutionFilter1D = _mesa_CopyConvolutionFilter1D;
518   exec->CopyConvolutionFilter2D = _mesa_CopyConvolutionFilter2D;
519   exec->GetColorTable = _mesa_GetColorTable;
520   exec->GetColorTableParameterfv = _mesa_GetColorTableParameterfv;
521   exec->GetColorTableParameteriv = _mesa_GetColorTableParameteriv;
522   exec->GetConvolutionFilter = _mesa_GetConvolutionFilter;
523   exec->GetConvolutionParameterfv = _mesa_GetConvolutionParameterfv;
524   exec->GetConvolutionParameteriv = _mesa_GetConvolutionParameteriv;
525   exec->GetHistogram = _mesa_GetHistogram;
526   exec->GetHistogramParameterfv = _mesa_GetHistogramParameterfv;
527   exec->GetHistogramParameteriv = _mesa_GetHistogramParameteriv;
528   exec->GetMinmax = _mesa_GetMinmax;
529   exec->GetMinmaxParameterfv = _mesa_GetMinmaxParameterfv;
530   exec->GetMinmaxParameteriv = _mesa_GetMinmaxParameteriv;
531   exec->GetSeparableFilter = _mesa_GetSeparableFilter;
532   exec->Histogram = _mesa_Histogram;
533   exec->Minmax = _mesa_Minmax;
534   exec->ResetHistogram = _mesa_ResetHistogram;
535   exec->ResetMinmax = _mesa_ResetMinmax;
536   exec->SeparableFilter2D = _mesa_SeparableFilter2D;
537
538   /* 2. GL_EXT_blend_color */
539#if 0
540   exec->BlendColorEXT = _mesa_BlendColorEXT;
541#endif
542
543   /* 3. GL_EXT_polygon_offset */
544   exec->PolygonOffsetEXT = _mesa_PolygonOffsetEXT;
545
546   /* 6. GL_EXT_texture3d */
547#if 0
548   exec->CopyTexSubImage3DEXT = _mesa_CopyTexSubImage3D;
549   exec->TexImage3DEXT = _mesa_TexImage3DEXT;
550   exec->TexSubImage3DEXT = _mesa_TexSubImage3D;
551#endif
552
553   /* 11. GL_EXT_histogram */
554   exec->GetHistogramEXT = _mesa_GetHistogram;
555   exec->GetHistogramParameterfvEXT = _mesa_GetHistogramParameterfv;
556   exec->GetHistogramParameterivEXT = _mesa_GetHistogramParameteriv;
557   exec->GetMinmaxEXT = _mesa_GetMinmax;
558   exec->GetMinmaxParameterfvEXT = _mesa_GetMinmaxParameterfv;
559   exec->GetMinmaxParameterivEXT = _mesa_GetMinmaxParameteriv;
560
561   /* ?. GL_SGIX_pixel_texture */
562   exec->PixelTexGenSGIX = _mesa_PixelTexGenSGIX;
563
564   /* 15. GL_SGIS_pixel_texture */
565   exec->PixelTexGenParameteriSGIS = _mesa_PixelTexGenParameteriSGIS;
566   exec->PixelTexGenParameterivSGIS = _mesa_PixelTexGenParameterivSGIS;
567   exec->PixelTexGenParameterfSGIS = _mesa_PixelTexGenParameterfSGIS;
568   exec->PixelTexGenParameterfvSGIS = _mesa_PixelTexGenParameterfvSGIS;
569   exec->GetPixelTexGenParameterivSGIS = _mesa_GetPixelTexGenParameterivSGIS;
570   exec->GetPixelTexGenParameterfvSGIS = _mesa_GetPixelTexGenParameterfvSGIS;
571
572   /* 30. GL_EXT_vertex_array */
573   exec->ColorPointerEXT = _mesa_ColorPointerEXT;
574   exec->EdgeFlagPointerEXT = _mesa_EdgeFlagPointerEXT;
575   exec->IndexPointerEXT = _mesa_IndexPointerEXT;
576   exec->NormalPointerEXT = _mesa_NormalPointerEXT;
577   exec->TexCoordPointerEXT = _mesa_TexCoordPointerEXT;
578   exec->VertexPointerEXT = _mesa_VertexPointerEXT;
579
580   /* 37. GL_EXT_blend_minmax */
581#if 0
582   exec->BlendEquationEXT = _mesa_BlendEquationEXT;
583#endif
584
585   /* 54. GL_EXT_point_parameters */
586   exec->PointParameterfEXT = _mesa_PointParameterfEXT;
587   exec->PointParameterfvEXT = _mesa_PointParameterfvEXT;
588
589   /* 77. GL_PGI_misc_hints */
590   exec->HintPGI = _mesa_HintPGI;
591
592   /* 78. GL_EXT_paletted_texture */
593#if 0
594   exec->ColorTableEXT = _mesa_ColorTableEXT;
595   exec->ColorSubTableEXT = _mesa_ColorSubTableEXT;
596#endif
597   exec->GetColorTableEXT = _mesa_GetColorTable;
598   exec->GetColorTableParameterfvEXT = _mesa_GetColorTableParameterfv;
599   exec->GetColorTableParameterivEXT = _mesa_GetColorTableParameteriv;
600
601   /* 97. GL_EXT_compiled_vertex_array */
602   exec->LockArraysEXT = _mesa_LockArraysEXT;
603   exec->UnlockArraysEXT = _mesa_UnlockArraysEXT;
604
605   /* 173. GL_INGR_blend_func_separate */
606   exec->BlendFuncSeparateEXT = _mesa_BlendFuncSeparateEXT;
607
608   /* 196. GL_MESA_resize_buffers */
609   exec->ResizeBuffersMESA = _mesa_ResizeBuffersMESA;
610
611   /* 197. GL_MESA_window_pos */
612   exec->WindowPos2dMESA = _mesa_WindowPos2dMESA;
613   exec->WindowPos2dvMESA = _mesa_WindowPos2dvMESA;
614   exec->WindowPos2fMESA = _mesa_WindowPos2fMESA;
615   exec->WindowPos2fvMESA = _mesa_WindowPos2fvMESA;
616   exec->WindowPos2iMESA = _mesa_WindowPos2iMESA;
617   exec->WindowPos2ivMESA = _mesa_WindowPos2ivMESA;
618   exec->WindowPos2sMESA = _mesa_WindowPos2sMESA;
619   exec->WindowPos2svMESA = _mesa_WindowPos2svMESA;
620   exec->WindowPos3dMESA = _mesa_WindowPos3dMESA;
621   exec->WindowPos3dvMESA = _mesa_WindowPos3dvMESA;
622   exec->WindowPos3fMESA = _mesa_WindowPos3fMESA;
623   exec->WindowPos3fvMESA = _mesa_WindowPos3fvMESA;
624   exec->WindowPos3iMESA = _mesa_WindowPos3iMESA;
625   exec->WindowPos3ivMESA = _mesa_WindowPos3ivMESA;
626   exec->WindowPos3sMESA = _mesa_WindowPos3sMESA;
627   exec->WindowPos3svMESA = _mesa_WindowPos3svMESA;
628   exec->WindowPos4dMESA = _mesa_WindowPos4dMESA;
629   exec->WindowPos4dvMESA = _mesa_WindowPos4dvMESA;
630   exec->WindowPos4fMESA = _mesa_WindowPos4fMESA;
631   exec->WindowPos4fvMESA = _mesa_WindowPos4fvMESA;
632   exec->WindowPos4iMESA = _mesa_WindowPos4iMESA;
633   exec->WindowPos4ivMESA = _mesa_WindowPos4ivMESA;
634   exec->WindowPos4sMESA = _mesa_WindowPos4sMESA;
635   exec->WindowPos4svMESA = _mesa_WindowPos4svMESA;
636
637   /* ARB 1. GL_ARB_multitexture */
638   exec->ActiveTextureARB = _mesa_ActiveTextureARB;
639   exec->ClientActiveTextureARB = _mesa_ClientActiveTextureARB;
640   exec->MultiTexCoord1dARB = _mesa_MultiTexCoord1dARB;
641   exec->MultiTexCoord1dvARB = _mesa_MultiTexCoord1dvARB;
642   exec->MultiTexCoord1fARB = _mesa_MultiTexCoord1fARB;
643   exec->MultiTexCoord1fvARB = _mesa_MultiTexCoord1fvARB;
644   exec->MultiTexCoord1iARB = _mesa_MultiTexCoord1iARB;
645   exec->MultiTexCoord1ivARB = _mesa_MultiTexCoord1ivARB;
646   exec->MultiTexCoord1sARB = _mesa_MultiTexCoord1sARB;
647   exec->MultiTexCoord1svARB = _mesa_MultiTexCoord1svARB;
648   exec->MultiTexCoord2dARB = _mesa_MultiTexCoord2dARB;
649   exec->MultiTexCoord2dvARB = _mesa_MultiTexCoord2dvARB;
650   exec->MultiTexCoord2fARB = _mesa_MultiTexCoord2fARB;
651   exec->MultiTexCoord2fvARB = _mesa_MultiTexCoord2fvARB;
652   exec->MultiTexCoord2iARB = _mesa_MultiTexCoord2iARB;
653   exec->MultiTexCoord2ivARB = _mesa_MultiTexCoord2ivARB;
654   exec->MultiTexCoord2sARB = _mesa_MultiTexCoord2sARB;
655   exec->MultiTexCoord2svARB = _mesa_MultiTexCoord2svARB;
656   exec->MultiTexCoord3dARB = _mesa_MultiTexCoord3dARB;
657   exec->MultiTexCoord3dvARB = _mesa_MultiTexCoord3dvARB;
658   exec->MultiTexCoord3fARB = _mesa_MultiTexCoord3fARB;
659   exec->MultiTexCoord3fvARB = _mesa_MultiTexCoord3fvARB;
660   exec->MultiTexCoord3iARB = _mesa_MultiTexCoord3iARB;
661   exec->MultiTexCoord3ivARB = _mesa_MultiTexCoord3ivARB;
662   exec->MultiTexCoord3sARB = _mesa_MultiTexCoord3sARB;
663   exec->MultiTexCoord3svARB = _mesa_MultiTexCoord3svARB;
664   exec->MultiTexCoord4dARB = _mesa_MultiTexCoord4dARB;
665   exec->MultiTexCoord4dvARB = _mesa_MultiTexCoord4dvARB;
666   exec->MultiTexCoord4fARB = _mesa_MultiTexCoord4fARB;
667   exec->MultiTexCoord4fvARB = _mesa_MultiTexCoord4fvARB;
668   exec->MultiTexCoord4iARB = _mesa_MultiTexCoord4iARB;
669   exec->MultiTexCoord4ivARB = _mesa_MultiTexCoord4ivARB;
670   exec->MultiTexCoord4sARB = _mesa_MultiTexCoord4sARB;
671   exec->MultiTexCoord4svARB = _mesa_MultiTexCoord4svARB;
672
673   /* ARB 3. GL_ARB_transpose_matrix */
674   exec->LoadTransposeMatrixdARB = _mesa_LoadTransposeMatrixdARB;
675   exec->LoadTransposeMatrixfARB = _mesa_LoadTransposeMatrixfARB;
676   exec->MultTransposeMatrixdARB = _mesa_MultTransposeMatrixdARB;
677   exec->MultTransposeMatrixfARB = _mesa_MultTransposeMatrixfARB;
678
679   /* ARB 12. GL_ARB_texture_compression */
680   exec->CompressedTexImage3DARB = _mesa_CompressedTexImage3DARB;
681   exec->CompressedTexImage2DARB = _mesa_CompressedTexImage2DARB;
682   exec->CompressedTexImage1DARB = _mesa_CompressedTexImage1DARB;
683   exec->CompressedTexSubImage3DARB = _mesa_CompressedTexSubImage3DARB;
684   exec->CompressedTexSubImage2DARB = _mesa_CompressedTexSubImage2DARB;
685   exec->CompressedTexSubImage1DARB = _mesa_CompressedTexSubImage1DARB;
686   exec->GetCompressedTexImageARB = _mesa_GetCompressedTexImageARB;
687
688}
689
690
691
692/**********************************************************************/
693/*****                   State update logic                       *****/
694/**********************************************************************/
695
696
697
698/*
699 * Recompute the value of ctx->RasterMask, etc. according to
700 * the current context.
701 */
702static void update_rasterflags( GLcontext *ctx )
703{
704   ctx->RasterMask = 0;
705
706   if (ctx->Color.AlphaEnabled)           ctx->RasterMask |= ALPHATEST_BIT;
707   if (ctx->Color.BlendEnabled)           ctx->RasterMask |= BLEND_BIT;
708   if (ctx->Depth.Test)                   ctx->RasterMask |= DEPTH_BIT;
709   if (ctx->Fog.Enabled)                  ctx->RasterMask |= FOG_BIT;
710   if (ctx->Scissor.Enabled)              ctx->RasterMask |= SCISSOR_BIT;
711   if (ctx->Stencil.Enabled)              ctx->RasterMask |= STENCIL_BIT;
712   if (ctx->Visual.RGBAflag) {
713      const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask);
714      if (colorMask != 0xffffffff)        ctx->RasterMask |= MASKING_BIT;
715      if (ctx->Color.ColorLogicOpEnabled) ctx->RasterMask |= LOGIC_OP_BIT;
716      if (ctx->Texture.ReallyEnabled)     ctx->RasterMask |= TEXTURE_BIT;
717   }
718   else {
719      if (ctx->Color.IndexMask != 0xffffffff) ctx->RasterMask |= MASKING_BIT;
720      if (ctx->Color.IndexLogicOpEnabled)     ctx->RasterMask |= LOGIC_OP_BIT;
721   }
722
723   if (ctx->DrawBuffer->UseSoftwareAlphaBuffers
724       && ctx->Color.ColorMask[ACOMP]
725       && ctx->Color.DrawBuffer != GL_NONE)
726      ctx->RasterMask |= ALPHABUF_BIT;
727
728   if (   ctx->Viewport.X < 0
729       || ctx->Viewport.X + ctx->Viewport.Width > ctx->DrawBuffer->Width
730       || ctx->Viewport.Y < 0
731       || ctx->Viewport.Y + ctx->Viewport.Height > ctx->DrawBuffer->Height) {
732      ctx->RasterMask |= WINCLIP_BIT;
733   }
734
735   if (ctx->Depth.OcclusionTest)
736      ctx->RasterMask |= OCCLUSION_BIT;
737
738
739   /* If we're not drawing to exactly one color buffer set the
740    * MULTI_DRAW_BIT flag.  Also set it if we're drawing to no
741    * buffers or the RGBA or CI mask disables all writes.
742    */
743   ctx->TriangleCaps &= ~DD_MULTIDRAW;
744
745   if (ctx->Color.MultiDrawBuffer) {
746      ctx->RasterMask |= MULTI_DRAW_BIT;
747      ctx->TriangleCaps |= DD_MULTIDRAW;
748   }
749   else if (ctx->Color.DrawBuffer==GL_NONE) {
750      ctx->RasterMask |= MULTI_DRAW_BIT;
751      ctx->TriangleCaps |= DD_MULTIDRAW;
752   }
753   else if (ctx->Visual.RGBAflag && *((GLuint *) ctx->Color.ColorMask) == 0) {
754      /* all RGBA channels disabled */
755      ctx->RasterMask |= MULTI_DRAW_BIT;
756      ctx->TriangleCaps |= DD_MULTIDRAW;
757   }
758   else if (!ctx->Visual.RGBAflag && ctx->Color.IndexMask==0) {
759      /* all color index bits disabled */
760      ctx->RasterMask |= MULTI_DRAW_BIT;
761      ctx->TriangleCaps |= DD_MULTIDRAW;
762   }
763}
764
765
766void gl_print_state( const char *msg, GLuint state )
767{
768   fprintf(stderr,
769	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
770	   msg,
771	   state,
772	   (state & NEW_LIGHTING)         ? "lighting, " : "",
773	   (state & NEW_RASTER_OPS)       ? "raster-ops, " : "",
774	   (state & NEW_TEXTURING)        ? "texturing, " : "",
775	   (state & NEW_POLYGON)          ? "polygon, " : "",
776	   (state & NEW_MODELVIEW)        ? "modelview, " : "",
777	   (state & NEW_PROJECTION)       ? "projection, " : "",
778	   (state & NEW_TEXTURE_MATRIX)   ? "texture-matrix, " : "",
779	   (state & NEW_USER_CLIP)        ? "user-clip, " : "",
780	   (state & NEW_TEXTURE_ENV)      ? "texture-env, " : "",
781	   (state & NEW_CLIENT_STATE)     ? "client-state, " : "",
782	   (state & NEW_FOG)              ? "fog, " : "",
783	   (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "",
784	   (state & NEW_VIEWPORT)         ? "viewport, " : "",
785	   (state & NEW_TEXTURE_ENABLE)   ? "texture-enable, " : "");
786}
787
788
789void gl_print_enable_flags( const char *msg, GLuint flags )
790{
791   fprintf(stderr,
792	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
793	   msg,
794	   flags,
795	   (flags & ENABLE_TEX0)       ? "tex-0, " : "",
796	   (flags & ENABLE_TEX1)       ? "tex-1, " : "",
797	   (flags & ENABLE_LIGHT)      ? "light, " : "",
798	   (flags & ENABLE_FOG)        ? "fog, " : "",
799	   (flags & ENABLE_USERCLIP)   ? "userclip, " : "",
800	   (flags & ENABLE_TEXGEN0)    ? "tex-gen-0, " : "",
801	   (flags & ENABLE_TEXGEN1)    ? "tex-gen-1, " : "",
802	   (flags & ENABLE_TEXMAT0)    ? "tex-mat-0, " : "",
803	   (flags & ENABLE_TEXMAT1)    ? "tex-mat-1, " : "",
804	   (flags & ENABLE_NORMALIZE)  ? "normalize, " : "",
805	   (flags & ENABLE_RESCALE)    ? "rescale, " : "");
806}
807
808
809/*
810 * If ctx->NewState is non-zero then this function MUST be called before
811 * rendering any primitive.  Basically, function pointers and miscellaneous
812 * flags are updated to reflect the current state of the state machine.
813 */
814void gl_update_state( GLcontext *ctx )
815{
816   GLuint i;
817
818   if (MESA_VERBOSE & VERBOSE_STATE)
819      gl_print_state("", ctx->NewState);
820
821   if (ctx->NewState & NEW_CLIENT_STATE)
822      gl_update_client_state( ctx );
823
824   if ((ctx->NewState & NEW_TEXTURE_ENABLE) &&
825       (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.ReallyEnabled)
826      ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS;
827
828   if (ctx->NewState & NEW_TEXTURE_ENV) {
829      if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode &&
830	  ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode
831#if MAX_TEXTURE_UNITS > 2
832	  && ctx->Texture.Unit[2].EnvMode == ctx->Texture.Unit[2].LastEnvMode
833#endif
834         ) {
835	 ctx->NewState &= ~NEW_TEXTURE_ENV;
836      }
837      ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode;
838      ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode;
839#if MAX_TEXTURE_UNITS > 2
840      ctx->Texture.Unit[2].LastEnvMode = ctx->Texture.Unit[2].EnvMode;
841#endif
842   }
843
844   if (ctx->NewState & NEW_TEXTURE_MATRIX) {
845      ctx->Enabled &= ~(ENABLE_TEXMAT0 | ENABLE_TEXMAT1 | ENABLE_TEXMAT2);
846
847      for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
848	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) {
849	    gl_matrix_analyze( &ctx->TextureMatrix[i] );
850	    ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;
851
852	    if (ctx->Texture.Unit[i].Enabled &&
853		ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
854	       ctx->Enabled |= ENABLE_TEXMAT0 << i;
855	 }
856      }
857   }
858
859   if (ctx->NewState & (NEW_TEXTURING | NEW_TEXTURE_ENABLE)) {
860      ctx->Texture.MultiTextureEnabled = GL_FALSE;
861      ctx->Texture.NeedNormals = GL_FALSE;
862      gl_update_dirty_texobjs(ctx);
863      ctx->Enabled &= ~(ENABLE_TEXGEN0 | ENABLE_TEXGEN1 | ENABLE_TEXGEN2);
864      ctx->Texture.ReallyEnabled = 0;
865
866      for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
867	 if (ctx->Texture.Unit[i].Enabled) {
868	    gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );
869
870	    ctx->Texture.ReallyEnabled |=
871	       ctx->Texture.Unit[i].ReallyEnabled << (i * 4);
872
873	    if (ctx->Texture.Unit[i].GenFlags != 0) {
874	       ctx->Enabled |= ENABLE_TEXGEN0 << i;
875
876	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) {
877		  ctx->Texture.NeedNormals = GL_TRUE;
878		  ctx->Texture.NeedEyeCoords = GL_TRUE;
879	       }
880
881	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD) {
882		  ctx->Texture.NeedEyeCoords = GL_TRUE;
883	       }
884	    }
885
886            if (i > 0 && ctx->Texture.Unit[i].ReallyEnabled) {
887               ctx->Texture.MultiTextureEnabled = GL_TRUE;
888            }
889	 }
890         else {
891            ctx->Texture.Unit[i].ReallyEnabled = 0;
892         }
893      }
894      ctx->Enabled = (ctx->Enabled & ~ENABLE_TEX_ANY) | ctx->Texture.ReallyEnabled;
895      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
896   }
897
898
899   if (ctx->NewState & NEW_RASTER_OPS) {
900      update_rasterflags(ctx);
901
902      /* update scissor region */
903      ctx->DrawBuffer->Xmin = 0;
904      ctx->DrawBuffer->Ymin = 0;
905      ctx->DrawBuffer->Xmax = ctx->DrawBuffer->Width;
906      ctx->DrawBuffer->Ymax = ctx->DrawBuffer->Height;
907      if (ctx->Scissor.Enabled) {
908         if (ctx->Scissor.X > ctx->DrawBuffer->Xmin) {
909            ctx->DrawBuffer->Xmin = ctx->Scissor.X;
910         }
911         if (ctx->Scissor.Y > ctx->DrawBuffer->Ymin) {
912            ctx->DrawBuffer->Ymin = ctx->Scissor.Y;
913         }
914         if (ctx->Scissor.X + ctx->Scissor.Width < ctx->DrawBuffer->Xmax) {
915            ctx->DrawBuffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width;
916         }
917         if (ctx->Scissor.Y + ctx->Scissor.Height < ctx->DrawBuffer->Ymax) {
918            ctx->DrawBuffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height;
919         }
920      }
921   }
922
923   if (ctx->NewState & NEW_LIGHTING) {
924      ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
925      if (ctx->Light.Enabled) {
926         if (ctx->Light.Model.TwoSide)
927            ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_LIGHTING_CULL);
928         gl_update_lighting(ctx);
929      }
930   }
931
932   if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) {
933
934      ctx->TriangleCaps &= ~DD_TRI_CULL_FRONT_BACK;
935
936      if (ctx->NewState & NEW_POLYGON) {
937	 /* Setup CullBits bitmask */
938	 if (ctx->Polygon.CullFlag) {
939	    ctx->backface_sign = 1;
940	    switch(ctx->Polygon.CullFaceMode) {
941	    case GL_BACK:
942	       if(ctx->Polygon.FrontFace==GL_CCW)
943		  ctx->backface_sign = -1;
944	       ctx->Polygon.CullBits = 1;
945	       break;
946	    case GL_FRONT:
947	       if(ctx->Polygon.FrontFace!=GL_CCW)
948		  ctx->backface_sign = -1;
949	       ctx->Polygon.CullBits = 2;
950	       break;
951	    default:
952	    case GL_FRONT_AND_BACK:
953	       ctx->backface_sign = 0;
954	       ctx->Polygon.CullBits = 0;
955	       ctx->TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
956	       break;
957	    }
958	 }
959	 else {
960	    ctx->Polygon.CullBits = 3;
961	    ctx->backface_sign = 0;
962	 }
963
964	 /* Any Polygon offsets enabled? */
965	 ctx->TriangleCaps &= ~DD_TRI_OFFSET;
966
967	 if (ctx->Polygon.OffsetPoint ||
968	     ctx->Polygon.OffsetLine ||
969	     ctx->Polygon.OffsetFill)
970	    ctx->TriangleCaps |= DD_TRI_OFFSET;
971      }
972   }
973
974   if (ctx->NewState & ~(NEW_CLIENT_STATE | NEW_USER_CLIP | NEW_POLYGON))
975      gl_update_clipmask(ctx);
976
977   if (ctx->NewState & (NEW_LIGHTING|
978			NEW_RASTER_OPS|
979			NEW_TEXTURING|
980			NEW_TEXTURE_ENABLE|
981			NEW_TEXTURE_ENV|
982			NEW_POLYGON|
983			NEW_USER_CLIP))
984   {
985      ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;
986      ctx->IndirectTriangles |= DD_SW_RASTERIZE;
987
988      if (MESA_VERBOSE&VERBOSE_CULL)
989	 gl_print_tri_caps("initial indirect tris", ctx->IndirectTriangles);
990
991      ctx->Driver.PointsFunc = NULL;
992      ctx->Driver.LineFunc = NULL;
993      ctx->Driver.TriangleFunc = NULL;
994      ctx->Driver.QuadFunc = NULL;
995      ctx->Driver.RectFunc = NULL;
996      ctx->Driver.RenderVBClippedTab = NULL;
997      ctx->Driver.RenderVBCulledTab = NULL;
998      ctx->Driver.RenderVBRawTab = NULL;
999
1000      /*
1001       * Here the driver sets up all the ctx->Driver function pointers to
1002       * it's specific, private functions.
1003       */
1004      ctx->Driver.UpdateState(ctx);
1005
1006      if (MESA_VERBOSE&VERBOSE_CULL)
1007	 gl_print_tri_caps("indirect tris", ctx->IndirectTriangles);
1008
1009      /*
1010       * In case the driver didn't hook in an optimized point, line or
1011       * triangle function we'll now select "core/fallback" point, line
1012       * and triangle functions.
1013       */
1014      if (ctx->IndirectTriangles & DD_SW_RASTERIZE) {
1015	 gl_set_point_function(ctx);
1016	 gl_set_line_function(ctx);
1017	 gl_set_triangle_function(ctx);
1018	 gl_set_quad_function(ctx);
1019
1020	 if ((ctx->IndirectTriangles &
1021	      (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL)) ==
1022	     (DD_TRI_SW_RASTERIZE|DD_QUAD_SW_RASTERIZE|DD_TRI_CULL))
1023	    ctx->IndirectTriangles &= ~DD_TRI_CULL;
1024      }
1025
1026      if (MESA_VERBOSE&VERBOSE_CULL)
1027	 gl_print_tri_caps("indirect tris 2", ctx->IndirectTriangles);
1028
1029      gl_set_render_vb_function(ctx);
1030   }
1031
1032   /* Should only be calc'd when !need_eye_coords and not culling.
1033    */
1034   if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
1035      if (ctx->NewState & NEW_MODELVIEW) {
1036	 gl_matrix_analyze( &ctx->ModelView );
1037	 ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
1038      }
1039
1040      if (ctx->NewState & NEW_PROJECTION) {
1041	 gl_matrix_analyze( &ctx->ProjectionMatrix );
1042	 ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
1043
1044	 if (ctx->Transform.AnyClip) {
1045	    gl_update_userclip( ctx );
1046	 }
1047      }
1048
1049      gl_calculate_model_project_matrix( ctx );
1050      ctx->ModelProjectWinMatrixUptodate = 0;
1051   }
1052
1053   if (ctx->NewState & NEW_COLOR_MATRIX) {
1054      gl_matrix_analyze( &ctx->ColorMatrix );
1055   }
1056
1057   /* Figure out whether we can light in object space or not.  If we
1058    * can, find the current positions of the lights in object space
1059    */
1060   if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | ENABLE_FOG |
1061			ENABLE_TEXGEN0 | ENABLE_TEXGEN1 | ENABLE_TEXGEN2)) &&
1062       (ctx->NewState & (NEW_LIGHTING |
1063                         NEW_FOG |
1064			 NEW_MODELVIEW |
1065			 NEW_PROJECTION |
1066			 NEW_TEXTURING |
1067			 NEW_RASTER_OPS |
1068			 NEW_USER_CLIP)))
1069   {
1070      GLboolean oldcoord, oldnorm;
1071
1072      oldcoord = ctx->NeedEyeCoords;
1073      oldnorm = ctx->NeedEyeNormals;
1074
1075      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
1076      ctx->NeedEyeCoords = ((ctx->Fog.Enabled && ctx->Hint.Fog != GL_NICEST) ||
1077			    ctx->Point.Attenuated);
1078      ctx->NeedEyeNormals = GL_FALSE;
1079
1080      if (ctx->Light.Enabled) {
1081	 if ((ctx->Light.Flags & LIGHT_POSITIONAL) ||
1082             ctx->Light.NeedVertices ||
1083             !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) {
1084            /* Need length for attenuation or need angle for spotlights
1085             * or non-uniform scale matrix
1086             */
1087            ctx->NeedEyeCoords = GL_TRUE;
1088	 }
1089	 ctx->NeedEyeNormals = ctx->NeedEyeCoords;
1090      }
1091      if (ctx->Texture.ReallyEnabled || ctx->RenderMode==GL_FEEDBACK) {
1092	 if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;
1093	 if (ctx->Texture.NeedNormals)
1094	    ctx->NeedNormals = ctx->NeedEyeNormals = GL_TRUE;
1095      }
1096
1097      ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
1098
1099      if (ctx->NeedEyeCoords)
1100	 ctx->vb_proj_matrix = &ctx->ProjectionMatrix;
1101
1102      if (ctx->Light.Enabled) {
1103	 gl_update_lighting_function(ctx);
1104
1105	 if ( (ctx->NewState & NEW_LIGHTING) ||
1106	      ((ctx->NewState & (NEW_MODELVIEW| NEW_PROJECTION)) &&
1107	       !ctx->NeedEyeCoords) ||
1108	      oldcoord != ctx->NeedEyeCoords ||
1109	      oldnorm != ctx->NeedEyeNormals) {
1110	    gl_compute_light_positions(ctx);
1111	 }
1112
1113	 ctx->rescale_factor = 1.0F;
1114
1115	 if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
1116				     MAT_FLAG_GENERAL_SCALE |
1117				     MAT_FLAG_GENERAL_3D |
1118				     MAT_FLAG_GENERAL) )
1119
1120	 {
1121	    GLfloat *m = ctx->ModelView.inv;
1122	    GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10];
1123	    if (f > 1e-12 && (f-1)*(f-1) > 1e-12)
1124	       ctx->rescale_factor = 1.0/GL_SQRT(f);
1125	 }
1126      }
1127
1128      gl_update_normal_transform( ctx );
1129   }
1130
1131   gl_update_pipelines(ctx);
1132   ctx->NewState = 0;
1133}
1134
1135
1136
1137
1138/*
1139 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
1140 * pixel transfer operations are enabled.
1141 */
1142void
1143_mesa_update_image_transfer_state(GLcontext *ctx)
1144{
1145   GLuint mask = 0;
1146
1147   if (ctx->Pixel.RedScale   != 1.0F || ctx->Pixel.RedBias   != 0.0F ||
1148       ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
1149       ctx->Pixel.BlueScale  != 1.0F || ctx->Pixel.BlueBias  != 0.0F ||
1150       ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
1151      mask |= IMAGE_SCALE_BIAS_BIT;
1152
1153   if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
1154      mask |= IMAGE_SHIFT_OFFSET_BIT;
1155
1156   if (ctx->Pixel.MapColorFlag)
1157      mask |= IMAGE_MAP_COLOR_BIT;
1158
1159   if (ctx->Pixel.ColorTableEnabled)
1160      mask |= IMAGE_COLOR_TABLE_BIT;
1161
1162   if (ctx->Pixel.Convolution1DEnabled ||
1163       ctx->Pixel.Convolution2DEnabled ||
1164       ctx->Pixel.Separable2DEnabled)
1165      mask |= IMAGE_CONVOLUTION_BIT;
1166
1167   if (ctx->Pixel.PostConvolutionColorTableEnabled)
1168      mask |= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT;
1169
1170   if (ctx->ColorMatrix.type != MATRIX_IDENTITY ||
1171       ctx->Pixel.PostColorMatrixScale[0] != 1.0F ||
1172       ctx->Pixel.PostColorMatrixBias[0]  != 0.0F ||
1173       ctx->Pixel.PostColorMatrixScale[1] != 1.0F ||
1174       ctx->Pixel.PostColorMatrixBias[1]  != 0.0F ||
1175       ctx->Pixel.PostColorMatrixScale[2] != 1.0F ||
1176       ctx->Pixel.PostColorMatrixBias[2]  != 0.0F ||
1177       ctx->Pixel.PostColorMatrixScale[3] != 1.0F ||
1178       ctx->Pixel.PostColorMatrixBias[3]  != 0.0F)
1179      mask |= IMAGE_COLOR_MATRIX_BIT;
1180
1181   if (ctx->Pixel.PostColorMatrixColorTableEnabled)
1182      mask |= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT;
1183
1184   if (ctx->Pixel.HistogramEnabled)
1185      mask |= IMAGE_HISTOGRAM_BIT;
1186
1187   if (ctx->Pixel.MinMaxEnabled)
1188      mask |= IMAGE_MIN_MAX_BIT;
1189
1190   ctx->ImageTransferState = mask;
1191}
1192