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 '}'
print
+ self.defineShadowBufferHelper()
+
# Whether we need user arrays
print 'static inline bool _need_user_arrays(void)'
print '{'
print '}'
print
- print 'static void _trace_user_arrays(GLuint maxindex);'
+ print 'static void _trace_user_arrays(GLuint count);'
print
# Buffer mappings
else:
Tracer.traceApi(self, api)
+ def defineShadowBufferHelper(self):
+ print 'void _shadow_glGetBufferSubData(GLenum target, GLintptr offset,'
+ print ' GLsizeiptr size, GLvoid *data)'
+ print '{'
+ print ' struct gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (!ctx->needsShadowBuffers() || target != GL_ELEMENT_ARRAY_BUFFER) {'
+ print ' glGetBufferSubData(target, offset, size, data);'
+ print ' return;'
+ print ' }'
+ print
+ print ' struct gltrace::Buffer *buf;'
+ print ' GLint buf_id;'
+ print
+ print ' glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buf_id);'
+ print ' buf = ctx->buffers[buf_id];'
+ print ' assert(size + offset <= buf->size);'
+ print ' memcpy(data, (uint8_t *)buf->data + offset, size);'
+ print '}'
+
+ def shadowBufferProlog(self, function):
+ if function.name == 'glBufferData':
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers() && target == GL_ELEMENT_ARRAY_BUFFER) {'
+ print ' struct gltrace::Buffer *buf;'
+ print ' GLint buf_id;'
+ print
+ print ' glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buf_id);'
+ print ' buf = ctx->buffers[buf_id];'
+ print ' buf->resetData(data, size);'
+ print ' }'
+ print
+
+ if function.name == 'glBufferSubData':
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers() && target == GL_ELEMENT_ARRAY_BUFFER) {'
+ print ' struct gltrace::Buffer *buf;'
+ print ' GLint buf_id;'
+ print
+ print ' glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buf_id);'
+ print ' buf = ctx->buffers[buf_id];'
+ print ' memcpy((uint8_t *)buf->data + offset, data, size);'
+ print ' }'
+ print
+
+ if function.name == 'glDeleteBuffers':
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers()) {'
+ print ' int i;'
+ print
+ print ' for (i = 0; i < n; i++) {'
+ print ' unsigned long buf_id;'
+ print ' struct gltrace::Buffer *buf;'
+ print
+ print ' buf_id = buffer[i];'
+ print ' buf = ctx->buffers[buf_id];'
+ print ' if (buf) {'
+ print ' ctx->buffers.erase(buf_id);'
+ print ' delete buf;'
+ print ' }'
+ print ' }'
+ print ' }'
+
+ def shadowBufferEpilog(self, function):
+ if function.name == 'glGenBuffers':
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers()) {'
+ print ' int i;'
+ print ' for (i = 0; i < n; i++) {'
+ print ' GLuint buf_id = buffer[i];'
+ print ' ctx->buffers[buf_id] = new gltrace::Buffer;'
+ print ' }'
+ print ' }'
+ print
+
+
array_pointer_function_names = set((
"glVertexPointer",
"glNormalPointer",
if function.name in self.draw_function_names:
print ' if (_need_user_arrays()) {'
arg_names = ', '.join([arg.name for arg in function.args[1:]])
- print ' GLuint maxindex = _%s_maxindex(%s);' % (function.name, arg_names)
- print ' _trace_user_arrays(maxindex);'
+ print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names)
+ print ' _trace_user_arrays(_count);'
print ' }'
# Emit a fake memcpy on buffer uploads
print ' }'
print ' }'
+ self.shadowBufferProlog(function)
+
Tracer.traceFunctionImplBody(self, function)
+ self.shadowBufferEpilog(function)
+
marker_functions = [
# GL_GREMEDY_string_marker
'glStringMarkerGREMEDY',
# A simple state tracker to track the pointer values
# update the state
- print 'static void _trace_user_arrays(GLuint maxindex)'
+ print 'static void _trace_user_arrays(GLuint count)'
print '{'
print ' gltrace::Context *ctx = gltrace::getContext();'
print ' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
arg_names = ', '.join([arg.name for arg in function.args[:-1]])
- print ' size_t _size = _%s_size(%s, maxindex);' % (function.name, arg_names)
+ print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
# Emit a fake function
self.array_trace_intermezzo(api, uppercase_name)
print ' _%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
arg_names = ', '.join([arg.name for arg in function.args[1:-1]])
- print ' size_t _size = _%s_size(%s, maxindex);' % (function.name, arg_names)
+ print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
# Emit a fake function
print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig);' % (function.name,)
function = api.getFunctionByName('glClientActiveTexture')
self.fake_call(function, [texture])
- def fake_call(self, function, args):
- print ' unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig);' % (function.name,)
- for arg, instance in zip(function.args, args):
- assert not arg.output
- print ' trace::localWriter.beginArg(%u);' % (arg.index,)
- self.serializeValue(arg.type, instance)
- print ' trace::localWriter.endArg();'
- print ' trace::localWriter.endEnter();'
- print ' trace::localWriter.beginLeave(_fake_call);'
- print ' trace::localWriter.endLeave();'