gl: Add support for subviews
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -353,7 +353,10 @@ namespace gl
|
|||||||
GLenum m_aspect_flags = 0;
|
GLenum m_aspect_flags = 0;
|
||||||
texture* m_image_data = nullptr;
|
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;
|
texture_view() = default;
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user