From 96ff1c41e260d61b8594e1b2305a9aa188dc3bbf Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 5 Jun 2026 14:51:40 +0200 Subject: [PATCH] Share retained mesh dispatch bridge --- docs/modernization/build-inventory.md | 16 +-- docs/modernization/debt.md | 9 +- docs/modernization/roadmap.md | 29 ++-- src/font.cpp | 124 ++---------------- src/legacy_gl_mesh_dispatch.h | 182 ++++++++++++++++++++++++++ src/node_colorwheel.cpp | 86 ++++++------ src/shape.cpp | 177 ++++--------------------- 7 files changed, 298 insertions(+), 325 deletions(-) create mode 100644 src/legacy_gl_mesh_dispatch.h diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 530245b..d7bb531 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -465,10 +465,11 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p validates renderer API primitive-topology to OpenGL draw-mode mapping, Shape index-type, fill/stroke primitive-mode, buffer target, static upload usage, and vertex attribute component/normalization mapping used by - the legacy mesh draw path. Legacy `Shape` mesh buffer/VAO creation, zero-byte - dynamic-buffer creation, dynamic vertex/index uploads, fill/stroke draw - calls, and buffer/VAO deletion now consume tested dispatch contracts here, - plus the PanoPainter cube-face to OpenGL + the legacy mesh draw path. Retained `Shape`, `TextMesh`, and + `NodeColorWheel` mesh buffer/VAO creation, zero-byte dynamic-buffer creation, + dynamic vertex/index uploads, fill/stroke/text draw calls, and buffer/VAO + deletion now consume tested dispatch contracts here through + `legacy_gl_mesh_dispatch`, plus the PanoPainter cube-face to OpenGL texture-target mapping used by `TextureCube`. It also owns and validates sampler wrap S/T/R, min/mag filter, and desktop border-color parameter mapping used by legacy `Sampler`, plus renderer API @@ -511,7 +512,7 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p texture unit selection also consume the backend mapping. Text mesh buffer/VAO creation, deferred index/vertex uploads, indexed draw calls, and draw-time texture-unit activation now consume tested `pp_renderer_gl` - dispatch contracts too. Canvas undo/redo dirty-region texture updates and + dispatch contracts through the shared retained mesh bridge too. Canvas undo/redo dirty-region texture updates and readbacks also consume the backend-owned 2D texture target, RGBA pixel format, and unsigned-byte component mapping; canvas stroke commit, thumbnail, and object-draw history paths now consume tested capability-state query @@ -523,9 +524,8 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p `NodeImage` drawing and remote-image texture creation also consume backend-owned mipmapped sampler filters, blend-state tokens, and RGBA8/RGBA texture format mapping. - `NodeColorWheel` triangle-buffer setup and draw-state handling also consume - backend-owned array-buffer, static-upload, vertex-attribute, primitive-mode, - and blend-state tokens. + `NodeColorWheel` triangle-buffer setup now shares the retained mesh bridge, + and its draw-state handling also consumes backend-owned blend-state tokens. Simple UI text, text-input, border, scroll, and animation timeline draw paths also consume backend-owned blend-state tokens. Canvas layer cube/equirect generation, clear, restore, and snapshot paths diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 234bdec..ce38f1d 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -378,6 +378,13 @@ agent or engineer to remove them without reconstructing context from chat. readback, map, unmap, and delete dispatch now share `legacy_gl_pixel_buffer_dispatch`. Renderer services still need to own sampler and pixel-buffer lifetime before these bridges can be removed. +- 2026-06-05: DEBT-0036 was narrowed again. Retained `Shape`, `TextMesh`, and + `NodeColorWheel` mesh buffer/VAO creation, dynamic vertex/index uploads, + fill/stroke/text draws, and buffer/VAO deletion now share + `legacy_gl_mesh_dispatch`, so `src/shape.cpp`, `src/font.cpp`, and + `src/node_colorwheel.cpp` no longer carry duplicated raw mesh callback + clusters. Renderer services still need to own mesh resource lifetime before + this bridge can be removed. ## Open Debt @@ -416,7 +423,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 share `legacy_ui_gl_dispatch` for active-texture selection, cube texture binding, viewport execution, blend capability execution, clear-color query/restore, and color-buffer clear adapter endpoints backed by tested `pp_renderer_gl` dispatch helpers, while the cube-face framebuffer-to-texture copy now uses the shared retained `copy_framebuffer_to_texture_target` utility bridge backed by tested `pp_renderer_gl` dispatch and remains tracked by DEBT-0036 until renderer services own copy execution, `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; its active-texture, depth/blend capability query/apply, viewport query/execution, depth-clear, and color-write-mask adapter endpoints now share `legacy_ui_gl_dispatch`, 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; their active-texture, capability query/apply, viewport, read-framebuffer query, and RGBA8 pixel-readback adapter endpoints now share `legacy_ui_gl_dispatch`, 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, retained `Canvas` stroke/object/thumbnail/export/frame-clear state endpoints now share `legacy_ui_gl_dispatch` for active-texture selection, fallback texture unbind, viewport/scissor execution, viewport and clear-color query, clear-color restore, and capability query/apply adapter endpoints, retained Canvas and RTT depth renderbuffer allocation/attachment/delete now share `legacy_gl_renderbuffer_dispatch` while renderer-resource ownership remains retained, retained `Texture2D`, `TextureCube`, and RTT texture allocation/delete/bind/parameter/update/mipmap dispatch now share `legacy_gl_texture_dispatch` while renderer-resource ownership remains retained, retained `Texture2D` readback plus RTT framebuffer allocation/delete/bind/restore/blit/readback and PBO readback dispatch now share `legacy_gl_framebuffer_dispatch` while renderer-resource ownership remains retained, retained Sampler create/parameter/border/bind dispatch shares `legacy_gl_sampler_dispatch` and retained PBO allocation/readback/map/unmap/delete dispatch shares `legacy_gl_pixel_buffer_dispatch` while renderer-resource ownership remains retained, and retained `CanvasLayer` frame-clear draw-state paths route saved 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, grid lightmap/heightmap mesh rendering, 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 share `legacy_ui_gl_dispatch` for active-texture selection, cube texture binding, viewport execution, blend capability execution, clear-color query/restore, and color-buffer clear adapter endpoints backed by tested `pp_renderer_gl` dispatch helpers, while the cube-face framebuffer-to-texture copy now uses the shared retained `copy_framebuffer_to_texture_target` utility bridge backed by tested `pp_renderer_gl` dispatch and remains tracked by DEBT-0036 until renderer services own copy execution, `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; its active-texture, depth/blend capability query/apply, viewport query/execution, depth-clear, and color-write-mask adapter endpoints now share `legacy_ui_gl_dispatch`, 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; their active-texture, capability query/apply, viewport, read-framebuffer query, and RGBA8 pixel-readback adapter endpoints now share `legacy_ui_gl_dispatch`, 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, retained `Canvas` stroke/object/thumbnail/export/frame-clear state endpoints now share `legacy_ui_gl_dispatch` for active-texture selection, fallback texture unbind, viewport/scissor execution, viewport and clear-color query, clear-color restore, and capability query/apply adapter endpoints, retained Canvas and RTT depth renderbuffer allocation/attachment/delete now share `legacy_gl_renderbuffer_dispatch` while renderer-resource ownership remains retained, retained `Texture2D`, `TextureCube`, and RTT texture allocation/delete/bind/parameter/update/mipmap dispatch now share `legacy_gl_texture_dispatch` while renderer-resource ownership remains retained, retained `Texture2D` readback plus RTT framebuffer allocation/delete/bind/restore/blit/readback and PBO readback dispatch now share `legacy_gl_framebuffer_dispatch` while renderer-resource ownership remains retained, retained Sampler create/parameter/border/bind dispatch shares `legacy_gl_sampler_dispatch` and retained PBO allocation/readback/map/unmap/delete dispatch shares `legacy_gl_pixel_buffer_dispatch` while renderer-resource ownership remains retained, retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation/upload/draw/delete dispatch now share `legacy_gl_mesh_dispatch` while renderer-resource ownership remains retained, and retained `CanvasLayer` frame-clear draw-state paths route saved 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, grid lightmap/heightmap mesh rendering, 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 f3c5f9b..a6b3f5b 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -1176,10 +1176,11 @@ 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 -tokens, also live in `pp_renderer_gl`. Legacy `Shape` mesh buffer/VAO -creation, dynamic vertex/index uploads, fill/stroke draws, and buffer/VAO -deletion now execute through tested `pp_renderer_gl` dispatch contracts, -leaving the retained shape utility with thin GL adapter functions. The +tokens, also live in `pp_renderer_gl`. Retained `Shape`, `TextMesh`, and +`NodeColorWheel` mesh buffer/VAO creation, dynamic vertex/index uploads, +fill/stroke/text draws, and buffer/VAO deletion now execute through tested +`pp_renderer_gl` dispatch contracts via the shared retained +`legacy_gl_mesh_dispatch` raw callback bridge. The PanoPainter cube-face to OpenGL texture-target mapping used by `TextureCube` also lives in `pp_renderer_gl`. The legacy app delegates extension, upload-format, @@ -1216,8 +1217,8 @@ formats, text mesh buffer targets, attribute component/normalization, draw primitive/index type, upload usage, and active texture unit selection also delegate to `pp_renderer_gl`; text mesh buffer/VAO creation, deferred index and vertex uploads, indexed draw calls, and text draw texture-unit activation -now execute through the same tested dispatch contracts used by `Shape`, leaving -the retained `Font` utility with thin GL adapter functions for mesh operations. +now execute through the same tested dispatch contracts used by `Shape` through +`legacy_gl_mesh_dispatch`. Canvas undo/redo dirty-region texture updates and readbacks now also execute through retained `RTT` helpers backed by `pp_renderer_gl`, including 2D texture target, dirty-region offsets, RGBA pixel format, and unsigned-byte component @@ -2322,13 +2323,10 @@ Results: attribute rebinding, active-uniform count/enumeration, and uniform-location discovery also execute through tested `pp_renderer_gl` dispatch contracts, leaving only thin GL adapter functions in the retained `Shader` utility. - Legacy `Shape` mesh buffer/VAO creation, zero-byte dynamic-buffer creation, - dynamic buffer uploads, indexed and non-indexed draws, and resource deletion - now execute through tested `pp_renderer_gl` dispatch contracts, leaving only - thin GL adapter functions in the retained shape utility. - Legacy `Font` text mesh creation now covers the one-VAO/deferred-upload case, - and its dynamic index/vertex uploads and indexed draw calls execute through - the same tested dispatch contracts. + Retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation, + zero-byte dynamic-buffer creation, dynamic buffer uploads, indexed and + non-indexed draws, and resource deletion now execute through tested + `pp_renderer_gl` dispatch contracts via `legacy_gl_mesh_dispatch`. - `pp_renderer_gl_command_plan_tests` covers the headless OpenGL command planner for recorded render-pass clear masks/values, viewport/scissor state, blend/depth/sampler state, texture format mapping, mesh/draw primitive modes, @@ -2573,6 +2571,11 @@ Results: `legacy_gl_pixel_buffer_dispatch`; this removes another pair of raw resource callback clusters from `src/texture.cpp` and `src/rtt.cpp` while sampler and pixel-buffer ownership remain retained under DEBT-0036. +- Retained `Shape`, `TextMesh`, and `NodeColorWheel` mesh buffer/VAO creation, + dynamic vertex/index uploads, fill/stroke/text draws, and buffer/VAO deletion + now share `legacy_gl_mesh_dispatch`, removing duplicated raw mesh callback + clusters from `src/shape.cpp`, `src/font.cpp`, and `src/node_colorwheel.cpp` + while mesh resource ownership remains retained under DEBT-0036. - Canvas draw-merge shader-blend selection now consumes the extracted `pp_paint_renderer` stroke composite planner for current layer and primary brush blend modes, while preserving legacy OpenGL compositing execution under diff --git a/src/font.cpp b/src/font.cpp index 17393e8..307cbe0 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "log.h" #include "font.h" +#include "legacy_gl_mesh_dispatch.h" #include "shader.h" #include "asset.h" #include "util.h" @@ -23,75 +24,6 @@ namespace { return static_cast(pp::renderer::gl::texture_format_for_channel_count(1U).pixel_format); } -void gen_buffers_adapter(std::uint32_t count, std::uint32_t* ids) noexcept -{ - glGenBuffers(static_cast(count), ids); -} - -void bind_buffer_adapter(std::uint32_t target, std::uint32_t buffer) noexcept -{ - glBindBuffer(static_cast(target), static_cast(buffer)); -} - -void buffer_data_adapter( - std::uint32_t target, - std::intptr_t byte_count, - const void* data, - std::uint32_t usage) noexcept -{ - glBufferData(static_cast(target), static_cast(byte_count), data, static_cast(usage)); -} - -void gen_vertex_arrays_adapter(std::uint32_t count, std::uint32_t* ids) noexcept -{ - glGenVertexArrays(static_cast(count), ids); -} - -void bind_vertex_array_adapter(std::uint32_t vertex_array) noexcept -{ - glBindVertexArray(static_cast(vertex_array)); -} - -void enable_vertex_attrib_array_adapter(std::uint32_t index) noexcept -{ - glEnableVertexAttribArray(static_cast(index)); -} - -void vertex_attrib_pointer_adapter( - std::uint32_t index, - std::int32_t component_count, - std::uint32_t component_type, - std::uint8_t normalized, - std::int32_t stride, - const void* offset) noexcept -{ - glVertexAttribPointer( - static_cast(index), - static_cast(component_count), - static_cast(component_type), - static_cast(normalized), - static_cast(stride), - offset); -} - -void draw_elements_adapter( - std::uint32_t mode, - std::int32_t count, - std::uint32_t index_type, - const void* index_offset) noexcept -{ - glDrawElements( - static_cast(mode), - static_cast(count), - static_cast(index_type), - index_offset); -} - -void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t count) noexcept -{ - glDrawArrays(static_cast(mode), static_cast(first), static_cast(count)); -} - void activate_texture_adapter(std::uint32_t texture_unit) noexcept { glActiveTexture(static_cast(texture_unit)); @@ -131,36 +63,6 @@ void activate_text_texture_unit(std::uint32_t unit_index) return attributes; } -[[nodiscard]] pp::renderer::gl::OpenGlMeshCreateDispatch text_mesh_create_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlMeshCreateDispatch { - .gen_buffers = gen_buffers_adapter, - .bind_buffer = bind_buffer_adapter, - .buffer_data = buffer_data_adapter, - .gen_vertex_arrays = gen_vertex_arrays_adapter, - .bind_vertex_array = bind_vertex_array_adapter, - .enable_vertex_attrib_array = enable_vertex_attrib_array_adapter, - .vertex_attrib_pointer = vertex_attrib_pointer_adapter, - }; -} - -[[nodiscard]] pp::renderer::gl::OpenGlBufferUploadDispatch text_buffer_upload_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlBufferUploadDispatch { - .bind_buffer = bind_buffer_adapter, - .buffer_data = buffer_data_adapter, - }; -} - -[[nodiscard]] pp::renderer::gl::OpenGlMeshDrawDispatch text_mesh_draw_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlMeshDrawDispatch { - .bind_vertex_array = bind_vertex_array_adapter, - .draw_elements = draw_elements_adapter, - .draw_arrays = draw_arrays_adapter, - }; -} - } std::map FontManager::m_fonts; @@ -312,7 +214,7 @@ bool TextMesh::create() { App::I->render_task([this] { - const auto mesh = pp::renderer::gl::create_opengl_mesh_objects( + const auto mesh = pp::legacy::gl_mesh::create_mesh_objects( pp::renderer::gl::OpenGlMeshUpload { .vertex_data = nullptr, .vertex_byte_count = 0, @@ -322,11 +224,11 @@ bool TextMesh::create() .vertex_array_count = 1U, .attributes = text_mesh_vertex_attributes(), }, - text_mesh_create_dispatch()); - if (mesh.ok()) { - font_buffers[0] = static_cast(mesh.value().vertex_buffer); - font_buffers[1] = static_cast(mesh.value().index_buffer); - font_array = static_cast(mesh.value().vertex_arrays[0]); + "TextMesh::create"); + if (mesh.vertex_buffer != 0U) { + font_buffers[0] = static_cast(mesh.vertex_buffer); + font_buffers[1] = static_cast(mesh.index_buffer); + font_array = static_cast(mesh.vertex_arrays[0]); } }); return true; @@ -415,7 +317,7 @@ void TextMesh::update(const std::string& text, const std::string& font, int size font_array_count = (int)idx.size(); App::I->render_task([&] { - (void)pp::renderer::gl::upload_opengl_buffer_data( + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::element_array_buffer_target(), .buffer_id = font_buffers[1], @@ -423,8 +325,8 @@ void TextMesh::update(const std::string& text, const std::string& font, int size .byte_count = static_cast(idx.size() * sizeof(GLushort)), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - text_buffer_upload_dispatch()); - (void)pp::renderer::gl::upload_opengl_buffer_data( + "TextMesh::update indices"); + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::array_buffer_target(), .buffer_id = font_buffers[0], @@ -432,7 +334,7 @@ void TextMesh::update(const std::string& text, const std::string& font, int size .byte_count = static_cast(v.size() * sizeof(glm::vec4)), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - text_buffer_upload_dispatch()); + "TextMesh::update vertices"); }); } } @@ -446,7 +348,7 @@ void TextMesh::draw() f.font_tex.bind(); FontManager::m_sampler.bind(0); - (void)pp::renderer::gl::draw_opengl_mesh( + (void)pp::legacy::gl_mesh::draw_mesh( pp::renderer::gl::OpenGlMeshDraw { .vertex_array = font_array, .mode = pp::renderer::gl::primitive_mode_for_fill_count(3U), @@ -455,7 +357,7 @@ void TextMesh::draw() .index_type = pp::renderer::gl::index_type_for_index_size(sizeof(GLushort)), .index_offset = nullptr, }, - text_mesh_draw_dispatch()); + "TextMesh::draw"); f.font_tex.unbind(); FontManager::m_sampler.unbind(); diff --git a/src/legacy_gl_mesh_dispatch.h b/src/legacy_gl_mesh_dispatch.h new file mode 100644 index 0000000..8db3704 --- /dev/null +++ b/src/legacy_gl_mesh_dispatch.h @@ -0,0 +1,182 @@ +#pragma once + +#include +#include + +#include "log.h" +#include "renderer_gl/opengl_capabilities.h" + +namespace pp::legacy::gl_mesh { + +inline void gen_opengl_buffers(std::uint32_t count, std::uint32_t* ids) noexcept +{ + glGenBuffers(static_cast(count), reinterpret_cast(ids)); +} + +inline void delete_opengl_buffers(std::uint32_t count, const std::uint32_t* ids) noexcept +{ + glDeleteBuffers(static_cast(count), reinterpret_cast(ids)); +} + +inline void bind_opengl_buffer(std::uint32_t target, std::uint32_t buffer) noexcept +{ + glBindBuffer(static_cast(target), static_cast(buffer)); +} + +inline void set_opengl_buffer_data( + std::uint32_t target, + std::intptr_t byte_count, + const void* data, + std::uint32_t usage) noexcept +{ + glBufferData( + static_cast(target), + static_cast(byte_count), + data, + static_cast(usage)); +} + +inline void gen_opengl_vertex_arrays(std::uint32_t count, std::uint32_t* ids) noexcept +{ + glGenVertexArrays(static_cast(count), reinterpret_cast(ids)); +} + +inline void delete_opengl_vertex_arrays(std::uint32_t count, const std::uint32_t* ids) noexcept +{ + glDeleteVertexArrays(static_cast(count), reinterpret_cast(ids)); +} + +inline void bind_opengl_vertex_array(std::uint32_t vertex_array) noexcept +{ + glBindVertexArray(static_cast(vertex_array)); +} + +inline void enable_opengl_vertex_attrib_array(std::uint32_t index) noexcept +{ + glEnableVertexAttribArray(static_cast(index)); +} + +inline void set_opengl_vertex_attrib_pointer( + std::uint32_t index, + std::int32_t component_count, + std::uint32_t component_type, + std::uint8_t normalized, + std::int32_t stride, + const void* offset) noexcept +{ + glVertexAttribPointer( + static_cast(index), + static_cast(component_count), + static_cast(component_type), + static_cast(normalized), + static_cast(stride), + offset); +} + +inline void draw_opengl_elements( + std::uint32_t mode, + std::int32_t count, + std::uint32_t index_type, + const void* index_offset) noexcept +{ + glDrawElements( + static_cast(mode), + static_cast(count), + static_cast(index_type), + index_offset); +} + +inline void draw_opengl_arrays(std::uint32_t mode, std::int32_t first, std::int32_t count) noexcept +{ + glDrawArrays(static_cast(mode), static_cast(first), static_cast(count)); +} + +inline pp::renderer::gl::OpenGlMeshCreateDispatch mesh_create_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlMeshCreateDispatch { + .gen_buffers = gen_opengl_buffers, + .bind_buffer = bind_opengl_buffer, + .buffer_data = set_opengl_buffer_data, + .gen_vertex_arrays = gen_opengl_vertex_arrays, + .bind_vertex_array = bind_opengl_vertex_array, + .enable_vertex_attrib_array = enable_opengl_vertex_attrib_array, + .vertex_attrib_pointer = set_opengl_vertex_attrib_pointer, + }; +} + +inline pp::renderer::gl::OpenGlBufferUploadDispatch buffer_upload_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlBufferUploadDispatch { + .bind_buffer = bind_opengl_buffer, + .buffer_data = set_opengl_buffer_data, + }; +} + +inline pp::renderer::gl::OpenGlMeshDrawDispatch mesh_draw_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlMeshDrawDispatch { + .bind_vertex_array = bind_opengl_vertex_array, + .draw_elements = draw_opengl_elements, + .draw_arrays = draw_opengl_arrays, + }; +} + +inline pp::renderer::gl::OpenGlMeshDeleteDispatch mesh_delete_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlMeshDeleteDispatch { + .delete_buffers = delete_opengl_buffers, + .delete_vertex_arrays = delete_opengl_vertex_arrays, + }; +} + +inline pp::renderer::gl::OpenGlMeshObjects create_mesh_objects( + pp::renderer::gl::OpenGlMeshUpload upload, + const char* context) +{ + const auto mesh = pp::renderer::gl::create_opengl_mesh_objects(upload, mesh_create_dispatch()); + if (!mesh.ok()) { + LOG("%s failed because: %s", context, mesh.status().message); + return {}; + } + return mesh.value(); +} + +inline bool upload_buffer_data(pp::renderer::gl::OpenGlBufferUpload upload, const char* context) +{ + const auto status = pp::renderer::gl::upload_opengl_buffer_data(upload, buffer_upload_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +inline bool draw_mesh(pp::renderer::gl::OpenGlMeshDraw draw, const char* context) +{ + const auto status = pp::renderer::gl::draw_opengl_mesh(draw, mesh_draw_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +inline bool delete_mesh_objects( + std::array buffers, + std::array vertex_arrays, + const char* context) +{ + const auto status = pp::renderer::gl::delete_opengl_mesh_objects( + pp::renderer::gl::OpenGlMeshDelete { + .buffers = buffers, + .vertex_arrays = vertex_arrays, + }, + mesh_delete_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +} // namespace pp::legacy::gl_mesh diff --git a/src/node_colorwheel.cpp b/src/node_colorwheel.cpp index 7f8e683..be7e4ee 100644 --- a/src/node_colorwheel.cpp +++ b/src/node_colorwheel.cpp @@ -1,4 +1,5 @@ #include "pch.h" +#include "legacy_gl_mesh_dispatch.h" #include "legacy_ui_gl_dispatch.h" #include "node_colorwheel.h" #include "renderer_gl/opengl_capabilities.h" @@ -6,6 +7,10 @@ #include "log.h" #include "app.h" +#include +#include +#include + Node* NodeColorWheel::clone_instantiate() const { return new NodeColorWheel; @@ -47,45 +52,47 @@ void NodeColorWheel::loaded() App::I->render_task([&] { - const auto buffer_target = pp::renderer::gl::array_buffer_target(); - const auto upload_usage = pp::renderer::gl::static_draw_buffer_usage(); const auto attribute_type = pp::renderer::gl::vertex_attribute_float_component_type(); const auto attribute_normalized = - static_cast(pp::renderer::gl::vertex_attribute_not_normalized()); + static_cast(pp::renderer::gl::vertex_attribute_not_normalized()); + const std::array attributes { + pp::renderer::gl::OpenGlVertexAttribute { + .index = 0U, + .component_count = 4, + .component_type = attribute_type, + .normalized = attribute_normalized, + .stride = static_cast(sizeof(vertex_t)), + .offset = 0U, + }, + pp::renderer::gl::OpenGlVertexAttribute { + .index = 1U, + .component_count = 2, + .component_type = attribute_type, + .normalized = attribute_normalized, + .stride = static_cast(sizeof(vertex_t)), + .offset = static_cast(offsetof(vertex_t, uvs)), + }, + pp::renderer::gl::OpenGlVertexAttribute { + .index = 2U, + .component_count = 4, + .component_type = attribute_type, + .normalized = attribute_normalized, + .stride = static_cast(sizeof(vertex_t)), + .offset = static_cast(offsetof(vertex_t, col)), + }, + }; - glGenBuffers(1, &buffers); - glBindBuffer(buffer_target, buffers); - glBufferData(buffer_target, vertices.size() * sizeof(vertex_t), vertices.data(), upload_usage); - glBindBuffer(buffer_target, 0); - - glGenVertexArrays(1, &arrays); - glBindVertexArray(arrays); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - glBindBuffer(buffer_target, buffers); - glVertexAttribPointer( - 0, - 4, - attribute_type, - attribute_normalized, - sizeof(vertex_t), - (GLvoid*)0); - glVertexAttribPointer( - 1, - 2, - attribute_type, - attribute_normalized, - sizeof(vertex_t), - (GLvoid*)offsetof(vertex_t, uvs)); - glVertexAttribPointer( - 2, - 4, - attribute_type, - attribute_normalized, - sizeof(vertex_t), - (GLvoid*)offsetof(vertex_t, col)); - glBindVertexArray(0); + const auto mesh = pp::legacy::gl_mesh::create_mesh_objects( + pp::renderer::gl::OpenGlMeshUpload { + .vertex_data = vertices.data(), + .vertex_byte_count = static_cast(vertices.size() * sizeof(vertex_t)), + .indexed = false, + .vertex_array_count = 1U, + .attributes = attributes, + }, + "NodeColorWheel::loaded"); + buffers = static_cast(mesh.vertex_buffer); + arrays = static_cast(mesh.vertex_arrays[0]); }); } @@ -97,13 +104,6 @@ void NodeColorWheel::draw() ShaderManager::u_int(kShaderUniform::Direction, 0); // set horizontal m_circle.draw_fill(); -// ShaderManager::use(kShader::ColorTri); -// ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp); -// ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(m_hsv, 0.f)); -// glBindVertexArray(arrays); -// glDrawArrays(pp::renderer::gl::primitive_mode_for_fill_count(3U), 0, 3); -// glBindVertexArray(0); - ShaderManager::use(kShader::Color); ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp * glm::eulerAngleZ(glm::radians(-360.f * m_hsv.x)) * glm::translate(glm::vec3(.45f,0.f,0.f))); ShaderManager::u_vec4(kShaderUniform::Col, {convert_hsv2rgb({glm::fract(m_hsv.x + 0.5f), 1.f, 1.f}), 1.f}); diff --git a/src/shape.cpp b/src/shape.cpp index 324a478..8c4eebf 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "log.h" +#include "legacy_gl_mesh_dispatch.h" #include "shape.h" #include "app.h" #include "renderer_gl/opengl_capabilities.h" @@ -10,85 +11,6 @@ namespace { -void gen_buffers_adapter(std::uint32_t count, std::uint32_t* ids) noexcept -{ - glGenBuffers(static_cast(count), ids); -} - -void delete_buffers_adapter(std::uint32_t count, const std::uint32_t* ids) noexcept -{ - glDeleteBuffers(static_cast(count), ids); -} - -void bind_buffer_adapter(std::uint32_t target, std::uint32_t buffer) noexcept -{ - glBindBuffer(static_cast(target), static_cast(buffer)); -} - -void buffer_data_adapter( - std::uint32_t target, - std::intptr_t byte_count, - const void* data, - std::uint32_t usage) noexcept -{ - glBufferData(static_cast(target), static_cast(byte_count), data, static_cast(usage)); -} - -void gen_vertex_arrays_adapter(std::uint32_t count, std::uint32_t* ids) noexcept -{ - glGenVertexArrays(static_cast(count), ids); -} - -void delete_vertex_arrays_adapter(std::uint32_t count, const std::uint32_t* ids) noexcept -{ - glDeleteVertexArrays(static_cast(count), ids); -} - -void bind_vertex_array_adapter(std::uint32_t vertex_array) noexcept -{ - glBindVertexArray(static_cast(vertex_array)); -} - -void enable_vertex_attrib_array_adapter(std::uint32_t index) noexcept -{ - glEnableVertexAttribArray(static_cast(index)); -} - -void vertex_attrib_pointer_adapter( - std::uint32_t index, - std::int32_t component_count, - std::uint32_t component_type, - std::uint8_t normalized, - std::int32_t stride, - const void* offset) noexcept -{ - glVertexAttribPointer( - static_cast(index), - static_cast(component_count), - static_cast(component_type), - static_cast(normalized), - static_cast(stride), - offset); -} - -void draw_elements_adapter( - std::uint32_t mode, - std::int32_t count, - std::uint32_t index_type, - const void* index_offset) noexcept -{ - glDrawElements( - static_cast(mode), - static_cast(count), - static_cast(index_type), - index_offset); -} - -void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t count) noexcept -{ - glDrawArrays(static_cast(mode), static_cast(first), static_cast(count)); -} - [[nodiscard]] std::span shape_vertex_attributes() noexcept { static const std::array attributes { @@ -128,44 +50,6 @@ void draw_arrays_adapter(std::uint32_t mode, std::int32_t first, std::int32_t co return attributes; } -[[nodiscard]] pp::renderer::gl::OpenGlMeshCreateDispatch mesh_create_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlMeshCreateDispatch { - .gen_buffers = gen_buffers_adapter, - .bind_buffer = bind_buffer_adapter, - .buffer_data = buffer_data_adapter, - .gen_vertex_arrays = gen_vertex_arrays_adapter, - .bind_vertex_array = bind_vertex_array_adapter, - .enable_vertex_attrib_array = enable_vertex_attrib_array_adapter, - .vertex_attrib_pointer = vertex_attrib_pointer_adapter, - }; -} - -[[nodiscard]] pp::renderer::gl::OpenGlBufferUploadDispatch buffer_upload_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlBufferUploadDispatch { - .bind_buffer = bind_buffer_adapter, - .buffer_data = buffer_data_adapter, - }; -} - -[[nodiscard]] pp::renderer::gl::OpenGlMeshDrawDispatch mesh_draw_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlMeshDrawDispatch { - .bind_vertex_array = bind_vertex_array_adapter, - .draw_elements = draw_elements_adapter, - .draw_arrays = draw_arrays_adapter, - }; -} - -[[nodiscard]] pp::renderer::gl::OpenGlMeshDeleteDispatch mesh_delete_dispatch() noexcept -{ - return pp::renderer::gl::OpenGlMeshDeleteDispatch { - .delete_buffers = delete_buffers_adapter, - .delete_vertex_arrays = delete_vertex_arrays_adapter, - }; -} - } bool Shape::create_buffers(GLushort * idx, GLvoid * vertices, int isize, int vsize) @@ -191,7 +75,7 @@ bool Shape::create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsi { destroy(); - const auto mesh = pp::renderer::gl::create_opengl_mesh_objects( + const auto mesh = pp::legacy::gl_mesh::create_mesh_objects( pp::renderer::gl::OpenGlMeshUpload { .vertex_data = vertices, .vertex_byte_count = vsize, @@ -200,15 +84,15 @@ bool Shape::create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsi .indexed = true, .attributes = shape_vertex_attributes(), }, - mesh_create_dispatch()); - if (!mesh.ok()) { + "Shape::create_buffers indexed"); + if (mesh.vertex_buffer == 0U) { ret = false; return; } - buffers[0] = static_cast(mesh.value().vertex_buffer); - buffers[1] = static_cast(mesh.value().index_buffer); - arrays[0] = static_cast(mesh.value().vertex_arrays[0]); - arrays[1] = static_cast(mesh.value().vertex_arrays[1]); + buffers[0] = static_cast(mesh.vertex_buffer); + buffers[1] = static_cast(mesh.index_buffer); + arrays[0] = static_cast(mesh.vertex_arrays[0]); + arrays[1] = static_cast(mesh.vertex_arrays[1]); }); return ret; } @@ -221,22 +105,22 @@ bool Shape::create_buffers(GLvoid* vertices, int vsize) { destroy(); - const auto mesh = pp::renderer::gl::create_opengl_mesh_objects( + const auto mesh = pp::legacy::gl_mesh::create_mesh_objects( pp::renderer::gl::OpenGlMeshUpload { .vertex_data = vertices, .vertex_byte_count = vsize, .indexed = false, .attributes = shape_vertex_attributes(), }, - mesh_create_dispatch()); - if (!mesh.ok()) { + "Shape::create_buffers"); + if (mesh.vertex_buffer == 0U) { ret = false; return; } - buffers[0] = static_cast(mesh.value().vertex_buffer); - buffers[1] = static_cast(mesh.value().index_buffer); - arrays[0] = static_cast(mesh.value().vertex_arrays[0]); - arrays[1] = static_cast(mesh.value().vertex_arrays[1]); + buffers[0] = static_cast(mesh.vertex_buffer); + buffers[1] = static_cast(mesh.index_buffer); + arrays[0] = static_cast(mesh.vertex_arrays[0]); + arrays[1] = static_cast(mesh.vertex_arrays[1]); }); return ret; } @@ -247,7 +131,7 @@ void Shape::draw_fill() const const auto type = static_cast(pp::renderer::gl::primitive_mode_for_fill_count(count[0])); App::I->render_task([=] { - (void)pp::renderer::gl::draw_opengl_mesh( + (void)pp::legacy::gl_mesh::draw_mesh( pp::renderer::gl::OpenGlMeshDraw { .vertex_array = arrays[0], .mode = type, @@ -256,7 +140,7 @@ void Shape::draw_fill() const .index_type = index_type, .index_offset = ioff[0], }, - mesh_draw_dispatch()); + "Shape::draw_fill"); }); } void Shape::draw_stroke() const @@ -266,7 +150,7 @@ void Shape::draw_stroke() const const auto type = static_cast(pp::renderer::gl::primitive_mode_for_stroke_count(count[1])); App::I->render_task([=] { - (void)pp::renderer::gl::draw_opengl_mesh( + (void)pp::legacy::gl_mesh::draw_mesh( pp::renderer::gl::OpenGlMeshDraw { .vertex_array = arrays[1], .mode = type, @@ -275,7 +159,7 @@ void Shape::draw_stroke() const .index_type = index_type, .index_offset = ioff[1], }, - mesh_draw_dispatch()); + "Shape::draw_stroke"); }); } @@ -283,12 +167,7 @@ void Shape::destroy() { if (App::I) App::I->render_task_async([b1=buffers[0],b2=buffers[1],a1=arrays[0],a2=arrays[1]] { - (void)pp::renderer::gl::delete_opengl_mesh_objects( - pp::renderer::gl::OpenGlMeshDelete { - .buffers = { b1, b2 }, - .vertex_arrays = { a1, a2 }, - }, - mesh_delete_dispatch()); + (void)pp::legacy::gl_mesh::delete_mesh_objects({ b1, b2 }, { a1, a2 }, "Shape::destroy"); }); buffers[0] = buffers[1] = 0; arrays[0] = arrays[1] = 0; @@ -574,7 +453,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g App::I->render_task([this] { - (void)pp::renderer::gl::upload_opengl_buffer_data( + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::array_buffer_target(), .buffer_id = buffers[0], @@ -582,7 +461,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g .byte_count = static_cast(sizeof(vertices)), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - buffer_upload_dispatch()); + "Plane::update_vertices vertices"); static GLushort idx[6 + 8]{ 0, 1, 2, 0, 2, 3, @@ -591,7 +470,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g 2, 3, 3, 0, }; - (void)pp::renderer::gl::upload_opengl_buffer_data( + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::element_array_buffer_target(), .buffer_id = buffers[1], @@ -599,7 +478,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g .byte_count = static_cast(sizeof(idx)), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - buffer_upload_dispatch()); + "Plane::update_vertices indices"); }); } void Circle::create_impl(float radius, int div, GLushort* idx, vertex_t* vertices) @@ -858,7 +737,7 @@ void LineSegment::update_vertices(const glm::vec4 data[2]) static vertex_t vertices[2]; vertices[0] = { data[0], { 0, 0 } }; // A vertices[1] = { data[1], { 0, 1 } }; // B - (void)pp::renderer::gl::upload_opengl_buffer_data( + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::array_buffer_target(), .buffer_id = buffers[0], @@ -866,7 +745,7 @@ void LineSegment::update_vertices(const glm::vec4 data[2]) .byte_count = static_cast(sizeof(vertices)), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - buffer_upload_dispatch()); + "LineSegment::update_vertices"); }); } void DynamicShape::update_vertices(vertex_t* vertices, int vcount) @@ -875,7 +754,7 @@ void DynamicShape::update_vertices(vertex_t* vertices, int vcount) { count[0] = vcount; count[1] = vcount; - (void)pp::renderer::gl::upload_opengl_buffer_data( + (void)pp::legacy::gl_mesh::upload_buffer_data( pp::renderer::gl::OpenGlBufferUpload { .target = pp::renderer::gl::array_buffer_target(), .buffer_id = buffers[0], @@ -883,6 +762,6 @@ void DynamicShape::update_vertices(vertex_t* vertices, int vcount) .byte_count = static_cast(sizeof(vertex_t) * vcount), .usage = pp::renderer::gl::static_draw_buffer_usage(), }, - buffer_upload_dispatch()); + "DynamicShape::update_vertices"); }); }