Esempio n. 1
0
    def __init__(self, width, height):
        import ctypes

        self.freed = False
        self.is_bound = False

        self.width = width
        self.height = height

        self.fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_color = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_depth = bgl.Buffer(bgl.GL_INT, 1)

        self.cur_fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.cur_viewport = bgl.Buffer(bgl.GL_INT, 4)

        bgl.glGenRenderbuffers(1, self.buf_depth)
        bgl.glBindRenderbuffer(bgl.GL_RENDERBUFFER, self.buf_depth[0])
        bgl.glRenderbufferStorage(bgl.GL_RENDERBUFFER, bgl.GL_DEPTH_COMPONENT,
                                  width, height)

        bgl.glGenTextures(1, self.buf_color)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.buf_color[0])
        NULL = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int32 * 1).from_address(0))
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_R32UI, width, height, 0,
                         bgl.GL_RED_INTEGER, bgl.GL_UNSIGNED_INT, NULL)
        del NULL
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                            bgl.GL_NEAREST)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_NEAREST)

        bgl.glGetIntegerv(bgl.GL_FRAMEBUFFER_BINDING, self.cur_fbo)

        bgl.glGenFramebuffers(1, self.fbo)
        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.fbo[0])
        bgl.glFramebufferRenderbuffer(bgl.GL_FRAMEBUFFER,
                                      bgl.GL_DEPTH_ATTACHMENT,
                                      bgl.GL_RENDERBUFFER, self.buf_depth[0])
        bgl.glFramebufferTexture(bgl.GL_FRAMEBUFFER, bgl.GL_COLOR_ATTACHMENT0,
                                 self.buf_color[0], 0)

        bgl.glDrawBuffers(
            1, bgl.Buffer(bgl.GL_INT, 1, [bgl.GL_COLOR_ATTACHMENT0]))

        status = bgl.glCheckFramebufferStatus(bgl.GL_FRAMEBUFFER)
        if status != bgl.GL_FRAMEBUFFER_COMPLETE:
            print("Framebuffer Invalid", status)

        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.cur_fbo[0])
Esempio n. 2
0
File: zu.py Progetto: vktec/zu
    def genfb(self, width, height):
        buf = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGenFramebuffers(1, buf)
        self.fb = buf[0]
        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.fb)

        bgl.glGenTextures(1, buf)
        self.tex = buf[0]
        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.tex)
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA16F, width, height,
                         0, bgl.GL_RGBA, bgl.GL_FLOAT, None)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_NEAREST)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                            bgl.GL_NEAREST)
        bgl.glFramebufferTexture(bgl.GL_FRAMEBUFFER, bgl.GL_COLOR_ATTACHMENT0,
                                 self.tex, 0)

        bgl.glGenRenderbuffers(1, buf)
        self.depth = buf[0]
        bgl.glBindRenderbuffer(bgl.GL_RENDERBUFFER, self.depth)
        bgl.glRenderbufferStorage(bgl.GL_RENDERBUFFER, bgl.GL_DEPTH_COMPONENT,
                                  width, height)
        bgl.glFramebufferRenderbuffer(bgl.GL_FRAMEBUFFER,
                                      bgl.GL_DEPTH_ATTACHMENT,
                                      bgl.GL_RENDERBUFFER, self.depth)

        status = bgl.glCheckFramebufferStatus(bgl.GL_FRAMEBUFFER)
        if status == 0:
            glerr("Could not get framebuffer status")
        elif status != bgl.GL_FRAMEBUFFER_COMPLETE:
            msg = {
                bgl.GL_FRAMEBUFFER_UNDEFINED:
                "undefined",
                bgl.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
                "incomplete attachment",
                bgl.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
                "missing attachment",
                bgl.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
                "incomplete draw buffer",
                bgl.GL_FRAMEBUFFER_UNSUPPORTED:
                "unsupported",
                bgl.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
                "incomplete multisample",
                bgl.GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
                "incomplete layer targets",
            }.get(status, "unknown ({:x})".format(status))
            raise RuntimeError("Could not initialize GL framebuffer: " + msg)
Esempio n. 3
0
    def __init__(self, width, height):
        self.freed = False
        self.is_bound = False

        self.width = width
        self.height = height

        self.fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_color = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_depth = bgl.Buffer(bgl.GL_INT, 1)

        self.cur_fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.cur_viewport = bgl.Buffer(bgl.GL_INT, 4)

        bgl.glGenRenderbuffers(1, self.buf_depth)
        bgl.glGenTextures(1, self.buf_color)
        self._config_textures()

        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                            bgl.GL_NEAREST)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_NEAREST)

        bgl.glGetIntegerv(bgl.GL_FRAMEBUFFER_BINDING, self.cur_fbo)

        bgl.glGenFramebuffers(1, self.fbo)
        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.fbo[0])
        bgl.glFramebufferRenderbuffer(bgl.GL_FRAMEBUFFER,
                                      bgl.GL_DEPTH_ATTACHMENT,
                                      bgl.GL_RENDERBUFFER, self.buf_depth[0])

        bgl.glFramebufferTexture(bgl.GL_FRAMEBUFFER, bgl.GL_COLOR_ATTACHMENT0,
                                 self.buf_color[0], 0)

        bgl.glDrawBuffers(
            1, bgl.Buffer(bgl.GL_INT, 1, [bgl.GL_COLOR_ATTACHMENT0]))

        status = bgl.glCheckFramebufferStatus(bgl.GL_FRAMEBUFFER)
        if status != bgl.GL_FRAMEBUFFER_COMPLETE:
            print("Framebuffer Invalid", status)

        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.cur_fbo[0])
Esempio n. 4
0
    def __init__(self, width, height):
        self.freed = False
        self.is_bound = False

        self.width = width
        self.height = height

        self.fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_color = bgl.Buffer(bgl.GL_INT, 1)
        self.buf_depth = bgl.Buffer(bgl.GL_INT, 1)

        self.cur_fbo = bgl.Buffer(bgl.GL_INT, 1)
        self.cur_viewport = bgl.Buffer(bgl.GL_INT, 4)

        bgl.glGenRenderbuffers(1, self.buf_depth)
        bgl.glGenTextures(1, self.buf_color)

        self._config_textures()

        bgl.glGetIntegerv(bgl.GL_FRAMEBUFFER_BINDING, self.cur_fbo)

        bgl.glGenFramebuffers(1, self.fbo)
        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.fbo[0])

        bgl.glFramebufferRenderbuffer(
                bgl.GL_FRAMEBUFFER, bgl.GL_DEPTH_ATTACHMENT,
                bgl.GL_RENDERBUFFER, self.buf_depth[0])

        bgl.glFramebufferTexture(bgl.GL_FRAMEBUFFER, bgl.GL_COLOR_ATTACHMENT0, self.buf_color[0], 0)

        bgl.glDrawBuffers(1, bgl.Buffer(bgl.GL_INT, 1, [bgl.GL_COLOR_ATTACHMENT0]))

        status = bgl.glCheckFramebufferStatus(bgl.GL_FRAMEBUFFER)
        if status != bgl.GL_FRAMEBUFFER_COMPLETE:
            print("Framebuffer Invalid", status)

        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, self.cur_fbo[0])