diff --git a/src/legacy_canvas_draw_merge_services.h b/src/legacy_canvas_draw_merge_services.h index b2e0b924..69935ba6 100644 --- a/src/legacy_canvas_draw_merge_services.h +++ b/src/legacy_canvas_draw_merge_services.h @@ -175,6 +175,20 @@ struct LegacyCanvasDrawMergeFinalPlaneCompositeExecution { std::function unbind_merged_texture; }; +struct LegacyCanvasDrawMergeDisplayResolveUniforms { + LegacyCanvasDrawMergeTextureUniforms texture; +}; + +struct LegacyCanvasDrawMergeDisplayResolveExecution { + std::function unbind_resolve_framebuffer; + std::function clear_color_buffer; + std::function apply_viewport; + std::function bind_sampler; + std::function bind_resolve_texture; + std::function draw; + std::function unbind_resolve_texture; +}; + [[nodiscard]] inline LegacyCanvasDrawMergeShaderExecution legacy_shader_manager_draw_merge_execution() noexcept { return { @@ -433,4 +447,18 @@ inline void execute_legacy_canvas_draw_merge_final_plane_composite( execution.unbind_merged_texture(); } +inline void execute_legacy_canvas_draw_merge_display_resolve( + const LegacyCanvasDrawMergeDisplayResolveUniforms& uniforms, + const LegacyCanvasDrawMergeDisplayResolveExecution& execution) +{ + execution.unbind_resolve_framebuffer(); + execution.clear_color_buffer(); + execution.apply_viewport(); + execution.bind_sampler(); + execution.bind_resolve_texture(); + setup_legacy_canvas_draw_merge_texture_shader(uniforms.texture); + execution.draw(); + execution.unbind_resolve_texture(); +} + } // namespace pp::panopainter diff --git a/src/node_canvas.cpp b/src/node_canvas.cpp index 7c8313b9..d09f53c4 100644 --- a/src/node_canvas.cpp +++ b/src/node_canvas.cpp @@ -762,22 +762,37 @@ void NodeCanvas::draw() if (m_density != 1.f) { - m_rtt.unbindFramebuffer(); - - clear_node_canvas_color_buffer({ 1.f, 1.f, 1.f, 0.f }); - apply_node_canvas_viewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w); - - // draw the canvas - m_sampler_nearest.bind(0); - set_active_texture_unit(0); - m_rtt.bindTexture(); - pp::panopainter::setup_legacy_canvas_draw_merge_texture_shader( - pp::panopainter::LegacyCanvasDrawMergeTextureUniforms { - .mvp = glm::ortho(-1, 1, -1, 1), - .texture_slot = 0, + pp::panopainter::execute_legacy_canvas_draw_merge_display_resolve( + pp::panopainter::LegacyCanvasDrawMergeDisplayResolveUniforms { + .texture = { + .mvp = glm::ortho(-1, 1, -1, 1), + .texture_slot = 0, + }, + }, + { + .unbind_resolve_framebuffer = [&] { + m_rtt.unbindFramebuffer(); + }, + .clear_color_buffer = [&] { + clear_node_canvas_color_buffer({ 1.f, 1.f, 1.f, 0.f }); + }, + .apply_viewport = [&] { + apply_node_canvas_viewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w); + }, + .bind_sampler = [&] { + m_sampler_nearest.bind(0); + }, + .bind_resolve_texture = [&] { + set_active_texture_unit(0); + m_rtt.bindTexture(); + }, + .draw = [&] { + m_face_plane.draw_fill(); + }, + .unbind_resolve_texture = [&] { + m_rtt.unbindTexture(); + }, }); - m_face_plane.draw_fill(); - m_rtt.unbindTexture(); } scissor ? apply_node_canvas_capability(pp::renderer::gl::scissor_test_state(), true) : apply_node_canvas_capability(pp::renderer::gl::scissor_test_state(), false);