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

@@ -437,7 +437,10 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
framebuffer targets, binding queries, attachment points, render-target
framebuffer allocation/delete, binding restore, and completion status used by
`RTT::create`/`RTT::destroy` and framebuffer bind/restore paths, plus RTT
clear color/depth masks. RTT render-target clear, masked color clear with
clear color/depth masks. Retained `Texture2D` readback and RTT framebuffer
allocation, deletion, bind/restore, blit, readback, and PBO readback dispatch
now share the retained `legacy_gl_framebuffer_dispatch` raw callback bridge.
RTT render-target clear, masked color clear with
color-write-mask restore, and texture bind/unbind now execute through tested
dispatch contracts here. Optional RTT depth renderbuffer
allocation/storage/delete and framebuffer depth attach/detach, plus canvas

File diff suppressed because one or more lines are too long

View File

@@ -1152,7 +1152,10 @@ render-target texture parameters and parameter dispatch, texture/renderbuffer
targets, depth format, framebuffer targets, binding queries, attachment points,
render-target framebuffer allocation/delete, binding restore, and completion
status used by `RTT::create`/`RTT::destroy` and framebuffer bind/restore paths,
also live in `pp_renderer_gl`. Depth renderbuffer allocation/storage/delete and
also live in `pp_renderer_gl`; retained `Texture2D` readback and RTT
framebuffer allocation, deletion, bind/restore, blit, readback, and PBO
readback dispatch now share the retained `legacy_gl_framebuffer_dispatch` raw
callback bridge. Depth renderbuffer allocation/storage/delete and
framebuffer depth attach/detach sequences used by retained `RTT` and canvas
object-drawing helpers now execute through tested `pp_renderer_gl` dispatch
contracts and share the retained `legacy_gl_renderbuffer_dispatch` raw callback
@@ -2555,6 +2558,11 @@ Results:
`legacy_gl_texture_dispatch`, removing duplicated raw texture callbacks from
`src/texture.cpp` and `src/rtt.cpp` while texture resource ownership remains
retained under DEBT-0036.
- Retained `Texture2D` readback plus RTT framebuffer allocation, deletion,
bind/restore, blit, readback, and PBO readback dispatch now share
`legacy_gl_framebuffer_dispatch`, removing duplicated raw framebuffer and
readback callbacks from `src/texture.cpp` and `src/rtt.cpp` while
framebuffer/readback ownership remains retained under DEBT-0036.
- Canvas draw-merge shader-blend selection now consumes the extracted
`pp_paint_renderer` stroke composite planner for current layer and primary
brush blend modes, while preserving legacy OpenGL compositing execution under

View File

@@ -0,0 +1,161 @@
#pragma once
#include <cstdint>
#include "legacy_gl_texture_dispatch.h"
#include "renderer_gl/opengl_capabilities.h"
namespace pp::legacy::gl_framebuffer {
inline void query_opengl_integer(std::uint32_t name, std::int32_t* value) noexcept
{
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(value));
}
inline void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
inline void delete_opengl_framebuffers(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
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 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));
}
inline std::uint32_t check_opengl_framebuffer_status(std::uint32_t target) noexcept
{
return static_cast<std::uint32_t>(glCheckFramebufferStatus(static_cast<GLenum>(target)));
}
inline void blit_opengl_framebuffer(
std::int32_t source_x0,
std::int32_t source_y0,
std::int32_t source_x1,
std::int32_t source_y1,
std::int32_t destination_x0,
std::int32_t destination_y0,
std::int32_t destination_x1,
std::int32_t destination_y1,
std::uint32_t mask,
std::uint32_t filter) noexcept
{
glBlitFramebuffer(
static_cast<GLint>(source_x0),
static_cast<GLint>(source_y0),
static_cast<GLint>(source_x1),
static_cast<GLint>(source_y1),
static_cast<GLint>(destination_x0),
static_cast<GLint>(destination_y0),
static_cast<GLint>(destination_x1),
static_cast<GLint>(destination_y1),
static_cast<GLbitfield>(mask),
static_cast<GLenum>(filter));
}
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 pp::renderer::gl::OpenGlTexture2DReadbackDispatch texture_2d_readback_dispatch() noexcept
{
return 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,
};
}
inline pp::renderer::gl::OpenGlFramebufferBlitDispatch framebuffer_blit_dispatch() noexcept
{
return pp::renderer::gl::OpenGlFramebufferBlitDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.blit_framebuffer = blit_opengl_framebuffer,
};
}
inline pp::renderer::gl::OpenGlFramebufferReadbackDispatch framebuffer_readback_dispatch() noexcept
{
return pp::renderer::gl::OpenGlFramebufferReadbackDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.read_pixels = read_opengl_pixels,
};
}
inline pp::renderer::gl::OpenGlFramebufferBindDispatch framebuffer_bind_dispatch() noexcept
{
return pp::renderer::gl::OpenGlFramebufferBindDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
};
}
inline pp::renderer::gl::OpenGlFramebufferRestoreDispatch framebuffer_restore_dispatch() noexcept
{
return pp::renderer::gl::OpenGlFramebufferRestoreDispatch {
.bind_framebuffer = bind_opengl_framebuffer,
};
}
inline pp::renderer::gl::OpenGlFramebufferDeleteDispatch framebuffer_delete_dispatch() noexcept
{
return pp::renderer::gl::OpenGlFramebufferDeleteDispatch {
.delete_framebuffers = delete_opengl_framebuffers,
};
}
inline pp::renderer::gl::OpenGlRenderTargetFramebufferAllocationDispatch render_target_allocation_dispatch(
pp::renderer::gl::OpenGlFramebufferRenderbufferFn framebuffer_renderbuffer) noexcept
{
return pp::renderer::gl::OpenGlRenderTargetFramebufferAllocationDispatch {
.gen_framebuffers = gen_opengl_framebuffers,
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.framebuffer_texture_2d = attach_opengl_framebuffer_texture_2d,
.framebuffer_renderbuffer = framebuffer_renderbuffer,
.check_framebuffer_status = check_opengl_framebuffer_status,
};
}
} // namespace pp::legacy::gl_framebuffer

View File

@@ -3,6 +3,7 @@
#include "rtt.h"
#include "util.h"
#include "app.h"
#include "legacy_gl_framebuffer_dispatch.h"
#include "legacy_gl_renderbuffer_dispatch.h"
#include "legacy_gl_texture_dispatch.h"
#include "renderer_gl/opengl_capabilities.h"
@@ -11,26 +12,11 @@
namespace {
[[nodiscard]] GLenum framebuffer_target() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::framebuffer_target());
}
void query_opengl_integer(std::uint32_t name, std::int32_t* value) noexcept
{
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(value));
}
void query_opengl_boolean(std::uint32_t name, std::uint8_t* value) noexcept
{
glGetBooleanv(static_cast<GLenum>(name), reinterpret_cast<GLboolean*>(value));
}
void bind_opengl_framebuffer(std::uint32_t target, std::uint32_t framebuffer) noexcept
{
glBindFramebuffer(static_cast<GLenum>(target), static_cast<GLuint>(framebuffer));
}
void set_opengl_clear_color(float r, float g, float b, float a) noexcept
{
glClearColor(r, g, b, a);
@@ -46,80 +32,6 @@ void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::
glColorMask(r, g, b, a);
}
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 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 blit_opengl_framebuffer(
std::int32_t source_x0,
std::int32_t source_y0,
std::int32_t source_x1,
std::int32_t source_y1,
std::int32_t destination_x0,
std::int32_t destination_y0,
std::int32_t destination_x1,
std::int32_t destination_y1,
std::uint32_t mask,
std::uint32_t filter) noexcept
{
glBlitFramebuffer(
static_cast<GLint>(source_x0),
static_cast<GLint>(source_y0),
static_cast<GLint>(source_x1),
static_cast<GLint>(source_y1),
static_cast<GLint>(destination_x0),
static_cast<GLint>(destination_y0),
static_cast<GLint>(destination_x1),
static_cast<GLint>(destination_y1),
static_cast<GLbitfield>(mask),
static_cast<GLenum>(filter));
}
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_buffers(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenBuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
@@ -253,11 +165,7 @@ bool RTT::resize(int width, int height)
.mask = pp::renderer::gl::framebuffer_color_buffer_mask(),
.filter = pp::renderer::gl::framebuffer_blit_filter(true),
},
pp::renderer::gl::OpenGlFramebufferBlitDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.blit_framebuffer = blit_opengl_framebuffer,
});
pp::legacy::gl_framebuffer::framebuffer_blit_dispatch());
if (!status.ok()) {
LOG("RTT::resize blit failed because: %s", status.message);
ret = false;
@@ -302,9 +210,7 @@ void RTT::destroy()
//unbindFramebuffer();
const auto status = pp::renderer::gl::delete_opengl_framebuffer(
static_cast<std::uint32_t>(fboID),
pp::renderer::gl::OpenGlFramebufferDeleteDispatch {
.delete_framebuffers = delete_opengl_framebuffers,
});
pp::legacy::gl_framebuffer::framebuffer_delete_dispatch());
if (!status.ok())
LOG("RTT::destroy framebuffer delete failed because: %s", status.message);
//LOG("RTT DESTROY %d", fboID);
@@ -332,11 +238,7 @@ void RTT::copy(const RTT & source)
.mask = pp::renderer::gl::framebuffer_color_buffer_mask(),
.filter = pp::renderer::gl::framebuffer_blit_filter(true),
},
pp::renderer::gl::OpenGlFramebufferBlitDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.blit_framebuffer = blit_opengl_framebuffer,
});
pp::legacy::gl_framebuffer::framebuffer_blit_dispatch());
if (!status.ok())
LOG("RTT::copy blit failed because: %s", status.message);
});
@@ -368,11 +270,7 @@ void RTT::copy(const RTT& source, const glm::vec4& rect)
.mask = pp::renderer::gl::framebuffer_color_buffer_mask(),
.filter = pp::renderer::gl::framebuffer_blit_filter(false),
},
pp::renderer::gl::OpenGlFramebufferBlitDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.blit_framebuffer = blit_opengl_framebuffer,
});
pp::legacy::gl_framebuffer::framebuffer_blit_dispatch());
if (!status.ok())
LOG("RTT::copy region blit failed because: %s", status.message);
});
@@ -470,14 +368,8 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
const auto framebuffer = pp::renderer::gl::allocate_opengl_render_target_framebuffer(
static_cast<std::uint32_t>(texID),
static_cast<std::uint32_t>(rboID),
pp::renderer::gl::OpenGlRenderTargetFramebufferAllocationDispatch {
.gen_framebuffers = gen_opengl_framebuffers,
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.framebuffer_texture_2d = attach_opengl_framebuffer_texture_2d,
.framebuffer_renderbuffer = pp::legacy::gl_renderbuffer::attach_opengl_framebuffer_renderbuffer,
.check_framebuffer_status = check_opengl_framebuffer_status,
});
pp::legacy::gl_framebuffer::render_target_allocation_dispatch(
pp::legacy::gl_renderbuffer::attach_opengl_framebuffer_renderbuffer));
if (!framebuffer.ok())
{
LOG("RTT::create framebuffer allocation failed because: %s", framebuffer.status().message);
@@ -514,10 +406,7 @@ void RTT::bindFramebuffer()
#endif // _DEBUG
const auto binding = pp::renderer::gl::bind_opengl_framebuffer_for_draw_read(
static_cast<std::uint32_t>(fboID),
pp::renderer::gl::OpenGlFramebufferBindDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
});
pp::legacy::gl_framebuffer::framebuffer_bind_dispatch());
if (!binding.ok()) {
LOG("RTT::bindFramebuffer() failed because: %s", binding.status().message);
return;
@@ -538,9 +427,7 @@ void RTT::unbindFramebuffer()
.draw_framebuffer = oldDFboID,
.read_framebuffer = oldRFboID,
},
pp::renderer::gl::OpenGlFramebufferRestoreDispatch {
.bind_framebuffer = bind_opengl_framebuffer,
});
pp::legacy::gl_framebuffer::framebuffer_restore_dispatch());
if (!status.ok()) {
LOG("RTT::unbindFramebuffer() failed because: %s", status.message);
return;
@@ -632,11 +519,7 @@ bool RTT::readPixelsRgba8(int x, int y, int width, int height, void* buffer) con
.format = readback,
.pixels = buffer,
},
pp::renderer::gl::OpenGlFramebufferReadbackDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.read_pixels = read_opengl_pixels,
});
pp::legacy::gl_framebuffer::framebuffer_readback_dispatch());
if (!status.ok()) {
LOG("RTT::readPixelsRgba8() failed because: %s", status.message);
ret = false;
@@ -685,11 +568,7 @@ uint8_t* RTT::readTextureData(uint8_t* buffer) const noexcept
.format = readback,
.pixels = buffer,
},
pp::renderer::gl::OpenGlFramebufferReadbackDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.read_pixels = read_opengl_pixels,
});
pp::legacy::gl_framebuffer::framebuffer_readback_dispatch());
if (!status.ok())
LOG("RTT::readTextureData() failed because: %s", status.message);
});
@@ -713,11 +592,7 @@ float* RTT::readTextureDataFloat(float* buffer) const noexcept
.format = readback,
.pixels = buffer,
},
pp::renderer::gl::OpenGlFramebufferReadbackDispatch {
.get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer,
.read_pixels = read_opengl_pixels,
});
pp::legacy::gl_framebuffer::framebuffer_readback_dispatch());
if (!status.ok())
LOG("RTT::readTextureDataFloat() failed because: %s", status.message);
});
@@ -838,7 +713,7 @@ bool PBO::create(RTT& rtt) noexcept
.gen_buffers = gen_opengl_buffers,
.bind_buffer = bind_opengl_buffer,
.buffer_data = set_opengl_buffer_data,
.read_pixels = read_opengl_pixels,
.read_pixels = pp::legacy::gl_framebuffer::read_opengl_pixels,
});
rtt.unbindFramebuffer();
if (!result.ok()) {

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;