Route retained draw state through GL dispatch

This commit is contained in:
2026-06-04 23:50:50 +02:00
parent 111cc8c892
commit 3cd1d46025
6 changed files with 92 additions and 29 deletions

View File

@@ -184,6 +184,11 @@ void disable_opengl_state(std::uint32_t state) noexcept
glDisable(static_cast<GLenum>(state));
}
std::uint8_t query_opengl_capability(std::uint32_t state) noexcept
{
return static_cast<std::uint8_t>(glIsEnabled(static_cast<GLenum>(state)));
}
void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept
{
glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
@@ -297,6 +302,19 @@ void apply_canvas_capability(std::uint32_t state, bool enabled)
LOG("Canvas capability dispatch failed because: %s", status.message);
}
bool query_canvas_capability(std::uint32_t state)
{
const auto result = pp::renderer::gl::query_opengl_capability_state(
state,
pp::renderer::gl::OpenGlCapabilityStateQueryDispatch {
.is_enabled = query_opengl_capability,
});
if (!result.ok()) {
LOG("Canvas capability query dispatch failed because: %s", result.status().message);
}
return result.value();
}
void gen_opengl_renderbuffers(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenRenderbuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
@@ -1121,7 +1139,7 @@ void Canvas::stroke_commit()
// save viewport and clear color states
const auto vp = query_canvas_viewport();
const auto cc = query_canvas_clear_color();
auto blend = glIsEnabled(blend_state());
auto blend = query_canvas_capability(blend_state());
// allocate action to add to history
auto action = new ActionStroke;
@@ -2992,7 +3010,7 @@ Image Canvas::thumbnail_generate(int w, int h)
// save viewport and clear color states
const auto vp = query_canvas_viewport();
const auto cc = query_canvas_clear_color();
auto blend = glIsEnabled(blend_state());
auto blend = query_canvas_capability(blend_state());
// prepare common states
apply_canvas_viewport(0, 0, w, h);
@@ -3125,7 +3143,7 @@ void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, con
// save viewport and clear color states
const auto vp = query_canvas_viewport();
const auto cc = query_canvas_clear_color();
auto blend = glIsEnabled(blend_state());
auto blend = query_canvas_capability(blend_state());
// prepare common states
apply_canvas_viewport(0, 0, layer.w, layer.h);
@@ -3166,7 +3184,7 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
// save viewport and clear color states
const auto vp = query_canvas_viewport();
const auto cc = query_canvas_clear_color();
auto blend = glIsEnabled(blend_state());
auto blend = query_canvas_capability(blend_state());
// prepare common states
apply_canvas_viewport(0, 0, layer.w, layer.h);

View File

@@ -32,6 +32,11 @@ void set_opengl_active_texture(std::uint32_t texture_unit) noexcept
glActiveTexture(static_cast<GLenum>(texture_unit));
}
void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept
{
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
}
void set_opengl_clear_color(float r, float g, float b, float a) noexcept
{
glClearColor(r, g, b, a);
@@ -108,6 +113,17 @@ void set_layer_active_texture_unit(std::uint32_t unit_index)
LOG("Layer active texture dispatch failed because: %s", status.message);
}
void bind_layer_texture_cube(std::uint32_t texture_id)
{
const auto status = pp::renderer::gl::bind_opengl_texture_cube(
texture_id,
pp::renderer::gl::OpenGlTexture2DBindDispatch {
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("Layer cube texture bind dispatch failed because: %s", status.message);
}
void copy_layer_framebuffer_to_texture(
std::uint32_t texture_target,
std::int32_t destination_x,
@@ -248,7 +264,7 @@ Texture2D Layer::gen_equirect(glm::ivec2 size /*= { 0, 0 }*/)
apply_layer_viewport(0, 0, latlong.getWidth(), latlong.getHeight());
set_layer_active_texture_unit(0U);
glBindTexture(pp::renderer::gl::texture_cube_map_target(), cube.m_cubetex_id);
bind_layer_texture_cube(cube.m_cubetex_id);
ShaderManager::use(kShader::Equirect);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
@@ -290,7 +306,7 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
apply_layer_viewport(0, 0, latlong.getWidth(), latlong.getHeight());
set_layer_active_texture_unit(0U);
glBindTexture(pp::renderer::gl::texture_cube_map_target(), cube.m_cubetex_id);
bind_layer_texture_cube(cube.m_cubetex_id);
ShaderManager::use(kShader::Equirect);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));

View File

@@ -23,11 +23,6 @@ namespace {
return static_cast<GLint>(pp::renderer::gl::texture_format_for_channel_count(1U).pixel_format);
}
[[nodiscard]] GLenum texture_unit(std::uint32_t unit_index) noexcept
{
return static_cast<GLenum>(pp::renderer::gl::active_texture_unit(unit_index));
}
void gen_buffers_adapter(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenBuffers(static_cast<GLsizei>(count), ids);
@@ -97,6 +92,22 @@ void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t co
glDrawArrays(static_cast<GLenum>(mode), static_cast<GLint>(first), static_cast<GLsizei>(count));
}
void activate_texture_adapter(std::uint32_t texture_unit) noexcept
{
glActiveTexture(static_cast<GLenum>(texture_unit));
}
void activate_text_texture_unit(std::uint32_t unit_index)
{
const auto status = pp::renderer::gl::activate_opengl_texture_unit(
unit_index,
pp::renderer::gl::OpenGlActiveTextureDispatch {
.active_texture = activate_texture_adapter,
});
if (!status.ok())
LOG("Text active texture dispatch failed because: %s", status.message);
}
[[nodiscard]] std::span<const pp::renderer::gl::OpenGlVertexAttribute> text_mesh_vertex_attributes() noexcept
{
static const std::array<pp::renderer::gl::OpenGlVertexAttribute, 2> attributes {
@@ -431,7 +442,7 @@ void TextMesh::draw()
auto& f = FontManager::get(font, size, weight, italic);
if (f.font_tex.ready())
{
glActiveTexture(texture_unit(0U));
activate_text_texture_unit(0U);
f.font_tex.bind();
FontManager::m_sampler.bind(0);