From 2ee65349187d12d3ac4e51d08766dcadc79a22ce Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 12 Jun 2026 22:44:15 +0200 Subject: [PATCH] Isolate legacy stroke edge shader setup --- docs/modernization/debt.md | 6 +++ docs/modernization/roadmap.md | 8 +-- src/canvas.cpp | 16 +++--- src/legacy_canvas_stroke_edge_services.h | 66 ++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 src/legacy_canvas_stroke_edge_services.h diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 3990337..9bff171 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -18,6 +18,12 @@ agent or engineer to remove them without reconstructing context from chat. ## Recent Reductions +- 2026-06-12: DEBT-0036 was narrowed again. Canvas stroke padding and commit + dilate shader setup now route retained `kShader::StrokePad` and + `kShader::StrokeDilate` binding/uniform writes through + `legacy_canvas_stroke_edge_services.h`. Quad expansion, dirty-box policy, + texture/framebuffer binding and copies, and draw ordering remain retained + legacy execution. - 2026-06-12: DEBT-0036 was narrowed again. Canvas live draw-merge and `NodeStrokePreview` final stroke composite `kShader::CompDraw` setup now share `legacy_canvas_stroke_composite_services.h` for retained shader binding diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 087483c..096931f 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -1350,9 +1350,11 @@ OpenGL stroke execution service seam. Live stroke `kShader::Stroke` binding, setup, blend, pattern, and per-sample uniform writes now pass through `legacy_canvas_stroke_shader_services.h`. Live draw-merge and preview final stroke composite `kShader::CompDraw` setup now pass through -`legacy_canvas_stroke_composite_services.h`, leaving RTT/texture ownership, -dirty-box policy, pad/checkerboard/commit composite shaders, and retained -callback execution under `DEBT-0036`. +`legacy_canvas_stroke_composite_services.h`. Stroke padding and commit dilate +`kShader::StrokePad`/`kShader::StrokeDilate` setup now pass through +`legacy_canvas_stroke_edge_services.h`, leaving RTT/texture ownership, +dirty-box policy, checkerboard/commit composite shaders, quad expansion, and +retained callback execution under `DEBT-0036`. It also owns renderer API texture-format to OpenGL internal/pixel/component token mapping, including depth-stencil formats, for future backend texture objects. `Texture2D` 2D texture binding, upload, diff --git a/src/canvas.cpp b/src/canvas.cpp index 5d92918..473ef12 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -4,6 +4,7 @@ #include "app.h" #include "legacy_gl_renderbuffer_dispatch.h" #include "legacy_canvas_stroke_composite_services.h" +#include "legacy_canvas_stroke_edge_services.h" #include "legacy_canvas_stroke_execution_services.h" #include "legacy_canvas_stroke_shader_services.h" #include "legacy_canvas_stroke_services.h" @@ -765,12 +766,14 @@ void Canvas::stroke_draw() // NOTE: at the moment this works on the whole canvas, but it can be optimized // to only affect the current dirty box. In this case it may be necessary to do this // work on documents that doesn't have the padding, so on document loading. - ShaderManager::use(kShader::StrokePad); - ShaderManager::u_vec4(kShaderUniform::Col, pad_color); + pp::panopainter::setup_legacy_stroke_pad_shader( + pp::panopainter::LegacyStrokePadUniforms { + .color = pad_color, + .uses_destination_feedback = copy_stroke_destination, + }); if (copy_stroke_destination) { set_active_texture_unit(1); - ShaderManager::u_int(kShaderUniform::TexBG, 1); } for (int i = 0; i < 6; i++) { @@ -1122,9 +1125,10 @@ void Canvas::stroke_commit() // } // Dilate borders to avoid interpolation bleeding - ShaderManager::use(kShader::StrokeDilate); - ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f)); - ShaderManager::u_int(kShaderUniform::TexBG, 0); + pp::panopainter::setup_legacy_stroke_dilate_shader( + pp::panopainter::LegacyStrokeDilateUniforms { + .mvp = glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f), + }); set_active_texture_unit(0); m_tex2[i].bind(); copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height); diff --git a/src/legacy_canvas_stroke_edge_services.h b/src/legacy_canvas_stroke_edge_services.h new file mode 100644 index 0000000..477d265 --- /dev/null +++ b/src/legacy_canvas_stroke_edge_services.h @@ -0,0 +1,66 @@ +#pragma once + +#include "shader.h" +#include "util.h" + +#include + +namespace pp::panopainter { + +struct LegacyStrokePadUniforms { + glm::vec4 color {}; + bool uses_destination_feedback = false; +}; + +struct LegacyStrokeDilateUniforms { + glm::mat4 mvp { 1.0f }; +}; + +struct LegacyStrokeEdgeShaderExecution { + std::function use_shader; + std::function set_int; + std::function set_vec4; + std::function set_mat4; +}; + +[[nodiscard]] inline LegacyStrokeEdgeShaderExecution legacy_shader_manager_stroke_edge_execution() noexcept +{ + return { + .use_shader = [](kShader shader) { ShaderManager::use(shader); }, + .set_int = [](kShaderUniform uniform, int value) { ShaderManager::u_int(uniform, value); }, + .set_vec4 = [](kShaderUniform uniform, const glm::vec4& value) { ShaderManager::u_vec4(uniform, value); }, + .set_mat4 = [](kShaderUniform uniform, const glm::mat4& value) { ShaderManager::u_mat4(uniform, value); }, + }; +} + +inline void setup_legacy_stroke_pad_shader( + const LegacyStrokePadUniforms& uniforms, + const LegacyStrokeEdgeShaderExecution& execution) noexcept +{ + execution.use_shader(kShader::StrokePad); + execution.set_vec4(kShaderUniform::Col, uniforms.color); + if (uniforms.uses_destination_feedback) { + execution.set_int(kShaderUniform::TexBG, 1); + } +} + +inline void setup_legacy_stroke_pad_shader(const LegacyStrokePadUniforms& uniforms) +{ + setup_legacy_stroke_pad_shader(uniforms, legacy_shader_manager_stroke_edge_execution()); +} + +inline void setup_legacy_stroke_dilate_shader( + const LegacyStrokeDilateUniforms& uniforms, + const LegacyStrokeEdgeShaderExecution& execution) noexcept +{ + execution.use_shader(kShader::StrokeDilate); + execution.set_mat4(kShaderUniform::MVP, uniforms.mvp); + execution.set_int(kShaderUniform::TexBG, 0); +} + +inline void setup_legacy_stroke_dilate_shader(const LegacyStrokeDilateUniforms& uniforms) +{ + setup_legacy_stroke_dilate_shader(uniforms, legacy_shader_manager_stroke_edge_execution()); +} + +} // namespace pp::panopainter