home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / state.cpp < prev    next >
C/C++ Source or Header  |  2002-11-06  |  39KB  |  1,074 lines

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