Skip to content

Commit

Permalink
[ren.quad] very basic quad rendering now has proof-of-concept
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Oct 31, 2024
1 parent cde3c2d commit 97fb355
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/tz/ren/quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ namespace tz::ren
tz::gpu::resource_handle data_buffer = tz::nullhand;
tz::gpu::pass_handle main_pass = tz::nullhand;
tz::gpu::graph_handle graph = tz::nullhand;
std::size_t quad_count = 0;
};

struct quad_data
{

tz::v4f pos_scale = {0.0f, 0.0f, 1.0f, 1.0f};
};

constexpr std::size_t initial_quad_capacity = 1024;
Expand Down Expand Up @@ -93,9 +94,15 @@ namespace tz::ren

std::expected<quad_handle, tz::error_code> quad_renderer_create_quad(quad_renderer_handle renh, quad_info info)
{
(void)renh;
quad_data new_data;
new_data.pos_scale = {0.0f, 0.0f, 0.25f, 0.25f};
(void)info;
UNERR(tz::error_code::engine_bug, "create quad is NYI");

auto& ren = renderers[renh.peek()];
tz::gpu::pass_set_triangle_count(ren.main_pass, (ren.quad_count + 1) * 2);
tz_must(tz::gpu::resource_write(ren.data_buffer, std::as_bytes(std::span<const quad_data>(&new_data, 1)), sizeof(quad_data) * ren.quad_count));

return static_cast<tz::hanval>(ren.quad_count++);
}

tz::gpu::graph_handle quad_renderer_graph(quad_renderer_handle renh)
Expand Down
4 changes: 3 additions & 1 deletion src/tz/ren/quad.fragment.tzsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
shader(type = fragment);

output(id = 0) vec4 colour;

void main()
{

colour = vec4(1.0f, 0.0f, 1.0f, 1.0f);
}
28 changes: 27 additions & 1 deletion src/tz/ren/quad.vertex.tzsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
shader(type = vertex);

struct quad_data
{
vec4 pos_scale;
};

resource(id = 0) const buffer quad
{
quad_data data[];
};

vec2 quad_positions[6] = vec2[](
vec2(1.0, -1.0), vec2(1.0, 1.0), vec2(-1.0, -1.0),
vec2(1.0, 1.0), vec2(-1.0, 1.0), vec2(-1.0, -1.0)
);

vec2 quad_texcoords[6] = vec2[](
vec2(1.0, 1.0), vec2(1.0, 0.0), vec2(0.0, 1.0),
vec2(1.0, 0.0), vec2(0.0, 0.0), vec2(0.0, 1.0)
);

void main()
{

const uint quad_id = in::vertex_id / 6;
vec2 local_pos = quad_positions[in::vertex_id % 6];
quad_data cur_quad = quad.data[quad_id];

vec2 position_worldspace = cur_quad.pos_scale.xy + (local_pos * cur_quad.pos_scale.zw);

out::position = vec4(position_worldspace, 0, 1);
}
3 changes: 3 additions & 0 deletions test/tz/ren_quad_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ int main()

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


tz::ren::quad_handle quad1 = tz_must(tz::ren::quad_renderer_create_quad(ren, {}));

while(tz::os::window_is_open())
{
tz::os::window_update();
Expand Down

0 comments on commit 97fb355

Please sign in to comment.