def header(self, api): for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def header(self, api): print ''' static HMODULE g_hDll = NULL; static PROC _getPublicProcAddress(LPCSTR lpProcName) { if (!g_hDll) { char szDll[MAX_PATH] = {0}; if (!GetSystemDirectoryA(szDll, MAX_PATH)) { return NULL; } strcat(szDll, "\\\\%s"); g_hDll = LoadLibraryA(szDll); if (!g_hDll) { return NULL; } } return GetProcAddress(g_hDll, lpProcName); } ''' % self.dllname dispatcher = Dispatcher() dispatcher.dispatchApi(api) Tracer.header(self, api)
def header(self, api): print ''' static HINSTANCE g_hDll = NULL; static PROC __getPublicProcAddress(LPCSTR lpProcName) { if (!g_hDll) { char szDll[MAX_PATH] = {0}; if (!GetSystemDirectoryA(szDll, MAX_PATH)) { return NULL; } strcat(szDll, "\\\\%s"); g_hDll = LoadLibraryA(szDll); if (!g_hDll) { return NULL; } } return GetProcAddress(g_hDll, lpProcName); } ''' % self.dllname dispatcher = Dispatcher() dispatcher.dispatch_api(api) Tracer.header(self, api)
def header(self, api): print r'#include "dlltrace.hpp"' print for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def header(self, api): print(r'#include "dlltrace.hpp"') print() for module in api.modules: dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api)
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'gltrace::Context *' print 'gltrace::getContext(void)' print '{' print ' // TODO return the context set by other APIs (GLX, EGL, and etc.)' print ' static gltrace::Context __ctx = { gltrace::PROFILE_COMPAT, false, false, false };' print ' return &__ctx;' print '}' print print 'static vertex_attrib __get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' 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 (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) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' 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 == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::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;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib __vertex_attrib = __get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (__vertex_attrib == VERTEX_ATTRIB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint __enabled = 0;' print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' print ' if (__enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' 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 ' default:' 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 ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'static vertex_attrib _get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' 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 (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) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print self.defineShadowBufferHelper() # Whether we need user arrays print 'static inline bool _need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' 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 == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::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;' print ' _glGetIntegerv(%s, &_binding);' % binding_name print ' if (!_binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (_vertex_attrib == VERTEX_ATTRIB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (_vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint _enabled = 0;' print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);' print ' if (_enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void _trace_user_arrays(GLuint count);' print # Buffer mappings print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called' print 'static bool _checkBufferMapRange = false;' print print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called' print 'static bool _checkBufferFlushingUnmapAPPLE = false;' print # Buffer mapping information, necessary for old Mesa 2.1 drivers which # do not support glGetBufferParameteriv(GL_BUFFER_ACCESS_FLAGS/GL_BUFFER_MAP_LENGTH) print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping _%s_mapping;' % target.lower() print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & _%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '_gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: 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;' 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 ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
def header(self, api): Tracer.header(self, api) print '// Whether user arrays were used' print 'static bool __user_arrays = false;' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' if (!__user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: 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 self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print print ' // glVertexAttribPointer' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower() print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch(target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' OS::DebugMessage("warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate memcpy's signature self.trace_function_decl(glapi.memcpy) # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch(pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' 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 ' default:' print r' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print # Which glVertexAttrib* variant to use print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' print ' VERTEX_ATTRIB_NV,' print '};' print print 'static vertex_attrib _get_vertex_attrib(void) {' print ' gltrace::Context *ctx = gltrace::getContext();' 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 (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) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print self.defineShadowBufferHelper() # Whether we need user arrays print 'static inline bool _need_user_arrays(void)' print '{' print ' gltrace::Context *ctx = gltrace::getContext();' 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 == gltrace::PROFILE_COMPAT' if camelcase_name in self.arrays_es1: profile_check = '(' + profile_check + ' || ctx->profile == gltrace::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;' print ' _glGetIntegerv(%s, &_binding);' % binding_name print ' if (!_binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print ' }' print print ' // ES1 does not support generic vertex attributes' print ' if (ctx->profile == gltrace::PROFILE_ES1)' print ' return false;' print print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();' print print ' // glVertexAttribPointer' print ' if (_vertex_attrib == VERTEX_ATTRIB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (_vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint _max_vertex_attribs = 0;' print ' _glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &_max_vertex_attribs);' print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {' print ' GLint _enabled = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &_enabled);' print ' if (_enabled) {' print ' GLint _binding = 0;' print ' _glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &_binding);' print ' if (!_binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint _enabled = 0;' print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);' print ' if (_enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void _trace_user_arrays(GLuint count);' print # Buffer mappings print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called' print 'static bool _checkBufferMapRange = false;' print print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called' print 'static bool _checkBufferFlushingUnmapAPPLE = false;' print # Buffer mapping information, necessary for old Mesa 2.1 drivers which # do not support glGetBufferParameteriv(GL_BUFFER_ACCESS_FLAGS/GL_BUFFER_MAP_LENGTH) print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping _%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & _%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '_gl_param_size(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is not None: 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;' 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 ' gltrace::Context *ctx = gltrace::getContext();' print ' return (ctx->profile == gltrace::PROFILE_COMPAT);' print '}' print
def header(self, api): Tracer.header(self, api) self.state_tracker_decl(api)
def header(self, api): Tracer.header(self, api) print '// Whether user arrays were used' print 'static bool __user_arrays = false;' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' print ' if (!__user_arrays) {' print ' return false;' print ' }' print for camelcase_name, uppercase_name in self.arrays: 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 self.array_prolog(api, uppercase_name) print ' if (__glIsEnabled(%s)) {' % enable_name print ' GLint __binding = 0;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' print ' }' print ' }' self.array_epilog(api, uppercase_name) print print ' // glVertexAttribPointer' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch(target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' OS::DebugMessage("warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate memcpy's signature self.trace_function_decl(glapi.memcpy) # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch(pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print 'pname_size(GLenum pname) {' 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 ' default:' print r' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);' print ' return 1;' print ' }' print '}' print
def header(self, api): Tracer.header(self, api) print '#include "gltrace.hpp"' print 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 print 'enum vertex_attrib {' print ' VERTEX_ATTRIB,' print ' VERTEX_ATTRIB_ARB,' 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 ' 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 (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) {' print ' return VERTEX_ATTRIB_NV;' print ' }' print ' }' print ' return VERTEX_ATTRIB_ARB;' print ' }' print ' }' print ' return VERTEX_ATTRIB;' print '}' print # Whether we need user arrays print 'static inline bool __need_user_arrays(void)' print '{' 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;' print ' __glGetIntegerv(%s, &__binding);' % binding_name print ' if (!__binding) {' self.array_cleanup(api, uppercase_name) print ' return true;' 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' print ' if (__vertex_attrib == VERTEX_ATTRIB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerARB' print ' if (__vertex_attrib == VERTEX_ATTRIB_ARB) {' print ' GLint __max_vertex_attribs = 0;' print ' __glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &__max_vertex_attribs);' print ' for (GLint index = 0; index < __max_vertex_attribs; ++index) {' print ' GLint __enabled = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB, &__enabled);' print ' if (__enabled) {' print ' GLint __binding = 0;' print ' __glGetVertexAttribivARB(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB, &__binding);' print ' if (!__binding) {' print ' return true;' print ' }' print ' }' print ' }' print ' }' print print ' // glVertexAttribPointerNV' print ' if (__vertex_attrib == VERTEX_ATTRIB_NV) {' print ' for (GLint index = 0; index < 16; ++index) {' print ' GLint __enabled = 0;' print ' __glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &__enabled);' print ' if (__enabled) {' print ' return true;' print ' }' print ' }' print ' }' print print ' return false;' print '}' print print 'static void __trace_user_arrays(GLuint maxindex);' print print 'struct buffer_mapping {' print ' void *map;' print ' GLint length;' print ' bool write;' print ' bool explicit_flush;' print '};' print for target in self.buffer_targets: print 'struct buffer_mapping __%s_mapping;' % target.lower(); print print 'static inline struct buffer_mapping *' print 'get_buffer_mapping(GLenum target) {' print ' switch (target) {' for target in self.buffer_targets: print ' case GL_%s:' % target print ' return & __%s_mapping;' % target.lower() print ' default:' print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);' print ' return NULL;' print ' }' print '}' print # Generate a helper function to determine whether a parameter name # refers to a symbolic value or not print 'static bool' print 'is_symbolic_pname(GLenum pname) {' print ' switch (pname) {' for function, type, count, name in glparams.parameters: if type is glapi.GLenum: print ' case %s:' % name print ' return true;' print ' default:' print ' return false;' print ' }' print '}' print # Generate a helper function to determine whether a parameter value is # potentially symbolic or not; i.e., if the value can be represented in # an enum or not print 'template<class T>' print 'static inline bool' print 'is_symbolic_param(T param) {' print ' return static_cast<T>(static_cast<GLenum>(param)) == param;' print '}' print # Generate a helper function to know how many elements a parameter has print 'static size_t' print '__gl_param_size(GLenum pname) {' 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 ' default:' 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