]> git.cworth.org Git - apitrace/blobdiff - gltrace.py
Merge branch 'trace-threads'
[apitrace] / gltrace.py
index a0d155e13388490d292e26d0cb7f4527a22f5bed..00dfc4ef69a513fc1e7429b916c2b9b4792720f9 100644 (file)
@@ -104,15 +104,26 @@ class GlTracer(Tracer):
     ]
     arrays.reverse()
 
+    # arrays available in PROFILE_ES1
+    arrays_es1 = ("Vertex", "Normal", "Color", "TexCoord")
+
     def header(self, api):
         Tracer.header(self, api)
 
         print '#include "gltrace.hpp"'
         print
-        print '// Whether user arrays were used'
-        print 'static bool __user_arrays = false;'
-        print 'static bool __user_arrays_arb = false;'
-        print 'static bool __user_arrays_nv = false;'
+        print 'enum tracer_context_profile {'
+        print '    PROFILE_COMPAT,'
+        print '    PROFILE_ES1,'
+        print '    PROFILE_ES2,'
+        print '};'
+        print
+        print 'struct tracer_context {'
+        print '    enum tracer_context_profile profile;'
+        print '    bool user_arrays;'
+        print '    bool user_arrays_arb;'
+        print '    bool user_arrays_nv;'
+        print '};'
         print
         
         # Which glVertexAttrib* variant to use
@@ -122,12 +133,20 @@ class GlTracer(Tracer):
         print '    VERTEX_ATTRIB_NV,'
         print '};'
         print
+        print 'static tracer_context *__get_context(void)'
+        print '{'
+        print '    // TODO return the context set by other APIs (GLX, EGL, and etc.)'
+        print '    static tracer_context __ctx = { PROFILE_COMPAT, false, false, false };'
+        print '    return &__ctx;'
+        print '}'
+        print
         print 'static vertex_attrib __get_vertex_attrib(void) {'
-        print '    if (__user_arrays_arb || __user_arrays_nv) {'
+        print '    tracer_context *ctx = __get_context();'
+        print '    if (ctx->user_arrays_arb || ctx->user_arrays_nv) {'
         print '        GLboolean __vertex_program = GL_FALSE;'
         print '        __glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &__vertex_program);'
         print '        if (__vertex_program) {'
-        print '            if (__user_arrays_nv) {'
+        print '            if (ctx->user_arrays_nv) {'
         print '                GLint __vertex_program_binding_nv = 0;'
         print '                __glGetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &__vertex_program_binding_nv);'
         print '                if (__vertex_program_binding_nv) {'
@@ -144,16 +163,23 @@ class GlTracer(Tracer):
         # Whether we need user arrays
         print 'static inline bool __need_user_arrays(void)'
         print '{'
-        print '    if (!__user_arrays) {'
+        print '    tracer_context *ctx = __get_context();'
+        print '    if (!ctx->user_arrays) {'
         print '        return false;'
         print '    }'
         print
 
         for camelcase_name, uppercase_name in self.arrays:
+            # in which profile is the array available?
+            profile_check = 'ctx->profile == PROFILE_COMPAT'
+            if camelcase_name in self.arrays_es1:
+                profile_check = '(' + profile_check + ' || ctx->profile == PROFILE_ES1)';
+
             function_name = 'gl%sPointer' % camelcase_name
             enable_name = 'GL_%s_ARRAY' % uppercase_name
             binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
             print '    // %s' % function_name
+            print '  if (%s) {' % profile_check
             self.array_prolog(api, uppercase_name)
             print '    if (__glIsEnabled(%s)) {' % enable_name
             print '        GLint __binding = 0;'
@@ -164,8 +190,13 @@ class GlTracer(Tracer):
             print '        }'
             print '    }'
             self.array_epilog(api, uppercase_name)
+            print '  }'
             print
 
+        print '    // ES1 does not support generic vertex attributes'
+        print '    if (ctx->profile == PROFILE_ES1)'
+        print '        return false;'
+        print
         print '    vertex_attrib __vertex_attrib = __get_vertex_attrib();'
         print
         print '    // glVertexAttribPointer'
@@ -238,7 +269,7 @@ class GlTracer(Tracer):
             print '    case GL_%s:' % target
             print '        return & __%s_mapping;' % target.lower()
         print '    default:'
-        print '        os::DebugMessage("apitrace: warning: unknown buffer target 0x%04X\\n", target);'
+        print '        os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);'
         print '        return NULL;'
         print '    }'
         print '}'
@@ -282,12 +313,20 @@ class GlTracer(Tracer):
         print '            return num_compressed_texture_formats;'
         print '        }'
         print '    default:'
-        print r'        os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
+        print r'        os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
         print '        return 1;'
         print '    }'
         print '}'
         print
 
+        # states such as GL_UNPACK_ROW_LENGTH are not available in GLES
+        print 'static inline bool'
+        print 'can_unpack_subimage(void) {'
+        print '    tracer_context *ctx = __get_context();'
+        print '    return (ctx->profile == PROFILE_COMPAT);'
+        print '}'
+        print
+
     array_pointer_function_names = set((
         "glVertexPointer",
         "glNormalPointer",
@@ -373,11 +412,12 @@ class GlTracer(Tracer):
             print '    GLint __array_buffer = 0;'
             print '    __glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &__array_buffer);'
             print '    if (!__array_buffer) {'
-            print '        __user_arrays = true;'
+            print '        tracer_context *ctx = __get_context();'
+            print '        ctx->user_arrays = true;'
             if function.name == "glVertexAttribPointerARB":
-                print '        __user_arrays_arb = true;'
+                print '        ctx->user_arrays_arb = true;'
             if function.name == "glVertexAttribPointerNV":
-                print '        __user_arrays_nv = true;'
+                print '        ctx->user_arrays_nv = true;'
             self.dispatch_function(function)
 
             # And also break down glInterleavedArrays into the individual calls
@@ -546,6 +586,13 @@ class GlTracer(Tracer):
         'ELEMENT_ARRAY_BUFFER',
         'PIXEL_PACK_BUFFER',
         'PIXEL_UNPACK_BUFFER',
+        'UNIFORM_BUFFER',
+        'TEXTURE_BUFFER',
+        'TRANSFORM_FEEDBACK_BUFFER',
+        'COPY_READ_BUFFER',
+        'COPY_WRITE_BUFFER',
+        'DRAW_INDIRECT_BUFFER',
+        'ATOMIC_COUNTER_BUFFER',
     ]
 
     def wrap_ret(self, function, instance):
@@ -651,8 +698,10 @@ class GlTracer(Tracer):
                 or (isinstance(arg.type, stdapi.Const) \
                     and isinstance(arg.type.type, stdapi.Blob))):
             print '    {'
+            print '        tracer_context *ctx = __get_context();'
             print '        GLint __unpack_buffer = 0;'
-            print '        __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);'
+            print '        if (ctx->profile == PROFILE_COMPAT)'
+            print '            __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);'
             print '        if (__unpack_buffer) {'
             print '            trace::localWriter.writeOpaque(%s);' % arg.name
             print '        } else {'
@@ -685,14 +734,21 @@ class GlTracer(Tracer):
         # update the state
         print 'static void __trace_user_arrays(GLuint maxindex)'
         print '{'
+        print '    tracer_context *ctx = __get_context();'
 
         for camelcase_name, uppercase_name in self.arrays:
+            # in which profile is the array available?
+            profile_check = 'ctx->profile == PROFILE_COMPAT'
+            if camelcase_name in self.arrays_es1:
+                profile_check = '(' + profile_check + ' || ctx->profile == PROFILE_ES1)';
+
             function_name = 'gl%sPointer' % camelcase_name
             enable_name = 'GL_%s_ARRAY' % uppercase_name
             binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
             function = api.get_function_by_name(function_name)
 
             print '    // %s' % function.prototype()
+            print '  if (%s) {' % profile_check
             self.array_trace_prolog(api, uppercase_name)
             self.array_prolog(api, uppercase_name)
             print '    if (__glIsEnabled(%s)) {' % enable_name
@@ -729,6 +785,7 @@ class GlTracer(Tracer):
             print '    }'
             self.array_epilog(api, uppercase_name)
             self.array_trace_epilog(api, uppercase_name)
+            print '  }'
             print
 
         # Samething, but for glVertexAttribPointer*
@@ -741,6 +798,10 @@ class GlTracer(Tracer):
         # This means that the implementations of these functions do not always
         # alias, and they need to be considered independently.
         #
+        print '    // ES1 does not support generic vertex attributes'
+        print '    if (ctx->profile == PROFILE_ES1)'
+        print '        return;'
+        print
         print '    vertex_attrib __vertex_attrib = __get_vertex_attrib();'
         print
         for suffix in ['', 'ARB', 'NV']:
@@ -817,7 +878,10 @@ class GlTracer(Tracer):
             print '    GLint client_active_texture = 0;'
             print '    __glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);'
             print '    GLint max_texture_coords = 0;'
-            print '    __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);'
+            print '    if (ctx->profile == PROFILE_COMPAT)'
+            print '        __glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);'
+            print '    else'
+            print '        __glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_coords);'
             print '    for (GLint unit = 0; unit < max_texture_coords; ++unit) {'
             print '        GLint texture = GL_TEXTURE0 + unit;'
             print '        __glClientActiveTexture(texture);'