gl: Add support for subviews

This commit is contained in:
kd-11 2026-02-22 20:26:26 +03:00 committed by kd-11
parent 07abde4e8d
commit 0f1735d0df
2 changed files with 34 additions and 1 deletions

View file

@ -318,6 +318,34 @@ namespace gl
}
}
texture_view* texture_view::as(GLenum format)
{
if (format == this->m_view_format)
{
return this;
}
auto self = m_root_view ? m_root_view : this;
if (auto found = self->m_subviews.find(format);
found != self->m_subviews.end())
{
return found->second.get();
}
GLenum swizzle_argb[4] =
{
component_swizzle[3],
component_swizzle[0],
component_swizzle[1],
component_swizzle[2],
};
auto view = std::make_unique<texture_view>(m_image_data, m_target, format, swizzle_argb, m_aspect_flags);
auto ret = view.get();
self->m_subviews.emplace(format, std::move(view));
return ret;
}
void texture_view::bind(gl::command_context& cmd, GLuint layer) const
{
cmd->bind_texture(layer, m_target, m_id);

View file

@ -353,7 +353,10 @@ namespace gl
GLenum m_aspect_flags = 0;
texture* m_image_data = nullptr;
GLenum component_swizzle[4] {};
GLenum component_swizzle[4]{};
std::unordered_map<GLenum, std::unique_ptr<texture_view>> m_subviews;
texture_view* m_root_view = nullptr;
texture_view() = default;
@ -395,6 +398,8 @@ namespace gl
virtual ~texture_view();
texture_view* as(GLenum format);
GLuint id() const
{
return m_id;