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
+28
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 void texture_view::bind(gl::command_context& cmd, GLuint layer) const
{ {
cmd->bind_texture(layer, m_target, m_id); cmd->bind_texture(layer, m_target, m_id);
+5
View File
@@ -355,6 +355,9 @@ namespace gl
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; texture_view() = default;
void create(texture* data, GLenum target, GLenum sized_format, const subresource_range& range, const GLenum* argb_swizzle = nullptr); void create(texture* data, GLenum target, GLenum sized_format, const subresource_range& range, const GLenum* argb_swizzle = nullptr);
@@ -395,6 +398,8 @@ namespace gl
virtual ~texture_view(); virtual ~texture_view();
texture_view* as(GLenum format);
GLuint id() const GLuint id() const
{ {
return m_id; return m_id;