예제 #1
0
    def createShader(vSource, fSource):
        #Creo y compilo el vertex shader
        vProgram = ShaderManager.compileProgram(vSource, GL_VERTEX_SHADER)
        #Creo y compilo el fragment shader
        fProgram = ShaderManager.compileProgram(fSource, GL_FRAGMENT_SHADER)
        #Creo un programa de shading vacio en memoria de video
        shader = glCreateProgram()
        #Le adjunto el codigo objeto del vertex shader compilado
        glAttachShader(shader, vProgram)
        #Le adjunto el codigo objeto del fragment shader compilado
        glAttachShader(shader, fProgram)
        #Intento linkear el programa para generar un ejecutable en memoria de video
        glLinkProgram(shader)
        #Chequeo si la ejecucion del linkeo del programa fue exitosa
        if glGetProgramiv(shader, GL_LINK_STATUS) != GL_TRUE:
            #Si falla, imprimo el mensaje de error y libero los recursos
            print(glGetProgramInfoLog(shader))
            glDeleteProgram(shader)
            return 0
        #Una vez que el programa fue linkeado, haya sido exitoso o no, ya no necesito los shaders
        #individuales compilados, asi que libero sus recursos
        glDeleteShader(vProgram)
        glDeleteShader(fProgram)

        return shader
예제 #2
0
    def __init__(self, vertex, fragment):
        """
        Parameters
        ----------
        vertex : str
            String containing shader source code for the vertex
            shader
        fragment : str
            String containing shader source code for the fragment
            shader

        """
        self.program_id = glCreateProgram()
        vs_id = self.add_shader(vertex, GL_VERTEX_SHADER)
        frag_id = self.add_shader(fragment, GL_FRAGMENT_SHADER)

        glAttachShader(self.program_id, vs_id)
        glAttachShader(self.program_id, frag_id)
        glLinkProgram(self.program_id)

        if glGetProgramiv(self.program_id, GL_LINK_STATUS) != GL_TRUE:
            info = glGetProgramInfoLog(self.program_id)
            glDeleteProgram(self.program_id)
            glDeleteShader(vs_id)
            glDeleteShader(frag_id)
            raise RuntimeError('Error linking program: %s' % (info))
        glDeleteShader(vs_id)
        glDeleteShader(frag_id)
 def initProgram(self):
     # create unique shader program id
     self.program_id = glCreateProgram()
     # load and compile individual shaders
     vertsource = self.loadShader(self.vertpath)
     fragsource = self.loadShader(self.fragpath)
     vert_id = self.getShader(vertsource, GL_VERTEX_SHADER)
     frag_id = self.getShader(fragsource, GL_FRAGMENT_SHADER)
     # if it's ok, attach them to shader program
     glAttachShader(self.program_id, vert_id)
     glAttachShader(self.program_id, frag_id)
     self.analyze(
         vertsource
     )  # in case of new (+#330 ;D) shaders - nothing will happen.
     # link program means make program obj with created executables for different programmable processors for shaders,
     # that were attached.
     glLinkProgram(self.program_id)
     # if something went wrong
     if glGetProgramiv(self.program_id, GL_LINK_STATUS) != GL_TRUE:
         info = glGetProgramInfoLog(self.program_id)
         glDeleteProgram(self.program_id)
         # they should be deleted anyway
         glDeleteShader(vert_id)
         glDeleteShader(frag_id)
         raise RuntimeError("Error in program linking: %s" % info)
     # shaders are attached, program is linked -> full shader program with compiled executables is ready,
     # no need in individual shaders ids, i suppose
     glDeleteShader(vert_id)
     glDeleteShader(frag_id)
예제 #4
0
      def init_shaders(self,vtx=None,frg=None):

          self.program_id = glCreateProgram()

          if vtx:
             self.VTX.source = vtx
             self.VTX.fname  = None

          #print self.VTX.source
          self.VTX.id = self.add_shader(self.VTX.source, GL_VERTEX_SHADER)

          if frg:
             self.FRG.source = frg
             self.FRG.fname  = None
          self.FRG.id = self.add_shader(self.FRG.source, GL_FRAGMENT_SHADER)


          glAttachShader(self.program_id, self.VTX.id)
          glAttachShader(self.program_id, self.FRG.id)
          glLinkProgram(self.program_id)

          if glGetProgramiv(self.program_id, GL_LINK_STATUS) != GL_TRUE:
             info = glGetProgramInfoLog(self.program_id)
             glDeleteProgram(self.program_id)
             glDeleteShader(self.VTX.id)
             glDeleteShader(self.FRG.id)
             raise RuntimeError('Error linking program: %s' % (info))
          glDeleteShader(self.VTX.id)
          glDeleteShader(self.FRG.id)
    def destroy(self) -> None:
        self.stop()

        glDetachShader(self.__program_id, self.__vertex_shader_id)
        glDetachShader(self.__program_id, self.__fragment_shader_id)
        glDeleteShader(self.__vertex_shader_id)
        glDeleteShader(self.__fragment_shader_id)
        glDeleteProgram(self.__program_id)
예제 #6
0
def make_program(vertex_shader, fragment_shader):
    program = glCreateProgram()
    glAttachShader(program, vertex_shader)
    glAttachShader(program, fragment_shader)
    glLinkProgram(program)
    retval = ctypes.c_int()
    glGetProgramiv(program, GL_LINK_STATUS, retval)
    if not retval:
        print >> sys.stderr, "Failed to link shader program."
        print glGetProgramInfoLog(program)
        glDeleteProgram(program)
        raise Exception("Failed to link shader program.")
    return program
예제 #7
0
 def _createProgram(self, shaders):
     prog = None
     try:
         prog = glCreateProgram()
         for shader in shaders: 
             glAttachShader(prog, shader)
         
         glLinkProgram(prog)            
         if glGetProgramiv(prog, GL_LINK_STATUS) != GL_TRUE:
             info = glGetProgramInfoLog(prog)
             raise Exception, "Unable to link program. Info log:\n%s" % (info)
         
         return prog
     except Exception:
         if prog != None:
             glDeleteProgram(prog)
         raise
예제 #8
0
    def __init__(self, shaderPaths=[]):

        self.shader_program = glCreateProgram()
        self.shader_objects = {}
        for (shader_type, path) in shaderPaths:
            self.shader_objects[shader_type] = self.loadAndCompileShaderObject(
                shader_type, path)
            glAttachShader(self.shader_program,
                           self.shader_objects[shader_type])

        glLinkProgram(self.shader_program)
        if glGetProgramiv(self.shader_program, GL_LINK_STATUS) != GL_TRUE:
            info = glGetProgramInfoLog(self.shader_program)
            glDeleteProgram(self.shader_program)
            for shader in self.shader_objects:
                glDeleteShader(shader)
            raise RuntimeError("Error in program linking: %s" % info)
예제 #9
0
def compile_shader(vertex_shader_source, fragment_shader_source):
    vertex_shader = load_shader(GL_VERTEX_SHADER, vertex_shader_source)
    fragment_shader = load_shader(GL_FRAGMENT_SHADER, fragment_shader_source)

    program = glCreateProgram()

    if program == 0:
        raise ShaderException()

    glAttachShader(program, vertex_shader)
    glAttachShader(program, fragment_shader)

    glLinkProgram(program)

    if glGetProgramiv(program, GL_LINK_STATUS, None) == GL_FALSE:
        info_log = glGetProgramInfoLog(program)
        glDeleteProgram(program)
        raise ShaderException(info_log)

    return program
예제 #10
0
 def __init__(self, vsource, fsource, gsource = None):
     self.uniformlocs = {}
     self.attributelocs = {}
     self.program = None
     try:
         shaders = []
         shaders.append(self._createShader(GL_VERTEX_SHADER, vsource))
         if gsource != None:
             shaders.append(self._createShader(GL_GEOMETRY_SHADER, gsource))
         shaders.append(self._createShader(GL_FRAGMENT_SHADER, fsource))
         self.program = self._createProgram(shaders)
         # Flag shader for deletion.
     except:
         if self.program != None:
             glDeleteProgram(self.program)
         raise
     finally:
         for shader in shaders:
             try:
                 glDeleteShader(shader)
             except:
                 pass
예제 #11
0
 def delete(self):
     try:
         glDeleteProgram(self.__programId)
         self.__programId = 0
     except NullFunctionError:
         pass
예제 #12
0
	def destruir(self):
		"""Elimina los shaders y el programa, y destruye referencias."""
		glDeleteShader(self.fshader)
		glDeleteShader(self.vshader)
		glDeleteProgram(self.programa)
예제 #13
0
파일: Shader.py 프로젝트: micage/play_one
 def delete(self):
     glDeleteProgram(self.program)
     self.program = 0
     self.status &= ~Resource.CREATED
예제 #14
0
 def __del__(self):
     glDeleteProgram(self.m_RendererID)
예제 #15
0
파일: myshaders.py 프로젝트: tom66/glscope
 def __del__(self):
     if self.owned and self.valid():
         self.detach(*self.shaders(
         ))  # Detach and mark for deletion all attahed shader object
         glDeleteProgram(self.pid)