コード例 #1
0
ファイル: Shader.py プロジェクト: micage/play_one
    def create(self):
        if not (self.status & Resource.LOADED):
            return

        vs = glCreateShader(GL_VERTEX_SHADER)
        glShaderSource(vs, self.vs_str)
        glCompileShader(vs)
        if glGetShaderiv(vs, GL_COMPILE_STATUS) != GL_TRUE:
            raise RuntimeError(glGetShaderInfoLog(vs))

        fs = glCreateShader(GL_FRAGMENT_SHADER)
        glShaderSource(fs, self.fs_str)
        glCompileShader(fs)
        if glGetShaderiv(fs, GL_COMPILE_STATUS) != GL_TRUE:
            raise RuntimeError(glGetShaderInfoLog(fs))

        program = glCreateProgram()
        glAttachShader(program, vs)
        glAttachShader(program, fs)

        glLinkProgram(program)
        if glGetProgramiv(program, GL_LINK_STATUS) != GL_TRUE:
            raise RuntimeError(glGetProgramInfoLog(program))

        glValidateProgram(program)
        validation = glGetProgramiv(program, GL_VALIDATE_STATUS)
        if validation == GL_FALSE:
            raise RuntimeError(glGetProgramInfoLog(program))

        # todo: check for errrors before setting status
        self.program = program
        self.status |= Resource.CREATED
コード例 #2
0
ファイル: 01_triangle.py プロジェクト: chrisidefix/glfwpy
    def add_shader(self, source, shader_type):
        """ Helper function for compiling a GLSL shader

        Parameters
        ----------
        source : str
            String containing shader source code

        shader_type : valid OpenGL shader type
            Type of shader to compile

        Returns
        -------
        value : int
            Identifier for shader if compilation is successful

        """
        try:
            shader_id = glCreateShader(shader_type)
            glShaderSource(shader_id, source)
            glCompileShader(shader_id)
            if glGetShaderiv(shader_id, GL_COMPILE_STATUS) != GL_TRUE:
                info = glGetShaderInfoLog(shader_id)
                raise RuntimeError('Shader compilation failed: %s' % (info))
            return shader_id
        except:
            glDeleteShader(shader_id)
            raise
コード例 #3
0
    def add_shader(self, source, shader_type):
        """ Helper function for compiling a GLSL shader

        Parameters
        ----------
        source : str
            String containing shader source code

        shader_type : valid OpenGL shader type
            Type of shader to compile

        Returns
        -------
        value : int
            Identifier for shader if compilation is successful

        """
        try:
            shader_id = glCreateShader(shader_type)
            glShaderSource(shader_id, source)
            glCompileShader(shader_id)
            if glGetShaderiv(shader_id, GL_COMPILE_STATUS) != GL_TRUE:
                info = glGetShaderInfoLog(shader_id)
                raise RuntimeError('Shader compilation failed: %s' % (info))
            return shader_id
        except:
            glDeleteShader(shader_id)
            raise
コード例 #4
0
ファイル: myshaders.py プロジェクト: tom66/glscope
    def compile(self):
        """
        Compile the shader. Return True if the compilation was successful,
        false other wise 
        """

        glCompileShader(self.sid)
        return self.compiled == GL_TRUE
コード例 #5
0
ファイル: Shader.py プロジェクト: meuns/Sandbox
def initialize_shader(shader_type, shader_source):

    shader = glCreateShader(shader_type)
    glShaderSource(shader, shader_source)
    glCompileShader(shader)
    result = glGetShaderiv(shader, GL_COMPILE_STATUS)
    if result == 0:
        raise RuntimeError(glGetShaderInfoLog(shader))
    return shader
コード例 #6
0
    def _load_shader(shader_code: str, shader_type: int) -> int:

        shader_id: int = glCreateShader(shader_type)
        glShaderSource(shader_id, shader_code)
        glCompileShader(shader_id)

        if glGetShaderiv(shader_id, GL_COMPILE_STATUS) == GL_FALSE:
            raise RuntimeError("Could not complie shader!")

        return shader_id
コード例 #7
0
    def __load_shader(self, shader_filename, shader_type):
        """Load shader of specific type from file."""
        shader_source = ''
        with open(shader_filename) as shader_file:
            shader_source = shader_file.read()
            assert shader_source

        shader_id = glCreateShader(shader_type)
        self.__shaders[shader_type].append(shader_id)
        glShaderSource(shader_id, shader_source)
        glCompileShader(shader_id)
コード例 #8
0
ファイル: Shader.py プロジェクト: poish/Py-Snowball
    def createShader(self, source, shaderType):

        shader = glCreateShader(shaderType)

        glShaderSource(shader, source, None)
        glCompileShader(shader)

        self.status[shaderType] = glGetShaderiv(shader, GL_COMPILE_STATUS)
        self.infoLog[shaderType] = glGetShaderInfoLog(shader)

        return shader
コード例 #9
0
ファイル: ShadersHelper.py プロジェクト: char-lie/mfm
    def __load_shader(self, shader_filename, shader_type):
        """Load shader of specific type from file."""
        shader_source = ''
        with open(shader_filename) as shader_file:
            shader_source = shader_file.read()
            assert shader_source

        shader_id = glCreateShader(shader_type)
        self.__shaders[shader_type].append(shader_id)
        glShaderSource(shader_id, shader_source)
        glCompileShader(shader_id)
コード例 #10
0
ファイル: hellogl2.py プロジェクト: DarkArtek/stuff
 def create_shader(self, source, shadertype):
     shader = glCreateShader(shadertype)
     # PyOpenGL bug ? He's waiting for a list of string, not a string
     # on some card, it failed :)
     if isinstance(source, basestring):
         source = [source]
     glShaderSource(shader, source)
     glCompileShader(shader)
     message = self.get_shader_log(shader)
     if message:
         pymt_logger.debug('Shader: shader message: %s' % message)
     return shader
コード例 #11
0
def make_shader(shadertype, source):
    shader = glCreateShader(shadertype)
    glShaderSource(shader, source)
    glCompileShader(shader)
    retval = ctypes.c_uint(GL_UNSIGNED_INT)
    glGetShaderiv(shader, GL_COMPILE_STATUS, retval)
    if not retval:
        print >> sys.stderr, "Failed to compile shader."
        print glGetShaderInfoLog(shader)
        glDeleteShader(shader)
        raise Exception("Failed to compile shader.")
    return shader
コード例 #12
0
ファイル: shader.py プロジェクト: Macbull/terrain
 def create_shader(self, source, shadertype):
     shader = glCreateShader(shadertype)
     # PyOpenGL bug ? He's waiting for a list of string, not a string
     # on some card, it failed :)
     # if isinstance(source, basestring):
     # source = [source]
     glShaderSource(shader, source)
     glCompileShader(shader)
     message = self.get_shader_log(shader)
     if message:
         print(' Create Shader: shader message: %s' % message)
     return shader
コード例 #13
0
 def getShader(self, shader_source, shader_type):
     try:
         shader_id = glCreateShader(shader_type)
         glShaderSource(shader_id, shader_source)
         glCompileShader(shader_id)
         if glGetShaderiv(shader_id, GL_COMPILE_STATUS) != GL_TRUE:
             info = glGetShaderInfoLog(shader_id)
             raise RuntimeError('Shader compilation failed:\n %s' % info)
         return shader_id
     except:
         glDeleteShader(shader_id)
         raise
コード例 #14
0
ファイル: jumeg_tsv_ogl_sl.py プロジェクト: fboers/jumeg
 def add_shader(self, source, shader_type):
     try:
         #print "TEST"
         #print source
         shader_id = glCreateShader(shader_type)
         glShaderSource(shader_id, source)
         glCompileShader(shader_id)
         if glGetShaderiv(shader_id, GL_COMPILE_STATUS) != GL_TRUE:
            info = glGetShaderInfoLog(shader_id)
            raise RuntimeError('Shader compilation failed: %s' % (info))
         return shader_id
     except:
         glDeleteShader(shader_id)
         raise
コード例 #15
0
    def CompileShader(self, type, source):
        id = glCreateShader(type)
        glShaderSource(id, source)
        glCompileShader(id)

        result = glGetShaderiv(id, GL_COMPILE_STATUS)
        if (result==GL_FALSE):
            message = glGetShaderInfoLog(id).decode('utf-8')
            shadertype = "Vertex" if type==GL_VERTEX_SHADER else "Fragment"
            print(f"Failed to compile {shadertype} shader!")
            print(message)
            glDeleteShader(id)
            return 0
        return id
コード例 #16
0
ファイル: shader.py プロジェクト: Lizard-13/LizardEngine
	def compilar(self, shader, nombre):
		"""Compila el shader e informa errores.
		shader = shader a compilar
		nombre = nombre del shader en el informe de errores"""
		# Compilamos el shader
		glCompileShader(shader)
		# Obtenemos su estado
		resultado = glGetShaderiv(shader,GL_COMPILE_STATUS)
		# Si el estado es != 1, hubo errores durante la compilación
		if resultado != 1:
			print "Error al compilar {n}, registro:\n".format(n=nombre) + \
					glGetShaderInfoLog(shader)
		# Devolvemos el estado
		return resultado
コード例 #17
0
ファイル: shaderutil.py プロジェクト: rpls/pycgutils
 def _createShader(self, shadertype, source):
     try:
         shader = None
         shader = glCreateShader(shadertype)
         glShaderSource(shader, source)
         glCompileShader(shader)
         if glGetShaderiv(shader, GL_COMPILE_STATUS) != GL_TRUE:
             info = glGetShaderInfoLog(shader)
             raise Exception, "Unable to compile shader. Infolog:\n%s" % (info,)
         return shader
     except Exception:
         # Cleanup on exception
         if shader != None:
             glDeleteShader(shader)
         raise
コード例 #18
0
ファイル: shader_program.py プロジェクト: razorkam/ACG-1
    def loadAndCompileShaderObject(self, shader_type, path):

        if not os.path.exists(path):
            raise RuntimeError('Shader source not found at: %s' % path)

        source_file = open(path)
        shader_source = source_file.read()
        source_file.close()
        shader_object = glCreateShader(shader_type)
        glShaderSource(shader_object, shader_source)
        glCompileShader(shader_object)
        if glGetShaderiv(shader_object, GL_COMPILE_STATUS) != GL_TRUE:
            info = glGetShaderInfoLog(shader_object)
            raise RuntimeError('Shader compilation failed:\n %s' % info)
        return shader_object
コード例 #19
0
	def attachShader(self,type,source):
		shader = glCreateShader(type)
		glShaderSource(shader,source)
		glCompileShader(shader)
		shader_log = glGetShaderInfoLog(shader)
		if shader_log:
			if type == GL_FRAGMENT_SHADER:
				str_type = "GL_FRAGMENT_SHADER"
			elif type == GL_VERTEX_SHADER:
				str_type = "GL_VERTEX_SHADER"
			elif type == GL_GEOMETRY_SHADER:
				str_type = "GL_GEOMETRY_SHADER"
			else:
				str_type = "unkown shader type %s" % str(type)
			raise RuntimeError("%s\n%s" % (str_type, shader_log))
		glAttachShader(self.program_id, shader)
		self._shaders.append(shader)
コード例 #20
0
def load_shader(shader_type, source):
    shader = glCreateShader(shader_type)

    if shader == 0:
        raise ShaderException()

    glShaderSource(shader, source)

    glCompileShader(shader)

    if glGetShaderiv(shader, GL_COMPILE_STATUS, None) == GL_FALSE:
        info_log = glGetShaderInfoLog(shader)
        glDeleteShader(shader)

        raise ShaderException(info_log)

    return shader
コード例 #21
0
ファイル: shader.py プロジェクト: nicholasbishop/bel
    def _compile(self):
        logging.info('glShaderSource(%d, ...)', self._hnd)
        glShaderSource(self._hnd, self._source)
        logging.info('glCompileShader(%d)', self._hnd)
        glCompileShader(self._hnd)

        if not glGetShaderiv(self._hnd, GL_COMPILE_STATUS):
            logging.error('glCompileShader failed')
            compile_log = glGetShaderInfoLog(self._hnd).decode('utf-8')

            glDeleteShader(self._hnd)

            if self._path == '':
                print_source(self._source)

            pretty_print_log(compile_log, self._path)

            raise RuntimeError('shader failed to compile', compile_log)
コード例 #22
0
ファイル: shader.py プロジェクト: nicholasbishop/bel
    def _compile(self):
        logging.info('glShaderSource(%d, ...)', self._hnd)
        glShaderSource(self._hnd, self._source)
        logging.info('glCompileShader(%d)', self._hnd)
        glCompileShader(self._hnd)

        if not glGetShaderiv(self._hnd, GL_COMPILE_STATUS):
            logging.error('glCompileShader failed')
            compile_log = glGetShaderInfoLog(self._hnd).decode('utf-8')

            glDeleteShader(self._hnd)

            if self._path == '':
                print_source(self._source)

            pretty_print_log(compile_log, self._path)

            raise RuntimeError('shader failed to compile', compile_log)
コード例 #23
0
 def compileProgram(path, type):
     #Leo el codigo fuente desde el archivo
     sourceFile = open(path, "r")
     source = sourceFile.read()
     #Creo un shader vacio en memoria de video, del tipo indicado
     #En la variable shader queda almacenado un indice que nos va a permitir identificar este shader de ahora en mas
     shader = glCreateShader(type)
     #Le adjunto el codigo fuente leido desde el archivo
     glShaderSource(shader, source)
     #Intento compilarlo
     glCompileShader(shader)
     #Con la funcion glGelShaderiv puedo obtener el estado del compilador de shaders
     #En este caso le pido el stado de la ultima compilacion ejecutada
     if glGetShaderiv(shader, GL_COMPILE_STATUS) != GL_TRUE:
         #Si la compilacion falla, muestro el error y retorno 0 (shader nulo)
         print(path + ': ' + glGetShaderInfoLog(shader))
         #Me aseguro de liberar los recursos que reserve en memoria de vide, ya que no los voy a usar
         glDeleteShader(shader)
         return 0
     else:
         return shader