def main(): import pygtk pygtk.require('2.0') import gtk.gdkgl, gtk.gtkgl #@UnresolvedImport assert gtk.gdkgl is not None and gtk.gtkgl is not None print("loading OpenGL.GL") from OpenGL.GL import GL_VERSION, glGetString from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB glconfig = gtk.gdkgl.Config(mode=gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DOUBLE | gtk.gdkgl.MODE_DEPTH) print("glconfig=%s" % glconfig) win = gtk.Window() win.set_title('test GL') glarea = gtk.gtkgl.DrawingArea(glconfig=glconfig, share_list=None, render_type=gtk.gdkgl.RGBA_TYPE) win.add(glarea) glarea.realize() glcontext = glarea.get_gl_context() print("glcontext=%s" % glcontext) pixmap = gtk.gdk.Pixmap(None, 120, 120, 24) print("pixmap=%s" % pixmap) glext = gtk.gdkgl.ext(pixmap) print("glext=%s" % glext) gldrawable = gtk.gdkgl.Pixmap(glconfig, pixmap) print("gldrawable=%s" % gldrawable) if gldrawable is None: raise ImportError("failed to initialize") glcontext = gtk.gdkgl.Context(gldrawable, direct=True) if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) try: gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) if gl_major <= 1 and gl_minor < 1: raise ImportError( "** OpenGL output requires OpenGL version 1.1 or greater, not %s.%s" % (gl_major, gl_minor)) print("found valid OpenGL: %s.%s" % (gl_major, gl_minor)) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt if not glInitFragmentProgramARB(): raise ImportError( "** OpenGL output requires glInitFragmentProgramARB") finally: gldrawable.gl_end() del glcontext, gldrawable, glext, glconfig
def main(): import pygtk pygtk.require("2.0") import gtk.gdkgl, gtk.gtkgl # @UnresolvedImport assert gtk.gdkgl is not None and gtk.gtkgl is not None print("loading OpenGL.GL") from OpenGL.GL import GL_VERSION, glGetString from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB glconfig = gtk.gdkgl.Config(mode=gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DOUBLE | gtk.gdkgl.MODE_DEPTH) print("glconfig=%s" % glconfig) win = gtk.Window() win.set_title("test GL") glarea = gtk.gtkgl.DrawingArea(glconfig=glconfig, share_list=None, render_type=gtk.gdkgl.RGBA_TYPE) win.add(glarea) glarea.realize() glcontext = glarea.get_gl_context() print("glcontext=%s" % glcontext) pixmap = gtk.gdk.Pixmap(None, 120, 120, 24) print("pixmap=%s" % pixmap) glext = gtk.gdkgl.ext(pixmap) print("glext=%s" % glext) gldrawable = gtk.gdkgl.Pixmap(glconfig, pixmap) print("gldrawable=%s" % gldrawable) if gldrawable is None: raise ImportError("failed to initialize") glcontext = gtk.gdkgl.Context(gldrawable, direct=True) if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) try: gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) if gl_major <= 1 and gl_minor < 1: raise ImportError( "** OpenGL output requires OpenGL version 1.1 or greater, not %s.%s" % (gl_major, gl_minor) ) print("found valid OpenGL: %s.%s" % (gl_major, gl_minor)) # this allows us to do CSC via OpenGL: # see http://www.opengl.org/registry/specs/ARB/fragment_program.txt if not glInitFragmentProgramARB(): raise ImportError("** OpenGL output requires glInitFragmentProgramARB") finally: gldrawable.gl_end() del glcontext, gldrawable, glext, glconfig
def do_check_GL_support(force_enable): props = {} try: #log redirection: def redirect_log(logger_name): logger = logging.getLogger(logger_name) assert logger is not None logger.saved_handlers = logger.handlers logger.saved_propagate = logger.propagate logger.handlers = [CaptureHandler()] logger.propagate = 0 return logger fhlogger = redirect_log('OpenGL.formathandler') elogger = redirect_log('OpenGL.extensions') alogger = redirect_log('OpenGL.acceleratesupport') arlogger = redirect_log('OpenGL.arrays') clogger = redirect_log('OpenGL.converters') import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger, glGetIntegerv gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: gl_check_error("OpenGL version is missing - cannot continue") return {} gl_major = int(gl_version_str[0]) gl_minor = int(gl_version_str[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1,1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error("OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) from OpenGL import version as OpenGL_version pyopengl_version = OpenGL_version.__version__ try: import OpenGL_accelerate accel_version = OpenGL_accelerate.__version__ props["accelerate"] = accel_version log("OpenGL_accelerate version %s", accel_version) except: log("OpenGL_accelerate not found") OpenGL_accelerate = None accel_version = None if accel_version is not None and pyopengl_version!=accel_version: global _version_warning_shown if not _version_warning_shown: log.warn("Warning: version mismatch between PyOpenGL and PyOpenGL-accelerate") log.warn(" this may cause crashes") _version_warning_shown = True vsplit = pyopengl_version.split('.') #we now require PyOpenGL 3.1 or later if vsplit[:2]<['3','1'] and not force_enable: gl_check_error("PyOpenGL version 3.1 or later is required (found version %s)" % pyopengl_version) return {} props["zerocopy"] = bool(OpenGL_accelerate) and is_pyopengl_memoryview_safe(pyopengl_version, accel_version) try: extensions = glGetString(GL_EXTENSIONS).decode().split(" ") except: log("error querying extensions", exc_info=True) extensions = [] gl_check_error("OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?") log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: log("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION def fixstring(v): try: return str(v).strip() except: return str(v) for d,s,fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading language version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) v = fixstring(v.decode()) log("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log("OpenGL property '%s' is missing", d) v = "" props[d] = v vendor = props["vendor"] version_req = VERSION_REQ.get(vendor) if version_req: req_maj, req_min = version_req if gl_major<req_maj or (gl_major==req_maj and gl_minor<req_min): if force_enable: log.warn("Warning: '%s' OpenGL driver requires version %i.%i", vendor, req_maj, req_min) log.warn(" version %i.%i was found", gl_major, gl_minor) else: gl_check_error("OpenGL version %i.%i is too old, %i.%i is required for %s" % (gl_major, gl_minor, req_maj, req_min, vendor)) from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d,s in {"GLU version": GLU_VERSION, "GLU extensions":GLU_EXTENSIONS}.items(): v = gluGetString(s) v = v.decode() log("%s: %s", d, v) props[d] = v blacklisted = None whitelisted = None greylisted = None for k,vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in blacklist: %s", k, v, vlist) blacklisted = k, v for k,vlist in GREYLIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in greylist: %s", k, v, vlist) greylisted = k, v for k,vlist in WHITELIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in whitelist: %s", k, v, vlist) whitelisted = k, v if blacklisted: if whitelisted: log.info("%s '%s' enabled (found in both blacklist and whitelist)", *whitelisted) elif force_enable: log.warn("Warning: %s '%s' is blacklisted!", *blacklisted) else: gl_check_error("%s '%s' is blacklisted!" % (blacklisted)) safe = bool(whitelisted) or not (bool(greylisted) or bool(blacklisted)) if safe and sys.version_info[0]>2: log.warn("Warning: OpenGL python3 support is not enabled by default") safe = False props["safe"] = safe #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) glEnablei = None try: from OpenGL.GL import glEnablei except: pass if not bool(glEnablei): log.warn("OpenGL glEnablei is not available, disabling transparency") global GL_ALPHA_SUPPORTED GL_ALPHA_SUPPORTED = False props["transparency"] = GL_ALPHA_SUPPORTED #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error("OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) try: from OpenGL.GL import GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) #this one may be missing? rect_texture_size = texture_size try: from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) except ImportError as e: log("OpenGL: %s", e) log("using GL_MAX_TEXTURE_SIZE=%s as default", texture_size) except Exception as e: emsg = str(e) if hasattr(e, "description"): emsg = e.description gl_check_error("unable to query max texture size: %s" % emsg) return props log("Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) texture_size_limit = min(rect_texture_size, texture_size) props["texture-size-limit"] = texture_size_limit try: from OpenGL.GL import GL_MAX_VIEWPORT_DIMS v = glGetIntegerv(GL_MAX_VIEWPORT_DIMS) max_viewport_dims = v[0], v[1] assert max_viewport_dims[0]>=texture_size_limit and max_viewport_dims[1]>=texture_size_limit log("GL_MAX_VIEWPORT_DIMS=%s", max_viewport_dims) except ImportError as e: log.error("Error querying max viewport dims: %s", e) max_viewport_dims = texture_size_limit, texture_size_limit props["max-viewport-dims"] = max_viewport_dims return props finally: for x in alogger.handlers[0].records: #strip default message prefix: msg = x.getMessage().replace("No OpenGL_accelerate module loaded: ", "") if msg=="No module named OpenGL_accelerate": msg = "missing accelerate module" if msg!="OpenGL_accelerate module loaded": msg = "PyOpenGL warning: %s" % msg log.info(msg) #format handler messages: STRIP_LOG_MESSAGE = "Unable to load registered array format handler " missing_handlers = [] for x in fhlogger.handlers[0].records: msg = x.getMessage() p = msg.find(STRIP_LOG_MESSAGE) if p<0: #unknown message, log it: log.info(msg) continue format_handler = msg[p+len(STRIP_LOG_MESSAGE):] p = format_handler.find(":") if p>0: format_handler = format_handler[:p] missing_handlers.append(format_handler) if len(missing_handlers)>0: log.warn("PyOpenGL warning: missing array format handlers: %s", ", ".join(missing_handlers)) for x in elogger.handlers[0].records: msg = x.getMessage() #ignore extension messages: p = msg.startswith("GL Extension ") and msg.endswith("available") if not p: log.info(msg) missing_accelerators = [] STRIP_AR_HEAD = "Unable to load" STRIP_AR_TAIL = "from OpenGL_accelerate" for x in arlogger.handlers[0].records+clogger.handlers[0].records: msg = x.getMessage() if msg.startswith(STRIP_AR_HEAD) and msg.endswith(STRIP_AR_TAIL): m = msg[len(STRIP_AR_HEAD):-len(STRIP_AR_TAIL)].strip() m = m.replace("accelerators", "").replace("accelerator", "").strip() missing_accelerators.append(m) continue elif msg.startswith("Using accelerated"): log(msg) else: log.info(msg) if missing_accelerators: log.info("OpenGL accelerate missing: %s", ", ".join(missing_accelerators)) def restore_logger(logger): logger.handlers = logger.saved_handlers logger.propagate = logger.saved_propagate restore_logger(fhlogger) restore_logger(elogger) restore_logger(alogger) restore_logger(arlogger) restore_logger(clogger)
gldrawable = glext.set_gl_capability(glconfig) glcontext = gtk.gdkgl.Context(gldrawable, direct=True) if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) try: gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) if gl_major <= 1 and gl_minor < 1: raise ImportError( "** OpenGL output requires OpenGL version 1.1 or greater, not %s.%s" % (gl_major, gl_minor)) log.info("found valid OpenGL: %s.%s", gl_major, gl_minor) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt use_openGL_CSC = glInitFragmentProgramARB() finally: gldrawable.gl_end() del glcontext, gldrawable, glext, glconfig except Exception, e: raise ImportError("** OpenGL initialization error: %s" % e) class GLClientWindow(ClientWindow): MODE_UNINITIALIZED = 0 MODE_RGB = 1 MODE_YUV = 2 def __init__(self, client, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay): ClientWindow.__init__(self, client, wid, x, y, w, h, metadata,
def check_GL_support(gldrawable, glcontext, min_texture_size=0, force_enable=False): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: if SILENCE_FORMAT_HANDLER_LOGGER: logging.getLogger('OpenGL.formathandler').setLevel(logging.WARN) import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1, 1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error( "OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) try: extensions = glGetString(GL_EXTENSIONS).split(" ") except: gl_check_error( "OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?" ) log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d, s in { "vendor": GL_VENDOR, "renderer": GL_RENDERER, "shading language version": GL_SHADING_LANGUAGE_VERSION }.items(): try: v = glGetString(s) log("%s: %s", d, v) except: gl_check_error("OpenGL property '%s' is missing" % d) v = "" props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d, s in { "GLU version": GLU_VERSION, "GLU extensions": GLU_EXTENSIONS }.items(): v = gluGetString(s) log("%s: %s", d, v) props[d] = v for k, vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: if force_enable: log.warn("Warning: %s '%s' is blacklisted!", k, v) else: gl_check_error("%s '%s' is blacklisted!" % (k, v)) #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error( "OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) if min_texture_size > texture_size: gl_check_error("The texture size is too small: %s" % texture_size) else: log("Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB=%s", texture_size) return props finally: if SILENCE_FORMAT_HANDLER_LOGGER: try: logging.getLogger('OpenGL.formathandler').setLevel( logging.INFO) except: pass gldrawable.gl_end()
def check_PyOpenGL_support(force_enable): props = {} try: if CRASH: import ctypes ctypes.string_at(0) raise Exception("should have crashed!") elif TIMEOUT > 0: import time time.sleep(TIMEOUT) #log redirection: def redirect_log(logger_name): logger = logging.getLogger(logger_name) assert logger is not None logger.saved_handlers = logger.handlers logger.saved_propagate = logger.propagate logger.handlers = [CaptureHandler()] logger.propagate = 0 return logger fhlogger = redirect_log('OpenGL.formathandler') elogger = redirect_log('OpenGL.extensions') alogger = redirect_log('OpenGL.acceleratesupport') arlogger = redirect_log('OpenGL.arrays') clogger = redirect_log('OpenGL.converters') import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger, glGetIntegerv gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: raise_fatal_error("OpenGL version is missing - cannot continue") return {} gl_major = int(bytestostr(gl_version_str)[0]) gl_minor = int(bytestostr(gl_version_str)[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1, 1) if (gl_major, gl_minor) < MIN_VERSION: raise_fatal_error( "OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) from OpenGL import version as OpenGL_version pyopengl_version = OpenGL_version.__version__ try: import OpenGL_accelerate #@UnresolvedImport accel_version = OpenGL_accelerate.__version__ props["accelerate"] = accel_version log("OpenGL_accelerate version %s", accel_version) except: log("OpenGL_accelerate not found") OpenGL_accelerate = None accel_version = None if accel_version is not None and pyopengl_version != accel_version: global _version_warning_shown if not _version_warning_shown: log.warn( "Warning: version mismatch between PyOpenGL and PyOpenGL-accelerate" ) log.warn(" %s vs %s", pyopengl_version, accel_version) log.warn(" this may cause crashes") _version_warning_shown = True gl_check_error( "PyOpenGL vs accelerate version mismatch: %s vs %s" % (pyopengl_version, accel_version)) vsplit = pyopengl_version.split('.') #we now require PyOpenGL 3.1 or later if vsplit[:3] < ['3', '1'] and not force_enable: raise_fatal_error("PyOpenGL version %s is too old and buggy" % pyopengl_version) return {} props["zerocopy"] = bool( OpenGL_accelerate) and is_pyopengl_memoryview_safe( pyopengl_version, accel_version) try: extensions = glGetString(GL_EXTENSIONS).decode().split(" ") except: log("error querying extensions", exc_info=True) extensions = [] raise_fatal_error( "OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?" ) log("OpenGL extensions found: %s", csv(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: log("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION def fixstring(v): try: return str(v).strip() except: return str(v) for d, s, fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading-language-version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) v = fixstring(v.decode()) log("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log("OpenGL property '%s' is missing", d) v = "" props[d] = v vendor = props["vendor"] version_req = VERSION_REQ.get(vendor) if version_req: req_maj, req_min = version_req if gl_major < req_maj or (gl_major == req_maj and gl_minor < req_min): if force_enable: log.warn( "Warning: '%s' OpenGL driver requires version %i.%i", vendor, req_maj, req_min) log.warn(" version %i.%i was found", gl_major, gl_minor) else: gl_check_error( "OpenGL version %i.%i is too old, %i.%i is required for %s" % (gl_major, gl_minor, req_maj, req_min, vendor)) from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d, s in { "GLU.version": GLU_VERSION, "GLU.extensions": GLU_EXTENSIONS }.items(): v = gluGetString(s) v = v.decode() log("%s: %s", d, v) props[d] = v def match_list(thelist, listname): for k, vlist in thelist.items(): v = props.get(k) matches = [x for x in vlist if v.find(x) >= 0] if matches: log("%s '%s' found in %s: %s", k, v, listname, vlist) return (k, v) log("%s '%s' not found in %s: %s", k, v, listname, vlist) return None blacklisted = match_list(BLACKLIST, "blacklist") greylisted = match_list(GREYLIST, "greylist") whitelisted = match_list(WHITELIST, "whitelist") if blacklisted: if whitelisted: log.info( "%s '%s' enabled (found in both blacklist and whitelist)", *whitelisted) elif force_enable: log.warn("Warning: %s '%s' is blacklisted!", *blacklisted) log.warn(" force enabled by option") else: raise_fatal_error("%s '%s' is blacklisted!" % (blacklisted)) safe = bool(whitelisted) or not bool(blacklisted) if greylisted and not whitelisted: log.warn("Warning: %s '%s' is greylisted,", *greylisted) log.warn(" you may want to turn off OpenGL if you encounter bugs") props["safe"] = safe #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) glEnablei = None try: from OpenGL.GL import glEnablei except: pass if not bool(glEnablei): log.warn( "OpenGL glEnablei is not available, disabling transparency") global GL_ALPHA_SUPPORTED GL_ALPHA_SUPPORTED = False props["transparency"] = GL_ALPHA_SUPPORTED for ext in required_extensions: if ext not in extensions: raise_fatal_error( "OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): raise_fatal_error( "OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): raise_fatal_error( "OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) try: from OpenGL.GL import GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) #this one may be missing? rect_texture_size = texture_size try: from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) except ImportError as e: log("OpenGL: %s", e) log("using GL_MAX_TEXTURE_SIZE=%s as default", texture_size) except Exception as e: emsg = str(e) if hasattr(e, "description"): emsg = e.description gl_check_error("unable to query max texture size: %s" % emsg) return props log( "Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) texture_size_limit = min(rect_texture_size, texture_size) props["texture-size-limit"] = int(texture_size_limit) try: from OpenGL.GL import GL_MAX_VIEWPORT_DIMS v = glGetIntegerv(GL_MAX_VIEWPORT_DIMS) max_viewport_dims = int(v[0]), int(v[1]) assert max_viewport_dims[ 0] >= texture_size_limit and max_viewport_dims[ 1] >= texture_size_limit log("GL_MAX_VIEWPORT_DIMS=%s", max_viewport_dims) except ImportError as e: log.error("Error querying max viewport dims: %s", e) max_viewport_dims = texture_size_limit, texture_size_limit props["max-viewport-dims"] = max_viewport_dims return props finally: for x in alogger.handlers[0].records: #strip default message prefix: msg = x.getMessage().replace( "No OpenGL_accelerate module loaded: ", "") if msg == "No module named OpenGL_accelerate": msg = "missing accelerate module" if msg == "OpenGL_accelerate module loaded": log.info(msg) else: log.warn("PyOpenGL warning: %s", msg) #format handler messages: STRIP_LOG_MESSAGE = "Unable to load registered array format handler " missing_handlers = [] for x in fhlogger.handlers[0].records: msg = x.getMessage() p = msg.find(STRIP_LOG_MESSAGE) if p < 0: #unknown message, log it: log.info(msg) continue format_handler = msg[p + len(STRIP_LOG_MESSAGE):] p = format_handler.find(":") if p > 0: format_handler = format_handler[:p] missing_handlers.append(format_handler) if len(missing_handlers) > 0: log.warn("PyOpenGL warning: missing array format handlers: %s", csv(missing_handlers)) for x in elogger.handlers[0].records: msg = x.getMessage() #ignore extension messages: p = msg.startswith("GL Extension ") and msg.endswith("available") if not p: log.info(msg) missing_accelerators = [] STRIP_AR_HEAD = "Unable to load" STRIP_AR_TAIL = "from OpenGL_accelerate" for x in arlogger.handlers[0].records + clogger.handlers[0].records: msg = x.getMessage() if msg.startswith(STRIP_AR_HEAD) and msg.endswith(STRIP_AR_TAIL): m = msg[len(STRIP_AR_HEAD):-len(STRIP_AR_TAIL)].strip() m = m.replace("accelerators", "").replace("accelerator", "").strip() missing_accelerators.append(m) continue elif msg.startswith("Using accelerated"): log(msg) else: log.info(msg) if missing_accelerators: log.info("OpenGL accelerate missing: %s", csv(missing_accelerators)) def restore_logger(logger): logger.handlers = logger.saved_handlers logger.propagate = logger.saved_propagate restore_logger(fhlogger) restore_logger(elogger) restore_logger(alogger) restore_logger(arlogger) restore_logger(clogger)
glconfig = gtk.gdkgl.Config(mode=gtk.gdkgl.MODE_RGB|gtk.gdkgl.MODE_SINGLE) glext = gtk.gdkgl.ext(gdk.Pixmap(gdk.get_default_root_window(), 1, 1)) gldrawable = glext.set_gl_capability(glconfig) glcontext = gtk.gdkgl.Context(gldrawable, direct=True) if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) try: gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) if gl_major<=1 and gl_minor<1: raise ImportError("** OpenGL output requires OpenGL version 1.1 or greater, not %s.%s" % (gl_major, gl_minor)) log.info("found valid OpenGL: %s.%s", gl_major, gl_minor) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt use_openGL_CSC = glInitFragmentProgramARB() finally: gldrawable.gl_end() del glcontext, gldrawable, glext, glconfig except Exception, e: raise ImportError("** OpenGL initialization error: %s" % e) class GLClientWindow(ClientWindow): MODE_UNINITIALIZED = 0 MODE_RGB = 1 MODE_YUV = 2 def __init__(self, client, wid, x, y, w, h, metadata, override_redirect, client_properties): ClientWindow.__init__(self, client, wid, x, y, w, h, metadata, override_redirect, client_properties) display_mode = (gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_SINGLE)
def check_GL_support(gldrawable, glcontext, min_texture_size=0, force_enable=False): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: if SILENCE_FORMAT_HANDLER_LOGGER: debug("silencing formathandler warnings") logging.getLogger('OpenGL.formathandler').setLevel(logging.WARN) import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: gl_check_error("OpenGL version is missing - cannot continue") return {} gl_major = int(gl_version_str[0]) gl_minor = int(gl_version_str[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1,1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error("OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: debug("found valid OpenGL version: %s.%s", gl_major, gl_minor) try: extensions = glGetString(GL_EXTENSIONS).split(" ") except: gl_check_error("OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?") debug("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: debug("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d,s,fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading language version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) debug("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log.warn("OpenGL property '%s' is missing" % d) v = "" props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d,s in {"GLU version": GLU_VERSION, "GLU extensions":GLU_EXTENSIONS}.items(): v = gluGetString(s) debug("%s: %s", d, v) props[d] = v for k,vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: if force_enable: log.warn("Warning: %s '%s' is blacklisted!", k, v) else: gl_check_error("%s '%s' is blacklisted!" % (k, v)) #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error("OpenGL driver lacks support for extension: %s" % ext) else: debug("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: debug("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: debug("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE, GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) if min_texture_size>texture_size or min_texture_size>rect_texture_size: gl_check_error("The texture size is too small: %s" % texture_size) else: debug("Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) return props finally: if SILENCE_FORMAT_HANDLER_LOGGER: try: logging.getLogger('OpenGL.formathandler').setLevel(logging.INFO) except: pass gldrawable.gl_end()
def check_GL_support(gldrawable, glcontext, min_texture_size=0, force_enable=False): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: #log redirection: def redirect_log(logger_name): logger = logging.getLogger(logger_name) assert logger is not None logger.saved_handlers = logger.handlers logger.saved_propagate = logger.propagate logger.handlers = [CaptureHandler()] logger.propagate = 0 return logger fhlogger = redirect_log('OpenGL.formathandler') elogger = redirect_log('OpenGL.extensions') alogger = redirect_log('OpenGL.acceleratesupport') arlogger = redirect_log('OpenGL.arrays') clogger = redirect_log('OpenGL.converters') import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: gl_check_error("OpenGL version is missing - cannot continue") return {} gl_major = int(gl_version_str[0]) gl_minor = int(gl_version_str[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1, 1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error( "OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) try: extensions = glGetString(GL_EXTENSIONS).split(" ") except: gl_check_error( "OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?" ) log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: log("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d, s, fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading language version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) log("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log.warn("OpenGL property '%s' is missing" % d) v = "" props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d, s in { "GLU version": GLU_VERSION, "GLU extensions": GLU_EXTENSIONS }.items(): v = gluGetString(s) log("%s: %s", d, v) props[d] = v for k, vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: if force_enable: log.warn("Warning: %s '%s' is blacklisted!", k, v) else: gl_check_error("%s '%s' is blacklisted!" % (k, v)) #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) glEnablei = None try: from OpenGL.GL import glEnablei except: pass if not bool(glEnablei): log.warn( "OpenGL glEnablei is not available, disabling transparency") global GL_ALPHA_SUPPORTED GL_ALPHA_SUPPORTED = False #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error( "OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) try: from OpenGL.GL import GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) #this one may be missing? rect_texture_size = texture_size try: from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) except ImportError, e: log("OpenGL: %s", e) log("using GL_MAX_TEXTURE_SIZE=%s as default", texture_size) except Exception, e: emsg = str(e) if hasattr(e, "description"): emsg = e.description gl_check_error("unable to query max texture size: %s" % emsg) return props if min_texture_size > texture_size or min_texture_size > rect_texture_size: gl_check_error("The texture size is too small: %s" % texture_size) else: log( "Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) return props
def check_GL_support(gldrawable, glcontext, min_texture_size=0, force_enable=False): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: #log redirection: def redirect_log(logger_name): logger = logging.getLogger(logger_name) assert logger is not None logger.saved_handlers = logger.handlers logger.saved_propagate = logger.propagate logger.handlers = [CaptureHandler()] logger.propagate = 0 return logger fhlogger = redirect_log('OpenGL.formathandler') elogger = redirect_log('OpenGL.extensions') alogger = redirect_log('OpenGL.acceleratesupport') arlogger = redirect_log('OpenGL.arrays') clogger = redirect_log('OpenGL.converters') import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: gl_check_error("OpenGL version is missing - cannot continue") return {} gl_major = int(gl_version_str[0]) gl_minor = int(gl_version_str[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1,1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error("OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) from OpenGL import version as OpenGL_version try: import OpenGL_accelerate except: OpenGL_accelerate = None props["zerocopy"] = is_pyopengl_memoryview_safe(OpenGL_version.__version__) and bool(OpenGL_accelerate) try: extensions = glGetString(GL_EXTENSIONS).split(" ") except: extensions = [] gl_check_error("OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?") log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: log("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d,s,fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading language version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) log("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log("OpenGL property '%s' is missing", d) v = "" props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d,s in {"GLU version": GLU_VERSION, "GLU extensions":GLU_EXTENSIONS}.items(): v = gluGetString(s) log("%s: %s", d, v) props[d] = v blacklisted = None whitelisted = None for k,vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in blacklist: %s", k, v, vlist) blacklisted = k, v for k,vlist in WHITELIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in whitelist: %s", k, v, vlist) whitelisted = k, v if blacklisted: if whitelisted: log.info("%s '%s' enabled (found in both blacklist and whitelist)", *whitelisted) elif force_enable: log.warn("Warning: %s '%s' is blacklisted!", *blacklisted) else: gl_check_error("%s '%s' is blacklisted!" % (blacklisted)) #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) glEnablei = None try: from OpenGL.GL import glEnablei except: pass if not bool(glEnablei): log.warn("OpenGL glEnablei is not available, disabling transparency") global GL_ALPHA_SUPPORTED GL_ALPHA_SUPPORTED = False #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error("OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) try: from OpenGL.GL import GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) #this one may be missing? rect_texture_size = texture_size try: from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) except ImportError, e: log("OpenGL: %s", e) log("using GL_MAX_TEXTURE_SIZE=%s as default", texture_size) except Exception, e: emsg = str(e) if hasattr(e, "description"): emsg = e.description gl_check_error("unable to query max texture size: %s" % emsg) return props if min_texture_size>texture_size or min_texture_size>rect_texture_size: gl_check_error("The texture size is too small: %s" % texture_size) else: log("Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) props["texture-size-limit"] = min(rect_texture_size, texture_size) return props
def do_check_GL_support(force_enable): props = {} try: #log redirection: def redirect_log(logger_name): logger = logging.getLogger(logger_name) assert logger is not None logger.saved_handlers = logger.handlers logger.saved_propagate = logger.propagate logger.handlers = [CaptureHandler()] logger.propagate = 0 return logger fhlogger = redirect_log('OpenGL.formathandler') elogger = redirect_log('OpenGL.extensions') alogger = redirect_log('OpenGL.acceleratesupport') arlogger = redirect_log('OpenGL.arrays') clogger = redirect_log('OpenGL.converters') import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString, glGetInteger gl_version_str = glGetString(GL_VERSION) if gl_version_str is None: gl_check_error("OpenGL version is missing - cannot continue") return {} gl_major = int(gl_version_str[0]) gl_minor = int(gl_version_str[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1, 1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error( "OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) from OpenGL import version as OpenGL_version try: import OpenGL_accelerate except: OpenGL_accelerate = None props["zerocopy"] = is_pyopengl_memoryview_safe( OpenGL_version.__version__) and bool(OpenGL_accelerate) try: extensions = glGetString(GL_EXTENSIONS).decode().split(" ") except: log("error querying extensions", exc_info=True) extensions = [] gl_check_error( "OpenGL could not find the list of GL extensions - does the graphics driver support OpenGL?" ) log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.arrays.arraydatatype import ArrayDatatype try: log("found the following array handlers: %s", set(ArrayDatatype.getRegistry().values())) except: pass from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d, s, fatal in (("vendor", GL_VENDOR, True), ("renderer", GL_RENDERER, True), ("shading language version", GL_SHADING_LANGUAGE_VERSION, False)): try: v = glGetString(s) v = v.decode() log("%s: %s", d, v) except: if fatal: gl_check_error("OpenGL property '%s' is missing" % d) else: log("OpenGL property '%s' is missing", d) v = "" props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d, s in { "GLU version": GLU_VERSION, "GLU extensions": GLU_EXTENSIONS }.items(): v = gluGetString(s) v = v.decode() log("%s: %s", d, v) props[d] = v blacklisted = None whitelisted = None greylisted = None for k, vlist in BLACKLIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in blacklist: %s", k, v, vlist) blacklisted = k, v for k, vlist in GREYLIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in greylist: %s", k, v, vlist) greylisted = k, v for k, vlist in WHITELIST.items(): v = props.get(k) if v in vlist: log("%s '%s' found in whitelist: %s", k, v, vlist) whitelisted = k, v if blacklisted: if whitelisted: log.info( "%s '%s' enabled (found in both blacklist and whitelist)", *whitelisted) elif force_enable: log.warn("Warning: %s '%s' is blacklisted!", *blacklisted) else: gl_check_error("%s '%s' is blacklisted!" % (blacklisted)) safe = bool(whitelisted) or not (bool(greylisted) or bool(blacklisted)) if safe and sys.version_info[0] > 2: log.warn( "Warning: OpenGL python3 support is not enabled by default") safe = False props["safe"] = safe #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, glTexEnvi, glHint, glBlendFunc, glLineStipple, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) glEnablei = None try: from OpenGL.GL import glEnablei except: pass if not bool(glEnablei): log.warn( "OpenGL glEnablei is not available, disabling transparency") global GL_ALPHA_SUPPORTED GL_ALPHA_SUPPORTED = False #check for framebuffer functions we need: from OpenGL.GL.ARB.framebuffer_object import GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D check_functions(GL_FRAMEBUFFER, \ GL_COLOR_ATTACHMENT0, glGenFramebuffers, glBindFramebuffer, glFramebufferTexture2D) for ext in required_extensions: if ext not in extensions: gl_check_error( "OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) try: from OpenGL.GL import GL_MAX_TEXTURE_SIZE texture_size = glGetInteger(GL_MAX_TEXTURE_SIZE) #this one may be missing? rect_texture_size = texture_size try: from OpenGL.GL import GL_MAX_RECTANGLE_TEXTURE_SIZE rect_texture_size = glGetInteger(GL_MAX_RECTANGLE_TEXTURE_SIZE) except ImportError as e: log("OpenGL: %s", e) log("using GL_MAX_TEXTURE_SIZE=%s as default", texture_size) except Exception as e: emsg = str(e) if hasattr(e, "description"): emsg = e.description gl_check_error("unable to query max texture size: %s" % emsg) return props log( "Texture size GL_MAX_RECTANGLE_TEXTURE_SIZE=%s, GL_MAX_TEXTURE_SIZE=%s", rect_texture_size, texture_size) props["texture-size-limit"] = min(rect_texture_size, texture_size) return props finally: for x in alogger.handlers[0].records: #strip default message prefix: msg = x.getMessage().replace( "No OpenGL_accelerate module loaded: ", "") if msg == "No module named OpenGL_accelerate": msg = "missing accelerate module" if msg != "OpenGL_accelerate module loaded": msg = "PyOpenGL warning: %s" % msg log.info(msg) #format handler messages: STRIP_LOG_MESSAGE = "Unable to load registered array format handler " missing_handlers = [] for x in fhlogger.handlers[0].records: msg = x.getMessage() p = msg.find(STRIP_LOG_MESSAGE) if p < 0: #unknown message, log it: log.info(msg) continue format_handler = msg[p + len(STRIP_LOG_MESSAGE):] p = format_handler.find(":") if p > 0: format_handler = format_handler[:p] missing_handlers.append(format_handler) if len(missing_handlers) > 0: log.warn("PyOpenGL warning: missing array format handlers: %s", ", ".join(missing_handlers)) for x in elogger.handlers[0].records: msg = x.getMessage() #ignore extension messages: p = msg.startswith("GL Extension ") and msg.endswith("available") if not p: log.info(msg) missing_accelerators = [] STRIP_AR_HEAD = "Unable to load" STRIP_AR_TAIL = "from OpenGL_accelerate" for x in arlogger.handlers[0].records + clogger.handlers[0].records: msg = x.getMessage() if msg.startswith(STRIP_AR_HEAD) and msg.endswith(STRIP_AR_TAIL): m = msg[len(STRIP_AR_HEAD):-len(STRIP_AR_TAIL)].strip() m = m.replace("accelerators", "").replace("accelerator", "").strip() missing_accelerators.append(m) continue log.info(msg) if missing_accelerators: log.info("OpenGL accelerate missing: %s", ", ".join(missing_accelerators)) def restore_logger(logger): logger.handlers = logger.saved_handlers logger.propagate = logger.saved_propagate restore_logger(fhlogger) restore_logger(elogger) restore_logger(alogger) restore_logger(arlogger) restore_logger(clogger)
def check_GL_support(gldrawable, glcontext): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: if SILENCE_FORMAT_HANDLER_LOGGER: logging.getLogger('OpenGL.formathandler').setLevel(logging.WARN) import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1, 1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error( "OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) extensions = glGetString(GL_EXTENSIONS).split(" ") log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d, s in { "vendor": GL_VENDOR, "renderer": GL_RENDERER, "shading language version": GL_SHADING_LANGUAGE_VERSION }.items(): v = glGetString(s) log("%s: %s", d, v) props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d, s in { "GLU version": GLU_VERSION, "GLU extensions": GLU_EXTENSIONS }.items(): v = gluGetString(s) log("%s: %s", d, v) props[d] = v #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) for ext in required_extensions: if ext not in extensions: gl_check_error( "OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) return props finally: if SILENCE_FORMAT_HANDLER_LOGGER: try: logging.getLogger('OpenGL.formathandler').setLevel( logging.INFO) except: pass gldrawable.gl_end()
def check_GL_support(gldrawable, glcontext): if not gldrawable.gl_begin(glcontext): raise ImportError("gl_begin failed on %s" % gldrawable) props = {} try: if SILENCE_FORMAT_HANDLER_LOGGER: logging.getLogger('OpenGL.formathandler').setLevel(logging.WARN) import OpenGL props["pyopengl"] = OpenGL.__version__ from OpenGL.GL import GL_VERSION, GL_EXTENSIONS from OpenGL.GL import glGetString gl_major = int(glGetString(GL_VERSION)[0]) gl_minor = int(glGetString(GL_VERSION)[2]) props["opengl"] = gl_major, gl_minor MIN_VERSION = (1,1) if (gl_major, gl_minor) < MIN_VERSION: gl_check_error("OpenGL output requires version %s or greater, not %s.%s" % (".".join([str(x) for x in MIN_VERSION]), gl_major, gl_minor)) else: log("found valid OpenGL version: %s.%s", gl_major, gl_minor) extensions = glGetString(GL_EXTENSIONS).split(" ") log("OpenGL extensions found: %s", ", ".join(extensions)) props["extensions"] = extensions from OpenGL.GL import GL_RENDERER, GL_VENDOR, GL_SHADING_LANGUAGE_VERSION for d,s in {"vendor":GL_VENDOR, "renderer":GL_RENDERER, "shading language version":GL_SHADING_LANGUAGE_VERSION}.items(): v = glGetString(s) log("%s: %s", d, v) props[d] = v from OpenGL.GLU import gluGetString, GLU_VERSION, GLU_EXTENSIONS for d,s in {"GLU version": GLU_VERSION, "GLU extensions":GLU_EXTENSIONS}.items(): v = gluGetString(s) log("%s: %s", d, v) props[d] = v #check for specific functions we need: from OpenGL.GL import glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd check_functions(glActiveTexture, glTexSubImage2D, glTexCoord2i, \ glViewport, glMatrixMode, glLoadIdentity, glOrtho, \ glEnableClientState, glGenTextures, glDisable, \ glBindTexture, glPixelStorei, glEnable, glBegin, glFlush, \ glTexParameteri, \ glTexImage2D, \ glMultiTexCoord2i, \ glVertex2i, glEnd) for ext in required_extensions: if ext not in extensions: gl_check_error("OpenGL driver lacks support for extension: %s" % ext) else: log("Extension %s is present", ext) #this allows us to do CSC via OpenGL: #see http://www.opengl.org/registry/specs/ARB/fragment_program.txt from OpenGL.GL.ARB.fragment_program import glInitFragmentProgramARB if not glInitFragmentProgramARB(): gl_check_error("OpenGL output requires glInitFragmentProgramARB") else: log("glInitFragmentProgramARB works") from OpenGL.GL.ARB.texture_rectangle import glInitTextureRectangleARB if not glInitTextureRectangleARB(): gl_check_error("OpenGL output requires glInitTextureRectangleARB") else: log("glInitTextureRectangleARB works") from OpenGL.GL.ARB.vertex_program import glGenProgramsARB, glDeleteProgramsARB, \ glBindProgramARB, glProgramStringARB check_functions(glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB) return props finally: if SILENCE_FORMAT_HANDLER_LOGGER: try: logging.getLogger('OpenGL.formathandler').setLevel(logging.INFO) except: pass gldrawable.gl_end()