Exemplo n.º 1
0
def checkFramebufferStatus():
    """Utility method to check status and raise errors"""
    status = glCheckFramebufferStatus( GL_FRAMEBUFFER )
    if status == GL_FRAMEBUFFER_COMPLETE:
        return True 
    from OpenGL.error import GLError
    description = None
    for error_constant in [
        GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
        GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
        GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
        GL_FRAMEBUFFER_INCOMPLETE_FORMATS,
        GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER,
        GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER,
        GL_FRAMEBUFFER_UNSUPPORTED,
    ]:
        if status == error_constant:
            status = error_constant
            description = str(status)
    raise GLError( 
        err=status, 
        result=status, 
        baseOperation=glCheckFramebufferStatus, 
        description=description,
    )
Exemplo n.º 2
0
    def compile(self):
        """Compiles the shader using the current content
        value.

        Shaders are required to be compiled before a
        `py:class:pygly.shader.ShaderProgram` can be linked.

        This is not required to be performed in order to
        attach a Shader to a ShaderProgram. As long as the
        Shader is compiled prior to the ShaderProgram being
        linked.
        """
        self._handle = GL.glCreateShader(self.type)

        GL.glShaderSource(self.handle, self.source)

        # compile the shader
        try:
            GL.glCompileShader(self.handle)
        except GLError as e:
            self._print_shader_errors(e.description)
            raise

        # retrieve the compile status
        if not GL.glGetShaderiv(self.handle, GL.GL_COMPILE_STATUS):
            errors = GL.glGetShaderInfoLog(self.handle)
            self._print_shader_errors(errors)

            raise GLError(errors)
Exemplo n.º 3
0
    def link(self):
        """Links the specified shader into a complete program.

        It is important to set any attribute locations and
        the frag data location BEFORE calling link or these calls
        will not take effect.
        """
        # link the program
        try:
            GL.glLinkProgram(self.handle)
        except GLError as e:
            self._print_shader_errors(e.description)
            raise

        # retrieve the compile status
        if not GL.glGetProgramiv(self.handle, GL.GL_LINK_STATUS):
            errors = GL.glGetProgramInfoLog(self.handle)
            self._print_shader_errors(errors)

            raise GLError(errors)

        self.uniforms._on_program_linked()
        self.attributes._on_program_linked()