Share CanvasMode GL dispatch adapters

This commit is contained in:
2026-06-05 13:44:57 +02:00
parent 92fa5b224a
commit 03b999e60f
5 changed files with 98 additions and 115 deletions

View File

@@ -53,6 +53,37 @@ inline void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noe
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
}
inline void bind_opengl_framebuffer(std::uint32_t target, std::uint32_t framebuffer) noexcept
{
glBindFramebuffer(static_cast<GLenum>(target), static_cast<GLuint>(framebuffer));
}
inline void read_opengl_pixels(
std::int32_t x,
std::int32_t y,
std::int32_t width,
std::int32_t height,
std::uint32_t pixel_format,
std::uint32_t component_type,
void* pixels) noexcept
{
glReadPixels(
static_cast<GLint>(x),
static_cast<GLint>(y),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
pixels);
}
inline void get_opengl_integer_scalar(std::uint32_t name, std::int32_t* value) noexcept
{
GLint raw_value = 0;
glGetIntegerv(static_cast<GLenum>(name), &raw_value);
*value = static_cast<std::int32_t>(raw_value);
}
inline void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept
{
GLint raw_values[4] {};
@@ -109,6 +140,14 @@ inline bool query_capability(std::uint32_t state, const char* context)
return result.value();
}
inline std::uint32_t query_read_framebuffer(const char* context)
{
std::int32_t read_framebuffer = 0;
get_opengl_integer_scalar(pp::renderer::gl::read_framebuffer_binding_query(), &read_framebuffer);
(void)context;
return static_cast<std::uint32_t>(read_framebuffer);
}
inline void set_capability(std::uint32_t state, bool enabled, const char* context)
{
const auto status = pp::renderer::gl::apply_opengl_capability(
@@ -183,6 +222,32 @@ inline void apply_scissor_rect(
LOG("%s scissor dispatch failed because: %s", context, status.message);
}
inline void read_framebuffer_rgba8_pixel(
std::uint32_t framebuffer,
std::int32_t x,
std::int32_t y,
void* pixel,
const char* context)
{
const auto status = pp::renderer::gl::readback_opengl_framebuffer(
pp::renderer::gl::OpenGlFramebufferReadback {
.framebuffer = framebuffer,
.x = x,
.y = y,
.width = 1,
.height = 1,
.format = pp::renderer::gl::rgba8_readback_format(),
.pixels = pixel,
},
pp::renderer::gl::OpenGlFramebufferReadbackDispatch {
.get_integer = get_opengl_integer_scalar,
.bind_framebuffer = bind_opengl_framebuffer,
.read_pixels = read_opengl_pixels,
});
if (!status.ok())
LOG("%s pixel readback dispatch failed because: %s", context, status.message);
}
inline void clear_color_buffer(std::array<float, 4> color, const char* context)
{
const auto status = pp::renderer::gl::clear_opengl_render_target(