From f7d32f283523de38358b0359045258a9595f53f3 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 2 Jun 2026 09:20:18 +0200 Subject: [PATCH] Move canvas merge GL mappings to renderer gl --- docs/modernization/build-inventory.md | 3 ++ docs/modernization/roadmap.md | 3 ++ src/canvas.cpp | 56 +++++++++++++-------------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index dbf7787..bd1360e 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -221,6 +221,9 @@ Known local toolchain state: 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. + Canvas layer merge rendering also consumes backend-owned depth/blend state, + active texture units, fallback 2D texture unbind targets, and merge + framebuffer copy targets. - `windows-msvc-vcpkg-headless` validates manifest install/configure/build/test for the current headless component matrix; see DEBT-0007 for remaining app and platform triplet migration. diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index ae16275..86d1908 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -765,6 +765,9 @@ Results: - 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. +- Canvas layer merge rendering now routes depth/blend state, active texture + units, fallback 2D texture unbinds, and merge framebuffer copy targets through + the renderer GL backend mapping. - Known remaining warnings: legacy project/vendor diagnostics, Visual Studio vcpkg-manifest warning, `LNK4099` missing libyuv PDBs, and `LNK4098` runtime library conflict from retained vendor binaries. diff --git a/src/canvas.cpp b/src/canvas.cpp index 4cba841..f720a3b 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -1076,7 +1076,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI use_blend |= Canvas::I->m_current_stroke->m_brush->m_blend_mode != 0; // if not using shader blend, use gl rasterizer blend - glDisable(GL_DEPTH_TEST); + glDisable(depth_test_state()); for (int plane_index = 0; plane_index < 6; plane_index++) { @@ -1088,7 +1088,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI if (use_blend) { - glDisable(GL_BLEND); + glDisable(blend_state()); m_layers_merge.rtt(plane_index).clear(); } else @@ -1100,7 +1100,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI ShaderManager::u_mat4(kShaderUniform::MVP, ortho); m_plane.draw_fill(); } - glEnable(GL_BLEND); + glEnable(blend_state()); } for (int layer_index = 0; layer_index < m_layers.size(); layer_index++) @@ -1132,17 +1132,17 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI //ShaderManager::u_int(kShaderUniform::Lock, m_layers[layer_index]->m_alpha_locked); ShaderManager::u_int(kShaderUniform::Mask, m_smask_active); ShaderManager::u_mat4(kShaderUniform::MVP, ortho); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_layers[layer_index]->rtt(plane_index).bindTexture(); - glActiveTexture(GL_TEXTURE1); + set_active_texture_unit(1); m_tmp[plane_index].bindTexture(); - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_smask.rtt(plane_index).bindTexture(); m_plane.draw_fill(); m_smask.rtt(plane_index).unbindTexture(); - glActiveTexture(GL_TEXTURE1); + set_active_texture_unit(1); m_tmp[plane_index].unbindTexture(); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_layers[layer_index]->rtt(plane_index).unbindTexture(); } else if (m_current_stroke && m_show_tmp && m_current_layer_idx == layer_index) @@ -1182,28 +1182,28 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI ShaderManager::u_vec2(kShaderUniform::PatternOffset, Canvas::I->m_pattern_offset); ShaderManager::u_float(kShaderUniform::DualAlpha, b->m_dual_opacity); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_layers[layer_index]->rtt(plane_index).bindTexture(); - glActiveTexture(GL_TEXTURE1); + set_active_texture_unit(1); m_tmp[plane_index].bindTexture(); - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_smask.rtt(plane_index).bindTexture(); - glActiveTexture(GL_TEXTURE3); + set_active_texture_unit(3); if (b->m_dual_enabled) m_tmp_dual[plane_index].bindTexture(); - glActiveTexture(GL_TEXTURE4); + set_active_texture_unit(4); b->m_pattern_texture ? b->m_pattern_texture->bind() : - glBindTexture(GL_TEXTURE_2D, 0); + unbind_texture_2d(); m_plane.draw_fill(); - glActiveTexture(GL_TEXTURE3); + set_active_texture_unit(3); if (b->m_dual_enabled) m_tmp_dual[plane_index].unbindTexture(); - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_smask.rtt(plane_index).unbindTexture(); - glActiveTexture(GL_TEXTURE1); + set_active_texture_unit(1); m_tmp[plane_index].unbindTexture(); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_layers[layer_index]->rtt(plane_index).unbindTexture(); } else @@ -1215,7 +1215,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI ShaderManager::u_int(kShaderUniform::Highlight, m_layers[layer_index]->m_hightlight); ShaderManager::u_mat4(kShaderUniform::MVP, ortho); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_layers[layer_index]->rtt(plane_index).bindTexture(); m_plane.draw_fill(); m_layers[layer_index]->rtt(plane_index).unbindTexture(); @@ -1243,35 +1243,35 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI ShaderManager::u_int(kShaderUniform::TexBG, 2); } - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_merge_rtt.bindTexture(); if (!ShaderManager::ext_framebuffer_fetch) { - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_merge_tex.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(); if (!ShaderManager::ext_framebuffer_fetch) { - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_merge_tex.unbind(); } - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_merge_rtt.unbindTexture(); } } - glActiveTexture(GL_TEXTURE2); + set_active_texture_unit(2); m_merge_tex.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); // draw the grid behind the layers using a temporary copy if (use_blend) { - glEnable(GL_BLEND); + glEnable(blend_state()); //draw the grid if (draw_checkerboard) @@ -1284,7 +1284,7 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI // draw the layers m_sampler.bind(0); - glActiveTexture(GL_TEXTURE0); + set_active_texture_unit(0); m_merge_tex.bind(); ShaderManager::use(kShader::Texture); ShaderManager::u_int(kShaderUniform::Tex, 0);