Merge branch 'origin'
[mesa.git] / src / mesa / main / state.c
index 56b835f5373a3296b169fd1fe889ab0cd1b40f63..4184aeb9d921c33413c2d3a0e16694ce69adfd3a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.1
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
@@ -70,7 +70,7 @@
 #include "lines.h"
 #include "macros.h"
 #include "matrix.h"
-#if FEATURE_ARB_occlusion_query
+#if FEATURE_ARB_occlusion_query || FEATURE_EXT_timer_query
 #include "occlude.h"
 #endif
 #include "pixel.h"
@@ -304,7 +304,6 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_GenTextures(exec, _mesa_GenTextures);
 #if _HAVE_FULL_GL
    SET_AreTexturesResident(exec, _mesa_AreTexturesResident);
-   SET_AreTexturesResidentEXT(exec, _mesa_AreTexturesResident);
    SET_ColorPointer(exec, _mesa_ColorPointer);
    SET_CopyTexImage1D(exec, _mesa_CopyTexImage1D);
    SET_CopyTexImage2D(exec, _mesa_CopyTexImage2D);
@@ -313,12 +312,10 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_DisableClientState(exec, _mesa_DisableClientState);
    SET_EdgeFlagPointer(exec, _mesa_EdgeFlagPointer);
    SET_EnableClientState(exec, _mesa_EnableClientState);
-   SET_GenTexturesEXT(exec, _mesa_GenTextures);
    SET_GetPointerv(exec, _mesa_GetPointerv);
    SET_IndexPointer(exec, _mesa_IndexPointer);
    SET_InterleavedArrays(exec, _mesa_InterleavedArrays);
    SET_IsTexture(exec, _mesa_IsTexture);
-   SET_IsTextureEXT(exec, _mesa_IsTexture);
    SET_NormalPointer(exec, _mesa_NormalPointer);
    SET_PopClientAttrib(exec, _mesa_PopClientAttrib);
    SET_PrioritizeTextures(exec, _mesa_PrioritizeTextures);
@@ -356,31 +353,18 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_CopyConvolutionFilter1D(exec, _mesa_CopyConvolutionFilter1D);
    SET_CopyConvolutionFilter2D(exec, _mesa_CopyConvolutionFilter2D);
    SET_GetColorTable(exec, _mesa_GetColorTable);
-   SET_GetColorTableEXT(exec, _mesa_GetColorTable);
    SET_GetColorTableParameterfv(exec, _mesa_GetColorTableParameterfv);
-   SET_GetColorTableParameterfvEXT(exec, _mesa_GetColorTableParameterfv);
    SET_GetColorTableParameteriv(exec, _mesa_GetColorTableParameteriv);
-   SET_GetColorTableParameterivEXT(exec, _mesa_GetColorTableParameteriv);
    SET_GetConvolutionFilter(exec, _mesa_GetConvolutionFilter);
-   SET_GetConvolutionFilterEXT(exec, _mesa_GetConvolutionFilter);
    SET_GetConvolutionParameterfv(exec, _mesa_GetConvolutionParameterfv);
-   SET_GetConvolutionParameterfvEXT(exec, _mesa_GetConvolutionParameterfv);
    SET_GetConvolutionParameteriv(exec, _mesa_GetConvolutionParameteriv);
-   SET_GetConvolutionParameterivEXT(exec, _mesa_GetConvolutionParameteriv);
    SET_GetHistogram(exec, _mesa_GetHistogram);
-   SET_GetHistogramEXT(exec, _mesa_GetHistogram);
    SET_GetHistogramParameterfv(exec, _mesa_GetHistogramParameterfv);
-   SET_GetHistogramParameterfvEXT(exec, _mesa_GetHistogramParameterfv);
    SET_GetHistogramParameteriv(exec, _mesa_GetHistogramParameteriv);
-   SET_GetHistogramParameterivEXT(exec, _mesa_GetHistogramParameteriv);
    SET_GetMinmax(exec, _mesa_GetMinmax);
-   SET_GetMinmaxEXT(exec, _mesa_GetMinmax);
    SET_GetMinmaxParameterfv(exec, _mesa_GetMinmaxParameterfv);
-   SET_GetMinmaxParameterfvEXT(exec, _mesa_GetMinmaxParameterfv);
    SET_GetMinmaxParameteriv(exec, _mesa_GetMinmaxParameteriv);
-   SET_GetMinmaxParameterivEXT(exec, _mesa_GetMinmaxParameteriv);
    SET_GetSeparableFilter(exec, _mesa_GetSeparableFilter);
-   SET_GetSeparableFilterEXT(exec, _mesa_GetSeparableFilter);
    SET_Histogram(exec, _mesa_Histogram);
    SET_Minmax(exec, _mesa_Minmax);
    SET_ResetHistogram(exec, _mesa_ResetHistogram);
@@ -392,6 +376,32 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_StencilFuncSeparate(exec, _mesa_StencilFuncSeparate);
    SET_StencilMaskSeparate(exec, _mesa_StencilMaskSeparate);
    SET_StencilOpSeparate(exec, _mesa_StencilOpSeparate);
+#if FEATURE_ARB_shader_objects
+   SET_AttachShader(exec, _mesa_AttachShader);
+   SET_CreateProgram(exec, _mesa_CreateProgram);
+   SET_CreateShader(exec, _mesa_CreateShader);
+   SET_DeleteProgram(exec, _mesa_DeleteProgram);
+   SET_DeleteShader(exec, _mesa_DeleteShader);
+   SET_DetachShader(exec, _mesa_DetachShader);
+   SET_GetAttachedShaders(exec, _mesa_GetAttachedShaders);
+   SET_GetProgramiv(exec, _mesa_GetProgramiv);
+   SET_GetProgramInfoLog(exec, _mesa_GetProgramInfoLog);
+   SET_GetShaderiv(exec, _mesa_GetShaderiv);
+   SET_GetShaderInfoLog(exec, _mesa_GetShaderInfoLog);
+   SET_IsProgram(exec, _mesa_IsProgram);
+   SET_IsShader(exec, _mesa_IsShader);
+#endif
+
+   /* OpenGL 2.1 */
+#if FEATURE_ARB_shader_objects
+   SET_UniformMatrix2x3fv(exec, _mesa_UniformMatrix2x3fv);
+   SET_UniformMatrix3x2fv(exec, _mesa_UniformMatrix3x2fv);
+   SET_UniformMatrix2x4fv(exec, _mesa_UniformMatrix2x4fv);
+   SET_UniformMatrix4x2fv(exec, _mesa_UniformMatrix4x2fv);
+   SET_UniformMatrix3x4fv(exec, _mesa_UniformMatrix3x4fv);
+   SET_UniformMatrix4x3fv(exec, _mesa_UniformMatrix4x3fv);
+#endif
+
 
    /* 2. GL_EXT_blend_color */
 #if 0
@@ -411,7 +421,7 @@ _mesa_init_exec_table(struct _glapi_table *exec)
 #endif
 
    /* 11. GL_EXT_histogram */
-#if _HAVE_FULL_GL
+#if 0
    SET_GetHistogramEXT(exec, _mesa_GetHistogram);
    SET_GetHistogramParameterfvEXT(exec, _mesa_GetHistogramParameterfv);
    SET_GetHistogramParameterivEXT(exec, _mesa_GetHistogramParameteriv);
@@ -420,6 +430,15 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_GetMinmaxParameterivEXT(exec, _mesa_GetMinmaxParameteriv);
 #endif
 
+   /* 14. SGI_color_table */
+#if 0
+   SET_ColorTableSGI(exec, _mesa_ColorTable);
+   SET_ColorSubTableSGI(exec, _mesa_ColorSubTable);
+   SET_GetColorTableSGI(exec, _mesa_GetColorTable);
+   SET_GetColorTableParameterfvSGI(exec, _mesa_GetColorTableParameterfv);
+   SET_GetColorTableParameterivSGI(exec, _mesa_GetColorTableParameteriv);
+#endif
+
    /* 30. GL_EXT_vertex_array */
 #if _HAVE_FULL_GL
    SET_ColorPointerEXT(exec, _mesa_ColorPointerEXT);
@@ -441,17 +460,6 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_PointParameterfvEXT(exec, _mesa_PointParameterfvEXT);
 #endif
 
-   /* 78. GL_EXT_paletted_texture */
-#if 0
-   SET_ColorTableEXT(exec, _mesa_ColorTableEXT);
-   SET_ColorSubTableEXT(exec, _mesa_ColorSubTableEXT);
-#endif
-#if _HAVE_FULL_GL
-   SET_GetColorTableEXT(exec, _mesa_GetColorTable);
-   SET_GetColorTableParameterfvEXT(exec, _mesa_GetColorTableParameterfv);
-   SET_GetColorTableParameterivEXT(exec, _mesa_GetColorTableParameteriv);
-#endif
-
    /* 97. GL_EXT_compiled_vertex_array */
 #if _HAVE_FULL_GL
    SET_LockArraysEXT(exec, _mesa_LockArraysEXT);
@@ -525,7 +533,7 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_GetVertexAttribfvNV(exec, _mesa_GetVertexAttribfvNV);
    SET_GetVertexAttribivNV(exec, _mesa_GetVertexAttribivNV);
    SET_GetVertexAttribPointervNV(exec, _mesa_GetVertexAttribPointervNV);
-   SET_IsProgramNV(exec, _mesa_IsProgram);
+   SET_IsProgramNV(exec, _mesa_IsProgramARB);
    SET_LoadProgramNV(exec, _mesa_LoadProgramNV);
    SET_ProgramParameter4dNV(exec, _mesa_ProgramParameter4dNV);
    SET_ProgramParameter4dvNV(exec, _mesa_ProgramParameter4dvNV);
@@ -790,13 +798,20 @@ _mesa_init_exec_table(struct _glapi_table *exec)
    SET_GenerateMipmapEXT(exec, _mesa_GenerateMipmapEXT);
 #endif
 
-   /* GL_EXT_timer_query */
+#if FEATURE_EXT_timer_query
    SET_GetQueryObjecti64vEXT(exec, _mesa_GetQueryObjecti64vEXT);
    SET_GetQueryObjectui64vEXT(exec, _mesa_GetQueryObjectui64vEXT);
+#endif
 
 #if FEATURE_EXT_framebuffer_blit
    SET_BlitFramebufferEXT(exec, _mesa_BlitFramebufferEXT);
 #endif
+
+   /* GL_EXT_gpu_program_parameters */
+#if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
+   SET_ProgramEnvParameters4fvEXT(exec, _mesa_ProgramEnvParameters4fvEXT);
+   SET_ProgramLocalParameters4fvEXT(exec, _mesa_ProgramLocalParameters4fvEXT);
+#endif
 }
 
 
@@ -806,16 +821,6 @@ _mesa_init_exec_table(struct _glapi_table *exec)
 /*@{*/
 
 
-static void
-update_separate_specular( GLcontext *ctx )
-{
-   if (NEED_SECONDARY_COLOR(ctx))
-      ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
-   else
-      ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
-}
-
-
 /**
  * Update state dependent on vertex arrays.
  */
@@ -955,7 +960,7 @@ update_program(GLcontext *ctx)
    if (ctx->_MaintainTexEnvProgram && !ctx->FragmentProgram._Enabled) {
 #if 0
       if (!ctx->_TexEnvProgram)
-        ctx->_TexEnvProgram = (struct fragment_program *)
+        ctx->_TexEnvProgram = (struct gl_fragment_program *)
            ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
       ctx->FragmentProgram._Current = ctx->_TexEnvProgram;
 #endif
@@ -985,22 +990,106 @@ update_viewport_matrix(GLcontext *ctx)
 }
 
 
+/**
+ * Update derived color/blend/logicop state.
+ */
+static void
+update_color(GLcontext *ctx)
+{
+   /* This is needed to support 1.1's RGB logic ops AND
+    * 1.0's blending logicops.
+    */
+   ctx->Color._LogicOpEnabled = RGBA_LOGICOP_ENABLED(ctx);
+}
+
+
+/**
+ * Update the ctx->_TriangleCaps bitfield.
+ * XXX that bitfield should really go away someday!
+ * This function must be called after other update_*() functions since
+ * there are dependencies on some other derived values.
+ */
+static void
+update_tricaps(GLcontext *ctx, GLbitfield new_state)
+{
+   ctx->_TriangleCaps = 0;
+
+   /*
+    * Points
+    */
+   if (new_state & _NEW_POINT) {
+      if (ctx->Point.SmoothFlag)
+         ctx->_TriangleCaps |= DD_POINT_SMOOTH;
+      if (ctx->Point._Size != 1.0F)
+         ctx->_TriangleCaps |= DD_POINT_SIZE;
+      if (ctx->Point._Attenuated)
+         ctx->_TriangleCaps |= DD_POINT_ATTEN;
+   }
+
+   /*
+    * Lines
+    */
+   if (new_state & _NEW_LINE) {
+      if (ctx->Line.SmoothFlag)
+         ctx->_TriangleCaps |= DD_LINE_SMOOTH;
+      if (ctx->Line.StippleFlag)
+         ctx->_TriangleCaps |= DD_LINE_STIPPLE;
+      if (ctx->Line._Width != 1.0)
+         ctx->_TriangleCaps |= DD_LINE_WIDTH;
+   }
+
+   /*
+    * Polygons
+    */
+   if (new_state & _NEW_POLYGON) {
+      if (ctx->Polygon.SmoothFlag)
+         ctx->_TriangleCaps |= DD_TRI_SMOOTH;
+      if (ctx->Polygon.StippleFlag)
+         ctx->_TriangleCaps |= DD_TRI_STIPPLE;
+      if (ctx->Polygon.FrontMode != GL_FILL
+          || ctx->Polygon.BackMode != GL_FILL)
+         ctx->_TriangleCaps |= DD_TRI_UNFILLED;
+      if (ctx->Polygon.CullFlag
+          && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
+         ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
+      if (ctx->Polygon.OffsetPoint ||
+          ctx->Polygon.OffsetLine ||
+          ctx->Polygon.OffsetFill)
+         ctx->_TriangleCaps |= DD_TRI_OFFSET;
+   }
+
+   /*
+    * Lighting and shading
+    */
+   if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
+      ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+   if (ctx->Light.ShadeModel == GL_FLAT)
+      ctx->_TriangleCaps |= DD_FLATSHADE;
+   if (NEED_SECONDARY_COLOR(ctx))
+      ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
+
+   /*
+    * Stencil
+    */
+   if (ctx->Stencil._TestTwoSide)
+      ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
+}
+
 
 /**
- * If __GLcontextRec::NewState is non-zero then this function \b must be called
- * before rendering any primitive.  Basically, function pointers and
- * miscellaneous flags are updated to reflect the current state of the state
- * machine.
+ * Compute derived GL state.
+ * If __GLcontextRec::NewState is non-zero then this function \b must
+ * be called before rendering anything.
  *
  * Calls dd_function_table::UpdateState to perform any internal state
  * management necessary.
  * 
  * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
- * _mesa_update_buffer_bounds(), _mesa_update_polygon(),
+ * _mesa_update_buffer_bounds(),
  * _mesa_update_lighting() and _mesa_update_tnl_spaces().
  */
 void
-_mesa_update_state( GLcontext *ctx )
+_mesa_update_state_locked( GLcontext *ctx )
 {
    GLbitfield new_state = ctx->NewState;
 
@@ -1025,9 +1114,6 @@ _mesa_update_state( GLcontext *ctx )
    if (new_state & _NEW_POINT)
       _mesa_update_point( ctx );
 
-   if (new_state & _NEW_POLYGON)
-      _mesa_update_polygon( ctx );
-
    if (new_state & _NEW_LIGHT)
       _mesa_update_lighting( ctx );
 
@@ -1037,15 +1123,19 @@ _mesa_update_state( GLcontext *ctx )
    if (new_state & _IMAGE_NEW_TRANSFER_STATE)
       _mesa_update_pixel( ctx, new_state );
 
-   if (new_state & _DD_NEW_SEPARATE_SPECULAR)
-      update_separate_specular( ctx );
-
    if (new_state & (_NEW_ARRAY | _NEW_PROGRAM))
       update_arrays( ctx );
 
    if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
       update_viewport_matrix(ctx);
 
+   if (new_state & _NEW_COLOR)
+      update_color( ctx );
+
+   if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT
+                    | _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR))
+      update_tricaps( ctx, new_state );
+
    if (ctx->_MaintainTexEnvProgram) {
       if (new_state & (_NEW_TEXTURE | _DD_NEW_SEPARATE_SPECULAR | _NEW_FOG))
         _mesa_UpdateTexEnvProgram(ctx);
@@ -1078,4 +1168,19 @@ _mesa_update_state( GLcontext *ctx )
    ctx->Array.NewState = 0;
 }
 
+
+/* This is the usual entrypoint for state updates:
+ */
+void
+_mesa_update_state( GLcontext *ctx )
+{
+   _mesa_lock_context_textures(ctx);
+   _mesa_update_state_locked(ctx);
+   _mesa_unlock_context_textures(ctx);
+}
+
+
+
 /*@}*/
+
+