Exemplo n.º 1
0
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))
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
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 )
    )
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
    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 )
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
 def __call__( self, result, baseOperation, pyArgs, cArgs ):
     contextdata.setValue( self.constant, pyArgs[self.pointerIndex] )
Exemplo n.º 16
0
                            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])
Exemplo n.º 18
0
					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 ):