From 4c61a490cef47c231dc7fea9370b449a8df21c2c Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 4 Jun 2026 21:58:27 +0200 Subject: [PATCH] Route RTT utility clears through GL backend --- docs/modernization/build-inventory.md | 8 +- docs/modernization/debt.md | 2 +- docs/modernization/roadmap.md | 12 ++- src/renderer_gl/opengl_capabilities.cpp | 39 +++++++ src/renderer_gl/opengl_capabilities.h | 24 +++++ src/rtt.cpp | 81 +++++++++++--- tests/renderer_gl/capabilities_tests.cpp | 132 +++++++++++++++++++++++ 7 files changed, 275 insertions(+), 23 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 6d98656..e9f81ad 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -292,7 +292,9 @@ Known local toolchain state: 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. Optional RTT depth renderbuffer allocation/storage/delete + clear color/depth masks. 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 object-drawing depth renderbuffer setup, also execute through tested dispatch contracts here. Renderer API render-pass color/depth/stencil clear-mask and clear-value mapping, and color-write-mask query tokens. `RTT` no longer @@ -629,7 +631,9 @@ Known local toolchain state: consumed by retained `RTT` resize/copy/readback and RGBA8 region-readback paths, tested render-target texture parameter, framebuffer allocation/delete, color/depth attachment, status-check, and binding-restore dispatch consumed - by retained `RTT::create`/`RTT::destroy`, tested pixel-buffer allocation/readback/map/unmap/delete dispatch + by retained `RTT::create`/`RTT::destroy`, tested RTT render-target clear, + masked color clear with color-write-mask restore, and texture-bind dispatch, + tested pixel-buffer allocation/readback/map/unmap/delete dispatch consumed by retained `PBO` recording readbacks, tested framebuffer-to-texture 2D copy dispatch consumed by retained canvas/UI paint paths, tested framebuffer bind/restore dispatch consumed by retained `RTT` render-target pass entry diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index b0113ca..16efe45 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -53,7 +53,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0033 | Open | Modernization | Tools menu planning and direct command execution dispatch now consume pure `pp_app_core` through `App::init_menu_tools`, `pano_cli plan-tools-menu`, `pano_cli plan-tools-panel`, and the `ToolsMenuServices` boundary, and direct command execution is centralized in `src/legacy_app_shell_services.*`; SonarPen availability/startup now routes through `PlatformServices`, but live adapters still construct legacy `NodePanelFloating` panels, mutate legacy panel nodes, clear `CanvasModeGrid`, reset `NodeCanvas` camera state, open legacy shortcuts UI, and rely on the legacy platform adapter for the retained iOS SonarPen bridge | Preserve current Tools menu behavior while UI shell actions move toward app/UI/platform services | `pp_app_core_tools_menu_tests`; `pp_platform_api_tests`; `pano_cli plan-tools-menu --command shortcuts`; `pano_cli plan-tools-panel --panel layers`; `pano_cli plan-tools-panel --panel animation --already-visible`; `ctest --preset desktop-fast --build-config Debug` | Tools panel creation, submenu routing, grid clear, camera reset, shortcuts dialog, and SonarPen dispatch are owned by injected app/UI/platform services with `App::init_menu_tools` acting only as a UI adapter and no legacy Tools adapter | | DEBT-0034 | Open | Modernization | About menu command planning and execution dispatch now consume pure `pp_app_core` through `App::init_menu_about`, `pano_cli plan-about-menu`, and the `AboutMenuServices` boundary, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy About/manual/what's-new dialogs, invokes the injected crash hook, and runs the legacy Canvas stroke performance test directly | Preserve About menu behavior while dialogs and diagnostics move toward app/UI/platform services | `pp_app_core_about_menu_tests`; `pano_cli plan-about-menu --command news --version-major 2 --version-minor 5 --version-fix 7`; `pano_cli plan-about-menu --command performance --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | About/manual/what's-new dialog dispatch, crash-test dispatch, and performance-test execution are owned by injected app/UI/platform services with `App::init_menu_about` acting only as a UI adapter and no legacy About adapter | | DEBT-0035 | Open | Modernization | Main toolbar/status command planning and execution dispatch now consume pure `pp_app_core` through `App::init_toolbar_main`, `pano_cli plan-main-toolbar`, and the `MainToolbarServices` boundary, history/canvas commands now hand off through `HistoryUiServices` and `DocumentCanvasClearServices`, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy open/save/settings/message-box dialogs and delegates to legacy history/canvas adapters | Preserve reachable toolbar/status behavior while app shell commands move toward app/document/UI services | `pp_app_core_main_toolbar_tests`; `pano_cli plan-main-toolbar --command undo --undo-count 2`; `pano_cli plan-main-toolbar --command clear-canvas --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Open/save/settings/message-box routing, undo/redo/clear-history execution, and canvas-clear execution are owned by injected app/document/UI services with `App::init_toolbar_main` acting only as a UI adapter and no legacy toolbar adapter | -| DEBT-0036 | Open | Modernization | `pp_renderer_api`, `pp_paint_renderer`, `pano_cli plan-paint-feedback`, and `pano_cli plan-stroke-composite` can choose backend-neutral complex paint feedback strategies for fixed-function blending, framebuffer-fetch-capable renderers, or ping-pong render targets. OpenGL extension detection now stores `pp::renderer::RenderDeviceFeatures` through `ShaderManager`, using `pp_renderer_gl::query_opengl_capability_detection`, `detect_opengl_feature_state`, and `render_device_features` as the backend conversion point; that feature snapshot now includes float32-linear filtering, so canvas stroke texture format selection, renderer diagnostics, grid lightmap render planning, and grid bake target selection no longer read `ShaderManager::ext_*` flags directly. `pp_paint_renderer::plan_canvas_blend_gate` owns the compatibility mapping from persisted layer/brush blend indices to the extracted stroke-composite planner, and live `Canvas::draw_merge` plus `NodeCanvas` panorama rendering both call it with the stored renderer-neutral feature set for their existing shader-blend gates and destination-copy versus framebuffer-fetch decisions. `pp_paint_renderer::plan_canvas_stroke_feedback` also owns the current destination-feedback decision, and live `Canvas::stroke_draw`, thumbnail layer blending, and `NodeStrokePreview` brush-preview rendering use it for framebuffer-fetch versus destination-copy decisions. The retained `copy_framebuffer_to_texture_2d` utility bridge now routes 2D framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch, and retained `RTT::create`/`RTT::destroy` render-target texture parameter setup, optional depth renderbuffer allocation, framebuffer allocation/attachment/status checks, binding restore, and resource deletion now route through tested `pp_renderer_gl` dispatch, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, the retained cube-map framebuffer copy, and the retained `ShaderManager::ext_*` compatibility fields still use legacy OpenGL canvas/UI execution | Preserve current painting behavior while the renderer boundary matures for OpenGL parity and later Vulkan/Metal experiments | `pp_renderer_api_tests`; `pp_renderer_gl_capabilities_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli plan-paint-feedback --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-paint-feedback --texture-copy`; `pano_cli plan-stroke-composite --stroke-blend 10 --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-stroke-composite --layer-blend 4 --dual-blend --texture-copy`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Live stroke/layer compositing chooses its feedback path through `pp_paint_renderer` and renderer services, with OpenGL golden parity and Vulkan/Metal lab tests covering framebuffer-fetch and ping-pong behavior | +| DEBT-0036 | Open | Modernization | `pp_renderer_api`, `pp_paint_renderer`, `pano_cli plan-paint-feedback`, and `pano_cli plan-stroke-composite` can choose backend-neutral complex paint feedback strategies for fixed-function blending, framebuffer-fetch-capable renderers, or ping-pong render targets. OpenGL extension detection now stores `pp::renderer::RenderDeviceFeatures` through `ShaderManager`, using `pp_renderer_gl::query_opengl_capability_detection`, `detect_opengl_feature_state`, and `render_device_features` as the backend conversion point; that feature snapshot now includes float32-linear filtering, so canvas stroke texture format selection, renderer diagnostics, grid lightmap render planning, and grid bake target selection no longer read `ShaderManager::ext_*` flags directly. `pp_paint_renderer::plan_canvas_blend_gate` owns the compatibility mapping from persisted layer/brush blend indices to the extracted stroke-composite planner, and live `Canvas::draw_merge` plus `NodeCanvas` panorama rendering both call it with the stored renderer-neutral feature set for their existing shader-blend gates and destination-copy versus framebuffer-fetch decisions. `pp_paint_renderer::plan_canvas_stroke_feedback` also owns the current destination-feedback decision, and live `Canvas::stroke_draw`, thumbnail layer blending, and `NodeStrokePreview` brush-preview rendering use it for framebuffer-fetch versus destination-copy decisions. The retained `copy_framebuffer_to_texture_2d` utility bridge now routes 2D framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch, retained `RTT::create`/`RTT::destroy` render-target texture parameter setup, optional depth renderbuffer allocation, framebuffer allocation/attachment/status checks, binding restore, and resource deletion now route through tested `pp_renderer_gl` dispatch, and retained RTT clear, masked clear with color-write-mask restore, and texture bind/unbind now route through tested `pp_renderer_gl` dispatch, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, the retained cube-map framebuffer copy, and the retained `ShaderManager::ext_*` compatibility fields still use legacy OpenGL canvas/UI execution | Preserve current painting behavior while the renderer boundary matures for OpenGL parity and later Vulkan/Metal experiments | `pp_renderer_api_tests`; `pp_renderer_gl_capabilities_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli plan-paint-feedback --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-paint-feedback --texture-copy`; `pano_cli plan-stroke-composite --stroke-blend 10 --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-stroke-composite --layer-blend 4 --dual-blend --texture-copy`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Live stroke/layer compositing chooses its feedback path through `pp_paint_renderer` and renderer services, with OpenGL golden parity and Vulkan/Metal lab tests covering framebuffer-fetch and ping-pong behavior | | DEBT-0037 | Open | Modernization | Recording lifecycle/export planning and execution dispatch now consume pure `pp_app_core` through `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, `pano_cli plan-recording-session`, and the `RecordingServices` boundary; live execution is centralized in `src/legacy_recording_services.*`, and retained `PBO` allocation/readback/map/unmap/delete operations now route through tested `pp_renderer_gl` dispatch, but the bridge still owns legacy recording thread startup/shutdown, platform recorded-file cleanup, progress UI, retained `App::rec_loop` readback call sites, and `MP4Encoder::write_mp4` execution | Preserve current timelapse/MP4 behavior while recording moves toward app/document/renderer/video services | `pp_app_core_document_recording_tests`; `pp_renderer_gl_capabilities_tests`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-recording-session --platform-clears-files`; `ctest --preset desktop-fast --build-config Debug` | Recording thread lifecycle, frame readback scheduling, platform cleanup, progress reporting, and MP4 writing are owned by injected app/renderer/video services with `App` methods acting only as adapters | | DEBT-0038 | Open | Modernization | Cloud upload/browse/bulk planning and execution dispatch now consume pure `pp_app_core` through `App::cloud_upload`, `App::cloud_upload_all`, `App::cloud_browse`, `pano_cli plan-cloud-upload`, `pano_cli plan-cloud-upload-all`, `pano_cli plan-cloud-browse`, and the `CloudServices` boundary; live execution is centralized in `src/legacy_cloud_services.*`, the app-owned `upload`/`download`/license curl helpers now ask `PlatformServices` for the Android TLS-verification bypass policy, and retained `Asset::open_url`, `LogRemote::net_init`, and `NodeDialogCloud::load_thumbs_thread` curl sites consume the `pp_platform_api` default TLS policy helper instead of spelling Android branches locally, but the bridge still uses legacy save-before-upload, app-owned curl helpers instead of an injected network service, progress/message UI, OpenGL context guarding, `NodeDialogCloud`, `Canvas` project open, layer refresh, and `ActionManager` reset | Preserve current cloud behavior while cloud/network/document import flows move toward app/document/platform services | `pp_app_core_document_cloud_tests`; `pp_platform_api_tests`; `pano_cli plan-cloud-upload --new-document --unsaved`; `pano_cli plan-cloud-browse --selected-file demo.ppi`; `pano_cli plan-cloud-upload-all --file-count 3`; `ctest --preset desktop-fast --build-config Debug` | Cloud upload/download, TLS policy, save-before-upload, progress reporting, cloud browse dialog, downloaded project opening, layer refresh, OpenGL context ownership, and action-history reset are owned by injected app/document/network/platform/renderer services with `App` methods acting only as adapters | | DEBT-0039 | Open | Modernization | Document-open planning and execution dispatch now consume pure `pp_app_core` through `App::open_document`, `pano_cli plan-open-route`, `DocumentOpenServices`, and `src/legacy_document_open_services.*`, but the bridge still opens ABR/PPBR import prompts before delegating import execution to `src/legacy_brush_package_import_services.*`, applies unsaved-project discard prompts, calls legacy project-open execution, refreshes layer UI, updates the app title, and clears legacy history directly | Preserve current file-open/import behavior while document loading and brush import move toward app/document/asset/UI services | `pp_app_core_document_route_tests`; `pp_app_core_document_session_tests`; `pano_cli plan-open-route --path D:/Paint/Scenes/demo.ppi --unsaved`; `pano_cli plan-open-route --path D:/Paint/Brushes/clouds.ABR --unsaved`; `ctest --preset desktop-fast --build-config Debug` | Brush import prompting, project-open execution, unsaved-project discard prompting, layer refresh, title updates, and history clearing are owned by injected app/document/asset/UI services with `App::open_document` acting only as an adapter | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 1abf30f..efadeb8 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -825,6 +825,10 @@ MP4 execution remain tracked by DEBT-0037. Legacy `RTT::bindFramebuffer` and `RTT::unbindFramebuffer` now use tested `pp_renderer_gl` draw/read framebuffer binding snapshot and restore contracts, moving render-target pass entry/exit state management behind the backend. +Legacy `RTT::clear`, `RTT::clear_mask`, `RTT::bindTexture`, and +`RTT::unbindTexture` now dispatch through `pp_renderer_gl` clear, +color-write-mask restore, and texture-bind contracts, keeping render-target +utility operations behind the backend boundary. Windows RenderDoc frame capture hooks now also dispatch through `PlatformServices`, keeping capture integration in the platform service while leaving non-Windows adapters as no-ops. @@ -1020,9 +1024,11 @@ contracts. 2D framebuffer-to-texture copies used by canvas, transform, layer-conversion, panorama UI, and brush preview paths now route through a tested `pp_renderer_gl` copy dispatch via the retained `copy_framebuffer_to_texture_2d` utility bridge; the remaining cube-map -copy is tracked under `DEBT-0036`. RTT clear color/depth masks, renderer API render-pass -color/depth/stencil clear-mask and clear-value mapping, and color-write-mask query tokens also -live in `pp_renderer_gl`. `RTT` no longer spells GL enum names directly. +copy is tracked under `DEBT-0036`. RTT render-target clear, masked color clear +with color-write-mask restore, and texture bind/unbind dispatch now execute +through `pp_renderer_gl`; renderer API render-pass color/depth/stencil +clear-mask and clear-value mapping, and color-write-mask query tokens also live +there. `RTT` no longer spells GL enum names directly. Renderer API primitive-topology to OpenGL draw-mode mapping, mesh index-type and primitive-mode decisions used by legacy `Shape` drawing, plus Shape buffer targets, static upload usage, and vertex attribute component/normalization diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index ca4c4f5..aaa5ad4 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -464,6 +464,45 @@ pp::foundation::Status clear_panopainter_default_target(OpenGlClearDispatch disp return pp::foundation::Status::success(); } +pp::foundation::Status clear_opengl_render_target( + OpenGlDefaultClear clear, + OpenGlClearDispatch dispatch) noexcept +{ + if (dispatch.clear_color == nullptr || dispatch.clear == nullptr) { + return pp::foundation::Status::invalid_argument("OpenGL render-target clear dispatch callbacks must not be null"); + } + + if (clear.mask == 0U) { + return pp::foundation::Status::invalid_argument("OpenGL render-target clear mask is invalid"); + } + + dispatch.clear_color(clear.color[0], clear.color[1], clear.color[2], clear.color[3]); + dispatch.clear(clear.mask); + return pp::foundation::Status::success(); +} + +pp::foundation::Status clear_opengl_color_buffer_with_write_mask( + OpenGlColorMaskedClear clear, + OpenGlColorMaskedClearDispatch dispatch) noexcept +{ + if (dispatch.get_boolean == nullptr + || dispatch.color_mask == nullptr + || dispatch.clear_color == nullptr + || dispatch.clear == nullptr) { + return pp::foundation::Status::invalid_argument( + "OpenGL color-masked clear dispatch callbacks must not be null"); + } + + std::array old_mask {}; + dispatch.get_boolean(color_write_mask_query(), old_mask.data()); + + dispatch.color_mask(clear.mask.r, clear.mask.g, clear.mask.b, clear.mask.a); + dispatch.clear_color(clear.color[0], clear.color[1], clear.color[2], clear.color[3]); + dispatch.clear(framebuffer_color_buffer_mask()); + dispatch.color_mask(old_mask[0], old_mask[1], old_mask[2], old_mask[3]); + return pp::foundation::Status::success(); +} + pp::foundation::Status apply_opengl_viewport( OpenGlViewportRect viewport, OpenGlViewportDispatch dispatch) noexcept diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index d44c9c9..7f14701 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -316,9 +316,15 @@ using OpenGlCapabilityFn = void (*)(std::uint32_t state) noexcept; using OpenGlIsEnabledFn = std::uint8_t (*)(std::uint32_t state) noexcept; using OpenGlGetIntegerFn = void (*)(std::uint32_t name, std::int32_t* value) noexcept; using OpenGlGetFloatFn = void (*)(std::uint32_t name, float* value) noexcept; +using OpenGlGetBooleanFn = void (*)(std::uint32_t name, std::uint8_t* value) noexcept; using OpenGlActiveTextureFn = void (*)(std::uint32_t texture_unit) noexcept; using OpenGlClearColorFn = void (*)(float r, float g, float b, float a) noexcept; using OpenGlClearFn = void (*)(std::uint32_t mask) noexcept; +using OpenGlColorMaskFn = void (*)( + std::uint8_t r, + std::uint8_t g, + std::uint8_t b, + std::uint8_t a) noexcept; using OpenGlViewportFn = void (*)(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept; using OpenGlScissorFn = void (*)(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept; using OpenGlBlendFuncFn = void (*)(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept; @@ -547,11 +553,23 @@ struct OpenGlDefaultClear { std::uint32_t mask = 0; }; +struct OpenGlColorMaskedClear { + OpenGlColorWriteMask mask; + std::array color {}; +}; + struct OpenGlClearDispatch { OpenGlClearColorFn clear_color = nullptr; OpenGlClearFn clear = nullptr; }; +struct OpenGlColorMaskedClearDispatch { + OpenGlGetBooleanFn get_boolean = nullptr; + OpenGlColorMaskFn color_mask = nullptr; + OpenGlClearColorFn clear_color = nullptr; + OpenGlClearFn clear = nullptr; +}; + struct OpenGlViewportDispatch { OpenGlViewportFn viewport = nullptr; }; @@ -854,6 +872,12 @@ struct OpenGlMeshDeleteDispatch { OpenGlExtensionQueryDispatch dispatch); [[nodiscard]] OpenGlDefaultClear panopainter_default_clear() noexcept; [[nodiscard]] pp::foundation::Status clear_panopainter_default_target(OpenGlClearDispatch dispatch) noexcept; +[[nodiscard]] pp::foundation::Status clear_opengl_render_target( + OpenGlDefaultClear clear, + OpenGlClearDispatch dispatch) noexcept; +[[nodiscard]] pp::foundation::Status clear_opengl_color_buffer_with_write_mask( + OpenGlColorMaskedClear clear, + OpenGlColorMaskedClearDispatch dispatch) noexcept; [[nodiscard]] pp::foundation::Status apply_opengl_viewport( OpenGlViewportRect viewport, OpenGlViewportDispatch dispatch) noexcept; diff --git a/src/rtt.cpp b/src/rtt.cpp index ac755a7..cdd35a0 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -29,11 +29,31 @@ void query_opengl_integer(std::uint32_t name, std::int32_t* value) noexcept glGetIntegerv(static_cast(name), reinterpret_cast(value)); } +void query_opengl_boolean(std::uint32_t name, std::uint8_t* value) noexcept +{ + glGetBooleanv(static_cast(name), reinterpret_cast(value)); +} + void bind_opengl_framebuffer(std::uint32_t target, std::uint32_t framebuffer) noexcept { glBindFramebuffer(static_cast(target), static_cast(framebuffer)); } +void set_opengl_clear_color(float r, float g, float b, float a) noexcept +{ + glClearColor(r, g, b, a); +} + +void clear_opengl_buffers(std::uint32_t mask) noexcept +{ + glClear(static_cast(mask)); +} + +void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept +{ + glColorMask(r, g, b, a); +} + void gen_opengl_textures(std::uint32_t count, std::uint32_t* ids) noexcept { glGenTextures(static_cast(count), reinterpret_cast(ids)); @@ -649,26 +669,41 @@ void RTT::unbindFramebuffer() void RTT::clear(glm::vec4 color) { assert(App::I->is_render_thread()); - glClearColor(color.r, color.g, color.b, color.a); - glClear(static_cast( - pp::renderer::gl::framebuffer_color_buffer_mask() - | pp::renderer::gl::framebuffer_depth_buffer_mask())); + const auto status = pp::renderer::gl::clear_opengl_render_target( + pp::renderer::gl::OpenGlDefaultClear { + .color = { color.r, color.g, color.b, color.a }, + .mask = pp::renderer::gl::framebuffer_color_buffer_mask() + | pp::renderer::gl::framebuffer_depth_buffer_mask(), + }, + pp::renderer::gl::OpenGlClearDispatch { + .clear_color = set_opengl_clear_color, + .clear = clear_opengl_buffers, + }); + if (!status.ok()) + LOG("RTT::clear() failed because: %s", status.message); } void RTT::clear_mask(glm::bool4 mask, glm::vec4 color) { assert(App::I->is_render_thread()); - // save old state - std::array old_mask; - glGetBooleanv(static_cast(pp::renderer::gl::color_write_mask_query()), old_mask.data()); - - // clear with mask - glColorMask(mask.r, mask.g, mask.b, mask.a); - glClearColor(color.r, color.g, color.b, color.a); - glClear(static_cast(pp::renderer::gl::framebuffer_color_buffer_mask())); - - // restore old state - glColorMask(old_mask[0], old_mask[1], old_mask[2], old_mask[3]); + const auto status = pp::renderer::gl::clear_opengl_color_buffer_with_write_mask( + pp::renderer::gl::OpenGlColorMaskedClear { + .mask = { + .r = static_cast(mask.r), + .g = static_cast(mask.g), + .b = static_cast(mask.b), + .a = static_cast(mask.a), + }, + .color = { color.r, color.g, color.b, color.a }, + }, + pp::renderer::gl::OpenGlColorMaskedClearDispatch { + .get_boolean = query_opengl_boolean, + .color_mask = set_opengl_color_mask, + .clear_color = set_opengl_clear_color, + .clear = clear_opengl_buffers, + }); + if (!status.ok()) + LOG("RTT::clear_mask() failed because: %s", status.message); } glm::ivec4 RTT::calc_bounds() const noexcept @@ -803,13 +838,25 @@ float * RTT::createBufferFloat() const noexcept void RTT::bindTexture() { assert(App::I->is_render_thread()); - glBindTexture(texture_2d_target(), texID); + const auto status = pp::renderer::gl::bind_opengl_texture_2d( + static_cast(texID), + pp::renderer::gl::OpenGlTexture2DBindDispatch { + .bind_texture = bind_opengl_texture, + }); + if (!status.ok()) + LOG("RTT::bindTexture() failed because: %s", status.message); } void RTT::unbindTexture() { assert(App::I->is_render_thread()); - glBindTexture(texture_2d_target(), 0); + const auto status = pp::renderer::gl::bind_opengl_texture_2d( + 0U, + pp::renderer::gl::OpenGlTexture2DBindDispatch { + .bind_texture = bind_opengl_texture, + }); + if (!status.ok()) + LOG("RTT::unbindTexture() failed because: %s", status.message); } Image RTT::get_image() const noexcept diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index f939672..0b93a70 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -61,6 +61,13 @@ struct RecordedOpenGlTextureParameterCall { float value = 0.0F; }; +struct RecordedOpenGlColorMaskCall { + std::uint8_t r = 0; + std::uint8_t g = 0; + std::uint8_t b = 0; + std::uint8_t a = 0; +}; + struct RecordedOpenGlFramebufferTextureCopyCall { std::uint32_t target = 0; std::int32_t level = 0; @@ -205,6 +212,8 @@ std::vector recorded_viewport_calls; std::vector recorded_scissor_calls; std::vector recorded_integer_queries; std::vector recorded_float_queries; +std::vector recorded_boolean_queries; +std::vector recorded_color_mask_calls; std::vector recorded_active_texture_calls; std::vector recorded_binding_calls; std::vector recorded_generated_texture_counts; @@ -448,6 +457,27 @@ void record_get_float(std::uint32_t name, float* value) noexcept } } +void record_get_boolean(std::uint32_t name, std::uint8_t* value) noexcept +{ + recorded_boolean_queries.push_back(name); + if (name == 0x0C23U) { + value[0] = 1U; + value[1] = 0U; + value[2] = 1U; + value[3] = 1U; + } +} + +void record_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept +{ + recorded_color_mask_calls.push_back(RecordedOpenGlColorMaskCall { + .r = r, + .g = g, + .b = b, + .a = a, + }); +} + void record_active_texture(std::uint32_t texture_unit) noexcept { recorded_active_texture_calls.push_back(texture_unit); @@ -2230,6 +2260,105 @@ void rejects_incomplete_app_clear_dispatch(pp::tests::Harness& h) PP_EXPECT(h, status.code == pp::foundation::StatusCode::invalid_argument); } +void clears_render_target_through_dispatch(pp::tests::Harness& h) +{ + recorded_clear_calls.clear(); + + const auto status = pp::renderer::gl::clear_opengl_render_target( + pp::renderer::gl::OpenGlDefaultClear { + .color = { 0.2F, 0.4F, 0.6F, 0.8F }, + .mask = 0x00004100U, + }, + pp::renderer::gl::OpenGlClearDispatch { + .clear_color = record_clear_color, + .clear = record_clear, + }); + + PP_EXPECT(h, status.ok()); + PP_EXPECT(h, recorded_clear_calls.size() == 2U); + PP_EXPECT(h, recorded_clear_calls[0].color[0] == 0.2F); + PP_EXPECT(h, recorded_clear_calls[0].color[1] == 0.4F); + PP_EXPECT(h, recorded_clear_calls[0].color[2] == 0.6F); + PP_EXPECT(h, recorded_clear_calls[0].color[3] == 0.8F); + PP_EXPECT(h, recorded_clear_calls[1].mask == 0x00004100U); +} + +void clears_color_buffer_with_write_mask_and_restores_previous_mask(pp::tests::Harness& h) +{ + recorded_boolean_queries.clear(); + recorded_color_mask_calls.clear(); + recorded_clear_calls.clear(); + + const auto status = pp::renderer::gl::clear_opengl_color_buffer_with_write_mask( + pp::renderer::gl::OpenGlColorMaskedClear { + .mask = { .r = 1U, .g = 0U, .b = 0U, .a = 1U }, + .color = { 0.75F, 0.5F, 0.25F, 1.0F }, + }, + pp::renderer::gl::OpenGlColorMaskedClearDispatch { + .get_boolean = record_get_boolean, + .color_mask = record_color_mask, + .clear_color = record_clear_color, + .clear = record_clear, + }); + + PP_EXPECT(h, status.ok()); + PP_EXPECT(h, recorded_boolean_queries.size() == 1U); + PP_EXPECT(h, recorded_boolean_queries[0] == 0x0C23U); + PP_EXPECT(h, recorded_color_mask_calls.size() == 2U); + PP_EXPECT(h, recorded_color_mask_calls[0].r == 1U); + PP_EXPECT(h, recorded_color_mask_calls[0].g == 0U); + PP_EXPECT(h, recorded_color_mask_calls[0].b == 0U); + PP_EXPECT(h, recorded_color_mask_calls[0].a == 1U); + PP_EXPECT(h, recorded_color_mask_calls[1].r == 1U); + PP_EXPECT(h, recorded_color_mask_calls[1].g == 0U); + PP_EXPECT(h, recorded_color_mask_calls[1].b == 1U); + PP_EXPECT(h, recorded_color_mask_calls[1].a == 1U); + PP_EXPECT(h, recorded_clear_calls.size() == 2U); + PP_EXPECT(h, recorded_clear_calls[0].color[0] == 0.75F); + PP_EXPECT(h, recorded_clear_calls[0].color[1] == 0.5F); + PP_EXPECT(h, recorded_clear_calls[0].color[2] == 0.25F); + PP_EXPECT(h, recorded_clear_calls[0].color[3] == 1.0F); + PP_EXPECT(h, recorded_clear_calls[1].mask == 0x00004000U); +} + +void rejects_invalid_render_target_clear_dispatch(pp::tests::Harness& h) +{ + const auto missing_clear = pp::renderer::gl::clear_opengl_render_target( + pp::renderer::gl::OpenGlDefaultClear { + .color = { 1.0F, 0.0F, 0.0F, 1.0F }, + .mask = 0x00004000U, + }, + pp::renderer::gl::OpenGlClearDispatch { + .clear_color = record_clear_color, + }); + const auto invalid_mask = pp::renderer::gl::clear_opengl_render_target( + pp::renderer::gl::OpenGlDefaultClear { + .color = { 1.0F, 0.0F, 0.0F, 1.0F }, + .mask = 0U, + }, + pp::renderer::gl::OpenGlClearDispatch { + .clear_color = record_clear_color, + .clear = record_clear, + }); + const auto missing_masked_dispatch = pp::renderer::gl::clear_opengl_color_buffer_with_write_mask( + pp::renderer::gl::OpenGlColorMaskedClear { + .mask = { .r = 1U, .g = 1U, .b = 1U, .a = 1U }, + .color = { 1.0F, 0.0F, 0.0F, 1.0F }, + }, + pp::renderer::gl::OpenGlColorMaskedClearDispatch { + .get_boolean = record_get_boolean, + .clear_color = record_clear_color, + .clear = record_clear, + }); + + PP_EXPECT(h, !missing_clear.ok()); + PP_EXPECT(h, missing_clear.code == pp::foundation::StatusCode::invalid_argument); + PP_EXPECT(h, !invalid_mask.ok()); + PP_EXPECT(h, invalid_mask.code == pp::foundation::StatusCode::invalid_argument); + PP_EXPECT(h, !missing_masked_dispatch.ok()); + PP_EXPECT(h, missing_masked_dispatch.code == pp::foundation::StatusCode::invalid_argument); +} + void applies_viewport_dispatch(pp::tests::Harness& h) { recorded_viewport_calls.clear(); @@ -5122,6 +5251,9 @@ int main() harness.run("rejects_incomplete_capability_detection_dispatch", rejects_incomplete_capability_detection_dispatch); harness.run("clears_app_default_target", clears_app_default_target); harness.run("rejects_incomplete_app_clear_dispatch", rejects_incomplete_app_clear_dispatch); + harness.run("clears_render_target_through_dispatch", clears_render_target_through_dispatch); + harness.run("clears_color_buffer_with_write_mask_and_restores_previous_mask", clears_color_buffer_with_write_mask_and_restores_previous_mask); + harness.run("rejects_invalid_render_target_clear_dispatch", rejects_invalid_render_target_clear_dispatch); harness.run("applies_viewport_dispatch", applies_viewport_dispatch); harness.run("rejects_incomplete_viewport_dispatch", rejects_incomplete_viewport_dispatch); harness.run("applies_scissor_dispatch", applies_scissor_dispatch);