Пример #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)
Пример #2
0
def attach_input(in_data, in_size):
    # Load input
    gl.glBindTexture(gl.GL_TEXTURE_3D, input_texture)
    glTypeFromNp = {
        np.dtype('uint8'): gl.GL_UNSIGNED_BYTE,
        np.dtype('uint16'): gl.GL_UNSIGNED_SHORT,
        np.dtype('uint32'): gl.GL_UNSIGNED_INT,
        np.dtype('float32'): gl.GL_FLOAT
    }
    gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
    gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, in_size[0], in_size[1],
                    in_size[2], 0, gl.GL_RED, glTypeFromNp[in_data.dtype],
                    ctypes.c_void_p(in_data.ctypes.data))
	def __init__(self, texture_width, texture_height, max_textures):
		self.texture_width = texture_width
		self.texture_height = texture_height

		self.max_textures = max_textures

		self.textures = [] # an array to keep track of the textures we've already added

		self.texture_array = gl.GLuint(0) # create our texture array
		gl.glGenTextures(1, self.texture_array)
		gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.texture_array)

		gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) # disable texture filtering for magnification (return the texel that's nearest to the fragment's texture coordinate)

		gl.glTexImage3D( # set the dimensions of our texture array
			gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA,
			self.texture_width, self.texture_height, self.max_textures,
			0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None)
	def __init__(self, texture_width, texture_height, max_textures):
		self.texture_width = texture_width
		self.texture_height = texture_height

		self.max_textures = max_textures

		self.textures = []

		self.texture_array = gl.GLuint(0)
		gl.glGenTextures(1, self.texture_array)
		gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.texture_array)

		gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, options.MIPMAP_TYPE)
		gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)

		gl.glTexImage3D(
			gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA,
			self.texture_width, self.texture_height, self.max_textures,
			0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, None)
Пример #5
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)
Пример #6
0
def attach_output(out_size):
    # Clear output
    gl.glBindTexture(gl.GL_TEXTURE_3D, rendered_texture)
    gl.glTexImage3D(gl.GL_TEXTURE_3D, 0, gl.GL_RED, out_size[0], out_size[1],
                    out_size[2], 0, gl.GL_RED, gl.GL_UNSIGNED_INT, 0)