Extract Canvas draw_merge layer blend helper
This commit is contained in:
@@ -1535,47 +1535,49 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SI
|
||||
|
||||
if (use_blend)
|
||||
{
|
||||
m_merge_rtt.unbindFramebuffer();
|
||||
}
|
||||
|
||||
// draw the blended
|
||||
if (use_blend)
|
||||
{
|
||||
m_sampler.bind(0);
|
||||
m_sampler.bind(2);
|
||||
|
||||
pp::panopainter::setup_legacy_canvas_draw_merge_texture_blend_shader(
|
||||
pp::panopainter::LegacyCanvasDrawMergeTextureBlendUniforms {
|
||||
.mvp = ortho,
|
||||
.texture_slot = 0,
|
||||
.destination_texture_slot = 2,
|
||||
.use_destination_texture = copy_blend_destination,
|
||||
.blend_mode = m_layers[layer_index]->m_blend_mode,
|
||||
.alpha = 1.f,
|
||||
pp::panopainter::execute_legacy_canvas_draw_merge_layer_blend(
|
||||
pp::panopainter::LegacyCanvasDrawMergeLayerBlendUniforms {
|
||||
.shader = {
|
||||
.mvp = ortho,
|
||||
.texture_slot = 0,
|
||||
.destination_texture_slot = 2,
|
||||
.use_destination_texture = copy_blend_destination,
|
||||
.blend_mode = m_layers[layer_index]->m_blend_mode,
|
||||
.alpha = 1.f,
|
||||
},
|
||||
.copy_destination = copy_blend_destination,
|
||||
},
|
||||
pp::panopainter::LegacyCanvasDrawMergeLayerBlendExecution {
|
||||
.unbind_merge_framebuffer = [&] {
|
||||
m_merge_rtt.unbindFramebuffer();
|
||||
},
|
||||
.bind_samplers = [&] {
|
||||
m_sampler.bind(0);
|
||||
m_sampler.bind(2);
|
||||
},
|
||||
.bind_merge_texture = [&] {
|
||||
set_active_texture_unit(0);
|
||||
m_merge_rtt.bindTexture();
|
||||
},
|
||||
.bind_destination_texture = [&] {
|
||||
set_active_texture_unit(2);
|
||||
m_merge_tex.bind();
|
||||
},
|
||||
.copy_destination_framebuffer = [&] {
|
||||
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
|
||||
},
|
||||
.draw = [&] {
|
||||
m_plane.draw_fill();
|
||||
},
|
||||
.unbind_destination_texture = [&] {
|
||||
set_active_texture_unit(2);
|
||||
m_merge_tex.unbind();
|
||||
},
|
||||
.unbind_merge_texture = [&] {
|
||||
set_active_texture_unit(0);
|
||||
m_merge_rtt.unbindTexture();
|
||||
},
|
||||
});
|
||||
if (copy_blend_destination)
|
||||
{
|
||||
m_sampler.bind(2);
|
||||
}
|
||||
|
||||
set_active_texture_unit(0);
|
||||
m_merge_rtt.bindTexture();
|
||||
if (copy_blend_destination)
|
||||
{
|
||||
set_active_texture_unit(2);
|
||||
m_merge_tex.bind();
|
||||
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
|
||||
}
|
||||
|
||||
m_plane.draw_fill();
|
||||
|
||||
if (copy_blend_destination)
|
||||
{
|
||||
set_active_texture_unit(2);
|
||||
m_merge_tex.unbind();
|
||||
}
|
||||
set_active_texture_unit(0);
|
||||
m_merge_rtt.unbindTexture();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,22 @@ struct LegacyCanvasDrawMergeShaderExecution {
|
||||
std::function<void(kShaderUniform, const glm::mat4&)> set_mat4;
|
||||
};
|
||||
|
||||
struct LegacyCanvasDrawMergeLayerBlendUniforms {
|
||||
LegacyCanvasDrawMergeTextureBlendUniforms shader;
|
||||
bool copy_destination = false;
|
||||
};
|
||||
|
||||
struct LegacyCanvasDrawMergeLayerBlendExecution {
|
||||
std::function<void()> unbind_merge_framebuffer;
|
||||
std::function<void()> bind_samplers;
|
||||
std::function<void()> bind_merge_texture;
|
||||
std::function<void()> bind_destination_texture;
|
||||
std::function<void()> copy_destination_framebuffer;
|
||||
std::function<void()> draw;
|
||||
std::function<void()> unbind_destination_texture;
|
||||
std::function<void()> unbind_merge_texture;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline LegacyCanvasDrawMergeShaderExecution legacy_shader_manager_draw_merge_execution() noexcept
|
||||
{
|
||||
return {
|
||||
@@ -218,4 +234,27 @@ inline void setup_legacy_canvas_draw_merge_texture_colorize_shader(
|
||||
setup_legacy_canvas_draw_merge_texture_colorize_shader(uniforms, legacy_shader_manager_draw_merge_execution());
|
||||
}
|
||||
|
||||
inline void execute_legacy_canvas_draw_merge_layer_blend(
|
||||
const LegacyCanvasDrawMergeLayerBlendUniforms& uniforms,
|
||||
const LegacyCanvasDrawMergeLayerBlendExecution& execution)
|
||||
{
|
||||
execution.unbind_merge_framebuffer();
|
||||
execution.bind_samplers();
|
||||
setup_legacy_canvas_draw_merge_texture_blend_shader(uniforms.shader);
|
||||
execution.bind_merge_texture();
|
||||
|
||||
if (uniforms.copy_destination) {
|
||||
execution.bind_destination_texture();
|
||||
execution.copy_destination_framebuffer();
|
||||
}
|
||||
|
||||
execution.draw();
|
||||
|
||||
if (uniforms.copy_destination) {
|
||||
execution.unbind_destination_texture();
|
||||
}
|
||||
|
||||
execution.unbind_merge_texture();
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
Reference in New Issue
Block a user