Skip to content

Commit

Permalink
* OGL side support for the resource access rework (entirely forgot ab…
Browse files Browse the repository at this point in the history
…out it LMAO)
  • Loading branch information
harrand committed Jun 22, 2023
1 parent e95eab5 commit 6f53ab5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
22 changes: 15 additions & 7 deletions src/tz/gl/impl/opengl/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ namespace tz::gl

void buffer_component_ogl::resize(std::size_t sz)
{
tz::assert(this->resource->get_access() == resource_access::dynamic_variable, "Requested to resize a buffer_component_ogl, but the underlying resource was not resource_access::dynamic_variable. Please submit a bug report.");
ogl2::buffer& old_buffer = this->ogl_get_buffer();
ogl2::buffer new_buffer = ogl2::buffer_helper::clone_resized(old_buffer, sz);
// Just set the new buffer range, clone resized already sorts out the data for us.
this->resource->set_mapped_data(new_buffer.map_as<std::byte>());
if(this->resource->get_access() == tz::gl::resource_access::dynamic_access)
{
this->resource->set_mapped_data(new_buffer.map_as<std::byte>());
}
else
{
auto old_data = this->resource->data();
std::size_t copy_length = std::min(old_data.size_bytes(), sz);
std::vector<std::byte> new_data;
new_data.resize(sz);
std::copy(old_data.begin(), old_data.begin() + copy_length, new_data.begin());
this->resource->set_mapped_data(new_data);
}
std::swap(old_buffer, new_buffer);
}

Expand All @@ -54,12 +65,10 @@ namespace tz::gl
default:
tz::error("Unknown resource_access. Please submit a bug report.");
[[fallthrough]];
case resource_access::static_fixed:
case resource_access::static_access:
residency = ogl2::buffer_residency::static_fixed;
break;
case resource_access::dynamic_fixed:
[[fallthrough]];
case resource_access::dynamic_variable:
case resource_access::dynamic_access:
residency = ogl2::buffer_residency::dynamic;
break;
}
Expand Down Expand Up @@ -98,7 +107,6 @@ namespace tz::gl

void image_component_ogl::resize(tz::vec2ui dims)
{
tz::assert(this->resource->get_access() == resource_access::dynamic_variable, "Requested resize of image_component_ogl, but the underlying resource did not have resource_access::dynamic_variable. Please submit a bug report.");
ogl2::image& old_image = this->ogl_get_image();
ogl2::image new_image = ogl2::image_helper::clone_resized(old_image, dims);

Expand Down
15 changes: 8 additions & 7 deletions src/tz/gl/impl/opengl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace tz::gl
tz::assert(res != nullptr, "buffer_component had null resource");
switch(res->get_access())
{
case resource_access::static_fixed:
case resource_access::static_access:
{
// Create a staging buffer, write the resource data into it, and then do a buffer copy to the component.
ogl2::buffer_target tar = ogl2::buffer_target::shader_storage;
Expand All @@ -43,9 +43,7 @@ namespace tz::gl
ogl2::buffer_helper::copy(staging_buffer, buffer);
}
break;
case resource_access::dynamic_fixed:
[[fallthrough]];
case resource_access::dynamic_variable:
case resource_access::dynamic_access:
{
// Map component buffer and write resource data directly into it, then pass the mapped ptr back into the resource to set it as the new data source.
auto resdata = res->data();
Expand Down Expand Up @@ -262,7 +260,7 @@ namespace tz::gl
for(auto& component_ptr : this->components)
{
tz::gl::iresource* res = component_ptr->get_resource();
if(res->get_type() == resource_type::image && res->get_access() != resource_access::static_fixed)
if(res->get_type() == resource_type::image && res->get_access() != resource_access::static_access)
{
// Get the underlying image, and set its data to whatever the span said it was.
ogl2::image& img = static_cast<image_component_ogl*>(component_ptr.get())->ogl_get_image();
Expand Down Expand Up @@ -725,7 +723,10 @@ namespace tz::gl
iresource* res = comp->get_resource();
switch(res->get_access())
{
case resource_access::static_fixed:
default:
tz::error("Unrecognised resource access");
[[fallthrough]];
case resource_access::static_access:
switch(res->get_type())
{
case resource_type::buffer:
Expand Down Expand Up @@ -759,7 +760,7 @@ namespace tz::gl
break;
}
break;
default:
case resource_access::dynamic_access:
tz::report("Received component write edit request for resource handle %zu, which is being carried out, but is unnecessary because the resource has dynamic access, meaning you can just mutate data().", static_cast<std::size_t>(static_cast<tz::hanval>(arg.resource)));
std::span<std::byte> data = res->data_as<std::byte>();
std::copy(arg.data.begin(), arg.data.end(), data.begin() + arg.offset);
Expand Down

0 comments on commit 6f53ab5

Please sign in to comment.