@@ -141,10 +141,10 @@ def dtype_gl_enum( dtype, name = None ):
141141
142142 # remove endian identifiers
143143 # http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.byteorder.html#numpy.dtype.byteorder
144- type = dtype_type ( dtype , name )
145- stripped_type = re .sub ('[=<>|]' , '' , type )
144+ type_ = dtype_type ( dtype , name )
145+ stripped_type = re .sub ('[=<>|]' , '' , type_ )
146146
147- return {
147+ types = {
148148 'int8' : GL .GL_BYTE ,
149149 'i1' : GL .GL_BYTE ,
150150 'uint8' : GL .GL_UNSIGNED_BYTE ,
@@ -161,5 +161,25 @@ def dtype_gl_enum( dtype, name = None ):
161161 'f4' : GL .GL_FLOAT ,
162162 'float64' : GL .GL_DOUBLE ,
163163 'f8' : GL .GL_DOUBLE ,
164- }[ stripped_type ]
164+ }
165+
166+ if stripped_type not in types :
167+ raise ValueError ('Cannot convert from {0}' .format (type_ ))
168+
169+ return types [ stripped_type ]
170+
171+ def gl_enum_dtype (enum , name = None ):
172+ from OpenGL import GL
173+
174+ types = {
175+ GL .GL_BYTE : 'int8' ,
176+ GL .GL_UNSIGNED_BYTE : 'uint8' ,
177+ GL .GL_SHORT : 'int16' ,
178+ GL .GL_UNSIGNED_SHORT : 'uint16' ,
179+ GL .GL_INT : 'int32' ,
180+ GL .GL_UNSIGNED_INT : 'uint32' ,
181+ GL .GL_FLOAT : 'float32' ,
182+ GL .GL_DOUBLE : 'float64' ,
183+ }
184+ return types [enum ]
165185
0 commit comments