Esempio n. 1
0
        def setupFBOandTextures(self):
            self.framebufferA0 = (gl.GLuint * args["resolution"])()

            self.A0_tex = gl.GLuint(0)

            self.draw_buffersA0 = (gl.GLenum * args["resolution"])(
                gl.GL_COLOR_ATTACHMENT0)

            gl.glGenFramebuffers(args["resolution"], self.framebufferA0)

            gl.glGenTextures(1, ctypes.byref(self.A0_tex))

            #create textures
            #A
            gl.glActiveTexture(gl.GL_TEXTURE0)
            gl.glBindTexture(gl.GL_TEXTURE_3D, self.A0_tex)
            gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, args["resolution"],
                            args["resolution"], args["resolution"], 0,
                            gl.GL_RED, gl.GL_FLOAT, 0)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)

            #A
            for i in range(args["resolution"]):
                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferA0[i])
                gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER,
                                          gl.GL_COLOR_ATTACHMENT0,
                                          gl.GL_TEXTURE_3D, self.A0_tex, 0, i)
                assert (gl.glCheckFramebufferStatus(
                    gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE)
Esempio n. 2
0
def render_to_texture(in_size, out_size, view_z=None):
    z0, z1 = (0, in_size[2]) if view_z == None else view_z
    vertices = (VERTEX * 6)(((-1, -1), (0, 0)), ((1, -1), (1, 0)),
                            ((1, 1), (1, 1)), ((1, 1), (1, 1)),
                            ((-1, 1), (0, 1)), ((-1, -1), (0, 0)))
    gl.glBindTexture(gl.GL_TEXTURE_3D, rendered_texture)
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, framebuffer)
    draw_buffers = (gl.GLenum * 1)(gl.GL_COLOR_ATTACHMENT0)
    gl.glDrawBuffers(1, draw_buffers)
    gl.glViewport(0, 0, out_size[0], out_size[1])
    gl.glUseProgram(render_program)
    loc_depth = gl.glGetUniformLocation(render_program,
                                        ctypes.create_string_buffer(b'depth'))
    loc_texelSize = gl.glGetUniformLocation(
        render_program, ctypes.create_string_buffer(b'texelSize'))
    gl.glUniform3f(loc_texelSize, 1 / in_size[0], 1 / in_size[1],
                   1 / in_size[2])
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, render_vertexbuffer)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, ctypes.sizeof(vertices), vertices,
                    gl.GL_DYNAMIC_DRAW)
    gl.glBindVertexArray(render_vao)
    gl.glClearColor(0.0, 0.0, 0.0, 0.0)
    for z in range(out_size[2]):
        gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER, gl.GL_COLOR_ATTACHMENT0,
                                  gl.GL_TEXTURE_3D, rendered_texture, 0, z)
        fbs = gl.glCheckFramebufferStatus(gl.GL_FRAMEBUFFER)
        assert fbs == gl.GL_FRAMEBUFFER_COMPLETE, 'FramebufferStatus is {}'.format(
            fbs)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glUniform1f(loc_depth,
                       (z0 + z * (z1 - z0)) / in_size[2] / out_size[2])
        gl.glBindTexture(gl.GL_TEXTURE_3D, input_texture)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6)
        if z % 10 == 0:
            gl.glFinish()
            print('\033[K{}/{}'.format(z, out_size[2] - 1), end='\r')
    gl.glFinish()

    gl.glBindVertexArray(0)
Esempio n. 3
0
        def setupFBOandTextures(self):
            self.framebufferA0 = (gl.GLuint * self.dimz)()
            self.framebufferA1 = (gl.GLuint * self.dimz)()
            self.framebufferB0 = (gl.GLuint * self.dimz)()
            self.framebufferB1 = (gl.GLuint * self.dimz)()

            self.A0_tex = gl.GLuint(0)
            self.A1_tex = gl.GLuint(0)
            self.B0_tex = gl.GLuint(0)
            self.B1_tex = gl.GLuint(0)

            self.draw_buffersA0 = (gl.GLenum * self.dimz)(
                gl.GL_COLOR_ATTACHMENT0)
            self.draw_buffersA1 = (gl.GLenum * self.dimz)(
                gl.GL_COLOR_ATTACHMENT0)
            self.draw_buffersB0 = (gl.GLenum * self.dimz)(
                gl.GL_COLOR_ATTACHMENT0)
            self.draw_buffersB1 = (gl.GLenum * self.dimz)(
                gl.GL_COLOR_ATTACHMENT0)

            #gl.glGenFramebuffers(self.dimz, ctypes.byref(self.framebufferA0))
            #gl.glGenFramebuffers(self.dimz, ctypes.byref(self.framebufferA1))
            #gl.glGenFramebuffers(self.dimz, ctypes.byref(self.framebufferB0))
            #gl.glGenFramebuffers(self.dimz, ctypes.byref(self.framebufferB1))
            gl.glGenFramebuffers(self.dimz, self.framebufferA0)
            gl.glGenFramebuffers(self.dimz, self.framebufferA1)
            gl.glGenFramebuffers(self.dimz, self.framebufferB0)
            gl.glGenFramebuffers(self.dimz, self.framebufferB1)

            gl.glGenTextures(1, ctypes.byref(self.A0_tex))
            gl.glGenTextures(1, ctypes.byref(self.A1_tex))
            gl.glGenTextures(1, ctypes.byref(self.B0_tex))
            gl.glGenTextures(1, ctypes.byref(self.B1_tex))

            #create textures
            #A
            gl.glActiveTexture(gl.GL_TEXTURE0)
            gl.glBindTexture(gl.GL_TEXTURE_3D, self.A0_tex)
            gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, self.dimx,
                            self.dimy, self.dimz, 0, gl.GL_RED, gl.GL_FLOAT,
                            self.Ap)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)

            gl.glActiveTexture(gl.GL_TEXTURE1)
            gl.glBindTexture(gl.GL_TEXTURE_3D, self.A1_tex)
            gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, self.dimx,
                            self.dimy, self.dimz, 0, gl.GL_RED, gl.GL_FLOAT,
                            self.Ap)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)

            #B
            gl.glActiveTexture(gl.GL_TEXTURE2)
            gl.glBindTexture(gl.GL_TEXTURE_3D, self.B0_tex)
            gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, self.dimx,
                            self.dimy, self.dimz, 0, gl.GL_RED, gl.GL_FLOAT,
                            self.Bp)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)

            gl.glActiveTexture(gl.GL_TEXTURE3)
            gl.glBindTexture(gl.GL_TEXTURE_3D, self.B1_tex)
            gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, self.dimx,
                            self.dimy, self.dimz, 0, gl.GL_RED, gl.GL_FLOAT,
                            self.Bp)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MAG_FILTER,
                               gl.GL_LINEAR)
            gl.glTexParameteri(gl.GL_TEXTURE_3D, gl.GL_TEXTURE_MIN_FILTER,
                               gl.GL_LINEAR)

            #A
            for i in range(self.dimz):
                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferA0[i])
                gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER,
                                          gl.GL_COLOR_ATTACHMENT0,
                                          gl.GL_TEXTURE_3D, self.A0_tex, 0, i)
                assert (gl.glCheckFramebufferStatus(
                    gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE)

                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferA1[i])
                gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER,
                                          gl.GL_COLOR_ATTACHMENT0,
                                          gl.GL_TEXTURE_3D, self.A1_tex, 0, i)
                assert (gl.glCheckFramebufferStatus(
                    gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE)

                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferB0[i])
                gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER,
                                          gl.GL_COLOR_ATTACHMENT0,
                                          gl.GL_TEXTURE_3D, self.B0_tex, 0, i)
                assert (gl.glCheckFramebufferStatus(
                    gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE)

                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, self.framebufferB1[i])
                gl.glFramebufferTexture3D(gl.GL_FRAMEBUFFER,
                                          gl.GL_COLOR_ATTACHMENT0,
                                          gl.GL_TEXTURE_3D, self.B1_tex, 0, i)
                assert (gl.glCheckFramebufferStatus(
                    gl.GL_FRAMEBUFFER) == gl.GL_FRAMEBUFFER_COMPLETE)