Route RTT lifecycle through GL backend
This commit is contained in:
@@ -748,6 +748,33 @@ pp::foundation::Status update_opengl_texture_2d(
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status set_opengl_texture_2d_parameters(
|
||||
std::uint32_t texture_id,
|
||||
std::span<const OpenGlTextureParameter> parameters,
|
||||
OpenGlTexture2DParameterDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.bind_texture == nullptr || dispatch.tex_parameter_f == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL texture parameter dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
if (texture_id == 0U || parameters.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL texture parameter request is invalid");
|
||||
}
|
||||
|
||||
for (const auto parameter : parameters) {
|
||||
if (parameter.name == 0U) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL texture parameter name is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
dispatch.bind_texture(texture_2d_target(), texture_id);
|
||||
for (const auto parameter : parameters) {
|
||||
dispatch.tex_parameter_f(texture_2d_target(), parameter.name, static_cast<float>(parameter.value));
|
||||
}
|
||||
dispatch.bind_texture(texture_2d_target(), default_framebuffer_id());
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status copy_opengl_framebuffer_to_texture_2d(
|
||||
OpenGlTexture2DFramebufferCopy copy,
|
||||
OpenGlTexture2DFramebufferCopyDispatch dispatch) noexcept
|
||||
@@ -969,6 +996,78 @@ pp::foundation::Status restore_opengl_framebuffer_binding(
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<OpenGlRenderTargetFramebufferAllocationResult> allocate_opengl_render_target_framebuffer(
|
||||
std::uint32_t texture_id,
|
||||
std::uint32_t depth_renderbuffer_id,
|
||||
OpenGlRenderTargetFramebufferAllocationDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.gen_framebuffers == nullptr
|
||||
|| dispatch.get_integer == nullptr
|
||||
|| dispatch.bind_framebuffer == nullptr
|
||||
|| dispatch.framebuffer_texture_2d == nullptr
|
||||
|| dispatch.framebuffer_renderbuffer == nullptr
|
||||
|| dispatch.check_framebuffer_status == nullptr) {
|
||||
return pp::foundation::Result<OpenGlRenderTargetFramebufferAllocationResult>::failure(
|
||||
pp::foundation::Status::invalid_argument(
|
||||
"OpenGL render-target framebuffer allocation dispatch callbacks must not be null"));
|
||||
}
|
||||
|
||||
if (texture_id == 0U) {
|
||||
return pp::foundation::Result<OpenGlRenderTargetFramebufferAllocationResult>::failure(
|
||||
pp::foundation::Status::invalid_argument("OpenGL render-target framebuffer texture id is invalid"));
|
||||
}
|
||||
|
||||
std::int32_t old_framebuffer = 0;
|
||||
dispatch.get_integer(draw_framebuffer_binding_query(), &old_framebuffer);
|
||||
|
||||
std::uint32_t framebuffer_id = 0U;
|
||||
dispatch.gen_framebuffers(1U, &framebuffer_id);
|
||||
if (framebuffer_id == 0U) {
|
||||
dispatch.bind_framebuffer(framebuffer_target(), static_cast<std::uint32_t>(old_framebuffer));
|
||||
return pp::foundation::Result<OpenGlRenderTargetFramebufferAllocationResult>::failure(
|
||||
pp::foundation::Status::out_of_range("OpenGL render-target framebuffer allocation returned id 0"));
|
||||
}
|
||||
|
||||
dispatch.bind_framebuffer(framebuffer_target(), framebuffer_id);
|
||||
dispatch.framebuffer_texture_2d(
|
||||
framebuffer_target(),
|
||||
framebuffer_color_attachment(),
|
||||
texture_2d_target(),
|
||||
texture_id,
|
||||
0);
|
||||
if (depth_renderbuffer_id != 0U) {
|
||||
dispatch.framebuffer_renderbuffer(
|
||||
framebuffer_target(),
|
||||
framebuffer_depth_attachment(),
|
||||
renderbuffer_target(),
|
||||
depth_renderbuffer_id);
|
||||
}
|
||||
|
||||
const auto framebuffer_status = dispatch.check_framebuffer_status(framebuffer_target());
|
||||
dispatch.bind_framebuffer(framebuffer_target(), static_cast<std::uint32_t>(old_framebuffer));
|
||||
return pp::foundation::Result<OpenGlRenderTargetFramebufferAllocationResult>::success(
|
||||
OpenGlRenderTargetFramebufferAllocationResult {
|
||||
.framebuffer_id = framebuffer_id,
|
||||
.framebuffer_status = framebuffer_status,
|
||||
});
|
||||
}
|
||||
|
||||
pp::foundation::Status delete_opengl_framebuffer(
|
||||
std::uint32_t framebuffer_id,
|
||||
OpenGlFramebufferDeleteDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.delete_framebuffers == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL framebuffer delete dispatch callback must not be null");
|
||||
}
|
||||
|
||||
if (framebuffer_id == 0U) {
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
dispatch.delete_framebuffers(1U, &framebuffer_id);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<std::uint32_t> allocate_opengl_pixel_buffer(
|
||||
OpenGlPixelBufferAllocationDispatch dispatch) noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user