Tracer.traceApi(self, api)
print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType)
+
+ # Provide fallback functions to missing debug functions
print ' if (!procPtr) {'
- print ' return procPtr;'
+ else_ = ''
+ for function_name in self.debug_functions:
+ if self.api.getFunctionByName(function_name):
+ print ' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name)
+ print ' return (%s)&%s;' % (retType, function_name)
+ print ' }'
+ else_ = 'else '
+ print ' %s{' % else_
+ print ' return NULL;'
+ print ' }'
print ' }'
+
for function in api.getAllFunctions():
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
print ' }'
print
print ' GLint buffer_binding = 0;'
- print ' _glGetIntegerv(target, &buffer_binding);'
+ print ' _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buffer_binding);'
print ' if (buffer_binding > 0) {'
print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
print ' buf.getSubData(offset, size, data);'
# Emit a fake function
print ' {'
- print ' static trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
+ print ' static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
print ' unsigned _call = trace::localWriter.beginEnter(&_sig);'
print ' trace::localWriter.beginArg(0);'
self.serializeValue(glapi.GLenum, enable_name)
Tracer.traceFunctionImplBody(self, function)
+ # These entrypoints are only expected to be implemented by tools;
+ # drivers will probably not implement them.
marker_functions = [
# GL_GREMEDY_string_marker
'glStringMarkerGREMEDY',
'glPopGroupMarkerEXT',
]
+ # These entrypoints may be implemented by drivers, but are also very useful
+ # for debugging / analysis tools.
+ debug_functions = [
+ # GL_KHR_debug
+ 'glDebugMessageControl',
+ 'glDebugMessageInsert',
+ 'glDebugMessageCallback',
+ 'glGetDebugMessageLog',
+ 'glPushDebugGroup',
+ 'glPopDebugGroup',
+ 'glObjectLabel',
+ 'glGetObjectLabel',
+ 'glObjectPtrLabel',
+ 'glGetObjectPtrLabel',
+ # GL_ARB_debug_output
+ 'glDebugMessageControlARB',
+ 'glDebugMessageInsertARB',
+ 'glDebugMessageCallbackARB',
+ 'glGetDebugMessageLogARB',
+ # GL_AMD_debug_output
+ 'glDebugMessageEnableAMD',
+ 'glDebugMessageInsertAMD',
+ 'glDebugMessageCallbackAMD',
+ 'glGetDebugMessageLogAMD',
+ ]
+
def invokeFunction(self, function):
if function.name in ('glLinkProgram', 'glLinkProgramARB'):
# These functions have been dispatched already
return
+ Tracer.invokeFunction(self, function)
+
+ def doInvokeFunction(self, function):
+ # Same as invokeFunction() but called both when trace is enabled or disabled.
+ #
+ # Used to modify the behavior of GL entry-points.
+
+ # Override GL extensions
+ if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
+ Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override')
+ return
+
# We implement GL_EXT_debug_marker, GL_GREMEDY_*, etc., and not the
# driver
if function.name in self.marker_functions:
return
- if function.name in ('glXGetProcAddress', 'glXGetProcAddressARB', 'wglGetProcAddress'):
+ # We may be faking KHR_debug, so ensure the pointer queries result is
+ # always zeroed to prevent dereference of unitialized pointers
+ if function.name == 'glGetPointerv':
+ print ' if (params &&'
+ print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||'
+ print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {'
+ print ' *params = NULL;'
+ print ' }'
+
+ if function.name in self.getProcAddressFunctionNames:
else_ = ''
for marker_function in self.marker_functions:
if self.api.getFunctionByName(marker_function):
print ' }'
else_ = 'else '
print ' %s{' % else_
- Tracer.invokeFunction(self, function)
- print ' }'
- return
+ Tracer.doInvokeFunction(self, function)
- # Override GL extensions
- if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
- Tracer.invokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override')
+ # Replace function addresses with ours
+ # XXX: Doing this here instead of wrapRet means that the trace will
+ # contain the addresses of the wrapper functions, and not the real
+ # functions, but in practice this should make no difference.
+ if function.name in self.getProcAddressFunctionNames:
+ print ' _result = _wrapProcAddress(%s, _result);' % (function.args[0].name,)
+
+ print ' }'
return
- Tracer.invokeFunction(self, function)
+ Tracer.doInvokeFunction(self, function)
buffer_targets = [
'ARRAY_BUFFER',
def wrapRet(self, function, instance):
Tracer.wrapRet(self, function, instance)
- # Replace function addresses with ours
- if function.name in self.getProcAddressFunctionNames:
- print ' %s = _wrapProcAddress(%s, %s);' % (instance, function.args[0].name, instance)
-
# Keep track of buffer mappings
if function.name in ('glMapBuffer', 'glMapBufferARB'):
print ' struct buffer_mapping *mapping = get_buffer_mapping(target);'
function = api.getFunctionByName('glClientActiveTexture')
self.fake_call(function, [texture])
+ def emitFakeTexture2D(self):
+ function = glapi.glapi.getFunctionByName('glTexImage2D')
+ instances = function.argNames()
+ print ' unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig);' % (function.name,)
+ for arg in function.args:
+ assert not arg.output
+ self.serializeArg(function, arg)
+ print ' trace::localWriter.endEnter();'
+ print ' trace::localWriter.beginLeave(_fake_call);'
+ print ' trace::localWriter.endLeave();'