From b11188fcb0d2407d3b63afe86897d06aea6af567 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 21 Nov 2010 01:53:58 +0000 Subject: [PATCH] Handle more calls correctly. --- glhelpers.hpp | 36 ++++++++++++++++++++++++++++++++++++ glretrace.py | 16 ++++++++-------- glx.py | 38 +++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/glhelpers.hpp b/glhelpers.hpp index cfd9545..99df9dd 100644 --- a/glhelpers.hpp +++ b/glhelpers.hpp @@ -30,6 +30,37 @@ #include static inline size_t +__gl_calllists_size(GLsizei n, GLenum type) +{ + size_t bytes; + switch(type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + bytes = 1; + break; + case GL_2_BYTES: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + bytes = 2; + break; + case GL_3_BYTES: + bytes = 3; + break; + case GL_4_BYTES: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + bytes = 4; + break; + default: + assert(0); + bytes = 1; + } + + return n*bytes; +} + +static inline size_t __gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) { size_t num_channels; switch (format) { @@ -111,4 +142,9 @@ __gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsiz return depth*slice_stride; } +static inline size_t +__gl_bitmap_size(GLsizei width, GLsizei height) { + return __gl_image_size(GL_COLOR_INDEX, GL_BITMAP, width, height, 1, 0); +} + #endif /* _GL_HELPERS_HPP_ */ diff --git a/glretrace.py b/glretrace.py index d8a3861..e6c3fb8 100644 --- a/glretrace.py +++ b/glretrace.py @@ -37,17 +37,17 @@ class ConstRemover(base.Rebuilder): class ValueExtractor(base.Visitor): - def visit_literal(self, type, lvalue, rvalue): + def visit_literal(self, literal, lvalue, rvalue): print ' %s = %s;' % (lvalue, rvalue) - def visit_alias(self, type, lvalue, rvalue): - self.visit(type.type, lvalue, rvalue) + def visit_alias(self, alias, lvalue, rvalue): + self.visit(alias.type, lvalue, rvalue) - def visit_enum(self, type, lvalue, rvalue): + def visit_enum(self, enum, lvalue, rvalue): print ' %s = %s;' % (lvalue, rvalue) - def visit_bitmask(self, type, lvalue, rvalue): - self.visit(type.type, lvalue, rvalue) + def visit_bitmask(self, bitmask, lvalue, rvalue): + self.visit(bitmask.type, lvalue, rvalue) def visit_array(self, array, lvalue, rvalue): print ' %s = new %s[%s];' % (lvalue, array.type, array.length) @@ -56,8 +56,8 @@ class ValueExtractor(base.Visitor): self.visit(array.type, '%s[%s]' % (lvalue, index), '%s[%s]' % (rvalue, index)) print ' }' - def visit_blob(self, type, lvalue, rvalue): - print ' %s = %s;' % (lvalue, rvalue) + def visit_blob(self, blob, lvalue, rvalue): + print ' %s = (%s)(void *)%s;' % (lvalue, blob, rvalue) diff --git a/glx.py b/glx.py index 30ae7b9..f228577 100644 --- a/glx.py +++ b/glx.py @@ -31,12 +31,12 @@ libgl.functions += [ DllFunction(Void, "glNewList", [(GLuint, "list"), (GLenum, "mode")]), DllFunction(Void, "glEndList", []), DllFunction(Void, "glCallList", [(GLuint, "list")]), - DllFunction(Void, "glCallLists", [(GLsizei, "n"), (GLenum, "type"), (Pointer(Const(GLvoid)), "lists")]), + DllFunction(Void, "glCallLists", [(GLsizei, "n"), (GLenum, "type"), (Blob(Const(GLvoid), "__gl_calllists_size(n, type)"), "lists")]), DllFunction(Void, "glDeleteLists", [(GLuint, "list"), (GLsizei, "range")]), DllFunction(GLuint, "glGenLists", [(GLsizei, "range")]), DllFunction(Void, "glListBase", [(GLuint, "base")]), DllFunction(Void, "glBegin", [(GLprimenum, "mode")]), - DllFunction(Void, "glBitmap", [(GLsizei, "width"), (GLsizei, "height"), (GLfloat, "xorig"), (GLfloat, "yorig"), (GLfloat, "xmove"), (GLfloat, "ymove"), (Pointer(Const(GLubyte)), "bitmap")]), + DllFunction(Void, "glBitmap", [(GLsizei, "width"), (GLsizei, "height"), (GLfloat, "xorig"), (GLfloat, "yorig"), (GLfloat, "xmove"), (GLfloat, "ymove"), (Blob(Const(GLubyte), "__gl_bitmap_size(width, height)"), "bitmap")]), DllFunction(Void, "glColor3b", [(GLbyte, "red"), (GLbyte, "green"), (GLbyte, "blue")]), DllFunction(Void, "glColor3bv", [(Array(Const(GLbyte), "3"), "v")]), DllFunction(Void, "glColor3d", [(GLdouble, "red"), (GLdouble, "green"), (GLdouble, "blue")]), @@ -182,9 +182,9 @@ libgl.functions += [ DllFunction(Void, "glColorMaterial", [(GLenum, "face"), (GLenum, "mode")]), DllFunction(Void, "glCullFace", [(GLenum, "mode")]), DllFunction(Void, "glFogf", [(GLenum, "pname"), (GLfloat, "param")]), - DllFunction(Void, "glFogfv", [(GLenum, "pname"), (Pointer(Const(GLfloat)), "params")]), + DllFunction(Void, "glFogfv", [(GLenum, "pname"), (Array(Const(GLfloat), "(pname == GL_FOG_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glFogi", [(GLenum, "pname"), (GLint, "param")]), - DllFunction(Void, "glFogiv", [(GLenum, "pname"), (Pointer(Const(GLint)), "params")]), + DllFunction(Void, "glFogiv", [(GLenum, "pname"), (Array(Const(GLint), "(pname == GL_FOG_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glFrontFace", [(GLenum, "mode")]), DllFunction(Void, "glHint", [(GLenum, "target"), (GLenum, "mode")]), DllFunction(Void, "glLightf", [(GLenum, "light"), (GLenum, "pname"), (GLfloat, "param")]), @@ -203,27 +203,27 @@ libgl.functions += [ DllFunction(Void, "glMaterialiv", [(GLenum, "face"), (GLenum, "pname"), (Array(Const(GLint), "4"), "params")]), # XXX DllFunction(Void, "glPointSize", [(GLfloat, "size")]), DllFunction(Void, "glPolygonMode", [(GLenum, "face"), (GLenum, "mode")]), - DllFunction(Void, "glPolygonStipple", [(Pointer(Const(GLubyte)), "mask")]), + DllFunction(Void, "glPolygonStipple", [(Blob(Const(GLubyte), "__gl_bitmap_size(32, 32)"), "mask")]), DllFunction(Void, "glScissor", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height")]), DllFunction(Void, "glShadeModel", [(GLenum, "mode")]), DllFunction(Void, "glTexParameterf", [(GLenum, "target"), (GLenum, "pname"), (GLfloat, "param")]), - DllFunction(Void, "glTexParameterfv", [(GLenum, "target"), (GLenum, "pname"), (Pointer(Const(GLfloat)), "params")]), + DllFunction(Void, "glTexParameterfv", [(GLenum, "target"), (GLenum, "pname"), (Array(Const(GLfloat), "(pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glTexParameteri", [(GLenum, "target"), (GLenum, "pname"), (GLint, "param")]), - DllFunction(Void, "glTexParameteriv", [(GLenum, "target"), (GLenum, "pname"), (Pointer(Const(GLint)), "params")]), + DllFunction(Void, "glTexParameteriv", [(GLenum, "target"), (GLenum, "pname"), (Array(Const(GLint), "(pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glTexImage1D", [(GLenum, "target"), (GLint, "level"), (GLint, "internalformat"), (GLsizei, "width"), (GLint, "border"), (GLenum, "format"), (GLenum, "type"), (Blob(Const(GLvoid), "__gl_image_size(format, type, width, 1, 1, border)"), "pixels")]), DllFunction(Void, "glTexImage2D", [(GLenum, "target"), (GLint, "level"), (GLint, "internalformat"), (GLsizei, "width"), (GLsizei, "height"), (GLint, "border"), (GLenum, "format"), (GLenum, "type"), (Blob(Const(GLvoid), "__gl_image_size(format, type, width, height, 1, border)"), "pixels")]), DllFunction(Void, "glTexEnvf", [(GLenum, "target"), (GLenum, "pname"), (GLfloat, "param")]), - DllFunction(Void, "glTexEnvfv", [(GLenum, "target"), (GLenum, "pname"), (Pointer(Const(GLfloat)), "params")]), + DllFunction(Void, "glTexEnvfv", [(GLenum, "target"), (GLenum, "pname"), (Array(Const(GLfloat), "(pname == GL_TEXTURE_ENV_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glTexEnvi", [(GLenum, "target"), (GLenum, "pname"), (GLint, "param")]), - DllFunction(Void, "glTexEnviv", [(GLenum, "target"), (GLenum, "pname"), (Pointer(Const(GLint)), "params")]), + DllFunction(Void, "glTexEnviv", [(GLenum, "target"), (GLenum, "pname"), (Array(Const(GLint), "(pname == GL_TEXTURE_ENV_COLOR ? 4 : 1)"), "params")]), DllFunction(Void, "glTexGend", [(GLenum, "coord"), (GLenum, "pname"), (GLdouble, "param")]), DllFunction(Void, "glTexGendv", [(GLenum, "coord"), (GLenum, "pname"), (Pointer(Const(GLdouble)), "params")]), DllFunction(Void, "glTexGenf", [(GLenum, "coord"), (GLenum, "pname"), (GLfloat, "param")]), DllFunction(Void, "glTexGenfv", [(GLenum, "coord"), (GLenum, "pname"), (Pointer(Const(GLfloat)), "params")]), DllFunction(Void, "glTexGeni", [(GLenum, "coord"), (GLenum, "pname"), (GLint, "param")]), DllFunction(Void, "glTexGeniv", [(GLenum, "coord"), (GLenum, "pname"), (Pointer(Const(GLint)), "params")]), - DllFunction(Void, "glFeedbackBuffer", [(GLsizei, "size"), (GLenum, "type"), (OutPointer(GLfloat), "buffer")]), - DllFunction(Void, "glSelectBuffer", [(GLsizei, "size"), (OutPointer(GLuint), "buffer")]), + DllFunction(Void, "glFeedbackBuffer", [(GLsizei, "size"), (GLenum, "type"), (OutArray(GLfloat, "size"), "buffer")]), + DllFunction(Void, "glSelectBuffer", [(GLsizei, "size"), (OutArray(GLuint, "size"), "buffer")]), DllFunction(GLint, "glRenderMode", [(GLenum, "mode")]), DllFunction(Void, "glInitNames", []), DllFunction(Void, "glLoadName", [(GLuint, "name")]), @@ -279,9 +279,9 @@ libgl.functions += [ DllFunction(Void, "glPixelTransferi", [(GLenum, "pname"), (GLint, "param")]), DllFunction(Void, "glPixelStoref", [(GLenum, "pname"), (GLfloat, "param")]), DllFunction(Void, "glPixelStorei", [(GLenum, "pname"), (GLint, "param")]), - DllFunction(Void, "glPixelMapfv", [(GLenum, "map"), (GLsizei, "mapsize"), (Pointer(Const(GLfloat)), "values")]), - DllFunction(Void, "glPixelMapuiv", [(GLenum, "map"), (GLsizei, "mapsize"), (Pointer(Const(GLuint)), "values")]), - DllFunction(Void, "glPixelMapusv", [(GLenum, "map"), (GLsizei, "mapsize"), (Pointer(Const(GLushort)), "values")]), + DllFunction(Void, "glPixelMapfv", [(GLenum, "map"), (GLsizei, "mapsize"), (Array(Const(GLfloat), "mapsize"), "values")]), + DllFunction(Void, "glPixelMapuiv", [(GLenum, "map"), (GLsizei, "mapsize"), (Array(Const(GLuint), "mapsize"), "values")]), + DllFunction(Void, "glPixelMapusv", [(GLenum, "map"), (GLsizei, "mapsize"), (Array(Const(GLushort), "mapsize"), "values")]), DllFunction(Void, "glReadBuffer", [(GLenum, "mode")]), DllFunction(Void, "glCopyPixels", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "type")]), DllFunction(Void, "glReadPixels", [(GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (OutPointer(GLvoid), "pixels")]), @@ -355,13 +355,13 @@ libgl.functions += [ DllFunction(Void, "glCopyTexImage2D", [(GLenum, "target"), (GLint, "level"), (GLenum, "internalformat"), (GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height"), (GLint, "border")]), DllFunction(Void, "glCopyTexSubImage1D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "x"), (GLint, "y"), (GLsizei, "width")]), DllFunction(Void, "glCopyTexSubImage2D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "yoffset"), (GLint, "x"), (GLint, "y"), (GLsizei, "width"), (GLsizei, "height")]), - DllFunction(Void, "glDeleteTextures", [(GLsizei, "n"), (Pointer(Const(GLuint)), "textures")]), - DllFunction(Void, "glGenTextures", [(GLsizei, "n"), (OutPointer(GLuint), "textures")]), + DllFunction(Void, "glDeleteTextures", [(GLsizei, "n"), (Array(Const(GLuint), "n"), "textures")]), + DllFunction(Void, "glGenTextures", [(GLsizei, "n"), (OutArray(GLuint, "n"), "textures")]), DllFunction(Void, "glGetPointerv", [(GLenum, "pname"), (OutPointer(Pointer(GLvoid)), "params")]), DllFunction(GLboolean, "glIsTexture", [(GLuint, "texture")]), - DllFunction(Void, "glPrioritizeTextures", [(GLsizei, "n"), (Pointer(Const(GLuint)), "textures"), (Pointer(Const(GLclampf)), "priorities")]), - DllFunction(Void, "glTexSubImage1D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLsizei, "width"), (GLenum, "format"), (GLenum, "type"), (Pointer(Const(GLvoid)), "pixels")]), - DllFunction(Void, "glTexSubImage2D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "yoffset"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (Pointer(Const(GLvoid)), "pixels")]), + DllFunction(Void, "glPrioritizeTextures", [(GLsizei, "n"), (Array(Const(GLuint), "n"), "textures"), (Array(Const(GLclampf), "n"), "priorities")]), + DllFunction(Void, "glTexSubImage1D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLsizei, "width"), (GLenum, "format"), (GLenum, "type"), (Blob(Const(GLvoid), "__gl_image_size(format, type, width, 1, 1, 0)"), "pixels")]), + DllFunction(Void, "glTexSubImage2D", [(GLenum, "target"), (GLint, "level"), (GLint, "xoffset"), (GLint, "yoffset"), (GLsizei, "width"), (GLsizei, "height"), (GLenum, "format"), (GLenum, "type"), (Blob(Const(GLvoid), "__gl_image_size(format, type, width, height, 1, 0)"), "pixels")]), DllFunction(Void, "glPopClientAttrib", []), DllFunction(Void, "glPushClientAttrib", [(GLbitfield, "mask")]), DllFunction(Void, "glBlendColor", [(GLclampf, "red"), (GLclampf, "green"), (GLclampf, "blue"), (GLclampf, "alpha")]), -- 2.7.4