+ def defineShadowBufferHelper(self):
+ print 'void _shadow_glGetBufferSubData(GLenum target, GLintptr offset,'
+ print ' GLsizeiptr size, GLvoid *data)'
+ print '{'
+ print ' 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 ' GLint buffer_binding = 0;'
+ print ' _glGetIntegerv(target, &buffer_binding);'
+ print ' if (buffer_binding > 0) {'
+ print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
+ print ' buf.getSubData(offset, size, data);'
+ print ' }'
+ print '}'
+
+ def shadowBufferMethod(self, method):
+ # Emit code to fetch the shadow buffer, and invoke a method
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers() && target == GL_ELEMENT_ARRAY_BUFFER) {'
+ print ' GLint buffer_binding = 0;'
+ print ' _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &buffer_binding);'
+ print ' if (buffer_binding > 0) {'
+ print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
+ print ' buf.' + method + ';'
+ print ' }'
+ print ' }'
+ print
+
+ def shadowBufferProlog(self, function):
+ if function.name == 'glBufferData':
+ self.shadowBufferMethod('bufferData(size, data)')
+
+ if function.name == 'glBufferSubData':
+ self.shadowBufferMethod('bufferSubData(offset, size, data)')
+
+ if function.name == 'glDeleteBuffers':
+ print ' gltrace::Context *ctx = gltrace::getContext();'
+ print ' if (ctx->needsShadowBuffers()) {'
+ print ' for (GLsizei i = 0; i < n; i++) {'
+ print ' ctx->buffers.erase(buffer[i]);'
+ print ' }'
+ print ' }'
+