From c29f4f1514e7c4d857583d3b5a8d3d7ba6d60a69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 11 Jun 2011 12:19:05 +0100 Subject: [PATCH] Handle ARB_pixel_buffer_object correctly. When a pack buffer object is bound, the pack functions *have* side-effects. --- glapi.py | 42 +++++++++++++++++++++--------------------- glretrace.py | 41 +++++++++++++++++++++++++++++++++++++++++ gltrace.py | 28 +++++++++++++++++++++++----- 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/glapi.py b/glapi.py index 31a5469..2b7572d 100644 --- a/glapi.py +++ b/glapi.py @@ -82,14 +82,14 @@ glapi.add_functions([ GlFunction(Void, "glPixelStoref", [(GLenum, "pname"), (GLfloat, "param")]), GlFunction(Void, "glPixelStorei", [(GLenum, "pname"), (GLint, "param")]), GlFunction(Void, "glReadBuffer", [(GLenum, "mode")]), - GlFunction(Void, "glReadPixels", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), Out(OpaquePointer(GLvoid), "pixels")], sideeffects=False), + GlFunction(Void, "glReadPixels", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), Out(OpaquePointer(GLvoid), "pixels")]), GlFunction(Void, "glGetBooleanv", [(GLenum, "pname"), Out(Array(GLboolean, "__glGetBooleanv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetDoublev", [(GLenum, "pname"), Out(Array(GLdouble, "__glGetDoublev_size(pname)"), "params")], sideeffects=False), GlFunction(GLenum_error, "glGetError", [], sideeffects=False), GlFunction(Void, "glGetFloatv", [(GLenum, "pname"), Out(Array(GLfloat, "__glGetFloatv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetIntegerv", [(GLenum, "pname"), Out(Array(GLint, "__glGetIntegerv_size(pname)"), "params")], sideeffects=False), GlFunction(String("const GLubyte *"), "glGetString", [(GLenum, "name")], sideeffects=False), - GlFunction(Void, "glGetTexImage", [(GLenum, "target"), (GLint, "level"), (GLenum, "format"), (GLenum, "type"), Out(OpaquePointer(GLvoid), "pixels")], sideeffects=False), + GlFunction(Void, "glGetTexImage", [(GLenum, "target"), (GLint, "level"), (GLenum, "format"), (GLenum, "type"), Out(OpaquePointer(GLvoid), "pixels")]), GlFunction(Void, "glGetTexParameterfv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetTexParameterfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetTexParameteriv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLint, "__glGetTexParameteriv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetTexLevelParameterfv", [(GLenum, "target"), (GLint, "level"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetTexLevelParameterfv_size(pname)"), "params")], sideeffects=False), @@ -331,10 +331,10 @@ glapi.add_functions([ GlFunction(Void, "glGetMapiv", [(GLenum, "target"), (GLenum, "query"), Out(Pointer(GLint), "v")], sideeffects=False), GlFunction(Void, "glGetMaterialfv", [(GLenum, "face"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetMaterialfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetMaterialiv", [(GLenum, "face"), (GLenum, "pname"), Out(Array(GLint, "__glGetMaterialiv_size(pname)"), "params")], sideeffects=False), - GlFunction(Void, "glGetPixelMapfv", [(GLenum, "map"), Out(Pointer(GLfloat), "values")], sideeffects=False), - GlFunction(Void, "glGetPixelMapuiv", [(GLenum, "map"), Out(Pointer(GLuint), "values")], sideeffects=False), - GlFunction(Void, "glGetPixelMapusv", [(GLenum, "map"), Out(Pointer(GLushort), "values")], sideeffects=False), - GlFunction(Void, "glGetPolygonStipple", [Out(OpaquePointer(GLubyte), "mask")], sideeffects=False), + GlFunction(Void, "glGetPixelMapfv", [(GLenum, "map"), Out(Pointer(GLfloat), "values")]), + GlFunction(Void, "glGetPixelMapuiv", [(GLenum, "map"), Out(Pointer(GLuint), "values")]), + GlFunction(Void, "glGetPixelMapusv", [(GLenum, "map"), Out(Pointer(GLushort), "values")]), + GlFunction(Void, "glGetPolygonStipple", [Out(OpaquePointer(GLubyte), "mask")]), GlFunction(Void, "glGetTexEnvfv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetTexEnvfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetTexEnviv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLint, "__glGetTexEnviv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetTexGendv", [(GLenum, "coord"), (GLenum, "pname"), Out(Array(GLdouble, "__glGetTexGendv_size(pname)"), "params")], sideeffects=False), @@ -418,15 +418,15 @@ glapi.add_functions([ GlFunction(Void, "glConvolutionParameteriv", [(GLenum, "target"), (GLenum, "pname"), (Const(Array(GLint, "__glConvolutionParameteriv_size(pname)")), "params")]), GlFunction(Void, "glCopyConvolutionFilter1D", [(GLenum, "target"), (GLenum, "internalformat"), (GLint, "x"), (GLint, "y"), (GLsizei, "width")]), GlFunction(Void, "glCopyConvolutionFilter2D", [(GLenum, "target"), (GLenum, "internalformat"), (GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height")]), - GlFunction(Void, "glGetConvolutionFilter", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetConvolutionFilter_size(target, format, type)"), "image")], sideeffects=False), + GlFunction(Void, "glGetConvolutionFilter", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetConvolutionFilter_size(target, format, type)"), "image")]), GlFunction(Void, "glGetConvolutionParameterfv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetConvolutionParameterfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetConvolutionParameteriv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLint, "__glGetConvolutionParameteriv_size(pname)"), "params")], sideeffects=False), - GlFunction(Void, "glGetSeparableFilter", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "row"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "column"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "span")], sideeffects=False), - GlFunction(Void, "glGetHistogram", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetHistogram_size(target, format, type)"), "values")], sideeffects=False), + GlFunction(Void, "glGetSeparableFilter", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "row"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "column"), Out(OpaqueBlob(GLvoid, "__glGetSeparableFilter_size(target, format, type)"), "span")]), GlFunction(Void, "glSeparableFilter2D", [(GLenum, "target"), (GLenum, "internalformat"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (Const(Blob(GLvoid, "__glConvolutionFilter1D_size(format, type, width)")), "row"), (Const(Blob(GLvoid, "__glConvolutionFilter1D_size(format, type, height)")), "column")]), + GlFunction(Void, "glGetHistogram", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetHistogram_size(target, format, type)"), "values")]), GlFunction(Void, "glGetHistogramParameterfv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetHistogramParameterfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetHistogramParameteriv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLint, "__glGetHistogramParameteriv_size(pname)"), "params")], sideeffects=False), - GlFunction(Void, "glGetMinmax", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetMinmax_size(target, format, type)"), "values")], sideeffects=False), + GlFunction(Void, "glGetMinmax", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), Out(OpaqueBlob(GLvoid, "__glGetMinmax_size(target, format, type)"), "values")]), GlFunction(Void, "glGetMinmaxParameterfv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLfloat, "__glGetMinmaxParameterfv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glGetMinmaxParameteriv", [(GLenum, "target"), (GLenum, "pname"), Out(Array(GLint, "__glGetMinmaxParameteriv_size(pname)"), "params")], sideeffects=False), GlFunction(Void, "glHistogram", [(GLenum, "target"), (GLsizei, "width"), (GLenum, "internalformat"), (GLboolean, "sink")]), @@ -443,7 +443,7 @@ glapi.add_functions([ GlFunction(Void, "glCompressedTexSubImage3D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "yoffset"), (GLint, "zoffset"), (GLsizei, "width"), (GLsizei, "height"), (GLsizei, "depth"), (GLenum, "format"), (GLsizei, "imageSize"), (Const(Blob(GLvoid, "imageSize")), "data")]), GlFunction(Void, "glCompressedTexSubImage2D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "yoffset"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLsizei, "imageSize"), (Const(Blob(GLvoid, "imageSize")), "data")]), GlFunction(Void, "glCompressedTexSubImage1D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLsizei, "width"), (GLenum, "format"), (GLsizei, "imageSize"), (Const(Blob(GLvoid, "imageSize")), "data")]), - GlFunction(Void, "glGetCompressedTexImage", [(GLenum, "target"), (GLint, "level"), Out(OpaqueBlob(GLvoid, "__glGetCompressedTexImage_size(target, level)"), "img")], sideeffects=False), + GlFunction(Void, "glGetCompressedTexImage", [(GLenum, "target"), (GLint, "level"), Out(OpaqueBlob(GLvoid, "__glGetCompressedTexImage_size(target, level)"), "img")]), # GL_VERSION_1_3_DEPRECATED GlFunction(Void, "glClientActiveTexture", [(GLenum, "texture")]), @@ -1300,17 +1300,17 @@ glapi.add_functions([ GlFunction(Void, "glGetnMapdvARB", [(GLenum, "target"), (GLenum, "query"), (GLsizei, "bufSize"), Out(Array(GLdouble, "bufSize"), "v")], sideeffects=False), GlFunction(Void, "glGetnMapfvARB", [(GLenum, "target"), (GLenum, "query"), (GLsizei, "bufSize"), Out(Array(GLfloat, "bufSize"), "v")], sideeffects=False), GlFunction(Void, "glGetnMapivARB", [(GLenum, "target"), (GLenum, "query"), (GLsizei, "bufSize"), Out(Array(GLint, "bufSize"), "v")], sideeffects=False), - GlFunction(Void, "glGetnPixelMapfvARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLfloat, "bufSize"), "values")], sideeffects=False), - GlFunction(Void, "glGetnPixelMapuivARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLuint, "bufSize"), "values")], sideeffects=False), - GlFunction(Void, "glGetnPixelMapusvARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLushort, "bufSize"), "values")], sideeffects=False), - GlFunction(Void, "glGetnPolygonStippleARB", [(GLsizei, "bufSize"), Out(Blob(GLubyte, "bufSize"), "pattern")], sideeffects=False), + GlFunction(Void, "glGetnPixelMapfvARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLfloat, "bufSize"), "values")]), + GlFunction(Void, "glGetnPixelMapuivARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLuint, "bufSize"), "values")]), + GlFunction(Void, "glGetnPixelMapusvARB", [(GLenum, "map"), (GLsizei, "bufSize"), Out(Array(GLushort, "bufSize"), "values")]), + GlFunction(Void, "glGetnPolygonStippleARB", [(GLsizei, "bufSize"), Out(Blob(GLubyte, "bufSize"), "pattern")]), GlFunction(Void, "glGetnColorTableARB", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "table")], sideeffects=False), - GlFunction(Void, "glGetnConvolutionFilterARB", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "image")], sideeffects=False), - GlFunction(Void, "glGetnSeparableFilterARB", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "rowBufSize"), Out(Blob(GLvoid, "rowBufSize"), "row"), (GLsizei, "columnBufSize"), Out(Blob(GLvoid, "columnBufSize"), "column"), Out(OpaquePointer(GLvoid), "span")], sideeffects=False), - GlFunction(Void, "glGetnHistogramARB", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "values")], sideeffects=False), - GlFunction(Void, "glGetnMinmaxARB", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "values")], sideeffects=False), - GlFunction(Void, "glGetnTexImageARB", [(GLenum, "target"), (GLint, "level"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "img")], sideeffects=False), - GlFunction(Void, "glReadnPixelsARB", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "data")], sideeffects=False), + GlFunction(Void, "glGetnConvolutionFilterARB", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "image")]), + GlFunction(Void, "glGetnSeparableFilterARB", [(GLenum, "target"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "rowBufSize"), Out(Blob(GLvoid, "rowBufSize"), "row"), (GLsizei, "columnBufSize"), Out(Blob(GLvoid, "columnBufSize"), "column"), Out(OpaquePointer(GLvoid), "span")]), + GlFunction(Void, "glGetnHistogramARB", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "values")]), + GlFunction(Void, "glGetnMinmaxARB", [(GLenum, "target"), (GLboolean, "reset"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "values")]), + GlFunction(Void, "glGetnTexImageARB", [(GLenum, "target"), (GLint, "level"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "img")]), + GlFunction(Void, "glReadnPixelsARB", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "data")]), GlFunction(Void, "glGetnCompressedTexImageARB", [(GLenum, "target"), (GLint, "lod"), (GLsizei, "bufSize"), Out(Blob(GLvoid, "bufSize"), "img")], sideeffects=False), GlFunction(Void, "glGetnUniformfvARB", [(GLprogram, "program"), (GLlocation, "location"), (GLsizei, "bufSize"), Out(Array(GLfloat, "bufSize"), "params")], sideeffects=False), GlFunction(Void, "glGetnUniformivARB", [(GLprogram, "program"), (GLlocation, "location"), (GLsizei, "bufSize"), Out(Array(GLint, "bufSize"), "params")], sideeffects=False), diff --git a/glretrace.py b/glretrace.py index c82c779..5d58b2d 100644 --- a/glretrace.py +++ b/glretrace.py @@ -113,6 +113,33 @@ class GlRetracer(Retracer): "glBindFramebufferEXT", ]) + # Names of the functions that can pack into the current pixel buffer + # object. See also the ARB_pixel_buffer_object specification. + pack_function_names = set([ + 'glGetCompressedTexImage', + 'glGetConvolutionFilter', + 'glGetHistogram', + 'glGetMinmax', + 'glGetPixelMapfv', + 'glGetPixelMapuiv', + 'glGetPixelMapusv', + 'glGetPolygonStipple', + 'glGetSeparableFilter,', + 'glGetTexImage', + 'glReadPixels', + 'glGetnCompressedTexImageARB', + 'glGetnConvolutionFilterARB', + 'glGetnHistogramARB', + 'glGetnMinmaxARB', + 'glGetnPixelMapfvARB', + 'glGetnPixelMapuivARB', + 'glGetnPixelMapusvARB', + 'glGetnPolygonStippleARB', + 'glGetnSeparableFilterARB', + 'glGetnTexImageARB', + 'glReadnPixelsARB', + ]) + def retrace_function_body(self, function): is_array_pointer = function.name in self.array_pointer_function_names is_draw_array = function.name in self.draw_array_function_names @@ -138,6 +165,14 @@ class GlRetracer(Retracer): print ' }' + # When no pack buffer object is bound, the pack functions are no-ops. + if function.name in self.pack_function_names: + print ' GLint __pack_buffer = 0;' + print ' glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &__pack_buffer);' + print ' if (!__pack_buffer) {' + print ' return;' + print ' }' + # Pre-snapshots if function.name in self.bind_framebuffer_function_names: print ' if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {' @@ -270,6 +305,12 @@ class GlRetracer(Retracer): self.extract_opaque_arg(function, arg, arg_type, lvalue, rvalue) return + # Handle pointer with offsets into the current pack pixel buffer + # object. + if function.name in self.pack_function_names and arg.output: + self.extract_opaque_arg(function, arg, arg_type, lvalue, rvalue) + return + if arg.type is glapi.GLlocation \ and 'program' not in [arg.name for arg in function.args]: print ' GLint program = -1;' diff --git a/gltrace.py b/gltrace.py index 6114feb..5dbef38 100644 --- a/gltrace.py +++ b/gltrace.py @@ -475,8 +475,20 @@ class GlTracer(Tracer): def gl_boolean(self, value): return self.boolean_names[int(bool(value))] + # Names of the functions that unpack from a pixel buffer object. See the + # ARB_pixel_buffer_object specification. unpack_function_names = set([ 'glBitmap', + 'glColorSubTable', + 'glColorTable', + 'glCompressedTexImage1D', + 'glCompressedTexImage2D', + 'glCompressedTexImage3D', + 'glCompressedTexSubImage1D', + 'glCompressedTexSubImage2D', + 'glCompressedTexSubImage3D', + 'glConvolutionFilter1D', + 'glConvolutionFilter2D', 'glDrawPixels', 'glMultiTexImage1DEXT', 'glMultiTexImage2DEXT', @@ -484,7 +496,11 @@ class GlTracer(Tracer): 'glMultiTexSubImage1DEXT', 'glMultiTexSubImage2DEXT', 'glMultiTexSubImage3DEXT', + 'glPixelMapfv', + 'glPixelMapuiv', + 'glPixelMapusv', 'glPolygonStipple', + 'glSeparableFilter2D', 'glTexImage1D', 'glTexImage1DEXT', 'glTexImage2D', @@ -530,12 +546,14 @@ class GlTracer(Tracer): and (isinstance(arg.type, stdapi.Blob) \ or (isinstance(arg.type, stdapi.Const) \ and isinstance(arg.type.type, stdapi.Blob))): - print ' GLint __unpack_buffer = 0;' - print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' - print ' if (__unpack_buffer) {' - print ' __writer.writeOpaque(%s);' % arg.name - print ' } else {' + print ' {' + print ' GLint __unpack_buffer = 0;' + print ' __glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &__unpack_buffer);' + print ' if (__unpack_buffer) {' + print ' __writer.writeOpaque(%s);' % arg.name + print ' } else {' Tracer.dump_arg_instance(self, function, arg) + print ' }' print ' }' return -- 2.7.4