Share retained stroke mix pass helper
This commit is contained in:
116
src/canvas.cpp
116
src/canvas.cpp
@@ -405,51 +405,81 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
|
||||
static_cast<std::int32_t>(bb_sz.y));
|
||||
|
||||
auto layer_index = m_current_layer_idx;
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
std::array<pp::panopainter::LegacyCanvasStrokeMixPassPlane, 6> mix_planes {};
|
||||
const auto mix_mvp_base =
|
||||
glm::scale(glm::vec3(1, -1, 1)) *
|
||||
m_proj * m_mv;
|
||||
for (int plane_index = 0; plane_index < 6; ++plane_index)
|
||||
{
|
||||
if (!m_layers[layer_index]->m_visible ||
|
||||
m_layers[layer_index]->m_opacity == .0f ||
|
||||
!m_layers[layer_index]->face(plane_index))
|
||||
continue;
|
||||
|
||||
//glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f);
|
||||
auto plane_mvp_z =
|
||||
glm::scale(glm::vec3(1, -1, 1)) *
|
||||
m_proj * m_mv *
|
||||
m_plane_transform[plane_index] *
|
||||
glm::translate(glm::vec3(0, 0, -1));
|
||||
|
||||
m_sampler.bind(0);
|
||||
m_sampler.bind(1);
|
||||
m_sampler.bind(2);
|
||||
const auto& b = m_current_stroke->m_brush;
|
||||
pp::panopainter::setup_legacy_stroke_composite_shader(
|
||||
pp::panopainter::LegacyStrokeCompositeUniforms {
|
||||
.resolution = m_size,
|
||||
.mvp = plane_mvp_z,
|
||||
.pattern_texture_slot = 3,
|
||||
.layer_alpha = 1.0f,
|
||||
.alpha_lock = false, /*m_layers[layer_index]->m_alpha_locked*/
|
||||
.mask_enabled = false, /*m_smask_active*/
|
||||
.use_fragcoord = false,
|
||||
.blend_mode = b->m_blend_mode,
|
||||
.use_dual = false,
|
||||
.use_pattern = false,
|
||||
});
|
||||
set_active_texture_unit(0);
|
||||
m_layers[layer_index]->rtt(plane_index).bindTexture();
|
||||
set_active_texture_unit(1);
|
||||
m_tmp[plane_index].bindTexture();
|
||||
set_active_texture_unit(2);
|
||||
m_smask.rtt(plane_index).bindTexture();
|
||||
m_node->m_face_plane.draw_fill();
|
||||
m_smask.rtt(plane_index).unbindTexture();
|
||||
set_active_texture_unit(1);
|
||||
m_tmp[plane_index].unbindTexture();
|
||||
set_active_texture_unit(0);
|
||||
m_layers[layer_index]->rtt(plane_index).unbindTexture();
|
||||
mix_planes[plane_index] = pp::panopainter::LegacyCanvasStrokeMixPassPlane {
|
||||
.index = plane_index,
|
||||
.visible = m_layers[layer_index]->m_visible,
|
||||
.has_target = static_cast<bool>(m_layers[layer_index]->face(plane_index)),
|
||||
.opacity = m_layers[layer_index]->m_opacity,
|
||||
.mvp = mix_mvp_base *
|
||||
m_plane_transform[plane_index] *
|
||||
glm::translate(glm::vec3(0, 0, -1)),
|
||||
};
|
||||
}
|
||||
m_sampler.unbind();
|
||||
|
||||
const auto& b = m_current_stroke->m_brush;
|
||||
[[maybe_unused]] const auto mix_result = pp::panopainter::execute_legacy_canvas_stroke_mix_pass(
|
||||
pp::panopainter::LegacyCanvasStrokeMixPassRequest {
|
||||
.context = "Canvas::stroke_draw_mix",
|
||||
.resolution = m_size,
|
||||
.planes = mix_planes,
|
||||
.bind_mix_samplers = [&] {
|
||||
m_sampler.bind(0);
|
||||
m_sampler.bind(1);
|
||||
m_sampler.bind(2);
|
||||
},
|
||||
.unbind_mix_samplers = [&] {
|
||||
m_sampler.unbind();
|
||||
},
|
||||
.setup_plane_shader = [&](int plane_index, const glm::mat4& plane_mvp_z) {
|
||||
(void)plane_index;
|
||||
pp::panopainter::setup_legacy_stroke_composite_shader(
|
||||
pp::panopainter::LegacyStrokeCompositeUniforms {
|
||||
.resolution = m_size,
|
||||
.mvp = plane_mvp_z,
|
||||
.pattern_texture_slot = 3,
|
||||
.layer_alpha = 1.0f,
|
||||
.alpha_lock = false, /*m_layers[layer_index]->m_alpha_locked*/
|
||||
.mask_enabled = false, /*m_smask_active*/
|
||||
.use_fragcoord = false,
|
||||
.blend_mode = b->m_blend_mode,
|
||||
.use_dual = false,
|
||||
.use_pattern = false,
|
||||
});
|
||||
},
|
||||
.bind_layer_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(0);
|
||||
m_layers[layer_index]->rtt(plane_index).bindTexture();
|
||||
},
|
||||
.bind_stroke_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(1);
|
||||
m_tmp[plane_index].bindTexture();
|
||||
},
|
||||
.bind_mask_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(2);
|
||||
m_smask.rtt(plane_index).bindTexture();
|
||||
},
|
||||
.draw_plane = [&] {
|
||||
m_node->m_face_plane.draw_fill();
|
||||
},
|
||||
.unbind_mask_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(2);
|
||||
m_smask.rtt(plane_index).unbindTexture();
|
||||
},
|
||||
.unbind_stroke_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(1);
|
||||
m_tmp[plane_index].unbindTexture();
|
||||
},
|
||||
.unbind_layer_texture = [&](int plane_index) {
|
||||
set_active_texture_unit(0);
|
||||
m_layers[layer_index]->rtt(plane_index).unbindTexture();
|
||||
},
|
||||
});
|
||||
m_mixer.unbindFramebuffer();
|
||||
|
||||
gl.restore();
|
||||
|
||||
@@ -137,6 +137,35 @@ struct LegacyCanvasStrokePadExecutionResult {
|
||||
std::size_t padded_faces = 0;
|
||||
};
|
||||
|
||||
struct LegacyCanvasStrokeMixPassPlane {
|
||||
int index = 0;
|
||||
bool visible = true;
|
||||
bool has_target = false;
|
||||
float opacity = 1.0f;
|
||||
glm::mat4 mvp { 1.0f };
|
||||
};
|
||||
|
||||
struct LegacyCanvasStrokeMixPassRequest {
|
||||
std::string_view context;
|
||||
glm::vec2 resolution {};
|
||||
std::span<const LegacyCanvasStrokeMixPassPlane> planes;
|
||||
std::function<void()> bind_mix_samplers;
|
||||
std::function<void()> unbind_mix_samplers;
|
||||
std::function<void(int, const glm::mat4&)> setup_plane_shader;
|
||||
std::function<void(int)> bind_layer_texture;
|
||||
std::function<void(int)> bind_stroke_texture;
|
||||
std::function<void(int)> bind_mask_texture;
|
||||
std::function<void()> draw_plane;
|
||||
std::function<void(int)> unbind_mask_texture;
|
||||
std::function<void(int)> unbind_stroke_texture;
|
||||
std::function<void(int)> unbind_layer_texture;
|
||||
};
|
||||
|
||||
struct LegacyCanvasStrokeMixPassResult {
|
||||
bool ok = false;
|
||||
std::size_t composed_planes = 0;
|
||||
};
|
||||
|
||||
struct LegacyCanvasStrokeComputeRequest {
|
||||
StrokeSample previous_sample {};
|
||||
std::span<const StrokeSample> samples;
|
||||
@@ -923,4 +952,49 @@ template <typename ExecuteSample, typename BeginFace, typename PrepareDirtyReque
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] inline LegacyCanvasStrokeMixPassResult execute_legacy_canvas_stroke_mix_pass(
|
||||
const LegacyCanvasStrokeMixPassRequest& request)
|
||||
{
|
||||
LegacyCanvasStrokeMixPassResult result;
|
||||
if (request.resolution.x <= 0.0f ||
|
||||
request.resolution.y <= 0.0f ||
|
||||
!request.setup_plane_shader ||
|
||||
!request.bind_layer_texture ||
|
||||
!request.bind_stroke_texture ||
|
||||
!request.bind_mask_texture ||
|
||||
!request.draw_plane ||
|
||||
!request.unbind_mask_texture ||
|
||||
!request.unbind_stroke_texture ||
|
||||
!request.unbind_layer_texture) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (request.bind_mix_samplers) {
|
||||
request.bind_mix_samplers();
|
||||
}
|
||||
|
||||
for (const auto& plane : request.planes) {
|
||||
if (!plane.visible || plane.opacity <= 0.0f || !plane.has_target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
request.setup_plane_shader(plane.index, plane.mvp);
|
||||
request.bind_layer_texture(plane.index);
|
||||
request.bind_stroke_texture(plane.index);
|
||||
request.bind_mask_texture(plane.index);
|
||||
request.draw_plane();
|
||||
request.unbind_mask_texture(plane.index);
|
||||
request.unbind_stroke_texture(plane.index);
|
||||
request.unbind_layer_texture(plane.index);
|
||||
++result.composed_planes;
|
||||
}
|
||||
|
||||
if (request.unbind_mix_samplers) {
|
||||
request.unbind_mix_samplers();
|
||||
}
|
||||
|
||||
result.ok = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
Reference in New Issue
Block a user