Permalink
Browse files

glxtrace: Basic EXT_texture_from_pixmap support.

Make EXT_texture_from_pixmap traces replayable, by emitting a fake
glTexImage2D calls on glXBindTexImageEXT calls.
  • Loading branch information...
1 parent 1fcc39c commit 151c370e340598cc2279e14e4513fa3247add12a @jrfonseca jrfonseca committed May 10, 2013
Showing with 76 additions and 12 deletions.
  1. +0 −12 wrappers/egltrace.py
  2. +10 −0 wrappers/gltrace.py
  3. +66 −0 wrappers/glxtrace.py
View
@@ -96,18 +96,6 @@ def traceFunctionImplBody(self, function):
print ' _EGLImageKHR_free_image_info(info);'
print ' }'
- def emitFakeTexture2D(self):
- function = 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();'
-
-
if __name__ == '__main__':
print '#include <stdlib.h>'
View
@@ -1059,6 +1059,16 @@ def fake_glClientActiveTexture_call(self, api, texture):
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();'
View
@@ -80,6 +80,72 @@ def traceFunctionImplBody(self, function):
print ' gltrace::clearContext();'
print ' }'
+ if function.name == 'glXBindTexImageEXT':
+ # FIXME: glXBindTexImageEXT gets called frequently, so we should
+ # avoid recording the same data over and over again somehow, e.g.:
+ # - get the pixels before and after glXBindTexImageEXT, and only
+ # emit emitFakeTexture2D when it changes
+ # - keep a global hash of the pixels
+ # FIXME: Handle mipmaps
+ print r'''
+ unsigned glx_target = 0;
+ _glXQueryDrawable(display, drawable, GLX_TEXTURE_TARGET_EXT, &glx_target);
+ GLenum target;
+ switch (glx_target) {
+ // FIXME
+ //case GLX_TEXTURE_1D_EXT:
+ // target = GL_TEXTURE_1D;
+ // break;
+ case GLX_TEXTURE_2D_EXT:
+ target = GL_TEXTURE_2D;
+ break;
+ case GLX_TEXTURE_RECTANGLE_EXT:
+ target = GL_TEXTURE_RECTANGLE;
+ break;
+ default:
+ os::log("apitrace: warning: %s: unsupported GLX_TEXTURE_TARGET_EXT 0x%u\n", __FUNCTION__, glx_target);
+ target = GL_NONE;
+ break;
+ }
+ GLint level = 0;
+ GLint internalformat = GL_NONE;
+ _glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
+ GLint width = 0;
+ _glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
+ GLint height = 0;
+ _glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
+ GLint border = 0;
+ unsigned glx_format = 0;
+ _glXQueryDrawable(display, drawable, GLX_TEXTURE_FORMAT_EXT, &glx_format);
+ GLenum format;
+ switch (glx_format) {
+ case GLX_TEXTURE_FORMAT_RGB_EXT:
+ format = GL_RGB;
+ break;
+ case GLX_TEXTURE_FORMAT_RGBA_EXT:
+ format = GL_RGBA;
+ break;
+ case GLX_TEXTURE_FORMAT_NONE_EXT:
+ // XXX: This really shouldn't happen but some
+ // implementations (Mesa) appear return bogus results to
+ // the GLX_TEXTURE_FORMAT_EXT query
+ default:
+ //os::log("apitrace: warning: %s: unexpected GLX_TEXTURE_FORMAT_EXT 0x%u\n", __FUNCTION__, glx_format);
+ format = GL_RGBA;
+ break;
+ }
+ GLenum type = GL_UNSIGNED_BYTE;
+ if (target && internalformat && height && width && format) {
+ GLint channels = _gl_format_channels(format);
+ GLvoid * pixels = malloc(height * width * channels);
+ _glGetTexImage(target, level, format, type, pixels);
+ '''
+ self.emitFakeTexture2D()
+ print r'''
+ free(pixels);
+ }
+ '''
+
if __name__ == '__main__':
print

0 comments on commit 151c370

Please sign in to comment.