Route framebuffer texture copies through GL backend

This commit is contained in:
2026-06-04 21:12:46 +02:00
parent 15c58bfb21
commit 6440bde002
13 changed files with 285 additions and 46 deletions

View File

@@ -6,6 +6,7 @@
#include "node_progress_bar.h"
#include "paint_renderer/compositor.h"
#include "renderer_gl/opengl_capabilities.h"
#include "util.h"
#include <thread>
#include <algorithm>
#include <cstdint>
@@ -564,8 +565,7 @@ glm::vec4 Canvas::stroke_draw_samples(
glm::ivec2 tex_sz = glm::clamp(glm::ceil(bb_sz) + pad * 2.f, { 0, 0 }, (glm::vec2)(glm::ivec2(m_width, m_height) - tex_pos));
if (copy_stroke_destination)
{
glCopyTexSubImage2D(texture_2d_target(), 0, tex_pos.x, tex_pos.y,
tex_pos.x, tex_pos.y, tex_sz.x, tex_sz.y);
copy_framebuffer_to_texture_2d(tex_pos.x, tex_pos.y, tex_pos.x, tex_pos.y, tex_sz.x, tex_sz.y);
}
if (P.size() == 4)
@@ -835,7 +835,7 @@ void Canvas::stroke_draw()
glm::vec2 sz = glm::min(m_size, zw(b) + pad) - o;
m_tex[i].bind();
if (sz.x > 0 && sz.y > 0)
glCopyTexSubImage2D(texture_2d_target(), 0, o.x, o.y, o.x, o.y, sz.x, sz.y);
copy_framebuffer_to_texture_2d(o.x, o.y, o.x, o.y, sz.x, sz.y);
}
m_brush_shape.draw_fill();
m_tmp[i].unbindFramebuffer();
@@ -1050,7 +1050,7 @@ void Canvas::stroke_commit()
// copy to tmp2 for layer blending
set_active_texture_unit(0);
m_tex2[i].bind();
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
m_tex2[i].unbind();
m_tmp[i].bindTexture();
@@ -1161,7 +1161,7 @@ void Canvas::stroke_commit()
ShaderManager::u_int(kShaderUniform::TexBG, 0);
set_active_texture_unit(0);
m_tex2[i].bind();
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
m_plane.draw_fill();
m_layers[m_current_layer_idx]->rtt(i).unbindFramebuffer();
@@ -1390,7 +1390,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SI
{
set_active_texture_unit(2);
m_merge_tex.bind();
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
}
m_plane.draw_fill();
@@ -1407,7 +1407,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SI
set_active_texture_unit(2);
m_merge_tex.bind();
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
// draw the grid behind the layers using a temporary copy
if (use_blend)
@@ -1593,7 +1593,7 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
// copy to tmp2 for layer blending
set_active_texture_unit(0);
m_tex2[i].bind();
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
m_tex2[i].unbind();
m_sampler.bind(0);
@@ -2920,7 +2920,7 @@ Image Canvas::thumbnail_generate(int w, int h)
if (copy_layer_destination)
{
set_active_texture_unit(2);
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, w, h);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, w, h);
}
ShaderManager::u_int(kShaderUniform::BlendMode, m_layers[layer_index]->m_blend_mode);
ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index]->m_opacity);
@@ -2939,7 +2939,7 @@ Image Canvas::thumbnail_generate(int w, int h)
set_active_texture_unit(0);
blendtex.bind();
// copy the content of the fb before drawing the grid
glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, w, h);
copy_framebuffer_to_texture_2d(0, 0, 0, 0, w, h);
// draw the grid
ShaderManager::use(kShader::Checkerboard);