Isolate legacy stroke edge shader setup

This commit is contained in:
2026-06-12 22:44:15 +02:00
parent e5d5d5f9ce
commit 2ee6534918
4 changed files with 87 additions and 9 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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);

View File

@@ -0,0 +1,66 @@
#pragma once
#include "shader.h"
#include "util.h"
#include <functional>
namespace pp::panopainter {
struct LegacyStrokePadUniforms {
glm::vec4 color {};
bool uses_destination_feedback = false;
};
struct LegacyStrokeDilateUniforms {
glm::mat4 mvp { 1.0f };
};
struct LegacyStrokeEdgeShaderExecution {
std::function<void(kShader)> use_shader;
std::function<void(kShaderUniform, int)> set_int;
std::function<void(kShaderUniform, const glm::vec4&)> set_vec4;
std::function<void(kShaderUniform, const glm::mat4&)> 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