shader.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:pycraft 作者: traverseda 项目源码 文件源码
def create_shader(self, strings, shader_type):
        count = len(strings)
        # if we have no source code, ignore this shader
        if count < 1:
            return

        # create the shader handle
        shader = glCreateShader(shader_type)

        shaderstrings = []
        for string in strings:
            shaderstrings.append(bytes(string, 'ascii'))

        # convert the source strings into a ctypes pointer-to-char array, and
        # upload them this is deep, dark, dangerous black magic - don't try
        # stuff like this at home!
        src = (c_char_p * count)(*shaderstrings)

        glShaderSource(shader, count, cast(
            pointer(src), POINTER(POINTER(c_char))), None)

        # compile the shader
        glCompileShader(shader)

        temp = c_int(0)
        # retrieve the compile status
        glGetShaderiv(shader, GL_COMPILE_STATUS, byref(temp))

        # if compilation failed, print the log
        if not temp:
            # retrieve the log length
            glGetShaderiv(shader, GL_INFO_LOG_LENGTH, byref(temp))
            # create a buffer for the log
            buffer = create_string_buffer(temp.value)
            # retrieve the log text
            glGetShaderInfoLog(shader, temp, None, buffer)
            # print the log to the console
            print(buffer.value)
        else:
            # all is well, so attach the shader to the program
            glAttachShader(self.handle, shader)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号