From d719a5a5e5ba1fd4cfda9496ab6551ffb2eef998 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 5 Jun 2026 14:42:40 +0200 Subject: [PATCH] Share retained sampler and pixel-buffer dispatch bridges --- docs/modernization/build-inventory.md | 6 +- docs/modernization/debt.md | 8 +- docs/modernization/roadmap.md | 12 +- src/legacy_gl_pixel_buffer_dispatch.h | 96 ++++++++++++++++ src/legacy_gl_sampler_dispatch.h | 154 ++++++++++++++++++++++++++ src/rtt.cpp | 90 +-------------- src/texture.cpp | 112 +++---------------- 7 files changed, 294 insertions(+), 184 deletions(-) create mode 100644 src/legacy_gl_pixel_buffer_dispatch.h create mode 100644 src/legacy_gl_sampler_dispatch.h diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 24ca2db..530245b 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -429,7 +429,11 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p tokens used by `Texture2D`, plus cube-map binding and allocation face targets used by `TextureCube`. Retained `Texture2D`, `TextureCube`, and RTT texture allocation, bind, parameter, update, mipmap, and delete dispatch now share - the retained `legacy_gl_texture_dispatch` raw callback bridge. It also owns and + the retained `legacy_gl_texture_dispatch` raw callback bridge. Retained + `Sampler` create, parameter, border-color, bind, and unbind dispatch now + share `legacy_gl_sampler_dispatch`, and retained `PBO` allocation, + framebuffer readback, map, unmap, and delete dispatch now share + `legacy_gl_pixel_buffer_dispatch`. It also owns and validates framebuffer blit color mask and linear/nearest filters used by `RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token mapping, plus the default linear clamp-to-edge render-target texture diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 1309457..234bdec 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -372,6 +372,12 @@ agent or engineer to remove them without reconstructing context from chat. `src/texture.cpp` and `src/rtt.cpp` no longer carry duplicated raw framebuffer/readback callbacks. Renderer services still need to own framebuffer and readback lifetime before this bridge can be removed. +- 2026-06-05: DEBT-0036 was narrowed again. Retained `Sampler` create, + parameter, border-color, bind, and unbind dispatch now share + `legacy_gl_sampler_dispatch`, and retained `PBO` allocation, framebuffer + 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. ## Open Debt @@ -410,7 +416,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, 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, 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 2858279..f3c5f9b 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -1145,7 +1145,11 @@ face targets, RGBA allocation format, and unsigned-byte component type also delegate to `pp_renderer_gl`. RGBA8/RGBA32F readback formats, checked byte-count math, PBO pixel-buffer target/usage/access tokens, and PBO allocation/readback/map/unmap/delete dispatch sequences used by retained recording readbacks now live in -`pp_renderer_gl`. The framebuffer blit color mask and linear/nearest +`pp_renderer_gl`; retained `PBO` allocation, framebuffer readback, map, unmap, +and delete dispatch now share the retained `legacy_gl_pixel_buffer_dispatch` +raw callback bridge. Retained `Sampler` create, parameter, border-color, bind, +and unbind dispatch now share the retained `legacy_gl_sampler_dispatch` raw +callback bridge. The framebuffer blit color mask and linear/nearest filter tokens used by `RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token mapping, plus the default render-target texture parameters and parameter dispatch, texture/renderbuffer @@ -2563,6 +2567,12 @@ Results: `legacy_gl_framebuffer_dispatch`, removing duplicated raw framebuffer and readback callbacks from `src/texture.cpp` and `src/rtt.cpp` while framebuffer/readback ownership remains retained under DEBT-0036. +- Retained `Sampler` create, parameter, border-color, bind, and unbind dispatch + now share `legacy_gl_sampler_dispatch`, and retained `PBO` allocation, + framebuffer readback, map, unmap, and delete dispatch now share + `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. - 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/legacy_gl_pixel_buffer_dispatch.h b/src/legacy_gl_pixel_buffer_dispatch.h new file mode 100644 index 0000000..806acbe --- /dev/null +++ b/src/legacy_gl_pixel_buffer_dispatch.h @@ -0,0 +1,96 @@ +#pragma once + +#include + +#include "legacy_gl_framebuffer_dispatch.h" +#include "renderer_gl/opengl_capabilities.h" + +namespace pp::legacy::gl_pixel_buffer { + +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* map_opengl_buffer_range( + std::uint32_t target, + std::intptr_t offset, + std::intptr_t byte_count, + std::uint32_t access) noexcept +{ + return glMapBufferRange( + static_cast(target), + static_cast(offset), + static_cast(byte_count), + static_cast(access)); +} + +inline void unmap_opengl_buffer(std::uint32_t target) noexcept +{ + glUnmapBuffer(static_cast(target)); +} + +inline pp::renderer::gl::OpenGlPixelBufferAllocationDispatch pixel_buffer_allocation_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlPixelBufferAllocationDispatch { + .gen_buffers = gen_opengl_buffers, + }; +} + +inline pp::renderer::gl::OpenGlPixelBufferReadbackDispatch pixel_buffer_readback_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlPixelBufferReadbackDispatch { + .gen_buffers = gen_opengl_buffers, + .bind_buffer = bind_opengl_buffer, + .buffer_data = set_opengl_buffer_data, + .read_pixels = pp::legacy::gl_framebuffer::read_opengl_pixels, + }; +} + +inline pp::renderer::gl::OpenGlPixelBufferMapDispatch pixel_buffer_map_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlPixelBufferMapDispatch { + .bind_buffer = bind_opengl_buffer, + .map_buffer_range = map_opengl_buffer_range, + }; +} + +inline pp::renderer::gl::OpenGlPixelBufferUnmapDispatch pixel_buffer_unmap_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlPixelBufferUnmapDispatch { + .bind_buffer = bind_opengl_buffer, + .unmap_buffer = unmap_opengl_buffer, + }; +} + +inline pp::renderer::gl::OpenGlPixelBufferDeleteDispatch pixel_buffer_delete_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlPixelBufferDeleteDispatch { + .delete_buffers = delete_opengl_buffers, + }; +} + +} // namespace pp::legacy::gl_pixel_buffer diff --git a/src/legacy_gl_sampler_dispatch.h b/src/legacy_gl_sampler_dispatch.h new file mode 100644 index 0000000..fb6e037 --- /dev/null +++ b/src/legacy_gl_sampler_dispatch.h @@ -0,0 +1,154 @@ +#pragma once + +#include +#include + +#include "log.h" +#include "renderer_gl/opengl_capabilities.h" + +namespace pp::legacy::gl_sampler { + +inline void gen_opengl_samplers(std::uint32_t count, std::uint32_t* ids) noexcept +{ +#if USE_SAMPLER + glGenSamplers(static_cast(count), reinterpret_cast(ids)); +#else + for (std::uint32_t i = 0U; i < count; ++i) { + ids[i] = 0U; + } +#endif +} + +inline void set_opengl_sampler_parameter_i( + std::uint32_t sampler, + std::uint32_t parameter, + std::int32_t value) noexcept +{ +#if USE_SAMPLER + glSamplerParameteri( + static_cast(sampler), + static_cast(parameter), + static_cast(value)); +#else + (void)sampler; + (void)parameter; + (void)value; +#endif +} + +inline void set_opengl_sampler_parameter_fv( + std::uint32_t sampler, + std::uint32_t parameter, + const float* values) noexcept +{ +#if USE_SAMPLER && !defined(__GLES__) + glSamplerParameterfv( + static_cast(sampler), + static_cast(parameter), + values); +#else + (void)sampler; + (void)parameter; + (void)values; +#endif +} + +inline void bind_opengl_sampler(std::uint32_t unit, std::uint32_t sampler) noexcept +{ +#if USE_SAMPLER + glBindSampler(static_cast(unit), static_cast(sampler)); +#else + (void)unit; + (void)sampler; +#endif +} + +inline pp::renderer::gl::OpenGlSamplerCreateDispatch sampler_create_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlSamplerCreateDispatch { + .gen_samplers = gen_opengl_samplers, + .sampler_parameter_i = set_opengl_sampler_parameter_i, + }; +} + +inline pp::renderer::gl::OpenGlSamplerParameterDispatch sampler_parameter_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlSamplerParameterDispatch { + .sampler_parameter_i = set_opengl_sampler_parameter_i, + }; +} + +inline pp::renderer::gl::OpenGlSamplerBorderDispatch sampler_border_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlSamplerBorderDispatch { + .sampler_parameter_fv = set_opengl_sampler_parameter_fv, + }; +} + +inline pp::renderer::gl::OpenGlSamplerBindDispatch sampler_bind_dispatch() noexcept +{ + return pp::renderer::gl::OpenGlSamplerBindDispatch { + .bind_sampler = bind_opengl_sampler, + }; +} + +inline std::uint32_t create_sampler( + std::span parameters, + const char* context) +{ + const auto result = pp::renderer::gl::create_opengl_sampler(parameters, sampler_create_dispatch()); + if (!result.ok()) { + LOG("%s failed because: %s", context, result.status().message); + return 0U; + } + return result.value(); +} + +inline bool set_sampler_parameters( + std::uint32_t sampler_id, + std::span parameters, + const char* context) +{ + const auto status = pp::renderer::gl::set_opengl_sampler_parameters( + sampler_id, + parameters, + sampler_parameter_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +inline bool set_sampler_border_color( + std::uint32_t sampler_id, + std::uint32_t parameter, + const float* rgba, + const char* context) +{ + const auto status = pp::renderer::gl::set_opengl_sampler_border_color( + sampler_id, + parameter, + rgba, + sampler_border_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +inline bool bind_sampler(std::uint32_t unit, std::uint32_t sampler_id, const char* context) +{ + const auto status = pp::renderer::gl::bind_opengl_sampler_object( + unit, + sampler_id, + sampler_bind_dispatch()); + if (!status.ok()) { + LOG("%s failed because: %s", context, status.message); + return false; + } + return true; +} + +} // namespace pp::legacy::gl_sampler diff --git a/src/rtt.cpp b/src/rtt.cpp index 06d9e70..5a966ba 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -4,6 +4,7 @@ #include "util.h" #include "app.h" #include "legacy_gl_framebuffer_dispatch.h" +#include "legacy_gl_pixel_buffer_dispatch.h" #include "legacy_gl_renderbuffer_dispatch.h" #include "legacy_gl_texture_dispatch.h" #include "renderer_gl/opengl_capabilities.h" @@ -32,52 +33,6 @@ void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std:: glColorMask(r, g, b, a); } -void gen_opengl_buffers(std::uint32_t count, std::uint32_t* ids) noexcept -{ - glGenBuffers(static_cast(count), reinterpret_cast(ids)); -} - -void delete_opengl_buffers(std::uint32_t count, const std::uint32_t* ids) noexcept -{ - glDeleteBuffers(static_cast(count), reinterpret_cast(ids)); -} - -void bind_opengl_buffer(std::uint32_t target, std::uint32_t buffer) noexcept -{ - glBindBuffer(static_cast(target), static_cast(buffer)); -} - -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)); -} - -void* map_opengl_buffer_range( - std::uint32_t target, - std::intptr_t offset, - std::intptr_t byte_count, - std::uint32_t access) noexcept -{ - return glMapBufferRange( - static_cast(target), - static_cast(offset), - static_cast(byte_count), - static_cast(access)); -} - -void unmap_opengl_buffer(std::uint32_t target) noexcept -{ - glUnmapBuffer(static_cast(target)); -} - } RTT& RTT::operator=(RTT&& other) @@ -686,9 +641,7 @@ bool PBO::create() noexcept { App::I->render_task([this] { const auto result = pp::renderer::gl::allocate_opengl_pixel_buffer( - pp::renderer::gl::OpenGlPixelBufferAllocationDispatch { - .gen_buffers = gen_opengl_buffers, - }); + pp::legacy::gl_pixel_buffer::pixel_buffer_allocation_dispatch()); if (!result.ok()) { LOG("%s", result.status().message); buffer_id = 0U; @@ -709,12 +662,7 @@ bool PBO::create(RTT& rtt) noexcept width, height, pp::renderer::gl::rgba8_readback_format(), - pp::renderer::gl::OpenGlPixelBufferReadbackDispatch { - .gen_buffers = gen_opengl_buffers, - .bind_buffer = bind_opengl_buffer, - .buffer_data = set_opengl_buffer_data, - .read_pixels = pp::legacy::gl_framebuffer::read_opengl_pixels, - }); + pp::legacy::gl_pixel_buffer::pixel_buffer_readback_dispatch()); rtt.unbindFramebuffer(); if (!result.ok()) { LOG("%s", result.status().message); @@ -733,9 +681,7 @@ void PBO::destroy() noexcept App::I->render_task_async([id=buffer_id] { const auto status = pp::renderer::gl::delete_opengl_pixel_buffer( id, - pp::renderer::gl::OpenGlPixelBufferDeleteDispatch { - .delete_buffers = delete_opengl_buffers, - }); + pp::legacy::gl_pixel_buffer::pixel_buffer_delete_dispatch()); if (!status.ok()) { LOG("%s", status.message); } @@ -748,24 +694,6 @@ void PBO::destroy() noexcept } } -/* -void PBO::bind_read() noexcept -{ - App::I->render_task([this] { - const auto buffer_target = static_cast(pp::renderer::gl::pixel_unpack_buffer_target()); - glBindBuffer(buffer_target, buffer_id); - bound_slot = buffer_target; - }); -} - -void PBO::unbind() noexcept -{ - App::I->render_task([this] { - glBindBuffer(bound_slot, buffer_id); - }); -} -*/ - glm::uint8_t* PBO::map() noexcept { App::I->render_task([this] { @@ -774,10 +702,7 @@ glm::uint8_t* PBO::map() noexcept width, height, pp::renderer::gl::rgba8_readback_format(), - pp::renderer::gl::OpenGlPixelBufferMapDispatch { - .bind_buffer = bind_opengl_buffer, - .map_buffer_range = map_opengl_buffer_range, - }); + pp::legacy::gl_pixel_buffer::pixel_buffer_map_dispatch()); if (!result.ok()) { LOG("%s", result.status().message); mapped_ptr = nullptr; @@ -793,10 +718,7 @@ void PBO::unmap() noexcept App::I->render_task([this] { const auto status = pp::renderer::gl::unmap_opengl_pixel_buffer( buffer_id, - pp::renderer::gl::OpenGlPixelBufferUnmapDispatch { - .bind_buffer = bind_opengl_buffer, - .unmap_buffer = unmap_opengl_buffer, - }); + pp::legacy::gl_pixel_buffer::pixel_buffer_unmap_dispatch()); if (!status.ok()) { LOG("%s", status.message); } diff --git a/src/texture.cpp b/src/texture.cpp index db6029d..67655b5 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -4,70 +4,12 @@ #include "util.h" #include "app.h" #include "legacy_gl_framebuffer_dispatch.h" +#include "legacy_gl_sampler_dispatch.h" #include "legacy_gl_texture_dispatch.h" #include "renderer_gl/opengl_capabilities.h" #include -namespace { - -void gen_opengl_samplers(std::uint32_t count, std::uint32_t* ids) noexcept -{ -#if USE_SAMPLER - glGenSamplers(static_cast(count), reinterpret_cast(ids)); -#else - for (std::uint32_t i = 0U; i < count; ++i) { - ids[i] = 0U; - } -#endif -} - -void set_opengl_sampler_parameter_i( - std::uint32_t sampler, - std::uint32_t parameter, - std::int32_t value) noexcept -{ -#if USE_SAMPLER - glSamplerParameteri( - static_cast(sampler), - static_cast(parameter), - static_cast(value)); -#else - (void)sampler; - (void)parameter; - (void)value; -#endif -} - -void set_opengl_sampler_parameter_fv( - std::uint32_t sampler, - std::uint32_t parameter, - const float* values) noexcept -{ -#if USE_SAMPLER && !defined(__GLES__) - glSamplerParameterfv( - static_cast(sampler), - static_cast(parameter), - values); -#else - (void)sampler; - (void)parameter; - (void)values; -#endif -} - -void bind_opengl_sampler(std::uint32_t unit, std::uint32_t sampler) noexcept -{ -#if USE_SAMPLER - glBindSampler(static_cast(unit), static_cast(sampler)); -#else - (void)unit; - (void)sampler; -#endif -} - -} - std::map TextureManager::m_textures; std::array TextureCube::m_faces_map { static_cast(pp::renderer::gl::cube_face_texture_target(0U)), @@ -419,19 +361,15 @@ bool Sampler::create(GLint filter, GLint wrap) const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap( static_cast(filter), static_cast(wrap)); - const auto sampler = pp::renderer::gl::create_opengl_sampler( + const auto sampler = pp::legacy::gl_sampler::create_sampler( parameters, - pp::renderer::gl::OpenGlSamplerCreateDispatch { - .gen_samplers = gen_opengl_samplers, - .sampler_parameter_i = set_opengl_sampler_parameter_i, - }); - if (!sampler.ok()) + "Sampler::create()"); + if (sampler == 0U) { ret = false; - LOG("Sampler::create() failed because: %s", sampler.status().message); return; } - id = static_cast(sampler.value()); + id = static_cast(sampler); ret = true; }); return ret; @@ -456,14 +394,10 @@ void Sampler::set(GLint filter, GLint wrap) const auto parameters = pp::renderer::gl::sampler_parameters_for_filter_wrap( static_cast(filter), static_cast(wrap)); - const auto status = pp::renderer::gl::set_opengl_sampler_parameters( + pp::legacy::gl_sampler::set_sampler_parameters( static_cast(id), parameters, - pp::renderer::gl::OpenGlSamplerParameterDispatch { - .sampler_parameter_i = set_opengl_sampler_parameter_i, - }); - if (!status.ok()) - LOG("Sampler::set() failed because: %s", status.message); + "Sampler::set()"); }); } @@ -486,54 +420,38 @@ void Sampler::set_filter(GLint filter_min, GLint filter_mag) const auto parameters = pp::renderer::gl::sampler_filter_parameters( static_cast(filter_min), static_cast(filter_mag)); - const auto status = pp::renderer::gl::set_opengl_sampler_parameters( + pp::legacy::gl_sampler::set_sampler_parameters( static_cast(id), parameters, - pp::renderer::gl::OpenGlSamplerParameterDispatch { - .sampler_parameter_i = set_opengl_sampler_parameter_i, - }); - if (!status.ok()) - LOG("Sampler::set_filter() failed because: %s", status.message); + "Sampler::set_filter()"); }); } void Sampler::set_border(glm::vec4 rgba) { App::I->render_task([this, rgba] { - const auto status = pp::renderer::gl::set_opengl_sampler_border_color( + pp::legacy::gl_sampler::set_sampler_border_color( static_cast(id), pp::renderer::gl::sampler_border_color_parameter_name(), glm::value_ptr(rgba), - pp::renderer::gl::OpenGlSamplerBorderDispatch { - .sampler_parameter_fv = set_opengl_sampler_parameter_fv, - }); - if (!status.ok()) - LOG("Sampler::set_border() failed because: %s", status.message); + "Sampler::set_border()"); }); } void Sampler::bind(int unit) const { assert(App::I->is_render_thread()); current_unit = unit; - const auto status = pp::renderer::gl::bind_opengl_sampler_object( + pp::legacy::gl_sampler::bind_sampler( static_cast(unit), static_cast(id), - pp::renderer::gl::OpenGlSamplerBindDispatch { - .bind_sampler = bind_opengl_sampler, - }); - if (!status.ok()) - LOG("Sampler::bind() failed because: %s", status.message); + "Sampler::bind()"); } void Sampler::unbind() { assert(App::I->is_render_thread()); - const auto status = pp::renderer::gl::bind_opengl_sampler_object( + pp::legacy::gl_sampler::bind_sampler( static_cast(current_unit), 0U, - pp::renderer::gl::OpenGlSamplerBindDispatch { - .bind_sampler = bind_opengl_sampler, - }); - if (!status.ok()) - LOG("Sampler::unbind() failed because: %s", status.message); + "Sampler::unbind()"); }