Skip to content

Commit

Permalink
[gpu] added a way to retrieve image width/height, it also works on wi…
Browse files Browse the repository at this point in the history
…ndow_resource (gets window dimensions)
  • Loading branch information
harrand committed Nov 1, 2024
1 parent 26a4c0e commit 6950328
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/tz/gpu/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ namespace tz::gpu
*/
tz::error_code resource_write(resource_handle res, std::span<const std::byte> new_data, std::size_t offset = 0);
std::size_t resource_size(resource_handle res);
unsigned int image_get_width(resource_handle res);
unsigned int image_get_height(resource_handle res);
/**
* @ingroup tz_gpu_resource
* @brief Retrieves the current data within a resource.
Expand Down
1 change: 1 addition & 0 deletions include/tz/ren/quad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace tz::ren
{
tz::v4f clear_colour = {0.0f, 0.0f, 0.0f, 1.0f};
quad_renderer_flag flags = static_cast<quad_renderer_flag>(0);
tz::gpu::resource_handle colour_target = tz::gpu::window_resource;
};

std::expected<quad_renderer_handle, tz::error_code> create_quad_renderer(quad_renderer_info info);
Expand Down
36 changes: 36 additions & 0 deletions src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,42 @@ namespace tz::gpu
return resources[resh.peek()].data.size();
}

unsigned int image_get_width(resource_handle res)
{
if(res == tz::nullhand)
{
return 0u;
}
if(res == tz::gpu::window_resource)
{
return swapchain_width;
}
const auto& resource = resources[res.peek()];
if(!resource.is_image())
{
return 0u;
}
return std::get<image_info>(resource.res).width;
}

unsigned int image_get_height(resource_handle res)
{
if(res == tz::nullhand)
{
return 0u;
}
if(res == tz::gpu::window_resource)
{
return swapchain_height;
}
const auto& resource = resources[res.peek()];
if(!resource.is_image())
{
return 0u;
}
return std::get<image_info>(resource.res).height;
}

std::span<const std::byte> resource_read(resource_handle resh)
{
auto& res = resources[resh.peek()];
Expand Down
6 changes: 3 additions & 3 deletions src/tz/ren/quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace tz::ren

tz::gpu::resource_handle colour_targets[] =
{
tz::gpu::window_resource
info.colour_target
};
tz::gpu::resource_handle resources[] =
{
Expand Down Expand Up @@ -253,8 +253,8 @@ namespace tz::ren
{
auto& ren = renderers[renh.peek()];

auto w = tz::os::window_get_width();
auto h = tz::os::window_get_height();
auto w = tz::gpu::image_get_width(ren.info.colour_target);
auto h = tz::gpu::image_get_height(ren.info.colour_target);
if((w != 0 && h != 0) && (ren.window_width_cache != w || ren.window_height_cache != h))
{
// window has resized
Expand Down

0 comments on commit 6950328

Please sign in to comment.