Beispiel #1
0
def link_shader_program(vertex_shader, fragment_shader):
    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    result = gl.glGetProgramiv(program, gl.GL_LINK_STATUS)
    if not (result):
        raise RuntimeError(gl.glGetProgramInfoLog(program))
    return program
Beispiel #2
0
    def _update(self):
        """ Called when the object is activated and the _need_update
        flag is set
        """

        # Check if we have something to link
        if not self._verts:
            raise ProgramError("No vertex shader has been given")
        if not self._frags:
            raise ProgramError("No fragment shader has been given")

        # Detach any attached shaders
        attached = gl.glGetAttachedShaders(self._handle)
        for handle in attached:
            gl.glDetachShader(self._handle, handle)

        # Attach and activate vertex and fragment shaders
        for shader in self.shaders:
            shader.activate()
            gl.glAttachShader(self._handle, shader.handle)

        # Only proceed if all shaders compiled ok
        oks = [shader._valid for shader in self.shaders]
        if not (oks and all(oks)):
            raise ProgramErrorr('Shaders did not compile.')

        # Link the program
        # todo: should there be a try-except around this?
        gl.glLinkProgram(self._handle)
        if not gl.glGetProgramiv(self._handle, gl.GL_LINK_STATUS):
            errors = gl.glGetProgramInfoLog(self._handle)
            print(errors)
            #parse_shader_errors(errors)
            raise ProgramError('Linking error')

        # Mark all active attributes and uniforms
        self._mark_active_attributes()
        self._mark_active_uniforms()