mesa: implement indexed glGet functions
authorBrian Paul <brianp@vmware.com>
Tue, 29 Dec 2009 22:09:16 +0000 (15:09 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 29 Dec 2009 22:09:16 +0000 (15:09 -0700)
The functions are _mesa_GetBooleanIndexedv(), _mesa_GetIntegerIndexedv(), and
_mesa_GetInteger64Indexedv().  These will be called from API functions such as
glGetBooleanIndexedvEXT() and glGetBooleani_v().

Only the GL_BLEND query is supported at this time.

src/mesa/main/get.c
src/mesa/main/get.h
src/mesa/main/get_gen.py

index 07507414d7049581a213509f0d9e9a00017e4e07..aff67466bcb9a839af33e83781b76131c08e6159 100644 (file)
@@ -7434,3 +7434,77 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
       params[i] = (GLdouble) values[i];
 }
 
+void GLAPIENTRY
+_mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!params)
+      return;
+
+   if (ctx->NewState)
+      _mesa_update_state(ctx);
+
+   switch (pname) {
+      case GL_BLEND:
+         if (index >= MAX_DRAW_BUFFERS) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glGetBooleanIndexedv(index=%u), index", pname);
+         }
+         params[0] = INT_TO_BOOLEAN(((ctx->Color.BlendEnabled >> index) & 1));
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetBooleanIndexedv(pname=0x%x)", pname);
+   }
+}
+
+void GLAPIENTRY
+_mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!params)
+      return;
+
+   if (ctx->NewState)
+      _mesa_update_state(ctx);
+
+   switch (pname) {
+      case GL_BLEND:
+         if (index >= MAX_DRAW_BUFFERS) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glGetIntegerIndexedv(index=%u), index", pname);
+         }
+         params[0] = ((ctx->Color.BlendEnabled >> index) & 1);
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetIntegerIndexedv(pname=0x%x)", pname);
+   }
+}
+
+#if FEATURE_ARB_sync
+void GLAPIENTRY
+_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!params)
+      return;
+
+   if (ctx->NewState)
+      _mesa_update_state(ctx);
+
+   switch (pname) {
+      case GL_BLEND:
+         if (index >= MAX_DRAW_BUFFERS) {
+            _mesa_error(ctx, GL_INVALID_VALUE, "glGetInteger64Indexedv(index=%u), index", pname);
+         }
+         params[0] = (GLint64)(((ctx->Color.BlendEnabled >> index) & 1));
+         break;
+      default:
+         _mesa_error(ctx, GL_INVALID_ENUM, "glGetInteger64Indexedv(pname=0x%x)", pname);
+   }
+}
+#endif /* FEATURE_ARB_sync */
+
index 77a9a7d04b4f8654d51109cd76cd032f90a17f80..076ab7a58bb5a59b65a4141afab2670a6b8b260d 100644 (file)
@@ -50,6 +50,15 @@ _mesa_GetIntegerv( GLenum pname, GLint *params );
 extern void GLAPIENTRY
 _mesa_GetInteger64v( GLenum pname, GLint64 *params );
 
+extern void GLAPIENTRY
+_mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params );
+
+extern void GLAPIENTRY
+_mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params );
+
+extern void GLAPIENTRY
+_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params );
+
 extern void GLAPIENTRY
 _mesa_GetPointerv( GLenum pname, GLvoid **params );
 
index 5aff9d3544e39220d3e437c590876750b83c6c6e..8b6500fae17842e94f7d7268f8caff5d03f2f28f 100644 (file)
@@ -1033,6 +1033,14 @@ StateVars = [
 ]
 
 
+# These are queried via glGetIntegetIndexdvEXT() or glGetIntegeri_v()
+IndexedStateVars = [
+       ( "GL_BLEND", GLint, ["((ctx->Color.BlendEnabled >> index) & 1)"], "MAX_DRAW_BUFFERS", None ),
+       # XXX more to come...
+]
+
+
+
 def ConversionFunc(fromType, toType):
        """Return the name of the macro to convert between two data types."""
        if fromType == toType:
@@ -1059,7 +1067,7 @@ def ConversionFunc(fromType, toType):
                return fromStr + "_TO_" + toStr
 
 
-def EmitGetFunction(stateVars, returnType):
+def EmitGetFunction(stateVars, returnType, indexed):
        """Emit the code to implement glGetBooleanv, glGetIntegerv or glGetFloatv."""
        assert (returnType == GLboolean or
                        returnType == GLint or
@@ -1068,22 +1076,35 @@ def EmitGetFunction(stateVars, returnType):
 
        strType = TypeStrings[returnType]
        # Capitalize first letter of return type
-       if returnType == GLint:
-               function = "GetIntegerv"
-       elif returnType == GLboolean:
-               function = "GetBooleanv"
-       elif returnType == GLfloat:
-               function = "GetFloatv"
-       elif returnType == GLint64:
-               function = "GetInteger64v"
+       if indexed:
+               if returnType == GLint:
+                       function = "GetIntegerIndexedv"
+               elif returnType == GLboolean:
+                       function = "GetBooleanIndexedv"
+               elif returnType == GLint64:
+                       function = "GetInteger64Indexedv"
+               else:
+                       function = "Foo"
        else:
-               abort()
+               if returnType == GLint:
+                       function = "GetIntegerv"
+               elif returnType == GLboolean:
+                       function = "GetBooleanv"
+               elif returnType == GLfloat:
+                       function = "GetFloatv"
+               elif returnType == GLint64:
+                       function = "GetInteger64v"
+               else:
+                       abort()
 
        if returnType == GLint64:
                print "#if FEATURE_ARB_sync"
 
        print "void GLAPIENTRY"
-       print "_mesa_%s( GLenum pname, %s *params )" % (function, strType)
+       if indexed:
+               print "_mesa_%s( GLenum pname, GLuint index, %s *params )" % (function, strType)
+       else:
+               print "_mesa_%s( GLenum pname, %s *params )" % (function, strType)
        print "{"
        print "   GET_CURRENT_CONTEXT(ctx);"
        print "   ASSERT_OUTSIDE_BEGIN_END(ctx);"
@@ -1094,14 +1115,26 @@ def EmitGetFunction(stateVars, returnType):
        print "   if (ctx->NewState)"
        print "      _mesa_update_state(ctx);"
        print ""
-       print "   if (ctx->Driver.%s &&" % function
-       print "       ctx->Driver.%s(ctx, pname, params))" % function
-       print "      return;"
-       print ""
+       if indexed == 0:
+               print "   if (ctx->Driver.%s &&" % function
+               print "       ctx->Driver.%s(ctx, pname, params))" % function
+               print "      return;"
+               print ""
        print "   switch (pname) {"
 
-       for (name, varType, state, optionalCode, extensions) in stateVars:
+       for state in stateVars:
+               if indexed:
+                       (name, varType, state, indexMax, extensions) = state
+                       optionalCode = 0
+               else:
+                       (name, varType, state, optionalCode, extensions) = state
+                       indexMax = 0
                print "      case " + name + ":"
+               if indexMax:
+                       print ('         if (index >= %s) {' % indexMax)
+                       print ('            _mesa_error(ctx, GL_INVALID_VALUE, "gl%s(index=%%u), index", pname);' % function)
+                       print ('         }')
+
                if extensions:
                        if len(extensions) == 1:
                                print ('         CHECK_EXT1(%s, "%s");' %
@@ -1249,9 +1282,13 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
 
 EmitHeader()
 # XXX Maybe sort the StateVars list
-EmitGetFunction(StateVars, GLboolean)
-EmitGetFunction(StateVars, GLfloat)
-EmitGetFunction(StateVars, GLint)
-EmitGetFunction(StateVars, GLint64)
+EmitGetFunction(StateVars, GLboolean, 0)
+EmitGetFunction(StateVars, GLfloat, 0)
+EmitGetFunction(StateVars, GLint, 0)
+EmitGetFunction(StateVars, GLint64, 0)
 EmitGetDoublev()
 
+EmitGetFunction(IndexedStateVars, GLboolean, 1)
+EmitGetFunction(IndexedStateVars, GLint, 1)
+EmitGetFunction(IndexedStateVars, GLint64, 1)
+