def _CreateProgramAndShaders(self): # clear any old programs and shaders if self._programId < 0: return # clear to be sure self.DestroyGl() if not self._fragmentCode and not self._vertexCode: self._programId = -1 # don't make a shader object return try: # create program object self._programId = gla.glCreateProgramObjectARB() # the two shaders codes = [self._fragmentCode, self._vertexCode] types = [gl.GL_FRAGMENT_SHADER, gl.GL_VERTEX_SHADER] for code, type in zip(codes, types): # only attach shaders that do something if not code: continue # create shader object myshader = gla.glCreateShaderObjectARB(type) self._shaderIds.append(myshader) # Set its source, pyopengl accepts the code as a string. gla.glShaderSourceARB(myshader, [code]) # compile shading code gla.glCompileShaderARB(myshader) # If it went well, attach! if self._CheckForErrors(myshader, True, False): self._programId = -1 return else: gla.glAttachObjectARB(self._programId, myshader) # link shader and check for errors gla.glLinkProgramARB(self._programId) if self._CheckForErrors(self._programId, False, True): self._programId = -1 except Exception: self._programId = -1 why = str(getExceptionInstance()) print("Unable to initialize shader code. %s" % why)
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = 'backend_' + name modNameFull = 'visvis.backends.backend_' + name modFileName = os.path.join(os.path.dirname(__file__), modName + '.py') # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith('.pyc'): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. why = str(getExceptionInstance()) print('Error importing %s backend: %s' % (name, why)) return False # Do some tests if not hasattr(module, 'newFigure'): raise Exception("Backend %s does not implement newFigure!" % be) elif not hasattr(module, 'Figure'): raise Exception("Backend %s does not implement Figure class!" % be) else: # All good (as far as I can tell). Update stuff if name does not match. module.app._backend = name if currentBackend.name != name: currentBackend.name = name currentBackend.newFigure = module.newFigure currentBackend.app = module.app return True
def _loadBackend(name): """ Load the backend with the specified name. Returns True on success and False otherwise. """ # Get module names modName = 'backend_' + name modNameFull = 'visvis.backends.backend_'+name modFileName = os.path.join(os.path.dirname(__file__), modName+'.py') # Test whether to use the pyc version load_module = imp.load_source if not os.path.isfile(modFileName): modFileName += "c" # Probably a frozen app # Try importing the backend toolkit try: modNameTk = backendMap[name] __import__(modNameTk) except ImportError: return False # Try importing the visvis backend module try: if modFileName.endswith('.pyc'): module = __import__(modNameFull, fromlist=[modName]) else: module = imp.load_source(modNameFull, modFileName) globals()[modName] = module except Exception: if not isFrozen(): # Only show if not frozen. If frozen, it can easily happen that # the GUI toolkit is available, but the visvis backend is not. why = str(getExceptionInstance()) print('Error importing %s backend: %s' % (name, why)) return False # Do some tests if not hasattr(module,'newFigure'): raise Exception("Backend %s does not implement newFigure!" % be) elif not hasattr(module,'Figure'): raise Exception("Backend %s does not implement Figure class!" % be) else: # All good (as far as I can tell). Update stuff if name does not match. module.app._backend = name if currentBackend.name != name: currentBackend.name = name currentBackend.newFigure = module.newFigure currentBackend.app = module.app return True