def link_GL(name, restype, argtypes, requires=None, suggestions=None): try: func = getattr(gl_lib, name) func.restype = restype func.argtypes = argtypes decorate_function(func, name) return func except AttributeError: # Not in opengl32.dll. Try and get a pointer from WGL. try: fargs = (restype,) + tuple(argtypes) ftype = ctypes.WINFUNCTYPE(*fargs) if _have_get_proc_address: from pyglet.gl import gl_info if gl_info.have_context(): address = wglGetProcAddress(name) if address: func = cast(address, ftype) decorate_function(func, name) return func else: # Insert proxy until we have a context return WGLFunctionProxy(name, ftype, requires, suggestions) except: pass return missing_function(name, requires, suggestions)
def get_matching_configs(self, template): # Determine which technique should be used for finding matching configs. # Use the builtin PIXELFORMATDESCRIPTOR if possible, otherwise resort # to the WGL_ARB_pixel_format extension. need_pixel_format_arb = False if template.sample_buffers or template.samples: need_pixel_format_arb = True if need_pixel_format_arb: # Need a GL context before we can query WGL extensions. dummy_window = None if not gl_info.have_context(): # Create a dummy context config = self.get_best_config() context = config.create_context(None) dummy_window = Win32Window(visible=False, context=context) try: # Check for required extensions if not wgl_info.have_extension('WGL_ARB_pixel_format'): return [] return self._get_arb_pixel_format_matching_configs(template) finally: if dummy_window: dummy_window.close() return self._get_pixel_format_descriptor_matching_configs(template)
def get_extensions(self): if not gl_info.have_context(): warnings.warn("Can't query WGL until a context is created.") return [] try: return wglGetExtensionsStringEXT().split() except MissingFunctionException: return cast(glGetString(GL_EXTENSIONS), c_char_p).value.split()
def match(self, canvas): if not isinstance(canvas, Win32Canvas): raise RuntimeError("Canvas must be instance of Win32Canvas") # Use ARB API if available if gl_info.have_context() and wgl_info.have_extension("WGL_ARB_pixel_format"): return self._get_arb_pixel_format_matching_configs(canvas) else: return self._get_pixel_format_descriptor_matching_configs(canvas)
def match(self, canvas): if not isinstance(canvas, Win32Canvas): raise RuntimeError('Canvas must be instance of Win32Canvas') # Use ARB API if available if gl_info.have_context() and wgl_info.have_extension('WGL_ARB_pixel_format'): return self._get_arb_pixel_format_matching_configs(canvas) else: return self._get_pixel_format_descriptor_matching_configs(canvas)
def __call__(self, *args, **kwargs): if self.func: return self.func(*args, **kwargs) from pyglet.gl import gl_info if not gl_info.have_context(): raise Exception( 'Call to function "%s" before GL context created' % self.name) address = wglGetProcAddress(self.name) if cast(address, POINTER(c_int)): # check cast because address is func self.func = cast(address, self.ftype) decorate_function(self.func, self.name) else: self.func = missing_function( self.name, self.requires, self.suggestions) result = self.func(*args, **kwargs) return result
def __call__(self, *args, **kwargs): if self.func: return self.func(*args, **kwargs) from pyglet.gl import gl_info if not gl_info.have_context(): raise Exception('Call to function "%s" before GL context created' % self.name) address = wglGetProcAddress(self.name) if cast(address, POINTER(c_int)): # check cast because address is func self.func = cast(address, self.ftype) decorate_function(self.func, self.name) else: self.func = missing_function(self.name, self.requires, self.suggestions) result = self.func(*args, **kwargs) return result