def compileFlat(self): if self.isCompiled(): return self.shader = gl.glCreateShaderObjectARB(self.shaderType()) if self.shader == 0: raise GLSLException('faled to create shader object') all_source = [b'\n'.join(self._source())] prog = (c_char_p * len(all_source))(*all_source) length = (c_int * len(all_source))(-1) gl.glShaderSourceARB(self.shader, len(all_source), cast(prog, POINTER(POINTER(c_char))), length) gl.glCompileShaderARB(self.shader) compile_status = c_int(0) gl.glGetObjectParameterivARB(self.shader, gl.GL_OBJECT_COMPILE_STATUS_ARB, byref(compile_status)) if not compile_status.value: err = glsl_log(self.shader) gl.glDeleteObjectARB(self.shader) self.shader = 0 raise GLSLException('failed to compile shader', err)
def __init__(self, src): sid = False try: sid = glCreateShaderObjectARB(self.shader_type) except GLException: pass if not sid: raise ShaderError("Can't create shader object!") l = GLsizei(len(src)) buf = create_string_buffer(src, len(src) + 10) pbuf = pointer(buf) glShaderSourceARB( sid, 1, cast(byref(pbuf), POINTER(POINTER(c_char))), byref(l) ) glCompileShader(sid) v = GLint() glGetShaderiv(sid, GL_COMPILE_STATUS, byref(v)) if not v: log = _get_infolog(sid) e = ShaderError("Error compiling shader!") e.infolog = log raise e self.sid = sid
def _compile(self): if self.shader: return if self.compiling: return self.compiling = True self.shader = gl.glCreateShaderObjectARB(self.shaderType()) if self.shader == 0: raise GLSLException('faled to create shader object') prog = c_char_p(self.prog) length = c_int(-1) gl.glShaderSourceARB(self.shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) gl.glCompileShaderARB(self.shader) self.compiling = False compile_status = c_int(0) gl.glGetObjectParameterivARB(self.shader, gl.GL_OBJECT_COMPILE_STATUS_ARB, byref(compile_status)) if not compile_status.value: err = glsl_log(self.shader) gl.glDeleteObjectARB(self.shader) self.shader = 0 raise GLSLException('failed to compile shader', err)
def __init__(self, src): sid = False try: sid = glCreateShaderObjectARB(self.shader_type) except GLException: pass if not sid: raise ShaderError("Can't create shader object!") l = GLsizei(len(src)) buf = create_string_buffer(src, len(src) + 10) pbuf = pointer(buf) glShaderSourceARB(sid, 1, cast(byref(pbuf), POINTER(POINTER(c_char))), byref(l)) glCompileShader(sid) v = GLint() glGetShaderiv(sid, GL_COMPILE_STATUS, byref(v)) if not v: log = _get_infolog(sid) e = ShaderError("Error compiling shader!") e.infolog = log raise e self.sid = sid
def compileShader( source, shaderType ): """Compile shader source of given type (only needed by compileProgram)""" shader = gl.glCreateShaderObjectARB(shaderType) #were we given a source string or a ShaderCode object? if hasattr(source, 'src'): source = source.src prog = c_char_p(source) length = c_int(-1) gl.glShaderSourceARB(shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) gl.glCompileShaderARB(shader) #check for errors status = c_int() gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS, byref(status)) if not status.value: # retrieve the log length gl.glGetShaderiv(shader, gl.GL_INFO_LOG_LENGTH, byref(status)) # create a buffer for the log buffer = create_string_buffer(status.value)#from ctypes # retrieve the log text gl.glGetProgramInfoLog(shader, status, None, buffer) # print the log to the console print buffer.value gl.glDeleteShader(shader) raise ValueError, 'Shader compilation failed' return shader
def compileShader(source, shaderType): """Compile shader source of given type (only needed by compileProgram)""" shader = gl.glCreateShaderObjectARB(shaderType) #were we given a source string or a ShaderCode object? if hasattr(source, 'src'): source = source.src prog = c_char_p(source) length = c_int(-1) gl.glShaderSourceARB(shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) gl.glCompileShaderARB(shader) #check for errors status = c_int() gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS, byref(status)) if not status.value: # retrieve the log length gl.glGetShaderiv(shader, gl.GL_INFO_LOG_LENGTH, byref(status)) # create a buffer for the log buffer = create_string_buffer(status.value) #from ctypes # retrieve the log text gl.glGetProgramInfoLog(shader, status, None, buffer) # print the log to the console print buffer.value gl.glDeleteShader(shader) raise ValueError, 'Shader compilation failed' return shader
def compileShader(source, shaderType): """Compile shader source of given type (only needed by compileProgram)""" shader = GL.glCreateShaderObjectARB(shaderType) prog = c_char_p(source) length = c_int(-1) GL.glShaderSourceARB(shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) GL.glCompileShaderARB(shader) #check for errors status = c_int() GL.glGetShaderiv(shader, GL.GL_COMPILE_STATUS, byref(status)) if not status.value: print_log(shader) GL.glDeleteShader(shader) raise ValueError, 'Shader compilation failed' return shader
def compileShader( source, shaderType ): """Compile shader source of given type (only needed by compileProgram)""" shader = GL.glCreateShaderObjectARB(shaderType) prog = c_char_p(source) length = c_int(-1) GL.glShaderSourceARB(shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) GL.glCompileShaderARB(shader) #check for errors status = c_int() GL.glGetShaderiv(shader, GL.GL_COMPILE_STATUS, byref(status)) if not status.value: print_log(shader) GL.glDeleteShader(shader) raise ValueError, 'Shader compilation failed' return shader
def compileShader(source, shaderType): """Compile shader source of given type (only needed by compileProgram) """ shader = GL.glCreateShaderObjectARB(shaderType) # if Py3 then we need to convert our (unicode) str into bytes for C if type(source) != bytes: source = source.encode() prog = c_char_p(source) length = c_int(-1) GL.glShaderSourceARB(shader, 1, cast(byref(prog), POINTER(POINTER(c_char))), byref(length)) GL.glCompileShaderARB(shader) # check for errors status = c_int() GL.glGetShaderiv(shader, GL.GL_COMPILE_STATUS, byref(status)) if not status.value: GL.glDeleteShader(shader) raise ValueError('Shader compilation failed') return shader