Move canvas stroke commit GL mappings to renderer gl

This commit is contained in:
2026-06-02 09:15:55 +02:00
parent 37a59c01ac
commit 737c29cca4
3 changed files with 40 additions and 27 deletions

View File

@@ -218,6 +218,9 @@ Known local toolchain state:
format/type, stroke mixer depth/scissor/blend state, saved viewport and format/type, stroke mixer depth/scissor/blend state, saved viewport and
clear-state queries, active texture units, fallback 2D texture unbind clear-state queries, active texture units, fallback 2D texture unbind
targets, and stroke background copy targets. targets, and stroke background copy targets.
Canvas stroke commit also consumes backend-owned saved viewport/clear/blend
state, history readback format/type, active texture units, fallback 2D
texture unbind targets, and layer compositing copy targets.
- `windows-msvc-vcpkg-headless` validates manifest install/configure/build/test - `windows-msvc-vcpkg-headless` validates manifest install/configure/build/test
for the current headless component matrix; see DEBT-0007 for remaining app for the current headless component matrix; see DEBT-0007 for remaining app
and platform triplet migration. and platform triplet migration.

View File

@@ -762,6 +762,9 @@ Results:
and blend state, saved viewport/clear-state queries, active texture units, and blend state, saved viewport/clear-state queries, active texture units,
fallback 2D texture unbinds, and stroke background copy targets through the fallback 2D texture unbinds, and stroke background copy targets through the
renderer GL backend mapping. renderer GL backend mapping.
- Canvas stroke commit now routes saved viewport/clear/blend state, history
readbacks, active texture units, fallback 2D texture unbinds, and layer
compositing copy targets through the renderer GL backend mapping.
- Known remaining warnings: legacy project/vendor diagnostics, Visual Studio - Known remaining warnings: legacy project/vendor diagnostics, Visual Studio
vcpkg-manifest warning, `LNK4099` missing libyuv PDBs, and `LNK4098` runtime vcpkg-manifest warning, `LNK4099` missing libyuv PDBs, and `LNK4098` runtime
library conflict from retained vendor binaries. library conflict from retained vendor binaries.

View File

@@ -854,9 +854,9 @@ void Canvas::stroke_commit()
// save viewport and clear color states // save viewport and clear color states
GLint vp[4]; GLint vp[4];
GLfloat cc[4]; GLfloat cc[4];
glGetIntegerv(GL_VIEWPORT, vp); glGetIntegerv(viewport_query(), vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc); glGetFloatv(color_clear_value_query(), cc);
GLboolean blend = glIsEnabled(GL_BLEND); auto blend = glIsEnabled(blend_state());
// allocate action to add to history // allocate action to add to history
auto action = new ActionStroke; auto action = new ActionStroke;
@@ -867,7 +867,7 @@ void Canvas::stroke_commit()
// prepare common states // prepare common states
glViewport(0, 0, m_width, m_height); glViewport(0, 0, m_width, m_height);
glDisable(GL_BLEND); glDisable(blend_state());
const auto& b = m_current_stroke->m_brush; const auto& b = m_current_stroke->m_brush;
@@ -882,7 +882,14 @@ void Canvas::stroke_commit()
// save image before commit // save image before commit
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]); glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4); action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get()); glReadPixels(
m_dirty_box[i].x,
m_dirty_box[i].y,
box_sz.x,
box_sz.y,
rgba_pixel_format(),
unsigned_byte_component_type(),
action->m_image[i].get());
action->m_box[i] = m_dirty_box[i]; action->m_box[i] = m_dirty_box[i];
action->m_old_box[i] = m_layers[m_current_layer_idx]->box(i); action->m_old_box[i] = m_layers[m_current_layer_idx]->box(i);
@@ -899,13 +906,13 @@ void Canvas::stroke_commit()
m_layers[m_current_layer_idx]->face(i) = true; m_layers[m_current_layer_idx]->face(i) = true;
// copy to tmp2 for layer blending // copy to tmp2 for layer blending
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].bind(); m_tex2[i].bind();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height); glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
m_tex2[i].unbind(); m_tex2[i].unbind();
m_tmp[i].bindTexture(); m_tmp[i].bindTexture();
glActiveTexture(GL_TEXTURE1); set_active_texture_unit(1);
m_tex2[i].bind(); m_tex2[i].bind();
m_sampler.bind(0); m_sampler.bind(0);
m_sampler_nearest.bind(1); m_sampler_nearest.bind(1);
@@ -922,17 +929,17 @@ void Canvas::stroke_commit()
ShaderManager::u_float(kShaderUniform::Alpha, 1); ShaderManager::u_float(kShaderUniform::Alpha, 1);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f)); ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].bind(); m_tex2[i].bind();
glActiveTexture(GL_TEXTURE1); set_active_texture_unit(1);
m_tmp[i].bindTexture(); m_tmp[i].bindTexture();
glActiveTexture(GL_TEXTURE2); set_active_texture_unit(2);
m_smask.rtt(i).bindTexture(); m_smask.rtt(i).bindTexture();
m_plane.draw_fill(); m_plane.draw_fill();
m_smask.rtt(i).unbindTexture(); m_smask.rtt(i).unbindTexture();
glActiveTexture(GL_TEXTURE1); set_active_texture_unit(1);
m_tmp[i].unbindTexture(); m_tmp[i].unbindTexture();
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].unbind(); m_tex2[i].unbind();
} }
else else
@@ -966,28 +973,28 @@ void Canvas::stroke_commit()
ShaderManager::u_int(kShaderUniform::PatternBlendMode, b->m_pattern_blend_mode); ShaderManager::u_int(kShaderUniform::PatternBlendMode, b->m_pattern_blend_mode);
ShaderManager::u_vec2(kShaderUniform::PatternOffset, m_pattern_offset); ShaderManager::u_vec2(kShaderUniform::PatternOffset, m_pattern_offset);
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].bind(); m_tex2[i].bind();
glActiveTexture(GL_TEXTURE1); set_active_texture_unit(1);
m_tmp[i].bindTexture(); m_tmp[i].bindTexture();
glActiveTexture(GL_TEXTURE2); set_active_texture_unit(2);
m_smask.rtt(i).bindTexture(); m_smask.rtt(i).bindTexture();
glActiveTexture(GL_TEXTURE3); set_active_texture_unit(3);
if (b->m_dual_enabled) if (b->m_dual_enabled)
m_tmp_dual[i].bindTexture(); m_tmp_dual[i].bindTexture();
glActiveTexture(GL_TEXTURE4); set_active_texture_unit(4);
b->m_pattern_texture ? b->m_pattern_texture ?
b->m_pattern_texture->bind() : b->m_pattern_texture->bind() :
glBindTexture(GL_TEXTURE_2D, 0); unbind_texture_2d();
m_plane.draw_fill(); m_plane.draw_fill();
glActiveTexture(GL_TEXTURE3); set_active_texture_unit(3);
if (b->m_dual_enabled) if (b->m_dual_enabled)
m_tmp_dual[i].unbindTexture(); m_tmp_dual[i].unbindTexture();
glActiveTexture(GL_TEXTURE2); set_active_texture_unit(2);
m_smask.rtt(i).unbindTexture(); m_smask.rtt(i).unbindTexture();
glActiveTexture(GL_TEXTURE1); set_active_texture_unit(1);
m_tmp[i].unbindTexture(); m_tmp[i].unbindTexture();
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].unbind(); m_tex2[i].unbind();
} }
// else // else
@@ -1010,19 +1017,19 @@ void Canvas::stroke_commit()
ShaderManager::use(kShader::StrokeDilate); ShaderManager::use(kShader::StrokeDilate);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f)); ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::TexBG, 0); ShaderManager::u_int(kShaderUniform::TexBG, 0);
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
m_tex2[i].bind(); m_tex2[i].bind();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height); glCopyTexSubImage2D(texture_2d_target(), 0, 0, 0, 0, 0, m_width, m_height);
m_plane.draw_fill(); m_plane.draw_fill();
m_layers[m_current_layer_idx]->rtt(i).unbindFramebuffer(); m_layers[m_current_layer_idx]->rtt(i).unbindFramebuffer();
} }
// restore viewport and clear color states // restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND); blend ? glEnable(blend_state()) : glDisable(blend_state());
glViewport(vp[0], vp[1], vp[2], vp[3]); glViewport(vp[0], vp[1], vp[2], vp[3]);
glClearColor(cc[0], cc[1], cc[2], cc[3]); glClearColor(cc[0], cc[1], cc[2], cc[3]);
glActiveTexture(GL_TEXTURE0); set_active_texture_unit(0);
// save history // save history
action->m_layer_idx = m_current_layer_idx; action->m_layer_idx = m_current_layer_idx;