mesa: add dlist support for indexed colormask and indexed enables/disables
[mesa.git] / src / mesa / main / get_gen.py
index e9c8226d08d572c352834dfa8bc6a75992af64d9..18708be26037d96cdfc35ed8fdcca97e3c21d57b 100644 (file)
@@ -35,6 +35,7 @@ GLfloat = 3
 GLdouble = 4
 GLboolean = 5
 GLfloatN = 6    # A normalized value, such as a color or depth range
+GLint64 = 7
 
 
 TypeStrings = {
@@ -42,7 +43,8 @@ TypeStrings = {
        GLenum : "GLenum",
        GLfloat : "GLfloat",
        GLdouble : "GLdouble",
-       GLboolean : "GLboolean"
+       GLboolean : "GLboolean",
+       GLint64 : "GLint64"
 }
 
 
@@ -80,7 +82,7 @@ StateVars = [
        ( "GL_AUTO_NORMAL", GLboolean, ["ctx->Eval.AutoNormal"], "", None ),
        ( "GL_AUX_BUFFERS", GLint, ["ctx->DrawBuffer->Visual.numAuxBuffers"],
          "", None ),
-       ( "GL_BLEND", GLboolean, ["ctx->Color.BlendEnabled"], "", None ),
+       ( "GL_BLEND", GLboolean, ["(ctx->Color.BlendEnabled & 1)"], "", None ),
        ( "GL_BLEND_DST", GLenum, ["ctx->Color.BlendDstRGB"], "", None ),
        ( "GL_BLEND_SRC", GLenum, ["ctx->Color.BlendSrcRGB"], "", None ),
        ( "GL_BLEND_SRC_RGB_EXT", GLenum, ["ctx->Color.BlendSrcRGB"], "", None ),
@@ -124,10 +126,10 @@ StateVars = [
        ( "GL_COLOR_MATERIAL_PARAMETER", GLenum,
          ["ctx->Light.ColorMaterialMode"], "", None ),
        ( "GL_COLOR_WRITEMASK", GLint,
-         [ "ctx->Color.ColorMask[RCOMP] ? 1 : 0",
-               "ctx->Color.ColorMask[GCOMP] ? 1 : 0",
-               "ctx->Color.ColorMask[BCOMP] ? 1 : 0",
-               "ctx->Color.ColorMask[ACOMP] ? 1 : 0" ], "", None ),
+         [ "ctx->Color.ColorMask[0][RCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[0][GCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[0][BCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[0][ACOMP] ? 1 : 0" ], "", None ),
        ( "GL_CULL_FACE", GLboolean, ["ctx->Polygon.CullFlag"], "", None ),
        ( "GL_CULL_FACE_MODE", GLenum, ["ctx->Polygon.CullFaceMode"], "", None ),
        ( "GL_CURRENT_COLOR", GLfloatN,
@@ -176,7 +178,8 @@ StateVars = [
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][1]",
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][2]",
           "ctx->Current.Attrib[VERT_ATTRIB_TEX0 + texUnit][3]"],
-         "const GLuint texUnit = ctx->Texture.CurrentUnit;", None ),
+         """const GLuint texUnit = ctx->Texture.CurrentUnit;
+         FLUSH_CURRENT(ctx, 0);""", None ),
        ( "GL_DEPTH_BIAS", GLfloat, ["ctx->Pixel.DepthBias"], "", None ),
        ( "GL_DEPTH_BITS", GLint, ["ctx->DrawBuffer->Visual.depthBits"],
          "", None ),
@@ -902,6 +905,10 @@ StateVars = [
          ["ctx->Depth.BoundsMin", "ctx->Depth.BoundsMax"],
          "", ["EXT_depth_bounds_test"] ),
 
+       # GL_ARB_depth_clamp
+       ( "GL_DEPTH_CLAMP", GLboolean, ["ctx->Transform.DepthClamp"], "",
+         ["ARB_depth_clamp"] ),
+
        # GL_ARB_draw_buffers
        ( "GL_MAX_DRAW_BUFFERS_ARB", GLint,
          ["ctx->Const.MaxDrawBuffers"], "", None ),
@@ -935,9 +942,9 @@ StateVars = [
 
        # GL_OES_read_format
        ( "GL_IMPLEMENTATION_COLOR_READ_TYPE_OES", GLint,
-         ["ctx->Const.ColorReadType"], "", ["OES_read_format"] ),
+         ["_mesa_get_color_read_type(ctx)"], "", ["OES_read_format"] ),
        ( "GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES", GLint,
-         ["ctx->Const.ColorReadFormat"], "", ["OES_read_format"] ),
+         ["_mesa_get_color_read_format(ctx)"], "", ["OES_read_format"] ),
 
        # GL_ATI_fragment_shader
        ( "GL_NUM_FRAGMENT_REGISTERS_ATI", GLint, ["6"], "", ["ATI_fragment_shader"] ),
@@ -999,7 +1006,7 @@ StateVars = [
        ( "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB", GLint,
          ["ctx->Const.MaxVertexTextureImageUnits"], "", ["ARB_vertex_shader"] ),
        ( "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB", GLint,
-         ["MAX_COMBINED_TEXTURE_IMAGE_UNITS"], "", ["ARB_vertex_shader"] ),
+         ["ctx->Const.MaxCombinedTextureImageUnits"], "", ["ARB_vertex_shader"] ),
 
        # GL_ARB_shader_objects
        # Actually, this token isn't part of GL_ARB_shader_objects, but is
@@ -1019,19 +1026,44 @@ StateVars = [
        # GL_ARB_seamless_cube_map
        ( "GL_TEXTURE_CUBE_MAP_SEAMLESS", GLboolean, ["ctx->Texture.CubeMapSeamless"], "",
          ["ARB_seamless_cube_map"] ),
+
+       # GL_ARB_sync
+       ( "GL_MAX_SERVER_WAIT_TIMEOUT", GLint64, ["ctx->Const.MaxServerWaitTimeout"], "",
+         ["ARB_sync"] ),
+]
+
+
+# These are queried via glGetIntegetIndexdvEXT() or glGetIntegeri_v()
+IndexedStateVars = [
+       ( "GL_BLEND", GLint, ["((ctx->Color.BlendEnabled >> index) & 1)"],
+         "ctx->Const.MaxDrawBuffers", None ),
+       ( "GL_COLOR_WRITEMASK", GLint,
+         [ "ctx->Color.ColorMask[index][RCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[index][GCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[index][BCOMP] ? 1 : 0",
+               "ctx->Color.ColorMask[index][ACOMP] ? 1 : 0" ],
+         "ctx->Const.MaxDrawBuffers", None ),
+       # XXX more to come...
 ]
 
 
+
 def ConversionFunc(fromType, toType):
        """Return the name of the macro to convert between two data types."""
        if fromType == toType:
                return ""
        elif fromType == GLfloat and toType == GLint:
                return "IROUND"
+       elif fromType == GLfloat and toType == GLint64:
+               return "IROUND64"
        elif fromType == GLfloatN and toType == GLfloat:
                return ""
        elif fromType == GLint and toType == GLfloat: # but not GLfloatN!
                return "(GLfloat)"
+       elif fromType == GLint and toType == GLint64:
+               return "(GLint64)"
+       elif fromType == GLint64 and toType == GLfloat: # but not GLfloatN!
+               return "(GLfloat)"
        else:
                if fromType == GLfloatN:
                        fromType = GLfloat
@@ -1042,25 +1074,44 @@ 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
+                       returnType == GLint64 or
                        returnType == GLfloat)
 
        strType = TypeStrings[returnType]
        # Capitalize first letter of return type
-       if returnType == GLint:
-               function = "GetIntegerv"
-       elif returnType == GLboolean:
-               function = "GetBooleanv"
-       elif returnType == GLfloat:
-               function = "GetFloatv"
+       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);"
@@ -1071,14 +1122,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");' %
@@ -1112,6 +1175,8 @@ def EmitGetFunction(stateVars, returnType):
        print '         _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(pname=0x%%x)", pname);' % function
        print "   }"
        print "}"
+       if returnType == GLint64:
+               print "#endif /* FEATURE_ARB_sync */"
        print ""
        return
 
@@ -1134,15 +1199,22 @@ def EmitHeader():
 #include "mtypes.h"
 #include "state.h"
 #include "texcompress.h"
+#include "framebuffer.h"
 
 
 #define FLOAT_TO_BOOLEAN(X)   ( (X) ? GL_TRUE : GL_FALSE )
 
 #define INT_TO_BOOLEAN(I)     ( (I) ? GL_TRUE : GL_FALSE )
 
+#define INT64_TO_BOOLEAN(I)   ( (I) ? GL_TRUE : GL_FALSE )
+#define INT64_TO_INT(I)       ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
+
 #define BOOLEAN_TO_INT(B)     ( (GLint) (B) )
+#define BOOLEAN_TO_INT64(B)   ( (GLint64) (B) )
 #define BOOLEAN_TO_FLOAT(B)   ( (B) ? 1.0F : 0.0F )
 
+#define ENUM_TO_INT64(E)      ( (GLint64) (E) )
+
 
 /*
  * Check if named extension is enabled, if not generate error and return.
@@ -1217,8 +1289,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, 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)
+