def glVertexAttribPointerARB( baseOperation, index, size, type, normalized, stride, pointer, ): """Set an attribute pointer for a given shader (index) index -- the index of the generic vertex to bind, see glGetAttribLocation for retrieval of the value, note that index is a global variable, not per-shader size -- number of basic elements per record, 1,2,3, or 4 type -- enum constant for data-type normalized -- whether to perform int to float normalization on integer-type values stride -- stride in machine units (bytes) between consecutive records, normally used to create "interleaved" arrays pointer -- data-pointer which provides the data-values, normally a vertex-buffer-object or offset into the same. This implementation stores a copy of the data-pointer in the contextdata structure in order to prevent null- reference errors in the renderer. """ array = ArrayDatatype.asArray(pointer, type) key = ('vertex-attrib', index) contextdata.setValue(key, array) return baseOperation(index, size, type, normalized, stride, ArrayDatatype.voidDataPointer(array))
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 __call__( self, function, *args ): if GLUT_GUARD_CALLBACKS and hasattr( function,'__call__' ): def safeCall( *args, **named ): """Safe calling of GUI callbacks, exits on failures""" try: if not CurrentContextIsValid(): raise RuntimeError( """No valid context!""" ) return function( *args, **named ) except Exception as err: traceback.print_exc() sys.stderr.write( """GLUT %s callback %s with %s,%s failed: returning None %s\n"""%( self.typeName, function, args, named, err, )) os._exit(1) #return None finalFunction = safeCall else: finalFunction = function if hasattr( finalFunction,'__call__' ): cCallback = self.callbackType( finalFunction ) else: cCallback = function # keep the function alive as long as the cCallback is... #cCallback.function = function contextdata.setValue( self.CONTEXT_DATA_KEY, cCallback ) self.wrappedOperation( cCallback, *args ) return cCallback
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 glVertexAttribPointer( baseOperation, index, size, type, normalized, stride, pointer, ): """Set an attribute pointer for a given shader (index) index -- the index of the generic vertex to bind, see glGetAttribLocation for retrieval of the value, note that index is a global variable, not per-shader size -- number of basic elements per record, 1,2,3, or 4 type -- enum constant for data-type normalized -- whether to perform int to float normalization on integer-type values stride -- stride in machine units (bytes) between consecutive records, normally used to create "interleaved" arrays pointer -- data-pointer which provides the data-values, normally a vertex-buffer-object or offset into the same. This implementation stores a copy of the data-pointer in the contextdata structure in order to prevent null- reference errors in the renderer. """ array = ArrayDatatype.asArray( pointer, type ) key = ('vertex-attrib',index) contextdata.setValue( key, array ) return baseOperation( index, size, type, normalized, stride, ArrayDatatype.voidDataPointer( array ) )
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 glSelectBuffer( size, buffer = None ): """Create a selection buffer of the given size """ if buffer is None: buffer = arrays.GLuintArray.zeros( (size,) ) simple.glSelectBuffer( size, buffer ) contextdata.setValue( simple.GL_SELECTION_BUFFER_POINTER, buffer ) return buffer
def glFeedbackBuffer( size, type, buffer = None ): """Create a selection buffer of the given size """ if buffer is None: buffer = arrays.GLfloatArray.zeros( (size,) ) simple.glFeedbackBuffer( size, type, buffer ) contextdata.setValue( simple.GL_FEEDBACK_BUFFER_POINTER, buffer ) contextdata.setValue( "GL_FEEDBACK_BUFFER_TYPE", type ) return buffer
def glutCreateMenu( cls, func ): """Create a new (current) menu, return small integer identifier func( int ) -- Function taking a single integer reflecting the user's choice, the value passed to glutAddMenuEntry return menuID (small integer) """ cCallback = cls.callbackType( func ) menu = simple.glutCreateMenu( cCallback ) contextdata.setValue( ('menucallback',menu), (cCallback,func) ) return menu
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
def __call__( self, result, baseOperation, pyArgs, cArgs ): contextdata.setValue( self.constant, pyArgs[self.pointerIndex] )
named, err, )) os._exit(1) #return None finalFunction = safeCall else: finalFunction = function if callable(finalFunction): cCallback = self.callbackType(finalFunction) else: cCallback = function # keep the function alive as long as the cCallback is... #cCallback.function = function contextdata.setValue(self.CONTEXT_DATA_KEY, cCallback) self.wrappedOperation(cCallback, *args) return cCallback class GLUTTimerCallback(GLUTCallback): """GLUT timer callbacks (completely nonstandard wrt other GLUT callbacks)""" 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 = []
def __call__(self, result, baseOperation, pyArgs, cArgs): contextdata.setValue(self.constant, pyArgs[self.pointerIndex])
traceback.print_exc() sys.stderr.write( """GLUT %s callback %s with %s,%s failed: returning None %s\n"""%( self.typeName, function, args, named, err, )) os._exit(1) #return None finalFunction = safeCall else: finalFunction = function if callable( finalFunction ): cCallback = self.callbackType( finalFunction ) else: cCallback = function # keep the function alive as long as the cCallback is... #cCallback.function = function contextdata.setValue( self.CONTEXT_DATA_KEY, cCallback ) self.wrappedOperation( cCallback, *args ) return cCallback class GLUTTimerCallback( GLUTCallback ): """GLUT timer callbacks (completely nonstandard wrt other GLUT callbacks)""" 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 ):