Пример #1
0
    def init(self, platform_data):
        self.init_conf.platform_data = platform_data
        bgfx.render_frame()
        bgfx.init(self.init_conf)
        bgfx.reset(
            self.width,
            self.height,
            BGFX_RESET_VSYNC,
            self.init_conf.resolution.format,
        )

        bgfx.set_debug(BGFX_DEBUG_TEXT)
        bgfx.set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF,
                            1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(
            bgfx.Attrib.POSITION, 3,
            bgfx.AttribType.FLOAT).add(bgfx.Attrib.COLOR0, 4,
                                       bgfx.AttribType.UINT8,
                                       True).add(bgfx.Attrib.TEXCOORD0, 2,
                                                 bgfx.AttribType.FLOAT).end()

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices),
                              sizeof(PosColorTexVertex) * num_vertices)
        self.vertex_buffer = bgfx.create_vertex_buffer(vb_memory,
                                                       self.vertex_layout)

        # Create index buffer
        ib_memory = bgfx.copy(as_void_ptr(cube_indices), cube_indices.nbytes)
        self.index_buffer = bgfx.create_index_buffer(ib_memory)

        # Create texture uniform
        self.texture_uniform = bgfx.create_uniform("s_tex",
                                                   bgfx.UniformType.SAMPLER)

        # Load the image using PIL and make the texture
        logo = Image.open(
            Path(__file__).parent.parent / "assets" / "textures" /
            "python_logo.png")
        logo_memory = bgfx.copy(as_void_ptr(logo.tobytes()),
                                len(logo.tobytes()))
        self.logo_texture = bgfx.create_texture2d(logo.width, logo.height,
                                                  False, 1,
                                                  bgfx.TextureFormat.RGBA8,
                                                  BGFX_TEXTURE_RT, logo_memory)

        # Create program from shaders.
        self.main_program = bgfx.create_program(
            load_shader("textures.VertexShader.vert",
                        ShaderType.VERTEX,
                        root_path=root_path),
            load_shader("textures.FragmentShader.frag",
                        ShaderType.FRAGMENT,
                        root_path=root_path),
            True,
        )

        ImGuiExtra.imgui_create()
Пример #2
0
    def init(self, platform_data):
        self.init_conf.platform_data = platform_data
        bgfx.render_frame()
        bgfx.init(self.init_conf)
        bgfx.reset(
            self.width,
            self.height,
            BGFX_RESET_VSYNC,
            self.init_conf.resolution.format,
        )

        bgfx.set_debug(BGFX_DEBUG_TEXT)
        bgfx.set_view_clear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF,
                            1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(bgfx.Attrib.POSITION, 3,
                                       bgfx.AttribType.FLOAT).add(
                                           bgfx.Attrib.COLOR0, 4,
                                           bgfx.AttribType.UINT8, True).end()

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices),
                              sizeof(PosColorVertex) * num_vertices)
        self.vertex_buffer = bgfx.create_vertex_buffer(vb_memory,
                                                       self.vertex_layout)

        self.index_buffers = []

        for i in range(0, len(primitives)):
            ib_memory = bgfx.copy(as_void_ptr(primitives[i]),
                                  primitives[i].nbytes)
            self.index_buffers.append(bgfx.create_index_buffer(ib_memory))

        # Create program from shaders.
        self.main_program = bgfx.create_program(
            load_shader("cubes.VertexShader.vert",
                        ShaderType.VERTEX,
                        root_path=root_path),
            load_shader("cubes.FragmentShader.frag",
                        ShaderType.FRAGMENT,
                        root_path=root_path),
            True,
        )

        ImGuiExtra.imgui_create()
Пример #3
0
    def init(self, platform_data):
        self.init_conf.platformData = platform_data

        bgfx.init(self.init_conf)
        bgfx.reset(
            self.fb_width,
            self.fb_height,
            BGFX_RESET_VSYNC | BGFX_RESET_HIDPI,
            self.init_conf.resolution.format,
        )

        bgfx.setDebug(BGFX_DEBUG_TEXT)
        bgfx.setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0, 0)

        self.vertex_layout = bgfx.VertexLayout()
        self.vertex_layout.begin().add(
            bgfx.Attrib.Position, 3, bgfx.AttribType.Float
        ).add(bgfx.Attrib.TexCoord0, 3, bgfx.AttribType.Float).end()

        self.fluid_simulator = FluidSimulator(
            self.width // 2, self.height // 2, self.vertex_layout
        )
        self.fluid_simulator.vorticity = 1.0
        self.fluid_simulator.viscosity = 0.0
        self.fluid_simulator.iterations = 100

        self.particle_area = SmoothParticlesArea(
            self.fb_width, self.fb_height, self.fluid_simulator, self.vertex_layout
        )
        self.particle_area.dissipation = 0.980

        # Create static vertex buffer
        vb_memory = bgfx.copy(as_void_ptr(cube_vertices), sizeof(PosColorVertex) * 4)
        self.vertex_buffer = bgfx.createVertexBuffer(vb_memory, self.vertex_layout)

        ib_memory = bgfx.copy(as_void_ptr(cube_indices), cube_indices.nbytes)
        self.index_buffer = bgfx.createIndexBuffer(ib_memory)

        self.output_texture = bgfx.createTexture2D(
            self.fb_width,
            self.fb_height,
            False,
            1,
            bgfx.TextureFormat.RGBA8,
            BGFX_TEXTURE_COMPUTE_WRITE,
        )

        self.texture_uniform = bgfx.createUniform(
            "InputTexture", bgfx.UniformType.Sampler
        )

        # Create program from shaders.
        self.main_program = bgfx.createProgram(
            load_shader(
                "demo.VertexShader.vert", ShaderType.VERTEX, root_path=root_path
            ),
            load_shader(
                "demo.FragmentShader.frag", ShaderType.FRAGMENT, root_path=root_path
            ),
            True,
        )
        self.cs_program = bgfx.createProgram(
            load_shader(
                "demo.ComputeShader.comp", ShaderType.COMPUTE, root_path=root_path
            ),
            True,
        )

        ImGuiExtra.imguiCreate(36.0)