add FreeTexImageData hook to help single-copy texturing in drivers
[mesa.git] / src / mesa / main / enable.c
index 3106a987f8a603c372796299166baa07befa4411..f53ae05d171346b356892e64b6012c72d7759884 100644 (file)
@@ -5,9 +5,9 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -49,7 +49,6 @@
    }
 
 
-
 static void
 client_state( GLcontext *ctx, GLenum cap, GLboolean state )
 {
@@ -150,7 +149,7 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls client_state().
  */
-void
+void GLAPIENTRY
 _mesa_EnableClientState( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -169,7 +168,7 @@ _mesa_EnableClientState( GLenum cap )
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls client_state().
  */
-void
+void GLAPIENTRY
 _mesa_DisableClientState( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -186,6 +185,14 @@ _mesa_DisableClientState( GLenum cap )
       return;                                                          \
    }
 
+#define CHECK_EXTENSION2(EXT1, EXT2, CAP)                              \
+   if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) {               \
+      _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",                  \
+                  state ? "Enable" : "Disable", CAP);                  \
+      return;                                                          \
+   }
+
+
 
 /**
  * Perform glEnable() and glDisable() calls.
@@ -225,9 +232,12 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
             return;
          FLUSH_VERTICES(ctx, _NEW_COLOR);
          ctx->Color.BlendEnabled = state;
-         /* The following needed to accomodate 1.0 RGB logic op blending */
-         ctx->Color.ColorLogicOpEnabled =
-            (ctx->Color.BlendEquation == GL_LOGIC_OP && state);
+         /* This is needed to support 1.1's RGB logic ops AND
+          * 1.0's blending logicops.
+          */
+         ctx->Color._LogicOpEnabled =
+            (ctx->Color.ColorLogicOpEnabled ||
+             (state && ctx->Color.BlendEquationRGB == GL_LOGIC_OP));
          break;
 #if FEATURE_userclip
       case GL_CLIP_PLANE0:
@@ -281,6 +291,15 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.CullFlag = state;
          break;
+
+      case GL_CULL_VERTEX_EXT:
+         CHECK_EXTENSION(EXT_cull_vertex, cap);
+         if (ctx->Transform.CullVertexFlag == state)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+         ctx->Transform.CullVertexFlag = state;
+         break;
+
       case GL_DEPTH_TEST:
          if (state && ctx->Visual.depthBits==0) {
             _mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer");
@@ -344,13 +363,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          else
           ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
  
-         if ((ctx->Light.Enabled &&
-              ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR)
-             || ctx->Fog.ColorSumEnabled)
-            ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
-         else
-            ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
-
          break;
       case GL_LINE_SMOOTH:
          if (ctx->Line.SmoothFlag == state)
@@ -377,6 +389,12 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
             return;
          FLUSH_VERTICES(ctx, _NEW_COLOR);
          ctx->Color.ColorLogicOpEnabled = state;
+         /* This is needed to support 1.1's RGB logic ops AND
+          * 1.0's blending logicops.
+          */
+         ctx->Color._LogicOpEnabled =
+            (state || (ctx->Color.BlendEnabled &&
+                       ctx->Color.BlendEquationRGB == GL_LOGIC_OP));
          break;
       case GL_MAP1_COLOR_4:
          if (ctx->Eval.Map1Color4 == state)
@@ -627,7 +645,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          texUnit->TexGenEnabled = newenabled;
          break;
       }
-      break;
       case GL_TEXTURE_GEN_S: {
          GLuint unit = ctx->Texture.CurrentUnit;
          struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
@@ -640,7 +657,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          texUnit->TexGenEnabled = newenabled;
          break;
       }
-      break;
       case GL_TEXTURE_GEN_T: {
          GLuint unit = ctx->Texture.CurrentUnit;
          struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
@@ -653,7 +669,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          texUnit->TexGenEnabled = newenabled;
          break;
       }
-      break;
 
       /*
        * CLIENT STATE!!!
@@ -776,14 +791,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
             return;
          FLUSH_VERTICES(ctx, _NEW_FOG);
          ctx->Fog.ColorSumEnabled = state;
-
-         if ((ctx->Light.Enabled &&
-              ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR)
-             || ctx->Fog.ColorSumEnabled)
-            ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
-         else
-            ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
-
          break;
 
       /* GL_ARB_multisample */
@@ -834,7 +841,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
 
       /* GL_NV_point_sprite */
       case GL_POINT_SPRITE_NV:
-         CHECK_EXTENSION(NV_point_sprite, cap);
+         CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
          if (ctx->Point.PointSprite == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POINT);
@@ -843,24 +850,24 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
 
 #if FEATURE_NV_vertex_program
       case GL_VERTEX_PROGRAM_NV:
-         CHECK_EXTENSION(NV_vertex_program, cap);
+         CHECK_EXTENSION2(NV_vertex_program, ARB_vertex_program, cap);
          if (ctx->VertexProgram.Enabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_PROGRAM);  /* XXX OK? */
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM); 
          ctx->VertexProgram.Enabled = state;
          break;
       case GL_VERTEX_PROGRAM_POINT_SIZE_NV:
-         CHECK_EXTENSION(NV_vertex_program, cap);
+         CHECK_EXTENSION2(NV_vertex_program, ARB_vertex_program, cap);
          if (ctx->VertexProgram.PointSizeEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_PROGRAM);
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->VertexProgram.PointSizeEnabled = state;
          break;
       case GL_VERTEX_PROGRAM_TWO_SIDE_NV:
-         CHECK_EXTENSION(NV_vertex_program, cap);
+         CHECK_EXTENSION2(NV_vertex_program, ARB_vertex_program, cap);
          if (ctx->VertexProgram.TwoSideEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_PROGRAM);  /* XXX OK? */
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM); 
          ctx->VertexProgram.TwoSideEnabled = state;
          break;
       case GL_MAP1_VERTEX_ATTRIB0_4_NV:
@@ -916,7 +923,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          CHECK_EXTENSION(NV_fragment_program, cap);
          if (ctx->FragmentProgram.Enabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_TEXTURE);
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->FragmentProgram.Enabled = state;
          break;
 #endif /* FEATURE_NV_fragment_program */
@@ -945,6 +952,11 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
             return;
          FLUSH_VERTICES(ctx, _NEW_STENCIL);
          ctx->Stencil.TestTwoSide = state;
+         if (state) {
+            ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
+         } else {
+            ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
+         }
          break;
 
 #if FEATURE_ARB_fragment_program
@@ -952,7 +964,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          CHECK_EXTENSION(ARB_fragment_program, cap);
          if (ctx->FragmentProgram.Enabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_TEXTURE);
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->FragmentProgram.Enabled = state;
          break;
 #endif /* FEATURE_ARB_fragment_program */
@@ -981,6 +993,15 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          ctx->VertexProgram.CallbackEnabled = state;
          break;
 
+#if FEATURE_ATI_fragment_shader
+      case GL_FRAGMENT_SHADER_ATI:
+        CHECK_EXTENSION(ATI_fragment_shader, cap);
+       if (ctx->ATIFragmentShader.Enabled == state)
+         return;
+       FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+       ctx->ATIFragmentShader.Enabled = state;
+        break;
+#endif
       default:
          _mesa_error(ctx, GL_INVALID_ENUM,
                      "%s(0x%x)", state ? "glEnable" : "glDisable", cap);
@@ -1003,7 +1024,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls _mesa_set_enable().
  */
-void
+void GLAPIENTRY
 _mesa_Enable( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1023,7 +1044,7 @@ _mesa_Enable( GLenum cap )
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls _mesa_set_enable().
  */
-void
+void GLAPIENTRY
 _mesa_Disable( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1050,7 +1071,7 @@ _mesa_Disable( GLenum cap )
  * For the capabilities associated with extensions verifies that those
  * extensions are effectively present before reporting.
  */
-GLboolean
+GLboolean GLAPIENTRY
 _mesa_IsEnabled( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1418,7 +1439,11 @@ _mesa_IsEnabled( GLenum cap )
       case GL_VERTEX_PROGRAM_CALLBACK_MESA:
          CHECK_EXTENSION(MESA_program_debug);
          return ctx->VertexProgram.CallbackEnabled;
-
+#if FEATURE_ATI_fragment_shader
+      case GL_FRAGMENT_SHADER_ATI:
+        CHECK_EXTENSION(ATI_fragment_shader);
+        return ctx->ATIFragmentShader.Enabled;
+#endif /* FEATURE_ATI_fragment_shader */
       default:
          _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
         return GL_FALSE;