diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index bbda723..cbcd8a3 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -540,8 +540,8 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p clear-color restore, active texture unit execution, fallback 2D texture unbinds, 2D texture targets, copy targets, and sampler filters/wraps. Its live stroke-mixer and brush-preview viewport, scissor, and depth/blend state - changes now execute through tested `pp_renderer_gl` dispatch with only local - OpenGL adapter endpoints retained. + changes now execute through tested `pp_renderer_gl` dispatch via the shared + `legacy_ui_gl_dispatch` bridge. Retained `Canvas` stroke/thumbnail/object/export paths and `NodeCanvas` panorama rendering use the same tested active-texture dispatch for texture-unit switches, and their live viewport, scissor, and generic @@ -552,7 +552,10 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p clear-color query plus clear-color restore paths also use tested `pp_renderer_gl` dispatch helpers. `NodeCanvas` saved viewport/clear-color query, density/offscreen color clear, and clear-color restore paths use the - same helpers. Retained desktop HMD eye rendering also routes viewport + same helpers. `NodeCanvas` and `NodeStrokePreview` now share + `legacy_ui_gl_dispatch` for active texture, texture unbind, viewport/scissor, + clear-color, color-buffer clear, and capability query/apply adapter endpoints. + Retained desktop HMD eye rendering also routes viewport execution through tested backend dispatch. Legacy `Texture2D`, `TextureManager`, `Sampler`, and `RTT` public headers no longer expose raw OpenGL enum defaults; default texture formats, sampler @@ -855,6 +858,9 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p `NodeImageTexture`, `NodeColorWheel`, `NodeAnimationTimeline`, `NodeScroll`, `NodeText`, `NodeTextInput`, and `NodeViewport` blend-state, fallback texture unbind, viewport, color clear, and clear-color restore paths, + plus retained `NodeCanvas` and `NodeStrokePreview` active-texture, fallback + texture unbind, viewport/scissor, clear-color, color-buffer clear, and + capability query/apply draw-state adapter endpoints, tested convert-command state dispatch consumed by `App::cmd_convert`, tested render platform hint dispatch consumed by `WindowsPlatformServices` and the retained macOS legacy fallback, tested diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index f36dfd9..49933d7 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -317,6 +317,13 @@ agent or engineer to remove them without reconstructing context from chat. rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, and retained `ShaderManager::ext_*` compatibility fields. +- 2026-06-05: DEBT-0036 was narrowed again. Retained `NodeCanvas` and + `NodeStrokePreview` draw-state paths now share `legacy_ui_gl_dispatch` for + active-texture selection, fallback 2D texture unbinds, viewport/scissor + execution, viewport and clear-color queries, clear-color restore, + color-buffer clears, and capability query/apply adapter endpoints. Their live + panorama and brush-preview compositing order remains legacy OpenGL and stays + open under DEBT-0036. ## Open Debt @@ -355,7 +362,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`, `pano_cli plan-canvas-camera-reset`, `pano_cli plan-canvas-view-density`, `pano_cli plan-canvas-view-cursor-mode`, and the `ToolsMenuServices` boundary, direct command execution is centralized in `src/legacy_app_shell_services.*`, SonarPen availability/startup now routes through `PlatformServices`, and reset-camera, viewport-density, and cursor-mode execution now share `src/legacy_canvas_view_services.*`, but live adapters still construct legacy `NodePanelFloating` panels, mutate legacy panel nodes, clear `CanvasModeGrid`, open legacy shortcuts UI, mutate retained `Canvas` camera/density/cursor state, write retained `Settings`, and rely on the legacy platform adapter for the retained iOS SonarPen bridge | Preserve current Tools menu and canvas-view behavior while UI shell actions move toward app/UI/platform/canvas services | `pp_app_core_tools_menu_tests`; `pp_app_core_canvas_view_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`; `pano_cli plan-canvas-camera-reset`; `pano_cli plan-canvas-view-density --density 1.5`; `pano_cli plan-canvas-view-cursor-mode --mode 3`; `ctest --preset desktop-fast --build-config Debug` | Tools panel creation, submenu routing, grid clear, camera reset, viewport density, cursor mode, shortcuts dialog, and SonarPen dispatch are owned by injected app/UI/platform/canvas services with `App::init_menu_tools` and options callbacks acting only as UI adapters and no legacy Tools/canvas-view 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; toolbar test-message dialog metadata now lives in `pp_app_core` through `plan_main_toolbar_message_dialog`, retained message-box creation routes through `src/legacy_app_dialog_services.*`, 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 dialogs, stores raw compatibility pointers, 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 message-box`; `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, 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, retained RTT clear, masked clear with color-write-mask restore, texture bind/unbind, and RGBA8 dirty-region texture writes now route through tested `pp_renderer_gl` dispatch, retained Canvas, NodeCanvas, and NodeStrokePreview texture-unit switches now route through tested active-texture dispatch, retained Canvas, NodeCanvas, NodeStrokePreview, and desktop HMD viewport/scissor/capability execution now route through tested `pp_renderer_gl` dispatch adapters, retained NodeCanvas, CanvasMode, and NodePanelGrid capability-state snapshots now route through tested `pp_renderer_gl` query dispatch, CanvasLayer cube/equirect generation plus frame clears now route blend state, active texture units, viewport execution, color clears, and cube-face framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch adapters, `NodePanelGrid` live heightmap draw and bake setup now route depth/blend state, depth clears, color-write-mask toggles, active texture selection, bake viewport execution, sun-overlay viewport query, and desktop texture-resize readback through tested `pp_renderer_gl` dispatch adapters, retained CanvasMode overlay/mask/transform paths now route active texture, depth/blend state, transform/cut viewport execution, paint-mode blend/depth state snapshots, and canvas-tip pick framebuffer readback through tested `pp_renderer_gl` dispatch adapters, retained simple UI draw paths now share `legacy_ui_gl_dispatch` for blend-state execution, fallback 2D texture unbinds, `NodeViewport` viewport query/restore, color-buffer clears, and clear-color restore, retained `NodeCanvas` plus `NodeStrokePreview` draw-state paths now route viewport query, clear-color query, color-buffer clear, and clear-color restore through tested `pp_renderer_gl` dispatch helpers, and retained `Canvas` plus `CanvasLayer` stroke/object/thumbnail/frame-clear draw-state paths now route saved viewport or clear-color query and restore through the same tested helpers, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, 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, retained RTT clear, masked clear with color-write-mask restore, texture bind/unbind, and RGBA8 dirty-region texture writes now route through tested `pp_renderer_gl` dispatch, retained Canvas, NodeCanvas, and NodeStrokePreview texture-unit switches now route through tested active-texture dispatch, retained Canvas, NodeCanvas, NodeStrokePreview, and desktop HMD viewport/scissor/capability execution now route through tested `pp_renderer_gl` dispatch adapters, retained NodeCanvas, CanvasMode, and NodePanelGrid capability-state snapshots now route through tested `pp_renderer_gl` query dispatch, CanvasLayer cube/equirect generation plus frame clears now route blend state, active texture units, viewport execution, color clears, and cube-face framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch adapters, `NodePanelGrid` live heightmap draw and bake setup now route depth/blend state, depth clears, color-write-mask toggles, active texture selection, bake viewport execution, sun-overlay viewport query, and desktop texture-resize readback through tested `pp_renderer_gl` dispatch adapters, retained CanvasMode overlay/mask/transform paths now route active texture, depth/blend state, transform/cut viewport execution, paint-mode blend/depth state snapshots, and canvas-tip pick framebuffer readback through tested `pp_renderer_gl` dispatch adapters, retained simple UI draw paths now share `legacy_ui_gl_dispatch` for blend-state execution, fallback 2D texture unbinds, `NodeViewport` viewport query/restore, color-buffer clears, and clear-color restore, retained `NodeCanvas` plus `NodeStrokePreview` draw-state paths now share `legacy_ui_gl_dispatch` for active-texture selection, fallback texture unbind, viewport/scissor execution, viewport and clear-color queries, color-buffer clears, clear-color restore, and capability query/apply adapter endpoints backed by tested `pp_renderer_gl` dispatch helpers, and retained `Canvas` plus `CanvasLayer` stroke/object/thumbnail/frame-clear draw-state paths now route saved viewport or clear-color query and restore through the same tested helpers, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, 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, export progress-dialog metadata, 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.*`, retained MP4 export progress bar creation routes through `src/legacy_app_dialog_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 lifetime, 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-deletes-recorded-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, cloud prompt/progress metadata, 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`, `pano_cli plan-cloud-transfer`, and the `CloudServices` boundary; live execution is centralized in `src/legacy_cloud_services.*`, the app-owned `upload`/`download` CURL helpers now consume `pp_app_core` cloud transfer request/progress planning and the platform TLS-verification bypass policy before retained CURL setup, upload warning/publish/success prompts, upload/bulk progress dialog titles, download-progress prompt metadata, and formatted download progress text come from tested app-core plans, retained cloud prompt/progress creation routes through `src/legacy_app_dialog_services.*` via `App::message_box`/`App::show_progress` or direct bridge calls, 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, upload form construction, response/error handling, retained prompt/progress lifetime, 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`; `pano_cli plan-cloud-transfer --direction download --progress --disable-tls-verification`; `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 a544a6f..b5ebe66 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -1252,8 +1252,8 @@ texture unit execution, fallback 2D texture unbinds, 2D texture targets, copy targets, sampler filters/wraps, and destination-feedback copy/fetch decisions to `pp_renderer_gl` and `pp_paint_renderer`. Its live stroke-mixer and brush-preview viewport, scissor, and depth/blend state changes now also -execute through tested `pp_renderer_gl` dispatch with only local OpenGL adapter -endpoints retained. +execute through tested `pp_renderer_gl` dispatch via the shared +`legacy_ui_gl_dispatch` bridge. Retained `Canvas` stroke/thumbnail/object/export paths and `NodeCanvas` panorama rendering use the same tested active-texture dispatch for their texture-unit switches, and their live viewport, scissor, and generic @@ -1263,7 +1263,10 @@ snapshots now route through the same backend dispatch contracts. Retained generation, object drawing, and `LayerFrame::clear` saved viewport/clear-color query plus clear-color restore paths also use tested `pp_renderer_gl` dispatch helpers. `NodeCanvas` saved viewport/clear-color query, density target color -clear, and clear-color restore paths use the same helpers. +clear, and clear-color restore paths use the same helpers. `NodeCanvas` and +`NodeStrokePreview` now share that retained UI GL dispatch bridge for +active-texture, fallback texture unbind, viewport/scissor, clear-color, +color-buffer clear, and capability query/apply adapter endpoints. Desktop HMD eye rendering now routes eye framebuffer viewport changes through the tested `pp_renderer_gl` viewport dispatch while platform VR SDK bridges remain isolated for later platform-shell extraction. @@ -2504,7 +2507,11 @@ Results: - Retained paint UI surface paths now use tested `pp_renderer_gl` viewport query, clear-color query, clear-color restore, and color-buffer clear helpers in `NodeCanvas` and `NodeStrokePreview`, removing direct query/clear calls - from those draw bodies while keeping their legacy compositing order. + from those draw bodies while keeping their legacy compositing order. Their + active-texture, fallback texture unbind, viewport/scissor, clear-color, + color-buffer clear, and capability query/apply adapter endpoints are now + centralized in `legacy_ui_gl_dispatch` instead of being duplicated in each + node implementation. - Retained Canvas stroke draw/commit, thumbnail, object-render, and `LayerFrame::clear` paths now use the same tested backend viewport query, clear-color query, and clear-color restore helpers, removing direct diff --git a/src/legacy_ui_gl_dispatch.h b/src/legacy_ui_gl_dispatch.h index 1983c39..bd14c18 100644 --- a/src/legacy_ui_gl_dispatch.h +++ b/src/legacy_ui_gl_dispatch.h @@ -13,11 +13,21 @@ inline void enable_opengl_state(std::uint32_t state) noexcept glEnable(static_cast(state)); } +inline std::uint8_t is_opengl_state_enabled(std::uint32_t state) noexcept +{ + return static_cast(glIsEnabled(static_cast(state))); +} + inline void disable_opengl_state(std::uint32_t state) noexcept { glDisable(static_cast(state)); } +inline void activate_opengl_texture(std::uint32_t texture_unit) noexcept +{ + glActiveTexture(static_cast(texture_unit)); +} + inline void clear_opengl_buffer(std::uint32_t mask) noexcept { glClear(static_cast(mask)); @@ -33,6 +43,11 @@ inline void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t wid glViewport(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); } +inline void set_opengl_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept +{ + glScissor(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); +} + inline void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept { glBindTexture(static_cast(target), static_cast(texture)); @@ -61,6 +76,17 @@ inline std::array query_viewport(const char* context) return viewport; } +inline pp::renderer::gl::OpenGlViewportRect query_viewport_rect(const char* context) +{ + const auto result = pp::renderer::gl::query_opengl_viewport( + pp::renderer::gl::OpenGlViewportQueryDispatch { + .get_integer = get_opengl_integer, + }); + if (!result.ok()) + LOG("%s viewport query dispatch failed because: %s", context, result.status().message); + return result.value(); +} + inline std::array query_clear_color(const char* context) { std::array color {}; @@ -69,6 +95,20 @@ inline std::array query_clear_color(const char* context) return color; } +inline bool query_capability(std::uint32_t state, const char* context) +{ + const auto result = pp::renderer::gl::query_opengl_capability_state( + state, + pp::renderer::gl::OpenGlCapabilityStateQueryDispatch { + .is_enabled = is_opengl_state_enabled, + }); + if (!result.ok()) { + LOG("%s capability query failed because: %s", context, result.status().message); + return false; + } + return result.value(); +} + inline void set_capability(std::uint32_t state, bool enabled, const char* context) { const auto status = pp::renderer::gl::apply_opengl_capability( @@ -82,6 +122,17 @@ inline void set_capability(std::uint32_t state, bool enabled, const char* contex LOG("%s capability dispatch failed because: %s", context, status.message); } +inline void activate_texture_unit(std::uint32_t unit_index, const char* context) +{ + const auto status = pp::renderer::gl::activate_opengl_texture_unit( + unit_index, + pp::renderer::gl::OpenGlActiveTextureDispatch { + .active_texture = activate_opengl_texture, + }); + if (!status.ok()) + LOG("%s active texture dispatch failed because: %s", context, status.message); +} + inline void set_blend_enabled(bool enabled, const char* context) { set_capability(pp::renderer::gl::blend_state(), enabled, context); @@ -108,6 +159,30 @@ inline void apply_viewport( LOG("%s viewport dispatch failed because: %s", context, status.message); } +inline void apply_scissor_rect( + std::int32_t x, + std::int32_t y, + std::int32_t width, + std::int32_t height, + const char* context) +{ + const auto status = pp::renderer::gl::apply_opengl_scissor_rect( + pp::renderer::gl::OpenGlScissorRect { + .enabled = 1U, + .x = x, + .y = y, + .width = width, + .height = height, + }, + pp::renderer::gl::OpenGlScissorDispatch { + .enable = enable_opengl_state, + .disable = disable_opengl_state, + .scissor = set_opengl_scissor, + }); + if (!status.ok()) + LOG("%s scissor dispatch failed because: %s", context, status.message); +} + inline void clear_color_buffer(std::array color, const char* context) { const auto status = pp::renderer::gl::clear_opengl_render_target( diff --git a/src/node_canvas.cpp b/src/node_canvas.cpp index 99d2b94..fec8bb8 100644 --- a/src/node_canvas.cpp +++ b/src/node_canvas.cpp @@ -12,6 +12,7 @@ #include "app_core/document_animation.h" #include "app.h" #include "node_panel_grid.h" +#include "legacy_ui_gl_dispatch.h" #include "legacy_canvas_tool_services.h" #include "legacy_history_services.h" #include "log.h" @@ -24,174 +25,49 @@ namespace { -void activate_opengl_texture(std::uint32_t texture_unit) noexcept -{ - glActiveTexture(static_cast(texture_unit)); -} - -void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept -{ - glBindTexture(static_cast(target), static_cast(texture)); -} - void set_active_texture_unit(std::uint32_t unit_index) { - const auto status = pp::renderer::gl::activate_opengl_texture_unit( - unit_index, - pp::renderer::gl::OpenGlActiveTextureDispatch { - .active_texture = activate_opengl_texture, - }); - if (!status.ok()) - LOG("NodeCanvas active texture dispatch failed because: %s", status.message); + pp::legacy::ui_gl::activate_texture_unit(unit_index, "NodeCanvas"); } void unbind_texture_2d() { - const auto status = pp::renderer::gl::bind_opengl_texture_2d( - 0U, - pp::renderer::gl::OpenGlTexture2DBindDispatch { - .bind_texture = bind_opengl_texture, - }); - if (!status.ok()) - LOG("NodeCanvas texture unbind dispatch failed because: %s", status.message); -} - -void enable_opengl_state(std::uint32_t state) noexcept -{ - glEnable(static_cast(state)); -} - -void disable_opengl_state(std::uint32_t state) noexcept -{ - glDisable(static_cast(state)); -} - -std::uint8_t is_opengl_state_enabled(std::uint32_t state) noexcept -{ - return static_cast(glIsEnabled(static_cast(state))); -} - -void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept -{ - glViewport(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); -} - -void set_opengl_clear_color(float r, float g, float b, float a) noexcept -{ - glClearColor(r, g, b, a); -} - -void clear_opengl_buffer(std::uint32_t mask) noexcept -{ - glClear(static_cast(mask)); -} - -void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept -{ - GLint raw_values[4] {}; - glGetIntegerv(static_cast(name), raw_values); - values[0] = static_cast(raw_values[0]); - values[1] = static_cast(raw_values[1]); - values[2] = static_cast(raw_values[2]); - values[3] = static_cast(raw_values[3]); -} - -void get_opengl_float(std::uint32_t name, float* values) noexcept -{ - glGetFloatv(static_cast(name), values); + pp::legacy::ui_gl::unbind_texture_2d("NodeCanvas"); } void apply_node_canvas_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) { - const auto status = pp::renderer::gl::apply_opengl_viewport( - pp::renderer::gl::OpenGlViewportRect { - .x = x, - .y = y, - .width = width, - .height = height, - }, - pp::renderer::gl::OpenGlViewportDispatch { - .viewport = set_opengl_viewport, - }); - if (!status.ok()) - LOG("NodeCanvas viewport dispatch failed because: %s", status.message); + pp::legacy::ui_gl::apply_viewport(x, y, width, height, "NodeCanvas"); } pp::renderer::gl::OpenGlViewportRect query_node_canvas_viewport() { - const auto result = pp::renderer::gl::query_opengl_viewport( - pp::renderer::gl::OpenGlViewportQueryDispatch { - .get_integer = get_opengl_integer, - }); - if (!result.ok()) { - LOG("NodeCanvas viewport query dispatch failed because: %s", result.status().message); - } - return result.value(); + return pp::legacy::ui_gl::query_viewport_rect("NodeCanvas"); } std::array query_node_canvas_clear_color() { - const auto result = pp::renderer::gl::query_opengl_clear_color( - pp::renderer::gl::OpenGlClearColorQueryDispatch { - .get_float = get_opengl_float, - }); - if (!result.ok()) { - LOG("NodeCanvas clear-color query dispatch failed because: %s", result.status().message); - } - return result.value(); + return pp::legacy::ui_gl::query_clear_color("NodeCanvas"); } void apply_node_canvas_clear_color(std::array color) { - const auto status = pp::renderer::gl::apply_opengl_clear_color( - color, - pp::renderer::gl::OpenGlClearColorDispatch { - .clear_color = set_opengl_clear_color, - }); - if (!status.ok()) - LOG("NodeCanvas clear-color dispatch failed because: %s", status.message); + pp::legacy::ui_gl::set_clear_color(color, "NodeCanvas"); } void clear_node_canvas_color_buffer(std::array color) { - const auto status = pp::renderer::gl::clear_opengl_render_target( - pp::renderer::gl::OpenGlDefaultClear { - .color = color, - .mask = pp::renderer::gl::framebuffer_color_buffer_mask(), - }, - pp::renderer::gl::OpenGlClearDispatch { - .clear_color = set_opengl_clear_color, - .clear = clear_opengl_buffer, - }); - if (!status.ok()) - LOG("NodeCanvas color-buffer clear dispatch failed because: %s", status.message); + pp::legacy::ui_gl::clear_color_buffer(color, "NodeCanvas"); } void apply_node_canvas_capability(std::uint32_t state, bool enabled) { - const auto status = pp::renderer::gl::apply_opengl_capability( - state, - enabled, - pp::renderer::gl::OpenGlCapabilityDispatch { - .enable = enable_opengl_state, - .disable = disable_opengl_state, - }); - if (!status.ok()) - LOG("NodeCanvas capability dispatch failed because: %s", status.message); + pp::legacy::ui_gl::set_capability(state, enabled, "NodeCanvas"); } bool query_node_canvas_capability(std::uint32_t state) { - const auto result = pp::renderer::gl::query_opengl_capability_state( - state, - pp::renderer::gl::OpenGlCapabilityStateQueryDispatch { - .is_enabled = is_opengl_state_enabled, - }); - if (!result.ok()) { - LOG("NodeCanvas capability query failed because: %s", result.status().message); - return false; - } - return result.value(); + return pp::legacy::ui_gl::query_capability(state, "NodeCanvas"); } pp::renderer::RenderDeviceFeatures node_canvas_stroke_composite_features() noexcept diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index aa05df0..2248740 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -6,6 +6,7 @@ #include "bezier.h" #include "canvas.h" #include "app.h" +#include "legacy_ui_gl_dispatch.h" #include "paint_renderer/compositor.h" #include "renderer_gl/opengl_capabilities.h" #include "util.h" @@ -41,159 +42,44 @@ pp::paint_renderer::CanvasStrokeFeedbackPlan stroke_preview_destination_feedback return fallback; } -void activate_opengl_texture(std::uint32_t texture_unit) noexcept -{ - glActiveTexture(static_cast(texture_unit)); -} - -void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept -{ - glBindTexture(static_cast(target), static_cast(texture)); -} - void set_active_texture_unit(std::uint32_t unit_index) { - const auto status = pp::renderer::gl::activate_opengl_texture_unit( - unit_index, - pp::renderer::gl::OpenGlActiveTextureDispatch { - .active_texture = activate_opengl_texture, - }); - if (!status.ok()) - LOG("NodeStrokePreview active texture dispatch failed because: %s", status.message); + pp::legacy::ui_gl::activate_texture_unit(unit_index, "NodeStrokePreview"); } void unbind_texture_2d() { - const auto status = pp::renderer::gl::bind_opengl_texture_2d( - 0U, - pp::renderer::gl::OpenGlTexture2DBindDispatch { - .bind_texture = bind_opengl_texture, - }); - if (!status.ok()) - LOG("NodeStrokePreview texture unbind dispatch failed because: %s", status.message); -} - -void enable_opengl_state(std::uint32_t state) noexcept -{ - glEnable(static_cast(state)); -} - -void disable_opengl_state(std::uint32_t state) noexcept -{ - glDisable(static_cast(state)); -} - -void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept -{ - glViewport(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); -} - -void set_opengl_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept -{ - glScissor(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); -} - -void set_opengl_clear_color(float r, float g, float b, float a) noexcept -{ - glClearColor(r, g, b, a); -} - -void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept -{ - GLint raw_values[4] {}; - glGetIntegerv(static_cast(name), raw_values); - values[0] = static_cast(raw_values[0]); - values[1] = static_cast(raw_values[1]); - values[2] = static_cast(raw_values[2]); - values[3] = static_cast(raw_values[3]); -} - -void get_opengl_float(std::uint32_t name, float* values) noexcept -{ - glGetFloatv(static_cast(name), values); + pp::legacy::ui_gl::unbind_texture_2d("NodeStrokePreview"); } void apply_stroke_preview_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) { - const auto status = pp::renderer::gl::apply_opengl_viewport( - pp::renderer::gl::OpenGlViewportRect { - .x = x, - .y = y, - .width = width, - .height = height, - }, - pp::renderer::gl::OpenGlViewportDispatch { - .viewport = set_opengl_viewport, - }); - if (!status.ok()) - LOG("NodeStrokePreview viewport dispatch failed because: %s", status.message); + pp::legacy::ui_gl::apply_viewport(x, y, width, height, "NodeStrokePreview"); } pp::renderer::gl::OpenGlViewportRect query_stroke_preview_viewport() { - const auto result = pp::renderer::gl::query_opengl_viewport( - pp::renderer::gl::OpenGlViewportQueryDispatch { - .get_integer = get_opengl_integer, - }); - if (!result.ok()) { - LOG("NodeStrokePreview viewport query dispatch failed because: %s", result.status().message); - } - return result.value(); + return pp::legacy::ui_gl::query_viewport_rect("NodeStrokePreview"); } std::array query_stroke_preview_clear_color() { - const auto result = pp::renderer::gl::query_opengl_clear_color( - pp::renderer::gl::OpenGlClearColorQueryDispatch { - .get_float = get_opengl_float, - }); - if (!result.ok()) { - LOG("NodeStrokePreview clear-color query dispatch failed because: %s", result.status().message); - } - return result.value(); + return pp::legacy::ui_gl::query_clear_color("NodeStrokePreview"); } void apply_stroke_preview_clear_color(std::array color) { - const auto status = pp::renderer::gl::apply_opengl_clear_color( - color, - pp::renderer::gl::OpenGlClearColorDispatch { - .clear_color = set_opengl_clear_color, - }); - if (!status.ok()) - LOG("NodeStrokePreview clear-color dispatch failed because: %s", status.message); + pp::legacy::ui_gl::set_clear_color(color, "NodeStrokePreview"); } void apply_stroke_preview_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) { - const auto status = pp::renderer::gl::apply_opengl_scissor_rect( - pp::renderer::gl::OpenGlScissorRect { - .enabled = 1U, - .x = x, - .y = y, - .width = width, - .height = height, - }, - pp::renderer::gl::OpenGlScissorDispatch { - .enable = enable_opengl_state, - .disable = disable_opengl_state, - .scissor = set_opengl_scissor, - }); - if (!status.ok()) - LOG("NodeStrokePreview scissor dispatch failed because: %s", status.message); + pp::legacy::ui_gl::apply_scissor_rect(x, y, width, height, "NodeStrokePreview"); } void apply_stroke_preview_capability(std::uint32_t state, bool enabled) { - const auto status = pp::renderer::gl::apply_opengl_capability( - state, - enabled, - pp::renderer::gl::OpenGlCapabilityDispatch { - .enable = enable_opengl_state, - .disable = disable_opengl_state, - }); - if (!status.ok()) - LOG("NodeStrokePreview capability dispatch failed because: %s", status.message); + pp::legacy::ui_gl::set_capability(state, enabled, "NodeStrokePreview"); } }