From 51601adf6db4c42024f705edf91a14ab8b3b2728 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 4 Jun 2026 20:12:54 +0200 Subject: [PATCH] Move render debug state setup into GL backend --- docs/modernization/build-inventory.md | 5 +- docs/modernization/debt.md | 2 +- docs/modernization/roadmap.md | 12 ++-- .../windows_platform_services.cpp | 31 +++++----- src/renderer_gl/opengl_capabilities.cpp | 26 +++++++++ src/renderer_gl/opengl_capabilities.h | 12 ++++ tests/renderer_gl/capabilities_tests.cpp | 56 +++++++++++++++++++ 7 files changed, 123 insertions(+), 21 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index b8de284..d587a26 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -605,8 +605,9 @@ Known local toolchain state: the retained `Texture2D` utility, tested framebuffer blit/readback dispatch consumed by retained `RTT` resize/copy/readback paths, tested framebuffer bind/restore dispatch consumed by retained `RTT` render-target pass entry - and exit paths, plus renderer API to OpenGL token mapping and command-planning - contracts used by the OpenGL parity work. + and exit paths, tested render platform hint and debug-output state dispatch + consumed by `WindowsPlatformServices`, plus renderer API to OpenGL token + mapping and command-planning contracts used by the OpenGL parity work. - `pano_cli plan-cloud-upload` exposes `pp_app_core` cloud upload availability, new-document warning, publish prompt, and save-before-upload planning as JSON; the live cloud upload command consumes the same start contract before diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 373ccc1..cd654b0 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -35,7 +35,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0014 | Open | Modernization | `windows-clangcl-asan` now configures as a headless Ninja/clang-cl preset and uses the release MSVC runtime required by ASan, but local builds still fail because installed clang-cl 18.1.8 is paired with VS 2026-preview STL headers that require Clang 20 or newer | Sanitizer validation should be local and repeatable, but this machine's compiler/header pairing is incompatible | `cmake --fresh --preset windows-clangcl-asan`; `cmake --build --preset windows-clangcl-asan --target pp_foundation` | Install/use Clang 20+ with the VS 2026 STL, or point the preset at a compatible VS 2022 toolchain, then make `platform-build.ps1 -Presets windows-clangcl-asan` pass for the headless matrix | | DEBT-0015 | Open | Modernization | Cursor visibility requests now consume pure `pp_app_core` planning through `pano_cli plan-cursor-visibility`, `App::show_cursor`/`App::hide_cursor` dispatch through `PlatformServices` without platform guards, and Windows live execution uses injected `WindowsPlatformServices`, but macOS cursor execution still reaches the retained fallback adapter | Keep canvas cursor behavior stable while platform shells are extracted incrementally | `pp_app_core_document_platform_io_tests`; `pano_cli plan-cursor-visibility --visible`; `ctest --preset desktop-fast --build-config Debug` | Cursor visibility execution is owned by injected `pp_platform_*` services for every supported platform | | DEBT-0016 | Open | Modernization | Clipboard get/set requests now consume pure `pp_app_core` planning through `pano_cli plan-clipboard-read` and `pano_cli plan-clipboard-write`, and Windows live execution uses injected `WindowsPlatformServices`, but Apple/Android clipboard execution still reaches retained fallback adapter branches from `App::clipboard_get_text` and `App::clipboard_set_text` | Keep picker/color text clipboard behavior stable while platform shells are extracted incrementally | `pp_app_core_document_platform_io_tests`; `pano_cli plan-clipboard-write --text #ff00aa`; `ctest --preset desktop-fast --build-config Debug` | Clipboard execution is owned by injected `pp_platform_*` services for every supported platform | -| DEBT-0017 | Open | Modernization | Startup storage path preparation, `App::clipboard_get_text`, `App::clipboard_set_text`, `App::show_cursor`, `App::hide_cursor`, `App::showKeyboard`, `App::hideKeyboard`, `App::display_file`, `App::share_file`, native app/window close, UI-thread lifecycle hooks, render-context acquire/release/present hooks, render-target binding hooks, render platform hint hooks, render debug callback hooks, render-capture frame hooks, recording cleanup, live asset/layout reload policy, diagnostic stacktrace/crash hooks, per-frame platform hooks, `App::pick_image`, `App::pick_file`, the non-writer `App::pick_file_save`, `App::pick_dir`, working-directory picker/display-path policy, canvas input tip/pressure policy, prepared-file save/download handoff, work-directory document export collection policy, app network TLS verification policy, PPBR export data-directory policy, SonarPen availability/startup, and VR mode start/stop now call the SDK-free `pp::platform::PlatformServices` interface, and Windows injects `WindowsPlatformServices` from `src/platform_windows/windows_platform_services.*`; non-Windows live implementations still use `src/platform_legacy/legacy_platform_services.*`, a named fallback adapter that forwards to retained Apple/Android/Linux/Web bridge functions and retained no-op branches, including retained iOS canvas tip behavior, retained macOS directory picker/display-path behavior, retained iOS SonarPen bridge, retained non-Windows VR unsupported/no-op behavior, and retained macOS PPBR export directory override; `pp_platform_api` also owns the default network TLS policy helper consumed by retained curl sites that cannot yet depend on injected services | Preserve behavior while moving platform execution behind a testable service boundary before platform shell implementations are injected | `pp_platform_api_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_platform_io_tests`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Replace `src/platform_legacy/legacy_platform_services.*` with injected `pp_platform_*` service implementations owned by each non-Windows platform shell | +| DEBT-0017 | Open | Modernization | Startup storage path preparation, `App::clipboard_get_text`, `App::clipboard_set_text`, `App::show_cursor`, `App::hide_cursor`, `App::showKeyboard`, `App::hideKeyboard`, `App::display_file`, `App::share_file`, native app/window close, UI-thread lifecycle hooks, render-context acquire/release/present hooks, render-target binding hooks, render platform hint hooks, render debug callback hooks, render-capture frame hooks, recording cleanup, live asset/layout reload policy, diagnostic stacktrace/crash hooks, per-frame platform hooks, `App::pick_image`, `App::pick_file`, the non-writer `App::pick_file_save`, `App::pick_dir`, working-directory picker/display-path policy, canvas input tip/pressure policy, prepared-file save/download handoff, work-directory document export collection policy, app network TLS verification policy, PPBR export data-directory policy, SonarPen availability/startup, and VR mode start/stop now call the SDK-free `pp::platform::PlatformServices` interface, and Windows injects `WindowsPlatformServices` from `src/platform_windows/windows_platform_services.*`; Windows render-platform hint and debug-output state token/enable sequencing now delegates to tested `pp_renderer_gl` helpers, leaving Windows with context, callback, console, and Win32 ownership; non-Windows live implementations still use `src/platform_legacy/legacy_platform_services.*`, a named fallback adapter that forwards to retained Apple/Android/Linux/Web bridge functions and retained no-op branches, including retained iOS canvas tip behavior, retained macOS directory picker/display-path behavior, retained iOS SonarPen bridge, retained non-Windows VR unsupported/no-op behavior, and retained macOS PPBR export directory override; `pp_platform_api` also owns the default network TLS policy helper consumed by retained curl sites that cannot yet depend on injected services | Preserve behavior while moving platform execution behind a testable service boundary before platform shell implementations are injected | `pp_platform_api_tests`; `pp_app_core_document_export_tests`; `pp_app_core_document_platform_io_tests`; `ctest --preset desktop-fast --build-config Debug`; `powershell -ExecutionPolicy Bypass -File scripts\automation\package-smoke.ps1 -Preset windows-msvc-default -Configuration Debug` | Replace `src/platform_legacy/legacy_platform_services.*` with injected `pp_platform_*` service implementations owned by each non-Windows platform shell | | DEBT-0019 | Open | Modernization | Unreferenced-parameter warnings are muted globally through `pp_project_warnings` with MSVC `/wd4100` and Clang/GCC `-Wno-unused-parameter` | Legacy callbacks, virtual hooks, serializer methods, and platform/API compatibility functions carry many intentionally unused parameters during the component split; muting this keeps stricter warning builds focused on higher-signal migration issues | `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset linux-clang --target pp_foundation` | Remove `/wd4100` and `-Wno-unused-parameter`, mark intentionally unused parameters with names/comments or `[[maybe_unused]]`, and make the Windows app plus headless Clang/GCC tests pass without unreferenced-parameter warnings | | DEBT-0020 | Open | Modernization | Document resize dialog state, selected-resolution planning, and execution dispatch now consume pure `pp_app_core` through `NodeDialogResize`, `App::dialog_resize`, `pano_cli plan-document-resize`, and the `DocumentResizeServices` boundary, and live resize shares `src/legacy_document_canvas_services.*` with canvas clear commands, but the shared live bridge still calls legacy `Canvas::resize`, updates the legacy app title, and clears legacy `ActionManager` history through the history bridge | Preserve existing layer/frame GPU resize behavior while the document model and canvas execution boundary are extracted incrementally | `pp_app_core_document_resize_tests`; `pano_cli plan-document-resize --current-resolution 2048 --selected-resolution-index 4`; `ctest --preset desktop-fast --build-config Debug` | Document resize execution is owned by injected document/app services with no legacy resize adapter, title shim, or direct `ActionManager` history clearing | | DEBT-0021 | Open | Modernization | Layer rename planning/execution dispatch and layer panel operation planning/execution dispatch now consume pure `pp_app_core` through `App::dialog_layer_rename`, `App::init_sidebar` layer callbacks, `pano_cli plan-layer-rename`, `pano_cli plan-layer-operation`, `DocumentLayerRenameServices`, and `DocumentLayerOperationServices`, and the live execution adapters are centralized in `src/legacy_document_layer_services.*`, but that shared bridge still mutates legacy `Canvas` layer state, `NodeLayer`/`NodePanelLayer`, and `ActionManager` undo entries | Preserve existing UI/canvas behavior while document layer commands and undo history are extracted incrementally | `pp_app_core_document_layer_tests`; `pano_cli plan-layer-rename --old-name Base --new-name Paint`; `pano_cli plan-layer-operation --kind add --layer-count 2 --index 1 --name Paint`; `ctest --preset desktop-fast --build-config Debug` | Layer command execution is owned by the document/app command boundary with legacy `Canvas`/UI nodes acting only as adapters or removed entirely | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index c891186..c596068 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -763,11 +763,15 @@ through `PlatformServices`, preserving the existing iOS drawable bind in the legacy adapter while removing the iOS drawable branch from `App::draw`. Initial render platform hints now also dispatch through `PlatformServices`, preserving the previous Windows/macOS program-point-size and line-smoothing -enablement while removing the Windows/macOS branch from `App::init`. +enablement while removing the Windows/macOS branch from `App::init`. The +Windows service now delegates the actual OpenGL program-point-size and +line-smooth enable sequence to a tested `pp_renderer_gl` dispatch helper, so +the platform shell no longer owns those backend state tokens. Windows OpenGL debug callback setup now dispatches through `PlatformServices`, -moving Win32 console coloring, debug-output enablement, and debug-break callback -behavior into `WindowsPlatformServices` while keeping other platform adapters -as no-ops. +moving Win32 console coloring and debug-break callback behavior into +`WindowsPlatformServices` while keeping other platform adapters as no-ops; the +debug-output/debug-output-synchronous state enable sequence is now a tested +`pp_renderer_gl` backend helper consumed by the Windows service. Initial PanoPainter OpenGL depth/blend startup state is now represented and applied by tested `pp_renderer_gl` startup-state contracts; `App::init` delegates to the backend dispatch path instead of hard-coding the policy or diff --git a/src/platform_windows/windows_platform_services.cpp b/src/platform_windows/windows_platform_services.cpp index bb372a2..43ba96c 100644 --- a/src/platform_windows/windows_platform_services.cpp +++ b/src/platform_windows/windows_platform_services.cpp @@ -48,16 +48,6 @@ static CONSOLE_SCREEN_BUFFER_INFO render_debug_console_info; return static_cast(pp::renderer::gl::debug_severity_high()); } -[[nodiscard]] GLenum debug_output_state() noexcept -{ - return static_cast(pp::renderer::gl::debug_output_state()); -} - -[[nodiscard]] GLenum debug_output_synchronous_state() noexcept -{ - return static_cast(pp::renderer::gl::debug_output_synchronous_state()); -} - void handle_gl_callback( GLenum source, GLenum type, @@ -93,6 +83,11 @@ void handle_gl_callback( } } +void enable_gl_capability(std::uint32_t state) noexcept +{ + glEnable(static_cast(state)); +} + void show_cursor(bool visible) { std::lock_guard lock(main_task_mutex); @@ -337,8 +332,12 @@ public: void apply_render_platform_hints() override { - glEnable(static_cast(pp::renderer::gl::program_point_size_state())); - glEnable(static_cast(pp::renderer::gl::line_smooth_state())); + const auto status = pp::renderer::gl::apply_opengl_render_platform_hints( + pp::renderer::gl::OpenGlRenderPlatformHintDispatch { + .enable = enable_gl_capability, + }); + if (!status.ok()) + LOG("OpenGL render platform hints failed: %s", status.message); } void install_render_debug_callback() override @@ -349,8 +348,12 @@ public: // colors: http://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &render_debug_console_info); glDebugMessageCallback(handle_gl_callback, nullptr); - glEnable(debug_output_state()); - glEnable(debug_output_synchronous_state()); + const auto status = pp::renderer::gl::apply_opengl_debug_output_states( + pp::renderer::gl::OpenGlDebugOutputStateDispatch { + .enable = enable_gl_capability, + }); + if (!status.ok()) + LOG("OpenGL debug output states failed: %s", status.message); } void begin_render_capture_frame() override diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index c9a5e19..4cea6f4 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -485,6 +485,32 @@ pp::foundation::Status apply_opengl_capability( return pp::foundation::Status::success(); } +pp::foundation::Status apply_opengl_render_platform_hints( + OpenGlRenderPlatformHintDispatch dispatch) noexcept +{ + if (dispatch.enable == nullptr) { + return pp::foundation::Status::invalid_argument( + "OpenGL render platform hint dispatch callback must not be null"); + } + + dispatch.enable(program_point_size_state()); + dispatch.enable(line_smooth_state()); + return pp::foundation::Status::success(); +} + +pp::foundation::Status apply_opengl_debug_output_states( + OpenGlDebugOutputStateDispatch dispatch) noexcept +{ + if (dispatch.enable == nullptr) { + return pp::foundation::Status::invalid_argument( + "OpenGL debug output state dispatch callback must not be null"); + } + + dispatch.enable(debug_output_state()); + dispatch.enable(debug_output_synchronous_state()); + return pp::foundation::Status::success(); +} + pp::foundation::Status clear_opengl_buffers( std::uint32_t mask, OpenGlBufferClearDispatch dispatch) noexcept diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index c50a68c..a0d08ff 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -512,6 +512,14 @@ struct OpenGlCapabilityDispatch { OpenGlCapabilityFn disable = nullptr; }; +struct OpenGlRenderPlatformHintDispatch { + OpenGlCapabilityFn enable = nullptr; +}; + +struct OpenGlDebugOutputStateDispatch { + OpenGlCapabilityFn enable = nullptr; +}; + struct OpenGlBufferClearDispatch { OpenGlClearFn clear = nullptr; }; @@ -731,6 +739,10 @@ struct OpenGlMeshDeleteDispatch { std::uint32_t state, bool enabled, OpenGlCapabilityDispatch dispatch) noexcept; +[[nodiscard]] pp::foundation::Status apply_opengl_render_platform_hints( + OpenGlRenderPlatformHintDispatch dispatch) noexcept; +[[nodiscard]] pp::foundation::Status apply_opengl_debug_output_states( + OpenGlDebugOutputStateDispatch dispatch) noexcept; [[nodiscard]] pp::foundation::Status clear_opengl_buffers( std::uint32_t mask, OpenGlBufferClearDispatch dispatch) noexcept; diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index 6639d2f..2192417 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -2190,6 +2190,58 @@ void rejects_incomplete_generic_capability_dispatch(pp::tests::Harness& h) PP_EXPECT(h, status.code == pp::foundation::StatusCode::invalid_argument); } +void applies_render_platform_hints(pp::tests::Harness& h) +{ + recorded_state_calls.clear(); + + const auto status = pp::renderer::gl::apply_opengl_render_platform_hints( + pp::renderer::gl::OpenGlRenderPlatformHintDispatch { + .enable = record_enable, + }); + + PP_EXPECT(h, status.ok()); + PP_EXPECT(h, recorded_state_calls.size() == 2U); + PP_EXPECT(h, recorded_state_calls[0].kind == RecordedOpenGlStateCall::Kind::enable); + PP_EXPECT(h, recorded_state_calls[0].first == 0x8642U); + PP_EXPECT(h, recorded_state_calls[1].kind == RecordedOpenGlStateCall::Kind::enable); + PP_EXPECT(h, recorded_state_calls[1].first == 0x0B20U); +} + +void rejects_incomplete_render_platform_hint_dispatch(pp::tests::Harness& h) +{ + const auto status = pp::renderer::gl::apply_opengl_render_platform_hints( + pp::renderer::gl::OpenGlRenderPlatformHintDispatch {}); + + PP_EXPECT(h, !status.ok()); + PP_EXPECT(h, status.code == pp::foundation::StatusCode::invalid_argument); +} + +void applies_debug_output_states(pp::tests::Harness& h) +{ + recorded_state_calls.clear(); + + const auto status = pp::renderer::gl::apply_opengl_debug_output_states( + pp::renderer::gl::OpenGlDebugOutputStateDispatch { + .enable = record_enable, + }); + + PP_EXPECT(h, status.ok()); + PP_EXPECT(h, recorded_state_calls.size() == 2U); + PP_EXPECT(h, recorded_state_calls[0].kind == RecordedOpenGlStateCall::Kind::enable); + PP_EXPECT(h, recorded_state_calls[0].first == 0x92E0U); + PP_EXPECT(h, recorded_state_calls[1].kind == RecordedOpenGlStateCall::Kind::enable); + PP_EXPECT(h, recorded_state_calls[1].first == 0x8242U); +} + +void rejects_incomplete_debug_output_state_dispatch(pp::tests::Harness& h) +{ + const auto status = pp::renderer::gl::apply_opengl_debug_output_states( + pp::renderer::gl::OpenGlDebugOutputStateDispatch {}); + + PP_EXPECT(h, !status.ok()); + PP_EXPECT(h, status.code == pp::foundation::StatusCode::invalid_argument); +} + void applies_buffer_clear_dispatch(pp::tests::Harness& h) { recorded_clear_calls.clear(); @@ -4325,6 +4377,10 @@ int main() harness.run("rejects_incomplete_scissor_test_dispatch", rejects_incomplete_scissor_test_dispatch); harness.run("applies_generic_capability_dispatch", applies_generic_capability_dispatch); harness.run("rejects_incomplete_generic_capability_dispatch", rejects_incomplete_generic_capability_dispatch); + harness.run("applies_render_platform_hints", applies_render_platform_hints); + harness.run("rejects_incomplete_render_platform_hint_dispatch", rejects_incomplete_render_platform_hint_dispatch); + harness.run("applies_debug_output_states", applies_debug_output_states); + harness.run("rejects_incomplete_debug_output_state_dispatch", rejects_incomplete_debug_output_state_dispatch); harness.run("applies_buffer_clear_dispatch", applies_buffer_clear_dispatch); harness.run("rejects_incomplete_buffer_clear_dispatch", rejects_incomplete_buffer_clear_dispatch); harness.run("allocates_texture_2d_through_dispatch", allocates_texture_2d_through_dispatch);