From: José Fonseca Date: Thu, 20 Dec 2012 15:34:50 +0000 (+0000) Subject: gltrace/retrace: Full support for variable length parameters. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=ddf6d2c5e347f8ca25dad4d9be4a1494d8929d30 gltrace/retrace: Full support for variable length parameters. Such as GL_COMPRESSED_TEXTURE_FORMATS. --- diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index b4ec251..c4fe9bf 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -329,11 +329,19 @@ _glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei count) #define _glVertexAttribPointerARB_size(size, type, normalized, stride, count) _glArrayPointer_size(size, type, stride, count) #define _glVertexAttribPointerNV_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count) +/** + * Same as glGetIntegerv, but passing the result in the return value. + */ +static inline GLint +_glGetInteger(GLenum pname) { + GLint param = 0; + _glGetIntegerv(pname, ¶m); + return param; +} + static inline GLint _element_array_buffer_binding(void) { - GLint element_array_buffer = 0; - _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &element_array_buffer); - return element_array_buffer; + return _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING); } static inline GLuint diff --git a/retrace/glstate_params.py b/retrace/glstate_params.py index 6db4b80..50693a9 100644 --- a/retrace/glstate_params.py +++ b/retrace/glstate_params.py @@ -156,12 +156,21 @@ class StateGetter(Visitor): elem_type = self.inflector.reduced_type(array.type) inflection = self.inflector.inflect(array.type) assert inflection.endswith('v') - print ' %s %s[%s + 1];' % (elem_type, temp_name, array.length) - print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array.length, temp_name) - print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array.length, elem_type) + array_length = array.length + if array_length.isdigit(): + # Static integer length + print ' %s %s[%s + 1];' % (elem_type, temp_name, array_length) + else: + # Put the length in a variable to avoid recomputing it every time + print ' size_t _%s_length = %s;' % (temp_name, array_length) + array_length = '_%s_length' % temp_name + # Allocate a dynamic sized array + print ' %s *%s = _allocator.alloc<%s>(%s + 1);' % (elem_type, temp_name, elem_type, array_length) + print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array_length, temp_name) + print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array_length, elem_type) print ' %s(%s, %s);' % (inflection + self.suffix, ', '.join(args), temp_name) # Simple buffer overflow detection - print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array.length, elem_type) + print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array_length, elem_type) return temp_name def visitOpaque(self, pointer, args): @@ -257,6 +266,7 @@ class StateDumper: print '#include ' print print '#include "json.hpp"' + print '#include "scoped_allocator.hpp"' print '#include "glproc.hpp"' print '#include "glsize.hpp"' print '#include "glstate.hpp"' @@ -316,6 +326,9 @@ class StateDumper: print 'void dumpParameters(JSONWriter &json, Context &context)' print '{' + print ' ScopedAllocator _allocator;' + print ' (void)_allocator;' + print print ' json.beginMember("parameters");' print ' json.beginObject();' diff --git a/specs/glparams.py b/specs/glparams.py index 3be99a8..2436724 100644 --- a/specs/glparams.py +++ b/specs/glparams.py @@ -1582,8 +1582,7 @@ parameters = [ ("glGetTexLevelParameter", I, 1, "GL_TEXTURE_COMPRESSED_IMAGE_SIZE"), # 0x86A0 ("glGetTexLevelParameter", B, 1, "GL_TEXTURE_COMPRESSED"), # 0x86A1 ("glGet", I, 1, "GL_NUM_COMPRESSED_TEXTURE_FORMATS"), # 0x86A2 - #XXX: the list is GL_NUM_COMPRESSED_TEXTURES - #("glGet", E, 1, "GL_COMPRESSED_TEXTURE_FORMATS"), # 0x86A3 + ("glGet", E, '_glGetInteger(GL_NUM_COMPRESSED_TEXTURE_FORMATS)', "GL_COMPRESSED_TEXTURE_FORMATS"), # 0x86A3 ("glGet", I, 1, "GL_MAX_VERTEX_UNITS_ARB"), # 0x86A4 ("glGet", I, 1, "GL_ACTIVE_VERTEX_UNITS_ARB"), # 0x86A5 ("glGet", B, 1, "GL_WEIGHT_SUM_UNITY_ARB"), # 0x86A6 diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index 4ee9373..853a4bc 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -298,12 +298,7 @@ class GlTracer(Tracer): print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: - print ' case %s: return %u;' % (name, count) - print ' case GL_COMPRESSED_TEXTURE_FORMATS: {' - print ' GLint num_compressed_texture_formats = 0;' - print ' _glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num_compressed_texture_formats);' - print ' return num_compressed_texture_formats;' - print ' }' + print ' case %s: return %s;' % (name, count) print ' default:' print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;'