diff --git a/OpenGL/platform/baseplatform.py b/OpenGL/platform/baseplatform.py index 645f371e..f7450ec3 100644 --- a/OpenGL/platform/baseplatform.py +++ b/OpenGL/platform/baseplatform.py @@ -6,365 +6,430 @@ import sys, logging from OpenGL import _configflags from OpenGL import logs, MODULE_ANNOTATIONS + log = logging.getLogger(__name__) -class lazy_property( object ): - def __init__( self, function ): - self.fget = function - def __get__( self, obj, cls ): - value = self.fget( obj ) - setattr( obj, self.fget.__name__, value) - return value - -class _CheckContext( object ): - def __init__( self, func, ccisvalid ): - self.func = func + +class lazy_property(object): + def __init__(self, function): + self.fget = function + + def __get__(self, obj, cls): + value = self.fget(obj) + setattr(obj, self.fget.__name__, value) + return value + + +class _CheckContext(object): + def __init__(self, func, ccisvalid): + self.func = func self.ccisvalid = ccisvalid - def __setattr__( self, key, value ): - if key not in ('func','ccisvalid'): - return setattr( self.func, key, value ) + + def __setattr__(self, key, value): + if key not in ('func', 'ccisvalid'): + return setattr(self.func, key, value) else: - self.__dict__[key] = value - def __repr__( self ): - if getattr( self.func, '__doc__', None ): - return self.func.__doc__ + self.__dict__[key] = value + + def __repr__(self): + if getattr(self.func, '__doc__', None): + return self.func.__doc__ else: - return repr( self.func ) - def __getattr__( self, key ): + return repr(self.func) + + def __getattr__(self, key): if key != 'func': - return getattr(self.func, key ) - raise AttributeError( key ) - def __call__( self, *args, **named ): + return getattr(self.func, key) + raise AttributeError(key) + + def __call__(self, *args, **named): if not self.ccisvalid(): from OpenGL import error - raise error.NoContext( self.func.__name__, args, named ) - return self.func( *args, **named ) -def _find_module( exclude = (__name__,)): + raise error.NoContext(self.func.__name__, args, named) + return self.func(*args, **named) + + +def _find_module(exclude=(__name__,)): frame = sys._getframe() while frame and '__name__' in frame.f_globals: if exclude: if not frame.f_globals['__name__'] in exclude: return frame.f_globals['__name__'] - + else: return frame.f_globals['__name__'] frame = frame.f_back return None -class BasePlatform( object ): + +class BasePlatform(object): """Base class for per-platform implementations - + Attributes of note: - - EXPORTED_NAMES -- set of names exported via the platform + + EXPORTED_NAMES -- set of names exported via the platform module's namespace... - + GL, GLU, GLUT, GLE, GLES1, GLES2, GLES3 -- ctypes libraries - - DEFAULT_FUNCTION_TYPE -- used as the default function + + DEFAULT_FUNCTION_TYPE -- used as the default function type for functions unless overridden on a per-DLL basis with a "FunctionType" member - - GLUT_GUARD_CALLBACKS -- if True, the GLUT wrappers - will provide guarding wrappers to prevent GLUT + + GLUT_GUARD_CALLBACKS -- if True, the GLUT wrappers + will provide guarding wrappers to prevent GLUT errors with uninitialised GLUT. - + EXTENSIONS_USE_BASE_FUNCTIONS -- if True, uses regular - dll attribute-based lookup to retrieve extension + dll attribute-based lookup to retrieve extension function pointers. """ - + EXPORTED_NAMES = [ 'GetCurrentContext', 'CurrentContextIsValid', - 'createBaseFunction', - 'createExtensionFunction', + 'createBaseFunction', + 'createExtensionFunction', 'copyBaseFunction', 'getGLUTFontPointer', 'nullFunction', 'GLUT_GUARD_CALLBACKS', ] - DEFAULT_FUNCTION_TYPE = None GLUT_GUARD_CALLBACKS = False EXTENSIONS_USE_BASE_FUNCTIONS = False - - def install( self, namespace ): + + def install(self, namespace): """Install this platform instance into the platform module""" for name in self.EXPORTED_NAMES: - namespace[ name ] = getattr(self,name,None) + namespace[name] = getattr(self, name, None) namespace['PLATFORM'] = self return self - - def functionTypeFor( self, dll ): + + def functionTypeFor(self, dll): """Given a DLL, determine appropriate function type...""" - if hasattr( dll, 'FunctionType' ): + if hasattr(dll, 'FunctionType'): return dll.FunctionType else: return self.DEFAULT_FUNCTION_TYPE - - def errorChecking( self, func, dll, error_checker=None ): + + def errorChecking(self, func, dll, error_checker=None): """Add error checking to the function if appropriate""" from OpenGL import error + if error_checker and _configflags.ERROR_CHECKING: - #GLUT spec says error-checking is basically undefined... - # there *may* be GL errors on GLUT calls that e.g. render + # GLUT spec says error-checking is basically undefined... + # there *may* be GL errors on GLUT calls that e.g. render # geometry, but that's all basically "maybe" stuff... func.errcheck = error_checker.glCheckError return func - def wrapContextCheck( self, func, dll ): + + def wrapContextCheck(self, func, dll): """Wrap function with context-checking if appropriate""" - if _configflags.CONTEXT_CHECKING and dll is self.GL and func.__name__ not in ( - 'glGetString', - 'glGetStringi', - 'glGetIntegerv', - ) and not func.__name__.startswith( 'glX' ): - return _CheckContext( func, self.CurrentContextIsValid ) - return func - def wrapLogging( self, func ): + if ( + _configflags.CONTEXT_CHECKING + and dll is self.GL + and func.__name__ + not in ( + 'glGetString', + 'glGetStringi', + 'glGetIntegerv', + ) + and not func.__name__.startswith('glX') + ): + return _CheckContext(func, self.CurrentContextIsValid) + return func + + def wrapLogging(self, func): """Wrap function with logging operations if appropriate""" - return logs.logOnFail( func, logs.getLog( 'OpenGL.errors' )) - - def finalArgType( self, typ ): + return logs.logOnFail(func, logs.getLog('OpenGL.errors')) + + def finalArgType(self, typ): """Retrieve a final type for arg-type""" - if typ == ctypes.POINTER( None ) and not getattr( typ, 'final',False): + if typ == ctypes.POINTER(None) and not getattr(typ, 'final', False): from OpenGL.arrays import ArrayDatatype + return ArrayDatatype else: return typ - def constructFunction( + + def constructFunction( self, - functionName, dll, - resultType=ctypes.c_int, argTypes=(), - doc = None, argNames = (), - extension = None, - deprecated = False, - module = None, - force_extension = False, - error_checker = None, + functionName, + dll, + resultType=ctypes.c_int, + argTypes=(), + doc=None, + argNames=(), + extension=None, + deprecated=False, + module=None, + force_extension=False, + error_checker=None, ): """Core operation to create a new base ctypes function - + raises AttributeError if can't find the procedure... """ is_core = (not extension) or extension.split('_')[1] == 'VERSION' - if (not is_core) and not self.checkExtension( extension ): - raise AttributeError( """Extension not available""" ) - argTypes = [ self.finalArgType( t ) for t in argTypes ] - - if force_extension or ((not is_core) and (not self.EXTENSIONS_USE_BASE_FUNCTIONS)): + if (not is_core) and not self.checkExtension(extension): + raise AttributeError("""Extension not available""") + argTypes = [self.finalArgType(t) for t in argTypes] + + if force_extension or ( + (not is_core) and (not self.EXTENSIONS_USE_BASE_FUNCTIONS) + ): # what about the VERSION values??? - pointer = self.getExtensionProcedure( as_8_bit(functionName) ) + pointer = self.getExtensionProcedure(as_8_bit(functionName)) if pointer: - func = self.functionTypeFor( dll )( - resultType, - *argTypes - )( - pointer - ) + func = self.functionTypeFor(dll)(resultType, *argTypes)(pointer) else: - raise AttributeError( """Extension %r available, but no pointer for function %r"""%(extension,functionName)) + raise AttributeError( + """Extension %r available, but no pointer for function %r""" + % (extension, functionName) + ) else: func = ctypesloader.buildFunction( - self.functionTypeFor( dll )( - resultType, - *argTypes - ), + self.functionTypeFor(dll)(resultType, *argTypes), functionName, dll, ) - func.__doc__ = doc + func.__doc__ = doc func.argNames = list(argNames or ()) func.__name__ = functionName func.DLL = dll func.extension = extension func.deprecated = deprecated - func = self.wrapLogging( + func = self.wrapLogging( self.wrapContextCheck( - self.errorChecking( func, dll, error_checker=error_checker ), + self.errorChecking(func, dll, error_checker=error_checker), dll, ) ) if MODULE_ANNOTATIONS: if not module: - module = _find_module( ) + module = _find_module() if module: func.__module__ = module return func - def createBaseFunction( + def createBaseFunction( self, - functionName, dll, - resultType=ctypes.c_int, argTypes=(), - doc = None, argNames = (), - extension = None, - deprecated = False, - module = None, - error_checker = None, + functionName, + dll, + resultType=ctypes.c_int, + argTypes=(), + doc=None, + argNames=(), + extension=None, + deprecated=False, + module=None, + error_checker=None, ): """Create a base function for given name - + Normally you can just use the dll.name hook to get the object, - but we want to be able to create different bindings for the + but we want to be able to create different bindings for the same function, so we do the work manually here to produce a base function from a DLL. """ from OpenGL import wrapper + result = None try: - if ( - _configflags.FORWARD_COMPATIBLE_ONLY and - dll is self.GL and - deprecated - ): + if _configflags.FORWARD_COMPATIBLE_ONLY and dll is self.GL and deprecated: result = self.nullFunction( - functionName, dll=dll, - resultType=resultType, + functionName, + dll=dll, + resultType=resultType, argTypes=argTypes, - doc = doc, argNames = argNames, - extension = extension, - deprecated = deprecated, - error_checker = error_checker, + doc=doc, + argNames=argNames, + extension=extension, + deprecated=deprecated, + error_checker=error_checker, ) else: result = self.constructFunction( - functionName, dll, - resultType=resultType, argTypes=argTypes, - doc = doc, argNames = argNames, - extension = extension, - error_checker = error_checker, + functionName, + dll, + resultType=resultType, + argTypes=argTypes, + doc=doc, + argNames=argNames, + extension=extension, + error_checker=error_checker, ) except AttributeError as err: - result = self.nullFunction( - functionName, dll=dll, - resultType=resultType, + result = self.nullFunction( + functionName, + dll=dll, + resultType=resultType, argTypes=argTypes, - doc = doc, argNames = argNames, - extension = extension, - error_checker = error_checker, + doc=doc, + argNames=argNames, + extension=extension, + error_checker=error_checker, ) if MODULE_ANNOTATIONS: if not module: - module = _find_module( ) + module = _find_module() if module: result.__module__ = module return result - def checkExtension( self, 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 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 ) + + set = contextdata.getValue('extensions', context=context) if set is None: set = {} - contextdata.setValue( - 'extensions', set, context=context, weak=False - ) - current = set.get( name ) + 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 + + result = extensions.ExtensionQuerier.hasExtension(name) + set[name] = result return result return current else: from OpenGL import extensions - return extensions.ExtensionQuerier.hasExtension( name ) + + return extensions.ExtensionQuerier.hasExtension(name) + createExtensionFunction = createBaseFunction - def copyBaseFunction( self, original ): + def copyBaseFunction(self, original): """Create a new base function based on an already-created function - + This is normally used to provide type-specific convenience versions of a definition created by the automated generator. """ from OpenGL import wrapper, error - if isinstance( original, _NullFunctionPointer ): + + if isinstance(original, _NullFunctionPointer): return self.nullFunction( original.__name__, original.DLL, - resultType = original.restype, - argTypes= original.argtypes, - doc = original.__doc__, - argNames = original.argNames, - extension = original.extension, - deprecated = original.deprecated, - error_checker = original.error_checker, + resultType=original.restype, + argTypes=original.argtypes, + doc=original.__doc__, + argNames=original.argNames, + extension=original.extension, + deprecated=original.deprecated, + error_checker=original.error_checker, ) - elif hasattr( original, 'originalFunction' ): + elif hasattr(original, 'originalFunction'): original = original.originalFunction return self.createBaseFunction( - original.__name__, original.DLL, - resultType=original.restype, argTypes=original.argtypes, - doc = original.__doc__, argNames = original.argNames, - extension = original.extension, - deprecated = original.deprecated, - error_checker = original.errcheck, + original.__name__, + original.DLL, + resultType=original.restype, + argTypes=original.argtypes, + doc=original.__doc__, + argNames=original.argNames, + extension=original.extension, + deprecated=original.deprecated, + error_checker=original.errcheck, ) - def nullFunction( + + def nullFunction( self, - functionName, dll, - resultType=ctypes.c_int, + functionName, + dll, + resultType=ctypes.c_int, argTypes=(), - doc = None, argNames = (), - extension = None, - deprecated = False, - module = None, - error_checker = None, - force_extension = False, + doc=None, + argNames=(), + extension=None, + deprecated=False, + module=None, + error_checker=None, + force_extension=False, ): """Construct a "null" function pointer""" if deprecated: base = _DeprecatedFunctionPointer else: base = _NullFunctionPointer - cls = type( functionName, (base,), { - '__doc__': doc, - 'deprecated': deprecated, - } ) + cls = type( + functionName, + (base,), + { + '__doc__': doc, + 'deprecated': deprecated, + }, + ) if MODULE_ANNOTATIONS: if not module: - module = _find_module( ) + module = _find_module() if module: cls.__module__ = module return cls( - functionName, dll, resultType, argTypes, argNames, extension=extension, doc=doc, - error_checker = error_checker, force_extension=force_extension, + functionName, + dll, + resultType, + argTypes, + argNames, + extension=extension, + doc=doc, + error_checker=error_checker, + force_extension=force_extension, ) - def GetCurrentContext( self ): + + def GetCurrentContext(self): """Retrieve opaque pointer for the current context""" - raise NotImplementedError( - """Platform does not define a GetCurrentContext function""" + raise NotImplementedError( + """Platform does not define a GetCurrentContext function""" ) - def getGLUTFontPointer(self, constant ): + + def getGLUTFontPointer(self, constant): """Retrieve a GLUT font pointer for this platform""" - raise NotImplementedError( - """Platform does not define a GLUT font retrieval function""" + raise NotImplementedError( + """Platform does not define a GLUT font retrieval function""" ) + # names that are normally just references to other items... @lazy_property - def CurrentContextIsValid( self ): + def CurrentContextIsValid(self): return self.GetCurrentContext + @lazy_property - def OpenGL(self): return self.GL + def OpenGL(self): + return self.GL + -class _NullFunctionPointer( object ): +class _NullFunctionPointer(object): """Function-pointer-like object for undefined functions""" - def __init__( - self, name, dll, resultType, argTypes, argNames, - extension=None, doc=None, deprecated=False, - error_checker = None, force_extension=None, + + def __init__( + self, + name, + dll, + resultType, + argTypes, + argNames, + extension=None, + doc=None, + deprecated=False, + error_checker=None, + force_extension=None, ): from OpenGL import error + self.__name__ = name self.DLL = dll self.argNames = argNames @@ -376,14 +441,18 @@ def __init__( self.deprecated = deprecated self.error_checker = error_checker self.force_extension = force_extension + resolved = False - def __nonzero__( self ): + + def __nonzero__(self): """Make this object appear to be NULL""" if (not self.resolved) and (self.extension or self.force_extension): self.load() return self.resolved + __bool__ = __nonzero__ - def load( self ): + + def load(self): """Attempt to load the function again, presumably with a context this time""" try: from OpenGL import platform @@ -393,26 +462,28 @@ def load( self ): return None try: func = platform.PLATFORM.constructFunction( - self.__name__, self.DLL, - resultType=self.restype, + self.__name__, + self.DLL, + resultType=self.restype, argTypes=self.argtypes, - doc = self.doc, - argNames = self.argNames, - extension = self.extension, - error_checker = self.error_checker, - force_extension = self.force_extension, + doc=self.doc, + argNames=self.argNames, + extension=self.extension, + error_checker=self.error_checker, + force_extension=self.force_extension, ) except AttributeError as err: - return None + return None else: # now short-circuit so that we don't need to check again... - self.__class__.__call__ = staticmethod( func.__call__ ) + self.__class__.__call__ = staticmethod(func.__call__) self.resolved = True return func return None - def __call__( self, *args, **named ): + + def __call__(self, *args, **named): if self.load(): - return self( *args, **named ) + return self(*args, **named) else: try: from OpenGL import error @@ -421,17 +492,21 @@ def __call__( self, *args, **named ): pass else: raise error.NullFunctionError( - """Attempt to call an undefined function %s, check for bool(%s) before calling"""%( - self.__name__, self.__name__, + """Attempt to call an undefined function %s, check for bool(%s) before calling""" + % ( + self.__name__, + self.__name__, ) ) -class _DeprecatedFunctionPointer( _NullFunctionPointer ): + +class _DeprecatedFunctionPointer(_NullFunctionPointer): deprecated = True - def __call__( self, *args, **named ): + + def __call__(self, *args, **named): from OpenGL import error + raise error.NullFunctionError( - """Attempt to call a deprecated function %s while OpenGL in FORWARD_COMPATIBLE_ONLY mode. Set OpenGL.FORWARD_COMPATIBLE_ONLY to False to use legacy entry points"""%( - self.__name__, - ) + """Attempt to call a deprecated function %s while OpenGL in FORWARD_COMPATIBLE_ONLY mode. Set OpenGL.FORWARD_COMPATIBLE_ONLY to False to use legacy entry points""" + % (self.__name__,) ) diff --git a/tests/egltest.py b/tests/egltest.py index 65f112f2..cc693569 100644 --- a/tests/egltest.py +++ b/tests/egltest.py @@ -1,29 +1,37 @@ """EGL Pygame test framework""" from __future__ import print_function import os -if not os.environ.get( 'PYOPENGL_PLATFORM' ): + +if not os.environ.get('PYOPENGL_PLATFORM'): os.environ['PYOPENGL_PLATFORM'] = 'egl' import ctypes -import pygame.display -import pygame +import pygame.display +import pygame import logging import OpenGL from functools import wraps -if os.environ.get( 'TEST_NO_ACCELERATE' ): +if os.environ.get('TEST_NO_ACCELERATE'): OpenGL.USE_ACCELERATE = False from OpenGL import arrays from OpenGL.EGL import * -log = logging.getLogger( __name__ ) + +log = logging.getLogger(__name__) DESIRED_ATTRIBUTES = [ - EGL_BLUE_SIZE, 8, - EGL_RED_SIZE,8, - EGL_GREEN_SIZE,8, - EGL_DEPTH_SIZE,24, - EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, - EGL_CONFIG_CAVEAT, EGL_NONE, # Don't allow slow/non-conformant + EGL_BLUE_SIZE, + 8, + EGL_RED_SIZE, + 8, + EGL_GREEN_SIZE, + 8, + EGL_DEPTH_SIZE, + 24, + EGL_COLOR_BUFFER_TYPE, + EGL_RGB_BUFFER, + EGL_CONFIG_CAVEAT, + EGL_NONE, # Don't allow slow/non-conformant ] API_BITS = { 'opengl': EGL_OPENGL_BIT, @@ -35,53 +43,64 @@ 'es1': EGL_OPENGL_ES_BIT, 'es': EGL_OPENGL_ES_BIT, } -API_NAMES = dict([ - (k,{ - EGL_OPENGL_BIT:EGL_OPENGL_API, - EGL_OPENGL_ES2_BIT:EGL_OPENGL_ES_API, - EGL_OPENGL_ES_BIT:EGL_OPENGL_ES_API - }[v]) - for k,v in API_BITS.items() -]) +API_NAMES = dict( + [ + ( + k, + { + EGL_OPENGL_BIT: EGL_OPENGL_API, + EGL_OPENGL_ES2_BIT: EGL_OPENGL_ES_API, + EGL_OPENGL_ES_BIT: EGL_OPENGL_ES_API, + }[v], + ) + for k, v in API_BITS.items() + ] +) -def egltest( size=(300,300), name=None, api='es2', attributes=DESIRED_ATTRIBUTES ): - def gltest( function ): +def egltest(size=(300, 300), name=None, api='es2', attributes=DESIRED_ATTRIBUTES): + def gltest(function): """Decorator to allow a function to run in a Pygame GLES[1,2,3] context""" - @wraps( function ) - def test_function( *args, **named ): - major,minor = ctypes.c_long(),ctypes.c_long() + + @wraps(function) + def test_function(*args, **named): + major, minor = ctypes.c_long(), ctypes.c_long() display = eglGetDisplay(EGL_DEFAULT_DISPLAY) - eglInitialize( display, major, minor) + eglInitialize(display, major, minor) num_configs = ctypes.c_long() - configs = (EGLConfig*2)() + configs = (EGLConfig * 2)() api_constant = API_NAMES[api.lower()] local_attributes = attributes[:] - local_attributes.extend( [ - EGL_CONFORMANT, API_BITS[api.lower()], - EGL_NONE, - ]) + local_attributes.extend( + [ + EGL_CONFORMANT, + API_BITS[api.lower()], + EGL_NONE, + ] + ) print('local_attributes', local_attributes) - local_attributes= arrays.GLintArray.asArray( local_attributes ) + local_attributes = arrays.GLintArray.asArray(local_attributes) eglChooseConfig(display, local_attributes, configs, 2, num_configs) print('API', api_constant) eglBindAPI(api_constant) - + # now need to get a raw X window handle... pygame.init() - pygame.display.set_mode( size ) + pygame.display.set_mode(size) window = pygame.display.get_wm_info()['window'] - surface = eglCreateWindowSurface(display, configs[0], window, None ) - + surface = eglCreateWindowSurface(display, configs[0], window, None) + ctx = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, None) if ctx == EGL_NO_CONTEXT: - raise RuntimeError( 'Unable to create context' ) + raise RuntimeError('Unable to create context') try: - eglMakeCurrent( display, surface, surface, ctx ) + eglMakeCurrent(display, surface, surface, ctx) function(*args, **named) - eglSwapBuffers( display, surface ) + eglSwapBuffers(display, surface) finally: pygame.display.quit() pygame.quit() + return test_function - return gltest + + return gltest diff --git a/tests/geomshader.py b/tests/geomshader.py index bb5a1951..7f506034 100644 --- a/tests/geomshader.py +++ b/tests/geomshader.py @@ -4,6 +4,7 @@ from OpenGL._bytes import as_8_bit from OpenGL.GL import * from OpenGL.GL import shaders + vertex_shader = """#version 150 core in float inValue; out float geoValue; @@ -31,77 +32,79 @@ } """ + @pygamegltest.pygametest(name="Geometry Shader Test") def main(): program = shaders.compileProgram( - shaders.compileShader([vertex_shader], GL_VERTEX_SHADER), - shaders.compileShader([geometry_shader], GL_GEOMETRY_SHADER) + shaders.compileShader([vertex_shader], GL_VERTEX_SHADER), + shaders.compileShader([geometry_shader], GL_GEOMETRY_SHADER), ) - + # test that we can describe the attributes in the shader - for i in range( glGetProgramiv( program, GL_ACTIVE_ATTRIBUTES )): - name,size,type = glGetActiveAttrib( program, i ) - print( 'Arribute %s(%i) -> %s %s'%(name,i,size,type)) - - length,size,type,name = GLsizei(),GLint(),GLenum(),(GLchar*8)() - glGetActiveAttrib( program, i, None, length,size,type,name ) - assert length.value == len(name.value),(length.value,name.value) + for i in range(glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES)): + name, size, type = glGetActiveAttrib(program, i) + print('Atribute %s(%i) -> %s %s' % (name, i, size, type)) + + length, size, type, name = GLsizei(), GLint(), GLenum(), (GLchar * 8)() + glGetActiveAttrib(program, i, None, length, size, type, name) + assert length.value == len(name.value), (length.value, name.value) assert type.value == 5126, type.value - - for i in range( glGetProgramiv( program, GL_ACTIVE_UNIFORMS )): - name,size,type = glGetActiveUniform( program, i ) - print( 'Uniform %s(%i) -> %s %s'%(name,i,size,type)) - - length,size,type,name = GLsizei(),GLint(),GLenum(),(GLchar*5)() - glGetActiveUniform( program, i, 5, length, size, type, name ) - assert length.value == len(name.value),(length.value,name.value) + + for i in range(glGetProgramiv(program, GL_ACTIVE_UNIFORMS)): + name, size, type = glGetActiveUniform(program, i) + print('Uniform %s(%i) -> %s %s' % (name, i, size, type)) + + length, size, type, name = GLsizei(), GLint(), GLenum(), (GLchar * 5)() + glGetActiveUniform(program, i, 5, length, size, type, name) + assert length.value == len(name.value), (length.value, name.value) assert type.value == 5126, type.value - - buff = (ctypes.c_char_p * 1)( as_8_bit("outValue\000") ) + buff = (ctypes.c_char_p * 1)(as_8_bit("outValue\000")) c_text = ctypes.cast(ctypes.pointer(buff), ctypes.POINTER(ctypes.POINTER(GLchar))) # modifies the state in the linking of the program - glTransformFeedbackVaryings(program, 1, c_text, GL_INTERLEAVED_ATTRIBS); + glTransformFeedbackVaryings(program, 1, c_text, GL_INTERLEAVED_ATTRIBS) # so have to re-link glLinkProgram(program) - - glUseProgram(program); + glUseProgram(program) - vao = glGenVertexArrays(1); - glBindVertexArray(vao); + vao = glGenVertexArrays(1) + glBindVertexArray(vao) data = (GLfloat * 5)(1.0, 2.0, 3.0, 4.0, 5.0) - - vbo = glGenBuffers(1); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), data, GL_STATIC_DRAW); - inputAttrib = glGetAttribLocation(program, "inValue"); - glEnableVertexAttribArray(inputAttrib); - glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0); + vbo = glGenBuffers(1) + glBindBuffer(GL_ARRAY_BUFFER, vbo) + glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data), data, GL_STATIC_DRAW) + + inputAttrib = glGetAttribLocation(program, "inValue") + glEnableVertexAttribArray(inputAttrib) + glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0) - tbo = glGenBuffers(1); - glBindBuffer(GL_ARRAY_BUFFER, tbo); - glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data) * 3, None, GL_STATIC_READ); + tbo = glGenBuffers(1) + glBindBuffer(GL_ARRAY_BUFFER, tbo) + glBufferData(GL_ARRAY_BUFFER, ctypes.sizeof(data) * 3, None, GL_STATIC_READ) - glEnable(GL_RASTERIZER_DISCARD); + glEnable(GL_RASTERIZER_DISCARD) - glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo); + glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo) - glBeginTransformFeedback(GL_TRIANGLES); - glDrawArrays(GL_POINTS, 0, 5); - glEndTransformFeedback(); + glBeginTransformFeedback(GL_TRIANGLES) + glDrawArrays(GL_POINTS, 0, 5) + glEndTransformFeedback() - glDisable(GL_RASTERIZER_DISCARD); + glDisable(GL_RASTERIZER_DISCARD) - glFlush(); + glFlush() - feedback = (GLfloat*15)(*([0]*15)) - glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctypes.sizeof(feedback), feedback); + feedback = (GLfloat * 15)(*([0] * 15)) + glGetBufferSubData( + GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctypes.sizeof(feedback), feedback + ) for value in feedback: print(value) + if __name__ == "__main__": main()