Route RTT blit readback through renderer GL
This commit is contained in:
@@ -608,6 +608,82 @@ pp::foundation::Result<OpenGlTexture2DReadbackResult> readback_opengl_texture_2d
|
||||
return pp::foundation::Result<OpenGlTexture2DReadbackResult>::success(result);
|
||||
}
|
||||
|
||||
pp::foundation::Status blit_opengl_framebuffer(
|
||||
OpenGlFramebufferBlit blit,
|
||||
OpenGlFramebufferBlitDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.get_integer == nullptr
|
||||
|| dispatch.bind_framebuffer == nullptr
|
||||
|| dispatch.blit_framebuffer == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL framebuffer blit dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
if (blit.source_rect.x1 <= blit.source_rect.x0
|
||||
|| blit.source_rect.y1 <= blit.source_rect.y0
|
||||
|| blit.destination_rect.x1 <= blit.destination_rect.x0
|
||||
|| blit.destination_rect.y1 <= blit.destination_rect.y0
|
||||
|| blit.mask == 0U
|
||||
|| blit.filter == 0U) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL framebuffer blit parameters are invalid");
|
||||
}
|
||||
|
||||
std::int32_t previous_draw_framebuffer = 0;
|
||||
std::int32_t previous_read_framebuffer = 0;
|
||||
dispatch.get_integer(draw_framebuffer_binding_query(), &previous_draw_framebuffer);
|
||||
dispatch.get_integer(read_framebuffer_binding_query(), &previous_read_framebuffer);
|
||||
dispatch.bind_framebuffer(draw_framebuffer_target(), blit.destination_framebuffer);
|
||||
dispatch.bind_framebuffer(read_framebuffer_target(), blit.source_framebuffer);
|
||||
dispatch.blit_framebuffer(
|
||||
blit.source_rect.x0,
|
||||
blit.source_rect.y0,
|
||||
blit.source_rect.x1,
|
||||
blit.source_rect.y1,
|
||||
blit.destination_rect.x0,
|
||||
blit.destination_rect.y0,
|
||||
blit.destination_rect.x1,
|
||||
blit.destination_rect.y1,
|
||||
blit.mask,
|
||||
blit.filter);
|
||||
dispatch.bind_framebuffer(draw_framebuffer_target(), static_cast<std::uint32_t>(previous_draw_framebuffer));
|
||||
dispatch.bind_framebuffer(read_framebuffer_target(), static_cast<std::uint32_t>(previous_read_framebuffer));
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status readback_opengl_framebuffer(
|
||||
OpenGlFramebufferReadback readback,
|
||||
OpenGlFramebufferReadbackDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.get_integer == nullptr
|
||||
|| dispatch.bind_framebuffer == nullptr
|
||||
|| dispatch.read_pixels == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument(
|
||||
"OpenGL framebuffer readback dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
if (readback.width <= 0
|
||||
|| readback.height <= 0
|
||||
|| readback.format.pixel_format == 0U
|
||||
|| readback.format.component_type == 0U
|
||||
|| readback.format.bytes_per_pixel == 0U
|
||||
|| readback.pixels == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL framebuffer readback parameters are invalid");
|
||||
}
|
||||
|
||||
std::int32_t previous_read_framebuffer = 0;
|
||||
dispatch.get_integer(read_framebuffer_binding_query(), &previous_read_framebuffer);
|
||||
dispatch.bind_framebuffer(read_framebuffer_target(), readback.framebuffer);
|
||||
dispatch.read_pixels(
|
||||
readback.x,
|
||||
readback.y,
|
||||
readback.width,
|
||||
readback.height,
|
||||
readback.format.pixel_format,
|
||||
readback.format.component_type,
|
||||
readback.pixels);
|
||||
dispatch.bind_framebuffer(read_framebuffer_target(), static_cast<std::uint32_t>(previous_read_framebuffer));
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
std::uint32_t extension_count_query() noexcept
|
||||
{
|
||||
return gl_num_extensions;
|
||||
|
||||
@@ -141,6 +141,32 @@ struct OpenGlTexture2DReadbackResult {
|
||||
bool pixels_read = false;
|
||||
};
|
||||
|
||||
struct OpenGlFramebufferRect {
|
||||
std::int32_t x0 = 0;
|
||||
std::int32_t y0 = 0;
|
||||
std::int32_t x1 = 0;
|
||||
std::int32_t y1 = 0;
|
||||
};
|
||||
|
||||
struct OpenGlFramebufferBlit {
|
||||
std::uint32_t source_framebuffer = 0;
|
||||
std::uint32_t destination_framebuffer = 0;
|
||||
OpenGlFramebufferRect source_rect;
|
||||
OpenGlFramebufferRect destination_rect;
|
||||
std::uint32_t mask = 0;
|
||||
std::uint32_t filter = 0;
|
||||
};
|
||||
|
||||
struct OpenGlFramebufferReadback {
|
||||
std::uint32_t framebuffer = 0;
|
||||
std::int32_t x = 0;
|
||||
std::int32_t y = 0;
|
||||
std::int32_t width = 0;
|
||||
std::int32_t height = 0;
|
||||
OpenGlReadbackFormat format;
|
||||
void* pixels = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlWindowsWglContextConfig {
|
||||
std::array<std::int32_t, 9> context_attributes {};
|
||||
std::array<std::int32_t, 15> pixel_format_attributes {};
|
||||
@@ -223,6 +249,17 @@ using OpenGlReadPixelsFn = void (*)(
|
||||
std::uint32_t pixel_format,
|
||||
std::uint32_t component_type,
|
||||
void* pixels) noexcept;
|
||||
using OpenGlBlitFramebufferFn = void (*)(
|
||||
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;
|
||||
|
||||
struct OpenGlStateDispatch {
|
||||
OpenGlCapabilityFn enable = nullptr;
|
||||
@@ -332,6 +369,18 @@ struct OpenGlTexture2DReadbackDispatch {
|
||||
OpenGlDeleteObjectsFn delete_framebuffers = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlFramebufferBlitDispatch {
|
||||
OpenGlGetIntegerFn get_integer = nullptr;
|
||||
OpenGlBindFramebufferFn bind_framebuffer = nullptr;
|
||||
OpenGlBlitFramebufferFn blit_framebuffer = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlFramebufferReadbackDispatch {
|
||||
OpenGlGetIntegerFn get_integer = nullptr;
|
||||
OpenGlBindFramebufferFn bind_framebuffer = nullptr;
|
||||
OpenGlReadPixelsFn read_pixels = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
@@ -382,6 +431,12 @@ struct OpenGlTexture2DReadbackDispatch {
|
||||
[[nodiscard]] pp::foundation::Result<OpenGlTexture2DReadbackResult> readback_opengl_texture_2d(
|
||||
OpenGlTexture2DReadback readback,
|
||||
OpenGlTexture2DReadbackDispatch dispatch) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status blit_opengl_framebuffer(
|
||||
OpenGlFramebufferBlit blit,
|
||||
OpenGlFramebufferBlitDispatch dispatch) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status readback_opengl_framebuffer(
|
||||
OpenGlFramebufferReadback readback,
|
||||
OpenGlFramebufferReadbackDispatch dispatch) noexcept;
|
||||
|
||||
[[nodiscard]] std::uint32_t extension_count_query() noexcept;
|
||||
[[nodiscard]] std::uint32_t extension_string_name() noexcept;
|
||||
|
||||
Reference in New Issue
Block a user