def OSMesaGetDepthBuffer(c): width, height, bytesPerValue = GLint(), GLint(), GLint() buffer = ctypes.POINTER(GLint)() if _p.PLATFORM.GL.OSMesaGetDepthBuffer(c, ctypes.byref(width), ctypes.byref(height), ctypes.byref(bytesPerValue), ctypes.byref(buffer)): return width.value, height.value, bytesPerValue.value, buffer else: return 0, 0, 0, None
def OSMesaGetColorBuffer(c): # TODO: make output array types which can handle the operation # provide an API to convert pointers + sizes to array instances, # e.g. numpy.ctypeslib.as_array( ptr, bytesize ).astype( 'B' ).reshape( height,width ) width, height, format = GLint(), GLint(), GLint() buffer = ctypes.c_void_p() if GL.OSMesaGetColorBuffer(c, ctypes.byref(width), ctypes.byref(height), ctypes.byref(format), ctypes.byref(buffer)): return width.value, height.value, format.value, buffer else: return 0, 0, 0, None
def retrieve( self ): """Attempt to retrieve binary for this compiled shader Note that binaries for a program are *not* generally portable, they should be used solely for caching compiled programs for local use; i.e. to reduce compilation overhead. returns (format,binaryData) for the shader program """ from OpenGL.raw.GL._types import GLint,GLenum from OpenGL.arrays import GLbyteArray size = GLint() glGetProgramiv( self, get_program_binary.GL_PROGRAM_BINARY_LENGTH, size ) result = GLbyteArray.zeros( (size.value,)) size2 = GLint() format = GLenum() get_program_binary.glGetProgramBinary( self, size.value, size2, format, result ) return format.value, result
def pullExtensions( self ): from OpenGL import platform if not platform.PLATFORM.CurrentContextIsValid(): return False from OpenGL.raw.GL._types import GLint from OpenGL.raw.GL.VERSION.GL_1_1 import glGetString, glGetError from OpenGL.raw.GL.VERSION.GL_1_1 import GL_EXTENSIONS from OpenGL import error try: extensions = glGetString( GL_EXTENSIONS ) if glGetError(): raise error.GLError() if extensions: extensions = extensions.split() else: return False except (AttributeError, error.GLError) as err: # OpenGL 3.0 deprecates glGetString( GL_EXTENSIONS ) from OpenGL.raw.GL.VERSION.GL_3_0 import GL_NUM_EXTENSIONS, glGetStringi from OpenGL.raw.GL.VERSION.GL_1_1 import glGetIntegerv count = GLint() glGetIntegerv( GL_NUM_EXTENSIONS, count ) extensions = [] for i in range( count.value ): extension = glGetStringi( GL_EXTENSIONS, i ) extensions.append( extension ) # Add included-by-reference extensions... version = self.getVersion() if not version: # should not be possible? return version check = tuple( version[:2] ) for (v,v_exts) in VERSION_EXTENSIONS: if v <= check: for v_ext in v_exts: if v_ext not in extensions: extensions.append( as_8_bit(v_ext) ) else: break return extensions
def glGetSync( sync, pname, bufSize=1,length=None,values=None ): """Wrapper around glGetSynciv that auto-allocates buffers sync -- the GLsync struct pointer (see glGetSynciv) pname -- constant to retrieve (see glGetSynciv) bufSize -- defaults to 1, maximum number of items to retrieve, currently all constants are defined to return a single value length -- None or a GLint() instance (ONLY!), must be a byref() capable object with a .value attribute which retrieves the set value values -- None or an array object, if None, will be a default return-array-type of length bufSize returns values[:length.value], i.e. an array with the values set by the call, currently always a single-value array. """ if values is None: values = GLintArray.zeros( (bufSize,) ) if length is None: length = GLint() glGetSynciv( sync, pname, bufSize, length, values ) written = length.value return values[:written]
def OSMesaGetIntegerv(pname): value = GLint() _p.PLATFORM.GL.OSMesaGetIntegerv(pname, ctypes.byref(value)) return value.value