diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 0c52665..b3b1305 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -377,7 +377,10 @@ Known local toolchain state: backend-owned texture readback formats, sampler filters, depth/blend state, depth clears, viewport queries, color-mask booleans, active texture units, and float render-target formats; CPU lightmap row dispatch now uses shared - `parallel_for` instead of platform-specific worker APIs. + `parallel_for` instead of platform-specific worker APIs. Its live heightmap + draw and bake paths now execute depth/blend state changes, depth clears, + color-write-mask toggles, active texture selection, and bake viewport changes + through tested `pp_renderer_gl` dispatch adapters. Legacy `util.cpp` OpenGL error naming and `gl_state` save/restore also consume backend-owned error codes, state queries, framebuffer targets, texture binding targets, and active texture units. @@ -648,6 +651,8 @@ Known local toolchain state: NodeStrokePreview texture-unit switches, tested viewport/scissor/capability dispatch consumed by retained Canvas, NodeCanvas, NodeStrokePreview, and HMD render-state paths, + tested color-write-mask dispatch consumed by retained `NodePanelGrid` + transparent heightmap rendering, tested pixel-buffer allocation/readback/map/unmap/delete dispatch consumed by retained `PBO` recording readbacks, tested framebuffer-to-texture copy dispatch consumed by retained canvas/UI paint paths and CanvasLayer diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 516531f..d5dddeb 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -53,7 +53,7 @@ agent or engineer to remove them without reconstructing context from chat. | DEBT-0033 | Open | Modernization | Tools menu planning and direct command execution dispatch now consume pure `pp_app_core` through `App::init_menu_tools`, `pano_cli plan-tools-menu`, `pano_cli plan-tools-panel`, and the `ToolsMenuServices` boundary, and direct command execution is centralized in `src/legacy_app_shell_services.*`; SonarPen availability/startup now routes through `PlatformServices`, but live adapters still construct legacy `NodePanelFloating` panels, mutate legacy panel nodes, clear `CanvasModeGrid`, reset `NodeCanvas` camera state, open legacy shortcuts UI, and rely on the legacy platform adapter for the retained iOS SonarPen bridge | Preserve current Tools menu behavior while UI shell actions move toward app/UI/platform services | `pp_app_core_tools_menu_tests`; `pp_platform_api_tests`; `pano_cli plan-tools-menu --command shortcuts`; `pano_cli plan-tools-panel --panel layers`; `pano_cli plan-tools-panel --panel animation --already-visible`; `ctest --preset desktop-fast --build-config Debug` | Tools panel creation, submenu routing, grid clear, camera reset, shortcuts dialog, and SonarPen dispatch are owned by injected app/UI/platform services with `App::init_menu_tools` acting only as a UI adapter and no legacy Tools adapter | | DEBT-0034 | Open | Modernization | About menu command planning and execution dispatch now consume pure `pp_app_core` through `App::init_menu_about`, `pano_cli plan-about-menu`, and the `AboutMenuServices` boundary, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy About/manual/what's-new dialogs, invokes the injected crash hook, and runs the legacy Canvas stroke performance test directly | Preserve About menu behavior while dialogs and diagnostics move toward app/UI/platform services | `pp_app_core_about_menu_tests`; `pano_cli plan-about-menu --command news --version-major 2 --version-minor 5 --version-fix 7`; `pano_cli plan-about-menu --command performance --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | About/manual/what's-new dialog dispatch, crash-test dispatch, and performance-test execution are owned by injected app/UI/platform services with `App::init_menu_about` acting only as a UI adapter and no legacy About adapter | | DEBT-0035 | Open | Modernization | Main toolbar/status command planning and execution dispatch now consume pure `pp_app_core` through `App::init_toolbar_main`, `pano_cli plan-main-toolbar`, and the `MainToolbarServices` boundary, history/canvas commands now hand off through `HistoryUiServices` and `DocumentCanvasClearServices`, and live execution is centralized in `src/legacy_app_shell_services.*`, but the bridge still opens legacy open/save/settings/message-box dialogs and delegates to legacy history/canvas adapters | Preserve reachable toolbar/status behavior while app shell commands move toward app/document/UI services | `pp_app_core_main_toolbar_tests`; `pano_cli plan-main-toolbar --command undo --undo-count 2`; `pano_cli plan-main-toolbar --command clear-canvas --no-canvas`; `ctest --preset desktop-fast --build-config Debug` | Open/save/settings/message-box routing, undo/redo/clear-history execution, and canvas-clear execution are owned by injected app/document/UI services with `App::init_toolbar_main` acting only as a UI adapter and no legacy toolbar adapter | -| DEBT-0036 | Open | Modernization | `pp_renderer_api`, `pp_paint_renderer`, `pano_cli plan-paint-feedback`, and `pano_cli plan-stroke-composite` can choose backend-neutral complex paint feedback strategies for fixed-function blending, framebuffer-fetch-capable renderers, or ping-pong render targets. OpenGL extension detection now stores `pp::renderer::RenderDeviceFeatures` through `ShaderManager`, using `pp_renderer_gl::query_opengl_capability_detection`, `detect_opengl_feature_state`, and `render_device_features` as the backend conversion point; that feature snapshot now includes float32-linear filtering, so canvas stroke texture format selection, renderer diagnostics, grid lightmap render planning, and grid bake target selection no longer read `ShaderManager::ext_*` flags directly. `pp_paint_renderer::plan_canvas_blend_gate` owns the compatibility mapping from persisted layer/brush blend indices to the extracted stroke-composite planner, and live `Canvas::draw_merge` plus `NodeCanvas` panorama rendering both call it with the stored renderer-neutral feature set for their existing shader-blend gates and destination-copy versus framebuffer-fetch decisions. `pp_paint_renderer::plan_canvas_stroke_feedback` also owns the current destination-feedback decision, and live `Canvas::stroke_draw`, thumbnail layer blending, and `NodeStrokePreview` brush-preview rendering use it for framebuffer-fetch versus destination-copy decisions. The retained `copy_framebuffer_to_texture_2d` utility bridge now routes 2D framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch, 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, and texture bind/unbind 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, and CanvasLayer cube/equirect generation plus frame clears now route blend state, active texture units, viewport execution, color clears, and cube-face framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch adapters, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, and the retained `ShaderManager::ext_*` compatibility fields still use legacy OpenGL canvas/UI execution | Preserve current painting behavior while the renderer boundary matures for OpenGL parity and later Vulkan/Metal experiments | `pp_renderer_api_tests`; `pp_renderer_gl_capabilities_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli plan-paint-feedback --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-paint-feedback --texture-copy`; `pano_cli plan-stroke-composite --stroke-blend 10 --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-stroke-composite --layer-blend 4 --dual-blend --texture-copy`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Live stroke/layer compositing chooses its feedback path through `pp_paint_renderer` and renderer services, with OpenGL golden parity and Vulkan/Metal lab tests covering framebuffer-fetch and ping-pong behavior | +| DEBT-0036 | Open | Modernization | `pp_renderer_api`, `pp_paint_renderer`, `pano_cli plan-paint-feedback`, and `pano_cli plan-stroke-composite` can choose backend-neutral complex paint feedback strategies for fixed-function blending, framebuffer-fetch-capable renderers, or ping-pong render targets. OpenGL extension detection now stores `pp::renderer::RenderDeviceFeatures` through `ShaderManager`, using `pp_renderer_gl::query_opengl_capability_detection`, `detect_opengl_feature_state`, and `render_device_features` as the backend conversion point; that feature snapshot now includes float32-linear filtering, so canvas stroke texture format selection, renderer diagnostics, grid lightmap render planning, and grid bake target selection no longer read `ShaderManager::ext_*` flags directly. `pp_paint_renderer::plan_canvas_blend_gate` owns the compatibility mapping from persisted layer/brush blend indices to the extracted stroke-composite planner, and live `Canvas::draw_merge` plus `NodeCanvas` panorama rendering both call it with the stored renderer-neutral feature set for their existing shader-blend gates and destination-copy versus framebuffer-fetch decisions. `pp_paint_renderer::plan_canvas_stroke_feedback` also owns the current destination-feedback decision, and live `Canvas::stroke_draw`, thumbnail layer blending, and `NodeStrokePreview` brush-preview rendering use it for framebuffer-fetch versus destination-copy decisions. The retained `copy_framebuffer_to_texture_2d` utility bridge now routes 2D framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch, retained `RTT::create`/`RTT::destroy` render-target texture parameter setup, optional depth renderbuffer allocation, framebuffer allocation/attachment/status checks, binding restore, and resource deletion now route through tested `pp_renderer_gl` dispatch, retained RTT clear, masked clear with color-write-mask restore, and texture bind/unbind 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, and CanvasLayer cube/equirect generation plus frame clears now route blend state, active texture units, viewport execution, color clears, and cube-face framebuffer-to-texture copies through tested `pp_renderer_gl` dispatch adapters, and `NodePanelGrid` live heightmap draw and bake setup now route depth/blend state, depth clears, color-write-mask toggles, active texture selection, and bake viewport execution through tested `pp_renderer_gl` dispatch adapters, but actual live stroke rasterization, dual-brush compositing, pattern feedback math, thumbnail layer compositing, brush-preview compositing, and the retained `ShaderManager::ext_*` compatibility fields still use legacy OpenGL canvas/UI execution | Preserve current painting behavior while the renderer boundary matures for OpenGL parity and later Vulkan/Metal experiments | `pp_renderer_api_tests`; `pp_renderer_gl_capabilities_tests`; `pp_paint_renderer_compositor_tests`; `pano_cli plan-paint-feedback --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-paint-feedback --texture-copy`; `pano_cli plan-stroke-composite --stroke-blend 10 --framebuffer-fetch --explicit-transitions --render-only`; `pano_cli plan-stroke-composite --layer-blend 4 --dual-blend --texture-copy`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Live stroke/layer compositing chooses its feedback path through `pp_paint_renderer` and renderer services, with OpenGL golden parity and Vulkan/Metal lab tests covering framebuffer-fetch and ping-pong behavior | | DEBT-0037 | Open | Modernization | Recording lifecycle/export planning and execution dispatch now consume pure `pp_app_core` through `App::rec_start`, `App::rec_stop`, `App::rec_clear`, `App::rec_export`, `pano_cli plan-recording-session`, and the `RecordingServices` boundary; live execution is centralized in `src/legacy_recording_services.*`, and retained `PBO` allocation/readback/map/unmap/delete operations now route through tested `pp_renderer_gl` dispatch, but the bridge still owns legacy recording thread startup/shutdown, platform recorded-file cleanup, progress UI, retained `App::rec_loop` readback call sites, and `MP4Encoder::write_mp4` execution | Preserve current timelapse/MP4 behavior while recording moves toward app/document/renderer/video services | `pp_app_core_document_recording_tests`; `pp_renderer_gl_capabilities_tests`; `pano_cli plan-recording-session --running --frame-count 12`; `pano_cli plan-recording-session --platform-clears-files`; `ctest --preset desktop-fast --build-config Debug` | Recording thread lifecycle, frame readback scheduling, platform cleanup, progress reporting, and MP4 writing are owned by injected app/renderer/video services with `App` methods acting only as adapters | | DEBT-0038 | Open | Modernization | Cloud upload/browse/bulk planning and execution dispatch now consume pure `pp_app_core` through `App::cloud_upload`, `App::cloud_upload_all`, `App::cloud_browse`, `pano_cli plan-cloud-upload`, `pano_cli plan-cloud-upload-all`, `pano_cli plan-cloud-browse`, and the `CloudServices` boundary; live execution is centralized in `src/legacy_cloud_services.*`, the app-owned `upload`/`download`/license curl helpers now ask `PlatformServices` for the Android TLS-verification bypass policy, and retained `Asset::open_url`, `LogRemote::net_init`, and `NodeDialogCloud::load_thumbs_thread` curl sites consume the `pp_platform_api` default TLS policy helper instead of spelling Android branches locally, but the bridge still uses legacy save-before-upload, app-owned curl helpers instead of an injected network service, progress/message UI, OpenGL context guarding, `NodeDialogCloud`, `Canvas` project open, layer refresh, and `ActionManager` reset | Preserve current cloud behavior while cloud/network/document import flows move toward app/document/platform services | `pp_app_core_document_cloud_tests`; `pp_platform_api_tests`; `pano_cli plan-cloud-upload --new-document --unsaved`; `pano_cli plan-cloud-browse --selected-file demo.ppi`; `pano_cli plan-cloud-upload-all --file-count 3`; `ctest --preset desktop-fast --build-config Debug` | Cloud upload/download, TLS policy, save-before-upload, progress reporting, cloud browse dialog, downloaded project opening, layer refresh, OpenGL context ownership, and action-history reset are owned by injected app/document/network/platform/renderer services with `App` methods acting only as adapters | | DEBT-0039 | Open | Modernization | Document-open planning and execution dispatch now consume pure `pp_app_core` through `App::open_document`, `pano_cli plan-open-route`, `DocumentOpenServices`, and `src/legacy_document_open_services.*`, but the bridge still opens ABR/PPBR import prompts before delegating import execution to `src/legacy_brush_package_import_services.*`, applies unsaved-project discard prompts, calls legacy project-open execution, refreshes layer UI, updates the app title, and clears legacy history directly | Preserve current file-open/import behavior while document loading and brush import move toward app/document/asset/UI services | `pp_app_core_document_route_tests`; `pp_app_core_document_session_tests`; `pano_cli plan-open-route --path D:/Paint/Scenes/demo.ppi --unsaved`; `pano_cli plan-open-route --path D:/Paint/Brushes/clouds.ABR --unsaved`; `ctest --preset desktop-fast --build-config Debug` | Brush import prompting, project-open execution, unsaved-project discard prompting, layer refresh, title updates, and history clearing are owned by injected app/document/asset/UI services with `App::open_document` acting only as an adapter | diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index ad1d56f..f6afd0d 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -1102,6 +1102,9 @@ readback formats, sampler filters, depth/blend state, depth clears, viewport queries, color-mask booleans, active texture units, and float render-target formats to `pp_renderer_gl`, and its CPU lightmap row dispatch now uses the shared legacy `parallel_for` helper rather than platform-specific worker APIs. +Its live heightmap draw and bake paths now execute depth/blend state changes, +depth clears, color-write-mask toggles, active texture selection, and bake +viewport changes through tested `pp_renderer_gl` dispatch adapters. Legacy `util.cpp` OpenGL error naming and `gl_state` save/restore now delegate error codes, state queries, framebuffer targets, texture binding targets, and active texture units to `pp_renderer_gl`. @@ -2050,6 +2053,10 @@ Results: active texture units, viewport execution, color clears, and cube-face framebuffer-to-texture copies through tested renderer GL backend dispatch contracts. +- `NodePanelGrid` live heightmap drawing and bake setup now route depth/blend + state, depth clears, color-write-mask toggles, active texture selection, and + bake viewport execution through tested renderer GL backend dispatch + contracts. - 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/node_panel_grid.cpp b/src/node_panel_grid.cpp index 274fe12..6d30517 100644 --- a/src/node_panel_grid.cpp +++ b/src/node_panel_grid.cpp @@ -9,6 +9,107 @@ #include "renderer_gl/opengl_capabilities.h" #include "util.h" +namespace { + +void enable_opengl_state(std::uint32_t state) noexcept +{ + glEnable(static_cast(state)); +} + +void disable_opengl_state(std::uint32_t state) noexcept +{ + glDisable(static_cast(state)); +} + +void set_opengl_active_texture(std::uint32_t texture_unit) noexcept +{ + glActiveTexture(static_cast(texture_unit)); +} + +void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept +{ + glViewport(static_cast(x), static_cast(y), static_cast(width), static_cast(height)); +} + +void clear_opengl_buffer(std::uint32_t mask) noexcept +{ + glClear(static_cast(mask)); +} + +void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) noexcept +{ + glColorMask(r, g, b, a); +} + +void apply_grid_capability(std::uint32_t state, bool enabled) +{ + const auto status = pp::renderer::gl::apply_opengl_capability( + state, + enabled, + pp::renderer::gl::OpenGlCapabilityDispatch { + .enable = enable_opengl_state, + .disable = disable_opengl_state, + }); + if (!status.ok()) + LOG("Grid capability dispatch failed because: %s", status.message); +} + +void set_grid_active_texture_unit(std::uint32_t unit_index) +{ + const auto status = pp::renderer::gl::activate_opengl_texture_unit( + unit_index, + pp::renderer::gl::OpenGlActiveTextureDispatch { + .active_texture = set_opengl_active_texture, + }); + if (!status.ok()) + LOG("Grid active texture dispatch failed because: %s", status.message); +} + +void apply_grid_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) +{ + const auto status = pp::renderer::gl::apply_opengl_viewport( + pp::renderer::gl::OpenGlViewportRect { + .x = x, + .y = y, + .width = width, + .height = height, + }, + pp::renderer::gl::OpenGlViewportDispatch { + .viewport = set_opengl_viewport, + }); + if (!status.ok()) + LOG("Grid viewport dispatch failed because: %s", status.message); +} + +void clear_grid_depth_buffer() +{ + const auto status = pp::renderer::gl::clear_opengl_buffers( + pp::renderer::gl::framebuffer_depth_buffer_mask(), + pp::renderer::gl::OpenGlBufferClearDispatch { + .clear = clear_opengl_buffer, + }); + if (!status.ok()) + LOG("Grid depth clear dispatch failed because: %s", status.message); +} + +void apply_grid_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) +{ + const auto status = pp::renderer::gl::apply_opengl_color_write_mask( + pp::renderer::gl::OpenGlColorWriteMask { + .r = r, + .g = g, + .b = b, + .a = a, + }, + pp::renderer::gl::OpenGlColorWriteMaskDispatch { + .color_mask = set_opengl_color_mask, + }); + if (!status.ok()) + LOG("Grid color mask dispatch failed because: %s", status.message); +} + +} + Node* NodePanelGrid::clone_instantiate() const { return new NodePanelGrid(); @@ -220,8 +321,8 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer if (m_groud_opacity->get_value() > 0.f) { bool depth = glIsEnabled(pp::renderer::gl::depth_test_state()); - glEnable(pp::renderer::gl::depth_test_state()); - glClear(pp::renderer::gl::framebuffer_depth_buffer_mask()); + apply_grid_capability(pp::renderer::gl::depth_test_state(), true); + clear_grid_depth_buffer(); auto nav = m_hm_image.m_data ? -(m_hm_preview_nav->m_value - 0.5f) : glm::vec2(0); auto mvp = proj * camera @@ -235,14 +336,14 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer auto light_pos = glm::vec3(sinf(light_yaw) + nav.x, light_pitch + get_offset(), cosf(light_yaw) + nav.y); auto light_dir = glm::normalize(light_pos); - glDisable(pp::renderer::gl::blend_state()); + apply_grid_capability(pp::renderer::gl::blend_state(), false); // DRAW SOLID if (m_hm_image.m_data) { if (m_shade_mode == ShadeMode::Solid) { - glDisable(pp::renderer::gl::blend_state()); + apply_grid_capability(pp::renderer::gl::blend_state(), false); ShaderManager::use(kShader::Lambert); ShaderManager::u_mat4(kShaderUniform::MVP, mvp); ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir); @@ -267,7 +368,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer ShaderManager::u_float(kShaderUniform::Ambient, get_ambient()); ShaderManager::u_int(kShaderUniform::Tex, 0); m_sampler_mipmap.bind(0); - glActiveTexture(pp::renderer::gl::active_texture_unit(0U)); + set_grid_active_texture_unit(0U); m_texture.bind(); m_hm_plane.draw_fill(); m_texture.unbind(); @@ -278,7 +379,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer auto wire_alpha = m_hm_image.m_data ? m_hm_wireframe->get_value() : 1.f; if (wire_alpha > 0.f) { - glEnable(pp::renderer::gl::blend_state()); + apply_grid_capability(pp::renderer::gl::blend_state(), true); ShaderManager::use(kShader::Color); ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4( glm::vec3(m_groud_value->get_value()), @@ -288,13 +389,13 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer ShaderManager::u_mat4(kShaderUniform::MVP, mvp); if (m_hm_image.m_data && m_shade_mode == ShadeMode::Transparent) { - glColorMask( + apply_grid_color_mask( pp::renderer::gl::color_write_disabled(), pp::renderer::gl::color_write_disabled(), pp::renderer::gl::color_write_disabled(), pp::renderer::gl::color_write_disabled()); m_hm_plane.draw_fill(); - glColorMask( + apply_grid_color_mask( pp::renderer::gl::color_write_enabled(), pp::renderer::gl::color_write_enabled(), pp::renderer::gl::color_write_enabled(), @@ -313,21 +414,21 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer GLint vp[4]; glGetIntegerv(pp::renderer::gl::viewport_query(), vp); auto aspect_ratio = (float)vp[3] / (float)vp[2]; - glEnable(pp::renderer::gl::blend_state()); - glDisable(pp::renderer::gl::depth_test_state()); + apply_grid_capability(pp::renderer::gl::blend_state(), true); + apply_grid_capability(pp::renderer::gl::depth_test_state(), false); ShaderManager::use(kShader::Texture); ShaderManager::u_int(kShaderUniform::Tex, 0); ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-1.f, 1.f, -1.f, 1.f) * //glm::scale(glm::vec3(100)) * glm::translate(glm::vec3(p2d, 0)) * glm::scale(glm::vec3(.1f * aspect_ratio, .1f, 1.f))); - glActiveTexture(pp::renderer::gl::active_texture_unit(0U)); + set_grid_active_texture_unit(0U); m_sampler_linear.bind(0); constexpr auto sun_tex = const_hash("data/sun.png"); TextureManager::get(sun_tex).bind(); m_plane.draw_fill(); } } - depth ? glEnable(pp::renderer::gl::depth_test_state()) : glDisable(pp::renderer::gl::depth_test_state()); + depth ? apply_grid_capability(pp::renderer::gl::depth_test_state(), true) : apply_grid_capability(pp::renderer::gl::depth_test_state(), false); } } @@ -372,9 +473,9 @@ void NodePanelGrid::bake_uvs() App::I->render_task([&]{ fb.bindFramebuffer(); fb.clear({ 1, 0, 0, 1 }); - glDisable(pp::renderer::gl::blend_state()); - glDisable(pp::renderer::gl::depth_test_state()); - glViewport(0, 0, fb.getWidth(), fb.getHeight()); + apply_grid_capability(pp::renderer::gl::blend_state(), false); + apply_grid_capability(pp::renderer::gl::depth_test_state(), false); + apply_grid_viewport(0, 0, fb.getWidth(), fb.getHeight()); ShaderManager::use(kShader::BakeUV); ShaderManager::u_mat4(kShaderUniform::MVP, glm::mat4(1)); diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index efa2ea1..e1e72c5 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -503,6 +503,18 @@ pp::foundation::Status clear_opengl_color_buffer_with_write_mask( return pp::foundation::Status::success(); } +pp::foundation::Status apply_opengl_color_write_mask( + OpenGlColorWriteMask mask, + OpenGlColorWriteMaskDispatch dispatch) noexcept +{ + if (dispatch.color_mask == nullptr) { + return pp::foundation::Status::invalid_argument("OpenGL color-write-mask dispatch callback must not be null"); + } + + dispatch.color_mask(mask.r, mask.g, mask.b, mask.a); + return pp::foundation::Status::success(); +} + pp::foundation::Status activate_opengl_texture_unit( std::uint32_t unit_index, OpenGlActiveTextureDispatch dispatch) noexcept diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index d9f2b69..b908d60 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -575,6 +575,10 @@ struct OpenGlColorMaskedClearDispatch { OpenGlClearFn clear = nullptr; }; +struct OpenGlColorWriteMaskDispatch { + OpenGlColorMaskFn color_mask = nullptr; +}; + struct OpenGlViewportDispatch { OpenGlViewportFn viewport = nullptr; }; @@ -883,6 +887,9 @@ struct OpenGlMeshDeleteDispatch { [[nodiscard]] pp::foundation::Status clear_opengl_color_buffer_with_write_mask( OpenGlColorMaskedClear clear, OpenGlColorMaskedClearDispatch dispatch) noexcept; +[[nodiscard]] pp::foundation::Status apply_opengl_color_write_mask( + OpenGlColorWriteMask mask, + OpenGlColorWriteMaskDispatch dispatch) noexcept; [[nodiscard]] pp::foundation::Status activate_opengl_texture_unit( std::uint32_t unit_index, OpenGlActiveTextureDispatch dispatch) noexcept; diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index 9d0c2fe..f063ec5 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -2321,6 +2321,24 @@ void clears_color_buffer_with_write_mask_and_restores_previous_mask(pp::tests::H PP_EXPECT(h, recorded_clear_calls[1].mask == 0x00004000U); } +void applies_color_write_mask_through_dispatch(pp::tests::Harness& h) +{ + recorded_color_mask_calls.clear(); + + const auto status = pp::renderer::gl::apply_opengl_color_write_mask( + pp::renderer::gl::OpenGlColorWriteMask { .r = 1U, .g = 0U, .b = 1U, .a = 0U }, + pp::renderer::gl::OpenGlColorWriteMaskDispatch { + .color_mask = record_color_mask, + }); + + PP_EXPECT(h, status.ok()); + PP_EXPECT(h, recorded_color_mask_calls.size() == 1U); + PP_EXPECT(h, recorded_color_mask_calls[0].r == 1U); + PP_EXPECT(h, recorded_color_mask_calls[0].g == 0U); + PP_EXPECT(h, recorded_color_mask_calls[0].b == 1U); + PP_EXPECT(h, recorded_color_mask_calls[0].a == 0U); +} + void rejects_invalid_render_target_clear_dispatch(pp::tests::Harness& h) { const auto missing_clear = pp::renderer::gl::clear_opengl_render_target( @@ -5304,6 +5322,7 @@ int main() harness.run("rejects_incomplete_app_clear_dispatch", rejects_incomplete_app_clear_dispatch); harness.run("clears_render_target_through_dispatch", clears_render_target_through_dispatch); harness.run("clears_color_buffer_with_write_mask_and_restores_previous_mask", clears_color_buffer_with_write_mask_and_restores_previous_mask); + harness.run("applies_color_write_mask_through_dispatch", applies_color_write_mask_through_dispatch); harness.run("rejects_invalid_render_target_clear_dispatch", rejects_invalid_render_target_clear_dispatch); harness.run("activates_texture_unit_through_dispatch", activates_texture_unit_through_dispatch); harness.run("rejects_incomplete_active_texture_dispatch", rejects_incomplete_active_texture_dispatch);