Share grid GL dispatch adapters

This commit is contained in:
2026-06-05 13:53:51 +02:00
parent 03b999e60f
commit 745a5898da
5 changed files with 64 additions and 108 deletions

View File

@@ -33,6 +33,11 @@ inline void clear_opengl_buffer(std::uint32_t mask) noexcept
glClear(static_cast<GLbitfield>(mask));
}
inline void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept
{
glColorMask(r, g, b, a);
}
inline void set_opengl_clear_color(float r, float g, float b, float a) noexcept
{
glClearColor(r, g, b, a);
@@ -222,6 +227,38 @@ inline void apply_scissor_rect(
LOG("%s scissor dispatch failed because: %s", context, status.message);
}
inline void clear_depth_buffer(const char* context)
{
const auto status = pp::renderer::gl::clear_opengl_buffers(
pp::renderer::gl::framebuffer_depth_buffer_mask(),
pp::renderer::gl::OpenGlBufferClearDispatch {
.clear = clear_opengl_buffer,
});
if (!status.ok())
LOG("%s depth clear dispatch failed because: %s", context, status.message);
}
inline void set_color_write_mask(
std::uint8_t r,
std::uint8_t g,
std::uint8_t b,
std::uint8_t a,
const char* context)
{
const auto status = pp::renderer::gl::apply_opengl_color_write_mask(
pp::renderer::gl::OpenGlColorWriteMask {
.r = r,
.g = g,
.b = b,
.a = a,
},
pp::renderer::gl::OpenGlColorWriteMaskDispatch {
.color_mask = set_opengl_color_mask,
});
if (!status.ok())
LOG("%s color mask dispatch failed because: %s", context, status.message);
}
inline void read_framebuffer_rgba8_pixel(
std::uint32_t framebuffer,
std::int32_t x,

View File

@@ -6,143 +6,45 @@
#include "canvas.h"
#include "app.h"
#include "image.h"
#include "legacy_ui_gl_dispatch.h"
#include "renderer_gl/opengl_capabilities.h"
#include "util.h"
namespace {
void enable_opengl_state(std::uint32_t state) noexcept
{
glEnable(static_cast<GLenum>(state));
}
void disable_opengl_state(std::uint32_t state) noexcept
{
glDisable(static_cast<GLenum>(state));
}
std::uint8_t is_opengl_state_enabled(std::uint32_t state) noexcept
{
return static_cast<std::uint8_t>(glIsEnabled(static_cast<GLenum>(state)));
}
void set_opengl_active_texture(std::uint32_t texture_unit) noexcept
{
glActiveTexture(static_cast<GLenum>(texture_unit));
}
void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept
{
static_assert(sizeof(GLint) == sizeof(std::int32_t));
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(values));
}
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));
}
void clear_opengl_buffer(std::uint32_t mask) noexcept
{
glClear(static_cast<GLbitfield>(mask));
}
void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept
{
glColorMask(r, g, b, a);
}
void apply_grid_capability(std::uint32_t state, bool enabled)
{
const auto status = pp::renderer::gl::apply_opengl_capability(
state,
enabled,
pp::renderer::gl::OpenGlCapabilityDispatch {
.enable = enable_opengl_state,
.disable = disable_opengl_state,
});
if (!status.ok())
LOG("Grid capability dispatch failed because: %s", status.message);
pp::legacy::ui_gl::set_capability(state, enabled, "Grid");
}
bool query_grid_capability(std::uint32_t state)
{
const auto result = pp::renderer::gl::query_opengl_capability_state(
state,
pp::renderer::gl::OpenGlCapabilityStateQueryDispatch {
.is_enabled = is_opengl_state_enabled,
});
if (!result.ok()) {
LOG("Grid capability query failed because: %s", result.status().message);
return false;
}
return result.value();
return pp::legacy::ui_gl::query_capability(state, "Grid");
}
void set_grid_active_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 = set_opengl_active_texture,
});
if (!status.ok())
LOG("Grid active texture dispatch failed because: %s", status.message);
pp::legacy::ui_gl::activate_texture_unit(unit_index, "Grid");
}
void apply_grid_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
{
const auto status = pp::renderer::gl::apply_opengl_viewport(
pp::renderer::gl::OpenGlViewportRect {
.x = x,
.y = y,
.width = width,
.height = height,
},
pp::renderer::gl::OpenGlViewportDispatch {
.viewport = set_opengl_viewport,
});
if (!status.ok())
LOG("Grid viewport dispatch failed because: %s", status.message);
pp::legacy::ui_gl::apply_viewport(x, y, width, height, "Grid");
}
pp::renderer::gl::OpenGlViewportRect query_grid_viewport()
{
const auto result = pp::renderer::gl::query_opengl_viewport(
pp::renderer::gl::OpenGlViewportQueryDispatch {
.get_integer = get_opengl_integer,
});
if (!result.ok()) {
LOG("Grid viewport query failed because: %s", result.status().message);
}
return result.value();
return pp::legacy::ui_gl::query_viewport_rect("Grid");
}
void clear_grid_depth_buffer()
{
const auto status = pp::renderer::gl::clear_opengl_buffers(
pp::renderer::gl::framebuffer_depth_buffer_mask(),
pp::renderer::gl::OpenGlBufferClearDispatch {
.clear = clear_opengl_buffer,
});
if (!status.ok())
LOG("Grid depth clear dispatch failed because: %s", status.message);
pp::legacy::ui_gl::clear_depth_buffer("Grid");
}
void apply_grid_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
{
const auto status = pp::renderer::gl::apply_opengl_color_write_mask(
pp::renderer::gl::OpenGlColorWriteMask {
.r = r,
.g = g,
.b = b,
.a = a,
},
pp::renderer::gl::OpenGlColorWriteMaskDispatch {
.color_mask = set_opengl_color_mask,
});
if (!status.ok())
LOG("Grid color mask dispatch failed because: %s", status.message);
pp::legacy::ui_gl::set_color_write_mask(r, g, b, a, "Grid");
}
}