コード例 #1
0
 def init(self):
     self._build_kernel()
     self.program = self._build_shader()
     self.mesh = StridedVertexMesh(
         mesh3d_rectangle(),
         GL_TRIANGLES,
         attribute_locations=self.program.attributes)
     self.on_tick.once(self.sync_gpu)
コード例 #2
0
ファイル: grid.py プロジェクト: keksnicoh/gpupy
    def _init_plane(self):
        self.program = GridProgram()

        self.program.uniform_block_binding(
            'camera', GPUPY_GL.CONTEXT.buffer_base('gpupy.gl.camera'))
        self.upload_uniforms()

        self.mesh = StridedVertexMesh(
            mesh3d_rectangle(),
            GL_TRIANGLES,
            attribute_locations=self.program.attributes)
コード例 #3
0
    def _init_plane(self):
        self.program = _CameraProgram(_GLSL_VRT, _GLSL_FRG)
        self.texture.activate()

        self.program.uniform('frame_texture', self.texture)
        self.program.uniform_block_binding(
            'camera', GPUPY_GL.CONTEXT.buffer_base('gpupy.gl.camera'))

        self.program.uniform('size', self.plane_size.xy)
        self.program.uniform('mat_model', np.identity(4, dtype=np.float32))
        self.program.uniform('position', self.position.xyzw)
        self.program.uniform('rf', (self.resulution[0] / self._res[0],
                                    self.resulution[1] / self._res[1]))
        self.position.on_change.append(
            partial(self.program.uniform, 'position'))
        self.size.on_change.append(partial(self.program.uniform, 'size'))

        self.mesh = StridedVertexMesh(
            mesh3d_rectangle(),
            GL_TRIANGLES,
            attribute_locations=self.program.attributes)
コード例 #4
0
ファイル: texture_2d_random.py プロジェクト: keksnicoh/gpupy
    def init(self):
        # note that in Widget init the context should be active!
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        self.program = create_program(vertex=VERTEX_SHADER,
                                      fragment=FRAGMENT_SHADER,
                                      link=False)

        # the shader uses {% uniform block %} tags which we must
        # declare before linking the program
        self.program.declare_uniform('camera',
                                     Cartesian2D.DTYPE,
                                     variable='camera')
        self.program.link()

        # we need to tell the shader which is is buffer base.
        # the GPUPY_GL.CONTEXT.buffer_base returns a free buffer
        # base which is reserved for the active context.
        self.program.uniform_blocks['camera'] = GPUPY_GL.CONTEXT.buffer_base(
            'gpupy.gl.camera')

        # the mesh represents VAO and VBO
        self.mesh = StridedVertexMesh(
            mesh3d_rectangle(center=(-self.size[0] / 2, -self.size[1] / 2),
                             *self.size),
            GL_TRIANGLES,
            attribute_locations=self.program.attributes)

        # create texture and buffers
        self.texture = Texture2D.from_numpy(
            np.random.random((500, 500, 3)).astype(np.float32))
        self.texture.interpolation_linear()
        self.texture.activate(0)

        self.step = 1
        self.last_random = 1
コード例 #5
0
 def _init_mesh(self):
     self._rs_mesh = StridedVertexMesh(
         mesh3d_rectangle(),
         GL_TRIANGLES,
         attribute_locations=self._rs_prg.attributes)
コード例 #6
0
ファイル: dicom.py プロジェクト: keksnicoh/gpupy
    def init(self):

        glEnable(GL_BLEND)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glFrontFace(GL_CW)

        self._create_shader()

        rect_size = self.size
        rect_position = (-rect_size[0] / 2, -rect_size[1] / 2)
        self.cube_buffer = BufferObject.to_device(
            mesh3d_cube((200, 200, 200), center=True))
        self.vao = create_vao_from_program_buffer_object(
            self.program_box, self.cube_buffer)

        # create texture for front and backside
        #
        # since we'll use the same camera inside the framebuffer we have
        # to put the framebuffer size to the size of the main window framebuffer.
        # w
        # otherwise we could scale the camera to compensate the difference in window
        # size and framebuffer size.
        self.texture_front = Texture2D.empty((*CUBE_FRAMEBUFFER, 4),
                                             np.float32)
        self.framebuffer_front = Framebuffer()
        self.framebuffer_front.color_attachment(self.texture_front)
        self.texture_back = Texture2D.empty((*CUBE_FRAMEBUFFER, 4), np.float32)
        self.framebuffer_back = Framebuffer()
        self.framebuffer_back.color_attachment(self.texture_back)

        # create framebuffer screen (this is the widget main screen)
        rect_size = [2, 2]
        rect_position = (-rect_size[0] / 2, -rect_size[1] / 2)
        self.screen_buffer = BufferObject.to_device(
            mesh3d_rectangle(center=rect_position, *rect_size))
        self.screen_vao = create_vao_from_program_buffer_object(
            self.program_ray, self.screen_buffer)

        # create 3d texture
        self.texture = Texture3D.from_numpy(self.volumedata)
        self.texture.interpolation_nearest()
        self.texture.parameters.update({
            GL_TEXTURE_WRAP_S: GL_CLAMP_TO_BORDER,
            GL_TEXTURE_WRAP_T: GL_CLAMP_TO_BORDER,
            GL_TEXTURE_WRAP_R: GL_CLAMP_TO_BORDER
        })

        self.program_ray.uniform({
            'tex':
            self.texture_front.activate(0),
            'back':
            self.texture_back.activate(1),
            'vol':
            self.texture.activate(2),
            'v_ray':
            V_RAY,
            'v_iter':
            V_ITER,
            'mat_volume':
            np.array([0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1.0],
                     dtype=np.float32)
        })

        self.force_viewbox_render = True

        self.upload_mat_model()
        self.upload_mat_volume()