supporting buffer as array type in pyopengl 3.0.0
Renaud Blanch <[email protected]> Fri, 20 Jun 2008 11:38:52 +0200
| Newsgroups | gmane.comp.python.opengl.devel |
|---|---|
| Message-ID | <[email protected]> |
hi list, i'm using pycairo to generate pictures. it uses the python buffer type to return the raw data. it would be great if functions such as DrawPixels could handle such array object. attached is a small patch against PyOpenGL-3.0.0b3 that modifies OpenGL/arrays/strings.py to make StringHandler also handle buffer objects. it works for my use case, but it may not be the best way to handle buffer. any suggestion ? if this patch is reasonable, what is the way to push it into the PyOpenGL distribution ? thanks, renaud diff -ru PyOpenGL-3.0.0b3/OpenGL/arrays/strings.py PyOpenGL-3.0.0b3- mine/OpenGL/arrays/strings.py --- PyOpenGL-3.0.0b3/OpenGL/arrays/strings.py 2008-06-13 18:17:52.000000000 +0200 +++ PyOpenGL-3.0.0b3-mine/OpenGL/arrays/strings.py 2008-06-20 11:18:06.000000000 +0200 @@ -7,7 +7,7 @@ class StringHandler( formathandler.FormatHandler ): """String-specific data-type handler for OpenGL""" - HANDLED_TYPES = (str, ) + HANDLED_TYPES = (str, buffer) from_param = staticmethod( dataPointer ) dataPointer = staticmethod( dataPointer ) def zeros( self, dims, typeCode=None ): @@ -31,6 +31,8 @@ """Convert given value to an array value of given typeCode""" if isinstance( value, str ): return value + elif isinstance( value, buffer ): + return str(value) elif hasattr( value, 'tostring' ): return value.tostring() elif hasattr( value, 'raw' ): -- Renaud Blanch http://iihm.imag.fr/blanch/ mailto:[email protected] tel:+33.4.76.51.43.65 ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ PyOpenGL Homepage http://pyopengl.sourceforge.net _______________________________________________ PyOpenGL-Devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyopengl-devel
PyOpenGL-3.0.0b3-bufferhandler.patch
(application/octet-stream, 869 B)
diff -ru PyOpenGL-3.0.0b3/OpenGL/arrays/strings.py PyOpenGL-3.0.0b3-mine/OpenGL/arrays/strings.py --- PyOpenGL-3.0.0b3/OpenGL/arrays/strings.py 2008-06-13 18:17:52.000000000 +0200 +++ PyOpenGL-3.0.0b3-mine/OpenGL/arrays/strings.py 2008-06-20 11:18:06.000000000 +0200 @@ -7,7 +7,7 @@ class StringHandler( formathandler.FormatHandler ): """String-specific data-type handler for OpenGL""" - HANDLED_TYPES = (str, ) + HANDLED_TYPES = (str, buffer) from_param = staticmethod( dataPointer ) dataPointer = staticmethod( dataPointer ) def zeros( self, dims, typeCode=None ): @@ -31,6 +31,8 @@ """Convert given value to an array value of given typeCode""" if isinstance( value, str ): return value + elif isinstance( value, buffer ): + return str(value) elif hasattr( value, 'tostring' ): return value.tostring() elif hasattr( value, 'raw' ):