Skip to content

Commit

Permalink
[ren] added beginning of impl of quad renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Oct 30, 2024
1 parent e208a6d commit 46a2b9e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ topaz_add_library(
src/tz/gpu/rhi_vulkan.cpp
src/tz/os/impl_win32.cpp
src/tz/io/image.cpp
src/tz/ren/quad.cpp
SHADERS
src/tz/ren/quad.vertex.tzsl
src/tz/ren/quad.fragment.tzsl
DEFINE_PACKAGE
)

Expand Down
33 changes: 33 additions & 0 deletions include/tz/ren/quad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef TOPAZ_REN_QUAD_HPP
#define TOPAZ_REN_QUAD_HPP
#include "tz/core/handle.hpp"
#include "tz/gpu/graph.hpp"

namespace tz::ren
{
namespace detail
{
struct quad_t{};
struct quadren_t{};
}
using quad_handle = tz::handle<detail::quad_t>;
using quad_renderer_handle = tz::handle<detail::quadren_t>;

struct quad_renderer_info
{

};

std::expected<quad_renderer_handle, tz::error_code> create_quad_renderer(quad_renderer_info info);
tz::error_code destroy_quad_renderer(quad_renderer_handle renh);

struct quad_info
{

};
std::expected<quad_handle, tz::error_code> quad_renderer_create_quad(quad_renderer_handle renh, quad_info info);

tz::gpu::graph_handle quad_renderer_graph(quad_renderer_handle renh);
}

#endif // TOPAZ_REN_QUAD_HPP
52 changes: 52 additions & 0 deletions src/tz/ren/quad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "tz/ren/quad.hpp"
#include "tz/topaz.hpp"
#include "tz/gpu/resource.hpp"
#include "tz/gpu/pass.hpp"
#include "tz/gpu/graph.hpp"
#include "tz/gpu/shader.hpp"

#include ImportedShaderHeader(quad, vertex)
#include ImportedShaderHeader(quad, fragment)

namespace tz::ren
{
struct quad_renderer_data
{
quad_renderer_info info = {};
tz::gpu::resource_handle data_buffer = tz::nullhand;
tz::gpu::pass_handle main_pass = tz::nullhand;
tz::gpu::graph_handle graph = tz::nullhand;
};

std::vector<quad_renderer_data> renderers;

std::expected<quad_renderer_handle, tz::error_code> create_quad_renderer(quad_renderer_info info)
{
std::size_t id = renderers.size();
auto& ren = renderers.emplace_back();
ren.info = info;

return static_cast<tz::hanval>(id);
}

tz::error_code destroy_quad_renderer(quad_renderer_handle renh)
{
auto& ren = renderers[renh.peek()];
tz::gpu::destroy_pass(ren.main_pass);
auto ret = tz::gpu::destroy_resource(ren.data_buffer);
ren = {};
return ret;
}

std::expected<quad_handle, tz::error_code> quad_renderer_create_quad(quad_renderer_handle renh, quad_info info)
{
(void)renh;
(void)info;
UNERR(tz::error_code::engine_bug, "create quad is NYI");
}

tz::gpu::graph_handle quad_renderer_graph(quad_renderer_handle renh)
{
return renderers[renh.peek()].graph;
}
}
6 changes: 6 additions & 0 deletions src/tz/ren/quad.fragment.tzsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
shader(type = fragment);

void main()
{

}
6 changes: 6 additions & 0 deletions src/tz/ren/quad.vertex.tzsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
shader(type = vertex);

void main()
{

}
6 changes: 6 additions & 0 deletions test/tz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ topaz_add_test(
SHADERS
test/tz/shaders/triangle.vertex.tzsl
test/tz/shaders/triangle.fragment.tzsl
)

topaz_add_test(
TARGET tz_ren_quad_test
SOURCES
ren_quad_test.cpp
)
24 changes: 24 additions & 0 deletions test/tz/ren_quad_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "tz/topaz.hpp"
#include "tz/ren/quad.hpp"
#include "tz/os/window.hpp"
#include "tz/gpu/hardware.hpp"

int main()
{
tz::initialise();
tz::os::open_window({});

tz::gpu::hardware gpu = tz::gpu::find_best_hardware();
tz_must(tz::gpu::use_hardware(gpu));

tz::ren::quad_renderer_handle ren = tz_must(tz::ren::create_quad_renderer({}));

//tz_must(tz::ren::destroy_quad_renderer(ren));
while(tz::os::window_is_open())
{
tz::os::window_update();
tz::gpu::execute(tz::ren::quad_renderer_graph(ren));
}

tz::terminate();
}

0 comments on commit 46a2b9e

Please sign in to comment.