def get(self, vert_name, frag_name, defines={}, vertex_defines={}, fragment_defines={}): _fragment_defines = {} _fragment_defines.update(fragment_defines) _fragment_defines.update(defines) _vertex_defines = {} _vertex_defines.update(vertex_defines) _vertex_defines.update(defines) frag_prepend = self.__build_s(_fragment_defines) vert_prepend = self.__build_s(_vertex_defines) # The defines to a shader affect compilation, create an unordered key _defines_key = (frozenset(_fragment_defines.items()), frozenset(_vertex_defines.items())) key = vert_name, frag_name, _defines_key if key not in self.cache: frag1s = self.__get_shader_text(frag_name) vert1s = self.__get_shader_text(vert_name) frag_version, frag1s = self.extract_version(frag1s) vert_version, vert1s = self.extract_version(vert1s) try: frag = compileShader([frag_version, frag_prepend, frag1s], GL.GL_FRAGMENT_SHADER) vert = compileShader([vert_version, vert_prepend, vert1s], GL.GL_VERTEX_SHADER) obj = compileProgram(vert, frag) except RuntimeError as e: msg, shader, _ = e.args print("During Shader Compilation: ", msg) shader_body = b"".join(shader).decode('ascii') lines = shader_body.split("\n") for i in lines: print("\t%s" % i.strip()) return None obj.uniforms = UniformProxy(obj) self.cache[key] = obj return self.cache[key]
def setUp(self): f = QtOpenGL.QGLFormat() f.setVersion(3, 3) f.setProfile(QtOpenGL.QGLFormat.CoreProfile) c = QtOpenGL.QGLContext(f) self.mockWidget = QtOpenGL.QGLWidget(c) self.assertTrue(self.mockWidget.isValid()) self.mockWidget.makeCurrent() s1 = S.compileShader(VERT_1, GL.GL_VERTEX_SHADER) s2 = S.compileShader(FRAG_1, GL.GL_FRAGMENT_SHADER) self.prog = S.compileProgram(s1, s2)
def setUp(self): if self.ctx is None: f = QtOpenGL.QGLFormat() f.setVersion(3, 2) f.setProfile(QtOpenGL.QGLFormat.CoreProfile) self.ctx = QtOpenGL.QGLContext(f) self.mockWidget = QtOpenGL.QGLWidget(self.ctx) self.assertTrue(self.ctx.isValid()) self.ctx.makeCurrent() # Compile the two shaders individually s1 = S.compileShader(VERT_1, GL.GL_VERTEX_SHADER) s2 = S.compileShader(FRAG_1, GL.GL_FRAGMENT_SHADER) # now build the whole program self.prog = S.compileProgram(s1, s2)
def get(self, vert_name, frag_name, defines={}, vertex_defines={}, fragment_defines={}): _fragment_defines={} _fragment_defines.update(fragment_defines) _fragment_defines.update(defines) _vertex_defines={} _vertex_defines.update(vertex_defines) _vertex_defines.update(defines) frag_prepend = self.__build_s(_fragment_defines) vert_prepend = self.__build_s(_vertex_defines) # The defines to a shader affect compilation, create an unordered key _defines_key = (frozenset(_fragment_defines.items()), frozenset(_vertex_defines.items())) key = vert_name, frag_name, _defines_key if key not in self.cache: frag1s = self.__get_shader_text(frag_name) vert1s = self.__get_shader_text(vert_name) frag_version, frag1s = self.extract_version(frag1s) vert_version, vert1s = self.extract_version(vert1s) try: frag = compileShader([frag_version, frag_prepend, frag1s], GL.GL_FRAGMENT_SHADER) vert = compileShader([vert_version, vert_prepend, vert1s], GL.GL_VERTEX_SHADER) obj = compileProgram(vert, frag) except RuntimeError as e: msg, shader, _ = e.args print("During Shader Compilation: ", msg) shader_body = b"".join(shader).decode('ascii') lines = shader_body.split("\n") for i in lines: print("\t%s" % i.strip()) return None obj.uniforms = UniformProxy(obj) self.cache[key] = obj return self.cache[key]
def get(self, vert_name, frag_name, defines={}, vertex_defines={}, fragment_defines={}): _fragment_defines={} _fragment_defines.update(fragment_defines) _fragment_defines.update(defines) _vertex_defines={} _vertex_defines.update(vertex_defines) _vertex_defines.update(defines) frag_prepend = self.__build_s(_fragment_defines) vert_prepend = self.__build_s(_vertex_defines) # The defines to a shader affect compilation, create an unordered key _defines_key = (frozenset(_fragment_defines.items()), frozenset(_vertex_defines.items())) key = vert_name, frag_name, _defines_key if key not in self.cache: frag1s = self.__get_shader_text(frag_name) vert1s = self.__get_shader_text(vert_name) frag_version, frag1s = self.extract_version(frag1s) vert_version, vert1s = self.extract_version(vert1s) try: frag = compileShader([frag_version, frag_prepend, frag1s], GL.GL_FRAGMENT_SHADER) vert = compileShader([vert_version, vert_prepend, vert1s], GL.GL_VERTEX_SHADER) obj = compileProgram(vert, frag) except RuntimeError as e: print("During Shader Compilation: ", e) raise e obj.uniforms = UniformProxy(obj) self.cache[key] = obj return self.cache[key]
def setUp(self): # Ensure we have a qapplication - another testcase might have created it though try: app = QtWidgets.QApplication([]) except RuntimeError: pass if self.ctx is None: f = QtOpenGL.QGLFormat() f.setVersion(3, 2) f.setProfile(QtOpenGL.QGLFormat.CoreProfile) self.ctx = QtOpenGL.QGLContext(f) self.mockWidget = QtOpenGL.QGLWidget(self.ctx) self.assertTrue(self.ctx.isValid()) self.ctx.makeCurrent() # Compile the two shaders individually s1 = S.compileShader(VERT_1, GL.GL_VERTEX_SHADER) s2 = S.compileShader(FRAG_1, GL.GL_FRAGMENT_SHADER) # now build the whole program self.prog = S.compileProgram(s1, s2)
def get( self, vert_name: str, frag_name: str, defines: Optional[Dict[str, str]] = None, vertex_defines: Optional[Dict[str, str]] = None, fragment_defines: Optional[Dict[str, str]] = None, fragment_bindings: Optional[Dict[str, int]] = None) -> EnhShaderProgram: _fragment_defines = {} if fragment_defines is not None: _fragment_defines.update(fragment_defines) if defines is not None: _fragment_defines.update(defines) _vertex_defines = {} if vertex_defines is not None: _vertex_defines.update(vertex_defines) if defines is not None: _vertex_defines.update(defines) if fragment_bindings is None: fragment_bindings = {} frag_prepend = self.__build_s(_fragment_defines) vert_prepend = self.__build_s(_vertex_defines) # The defines to a shader affect compilation, create an unordered key _defines_key = (frozenset(_fragment_defines.items()), frozenset(_vertex_defines.items())) key = vert_name, frag_name, _defines_key if key not in self.cache: frag1s = self.__get_shader_text(frag_name) vert1s = self.__get_shader_text(vert_name) frag_version, frag1s = self.extract_version(frag1s) vert_version, vert1s = self.extract_version(vert1s) try: frag = compileShader([frag_version, frag_prepend, frag1s], GL.GL_FRAGMENT_SHADER) vert = compileShader([vert_version, vert_prepend, vert1s], GL.GL_VERTEX_SHADER) obj = compileProgram([vert, frag], fragment_bindings) except RuntimeError as e: msg, shader, _ = e.args print("During Shader Compilation: ", msg) shader_body = b"".join(shader).decode('ascii') lines = shader_body.split("\n") for i in lines: print("\t%s" % i.strip()) raise # TODO - determine if this is needed obj.uniforms = UniformProxy(obj) # type: ignore self.cache[key] = obj return self.cache[key]