Share retained framebuffer dispatch bridge

This commit is contained in:
2026-06-05 14:35:45 +02:00
parent 421f2713db
commit 84e63c0d34
6 changed files with 196 additions and 210 deletions

View File

@@ -3,6 +3,7 @@
#include "texture.h"
#include "util.h"
#include "app.h"
#include "legacy_gl_framebuffer_dispatch.h"
#include "legacy_gl_texture_dispatch.h"
#include "renderer_gl/opengl_capabilities.h"
@@ -10,65 +11,6 @@
namespace {
void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
void delete_opengl_framebuffers(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
void query_opengl_integer(std::uint32_t name, std::int32_t* value) noexcept
{
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(value));
}
void bind_opengl_framebuffer(std::uint32_t target, std::uint32_t framebuffer) noexcept
{
glBindFramebuffer(static_cast<GLenum>(target), static_cast<GLuint>(framebuffer));
}
void attach_opengl_framebuffer_texture_2d(
std::uint32_t target,
std::uint32_t attachment,
std::uint32_t texture_target,
std::uint32_t texture,
std::int32_t level) noexcept
{
glFramebufferTexture2D(
static_cast<GLenum>(target),
static_cast<GLenum>(attachment),
static_cast<GLenum>(texture_target),
static_cast<GLuint>(texture),
static_cast<GLint>(level));
}
std::uint32_t check_opengl_framebuffer_status(std::uint32_t target) noexcept
{
return static_cast<std::uint32_t>(glCheckFramebufferStatus(static_cast<GLenum>(target)));
}
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);
}
void gen_opengl_samplers(std::uint32_t count, std::uint32_t* ids) noexcept
{
#if USE_SAMPLER
@@ -265,16 +207,7 @@ Image Texture2D::get_image() const noexcept
.format = pp::renderer::gl::rgba8_readback_format(),
.pixels = ret.m_data.get(),
},
pp::renderer::gl::OpenGlTexture2DReadbackDispatch {
.bind_texture = pp::legacy::gl_texture::bind_opengl_texture,
.gen_framebuffers = gen_opengl_framebuffers,
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.framebuffer_texture_2d = attach_opengl_framebuffer_texture_2d,
.check_framebuffer_status = check_opengl_framebuffer_status,
.read_pixels = read_opengl_pixels,
.delete_framebuffers = delete_opengl_framebuffers,
});
pp::legacy::gl_framebuffer::texture_2d_readback_dispatch());
if (!readback.ok()) {
LOG("Texture2D::get_image() failed because: %s", readback.status().message);
return;