def __call__( self, milliseconds, function, value ): cCallback = self.callbackType( function ) # timers should de-register as soon as they are called... # Note: there's no good key to use! we want to allow for # multiple instances of the same function with the same value # which means we have nothing that can store it properly... callbacks = contextdata.getValue( self.CONTEXT_DATA_KEY ) if callbacks is None: callbacks = [] contextdata.setValue( self.CONTEXT_DATA_KEY, callbacks ) def deregister( value ): try: function( value ) finally: for item in callbacks: if item.function is deregister: callbacks.remove( item ) item.function = None break if not callbacks: contextdata.delValue( self.CONTEXT_DATA_KEY ) cCallback = self.callbackType( deregister ) cCallback.function = deregister callbacks.append( cCallback ) self.wrappedOperation( milliseconds, cCallback, value ) return cCallback
def createGetVertex( ): mode = contextdata.getValue( "GL_FEEDBACK_BUFFER_TYPE" ) indexMode = glget.glGetBoolean( simple.GL_INDEX_MODE ) colorSize = [ 4,1 ][ int(indexMode) ] if mode in (simple.GL_2D,simple.GL_3D): if mode == simple.GL_2D: size = 2 else: size = 3 def getVertex( buffer, bufferIndex ): end = bufferIndex+size return (buffer[bufferIndex:end],None,None),end elif mode == simple.GL_3D_COLOR: def getVertex( buffer, bufferIndex ): end = bufferIndex+3 colorEnd = end + colorSize return (buffer[bufferIndex:end],buffer[end:colorEnd],None),colorEnd else: if mode == simple.GL_3D_COLOR_TEXTURE: size = 3 else: size = 4 def getVertex( buffer, bufferIndex ): end = bufferIndex+size colorEnd = end + colorSize textureEnd = colorEnd + 4 return (buffer[bufferIndex:end],buffer[end:colorEnd],buffer[colorEnd:textureEnd]),textureEnd return getVertex
def checkExtension(self, name): """Check whether the given extension is supported by current context""" # if not name or name in ('GL_VERSION_GL_1_0', 'GL_VERSION_GL_1_1'): # return True # if name.startswith( 'EGL_' ) or name.startswith( 'GLX_' ) or name.startswith( 'WGL_' ): # # we can't check these extensions, have to rely on the function resolution # return True if not name: return True context = self.GetCurrentContext() if context: from OpenGL import contextdata set = contextdata.getValue('extensions', context=context) if set is None: set = {} contextdata.setValue('extensions', set, context=context, weak=False) current = set.get(name) if current is None: from OpenGL import extensions result = extensions.ExtensionQuerier.hasExtension(name) set[name] = result return result return current else: from OpenGL import extensions return extensions.ExtensionQuerier.hasExtension(name)
def checkExtension( self, name ): """Check whether the given extension is supported by current context""" # if not name or name in ('GL_VERSION_GL_1_0', 'GL_VERSION_GL_1_1'): # return True # if name.startswith( 'EGL_' ) or name.startswith( 'GLX_' ) or name.startswith( 'WGL_' ): # # we can't check these extensions, have to rely on the function resolution # return True if not name: return True context = self.GetCurrentContext() if context: from OpenGL import contextdata set = contextdata.getValue( 'extensions', context=context ) if set is None: set = {} contextdata.setValue( 'extensions', set, context=context, weak=False ) current = set.get( name ) if current is None: from OpenGL import extensions result = extensions.ExtensionQuerier.hasExtension( name ) set[name] = result return result return current else: from OpenGL import extensions return extensions.ExtensionQuerier.hasExtension( name )
def glRenderMode(newMode): """Change to the given rendering mode If the current mode is GL_FEEDBACK or GL_SELECT, return the current buffer appropriate to the mode """ # must get the current mode to determine operation... from OpenGL.GL import glGetIntegerv from OpenGL.GL import selection, feedback currentMode = glGetIntegerv(simple.GL_RENDER_MODE) try: currentMode = currentMode[0] except (TypeError, ValueError, IndexError) as err: pass if currentMode in (simple.GL_RENDER, 0): # no array needs to be returned... return simple.glRenderMode(newMode) result = simple.glRenderMode(newMode) # result is now an integer telling us how many elements were copied... if result < 0: if currentMode == simple.GL_SELECT: raise error.GLError( simple.GL_STACK_OVERFLOW, "glSelectBuffer too small to hold selection results", ) elif currentMode == simple.GL_FEEDBACK: raise error.GLError( simple.GL_STACK_OVERFLOW, "glFeedbackBuffer too small to hold selection results", ) else: raise error.GLError( simple.GL_STACK_OVERFLOW, "Unknown glRenderMode buffer (%s) too small to hold selection results" % (currentMode, ), ) # Okay, now that the easy cases are out of the way... # Do we have a pre-stored pointer about which the user already knows? context = platform.GetCurrentContext() if context == 0: raise error.Error( """Returning from glRenderMode without a valid context!""") arrayConstant, wrapperFunction = { simple.GL_FEEDBACK: (simple.GL_FEEDBACK_BUFFER_POINTER, feedback.parseFeedback), simple.GL_SELECT: (simple.GL_SELECTION_BUFFER_POINTER, selection.GLSelectRecord.fromArray), }[currentMode] current = contextdata.getValue(arrayConstant) # XXX check to see if it's the *same* array we set currently! if current is None: current = glGetPointerv(arrayConstant) # XXX now, can turn the array into the appropriate wrapper type... if wrapperFunction: current = wrapperFunction(current, result) return current
def glRenderMode( newMode ): """Change to the given rendering mode If the current mode is GL_FEEDBACK or GL_SELECT, return the current buffer appropriate to the mode """ # must get the current mode to determine operation... from OpenGL.GL import glGetIntegerv from OpenGL.GL import selection, feedback currentMode = glGetIntegerv( simple.GL_RENDER_MODE ) try: currentMode = currentMode[0] except (TypeError,ValueError,IndexError) as err: pass if currentMode in (simple.GL_RENDER,0): # no array needs to be returned... return simple.glRenderMode( newMode ) result = simple.glRenderMode( newMode ) # result is now an integer telling us how many elements were copied... if result < 0: if currentMode == simple.GL_SELECT: raise error.GLError( simple.GL_STACK_OVERFLOW, "glSelectBuffer too small to hold selection results", ) elif currentMode == simple.GL_FEEDBACK: raise error.GLError( simple.GL_STACK_OVERFLOW, "glFeedbackBuffer too small to hold selection results", ) else: raise error.GLError( simple.GL_STACK_OVERFLOW, "Unknown glRenderMode buffer (%s) too small to hold selection results"%( currentMode, ), ) # Okay, now that the easy cases are out of the way... # Do we have a pre-stored pointer about which the user already knows? context = platform.GetCurrentContext() if context == 0: raise error.Error( """Returning from glRenderMode without a valid context!""" ) arrayConstant, wrapperFunction = { simple.GL_FEEDBACK: (simple.GL_FEEDBACK_BUFFER_POINTER,feedback.parseFeedback), simple.GL_SELECT: (simple.GL_SELECTION_BUFFER_POINTER, selection.GLSelectRecord.fromArray), }[ currentMode ] current = contextdata.getValue( arrayConstant ) # XXX check to see if it's the *same* array we set currently! if current is None: current = glGetPointerv( arrayConstant ) # XXX now, can turn the array into the appropriate wrapper type... if wrapperFunction: current = wrapperFunction( current, result ) return current
def glGetPointerv( constant ): """Retrieve a stored pointer constant""" # do we have a cached version of the pointer? # get the base pointer from the underlying operation vp = ctypes.voidp() simple.glGetPointerv( constant, ctypes.byref(vp) ) current = contextdata.getValue( constant ) if current is not None: if arrays.ArrayDatatype.dataPointer( current ) == vp.value: return current # XXX should be coercing to the proper type and converting to an array return vp
def checkExtension( self, name ): """Check whether the given extension is supported by current context""" if not name or name == 'GL_VERSION_GL_1_1': return True context = self.GetCurrentContext() if context: from OpenGL import contextdata from OpenGL.raw.GL.VERSION.GL_1_1 import GL_EXTENSIONS set = contextdata.getValue( GL_EXTENSIONS, context=context ) if set is None: set = {} contextdata.setValue( GL_EXTENSIONS, set, context=context, weak=False ) current = set.get( name ) if current is None: from OpenGL import extensions result = extensions.hasGLExtension( name ) set[name] = result return result return current else: return False
"Unknown glRenderMode buffer (%s) too small to hold selection results"%( currentMode, ), ) # Okay, now that the easy cases are out of the way... # Do we have a pre-stored pointer about which the user already knows? context = platform.GetCurrentContext() if context == 0: raise error.Error( """Returning from glRenderMode without a valid context!""" ) arrayConstant, wrapperFunction = { simple.GL_FEEDBACK: (simple.GL_FEEDBACK_BUFFER_POINTER,feedback.parseFeedback), simple.GL_SELECT: (simple.GL_SELECTION_BUFFER_POINTER, selection.GLSelectRecord.fromArray), }[ currentMode ] current = contextdata.getValue( arrayConstant ) # XXX check to see if it's the *same* array we set currently! if current is None: current = glGetPointerv( arrayConstant ) # XXX now, can turn the array into the appropriate wrapper type... if wrapperFunction: current = wrapperFunction( current, result ) return current # XXX this belongs in the GL module, not here! def glGetPointerv( constant ): """Retrieve a stored pointer constant""" # do we have a cached version of the pointer? # get the base pointer from the underlying operation vp = ctypes.voidp() simple.glGetPointerv( constant, ctypes.byref(vp) )