Move grid panel render mapping to renderer gl

This commit is contained in:
2026-06-02 08:39:54 +02:00
parent 7280678593
commit 92e9de0441
6 changed files with 74 additions and 20 deletions

View File

@@ -182,6 +182,10 @@ Known local toolchain state:
Canvas layer cube/equirect generation, clear, restore, and snapshot paths
also consume backend-owned cube/2D texture targets, active texture units,
blend/clear state, and RGBA8 read/write pixel mapping.
`NodePanelGrid` heightmap preview and lightmap baking also consume
backend-owned texture readback formats, sampler filters, depth/blend state,
depth clears, viewport queries, color-mask booleans, active texture units,
and float render-target formats.
- `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.

View File

@@ -449,6 +449,10 @@ now also delegate blend-state tokens to `pp_renderer_gl`.
Canvas layer cube/equirect generation, clear, restore, and snapshot paths now
also delegate cube/2D texture targets, active texture units, blend/clear state,
and RGBA8 read/write pixel mapping to `pp_renderer_gl`.
`NodePanelGrid` heightmap preview and lightmap baking now delegate texture
readback formats, sampler filters, depth/blend state, depth clears, viewport
queries, color-mask booleans, active texture units, and float render-target
formats to `pp_renderer_gl`.
The existing renderer classes are not yet fully
behind the renderer interfaces.

View File

@@ -4,6 +4,7 @@
#include "canvas.h"
#include "app.h"
#include "image.h"
#include "renderer_gl/opengl_capabilities.h"
#include "util.h"
Node* NodePanelGrid::clone_instantiate() const
@@ -160,7 +161,12 @@ void NodePanelGrid::init_controls()
App::I->render_task([&]
{
m_texture.bind();
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data.get());
glGetTexImage(
pp::renderer::gl::texture_2d_target(),
0,
pp::renderer::gl::rgba_pixel_format(),
pp::renderer::gl::unsigned_byte_component_type(),
img.m_data.get());
m_texture.unbind();
});
Image resized = img.resize(texres, texres);
@@ -171,7 +177,9 @@ void NodePanelGrid::init_controls()
int rexres = get_texres();
m_texture.create(rexres, rexres);
m_sampler_mipmap.create();
m_sampler_mipmap.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
m_sampler_mipmap.set_filter(
pp::renderer::gl::linear_mipmap_linear_texture_filter(),
pp::renderer::gl::linear_texture_filter());
m_sampler_linear.create();
m_plane.create<1>(1, 1);
@@ -223,9 +231,9 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
assert(App::I->is_render_thread());
if (m_groud_opacity->get_value() > 0.f)
{
bool depth = glIsEnabled(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
bool depth = glIsEnabled(pp::renderer::gl::depth_test_state());
glEnable(pp::renderer::gl::depth_test_state());
glClear(pp::renderer::gl::framebuffer_depth_buffer_mask());
auto nav = m_hm_image.m_data ? -(m_hm_preview_nav->m_value - 0.5f) : glm::vec2(0);
auto mvp = proj * camera
@@ -239,14 +247,14 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
auto light_pos = glm::vec3(sinf(light_yaw) + nav.x, light_pitch + get_offset(), cosf(light_yaw) + nav.y);
auto light_dir = glm::normalize(light_pos);
glDisable(GL_BLEND);
glDisable(pp::renderer::gl::blend_state());
// DRAW SOLID
if (m_hm_image.m_data)
{
if (m_shade_mode == ShadeMode::Solid)
{
glDisable(GL_BLEND);
glDisable(pp::renderer::gl::blend_state());
ShaderManager::use(kShader::Lambert);
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
@@ -271,7 +279,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
ShaderManager::u_int(kShaderUniform::Tex, 0);
m_sampler_mipmap.bind(0);
glActiveTexture(GL_TEXTURE0);
glActiveTexture(pp::renderer::gl::active_texture_unit(0U));
m_texture.bind();
m_hm_plane.draw_fill();
m_texture.unbind();
@@ -282,7 +290,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
auto wire_alpha = m_hm_image.m_data ? m_hm_wireframe->get_value() : 1.f;
if (wire_alpha > 0.f)
{
glEnable(GL_BLEND);
glEnable(pp::renderer::gl::blend_state());
ShaderManager::use(kShader::Color);
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(
glm::vec3(m_groud_value->get_value()),
@@ -292,9 +300,17 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
if (m_hm_image.m_data && m_shade_mode == ShadeMode::Transparent)
{
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glColorMask(
pp::renderer::gl::color_write_disabled(),
pp::renderer::gl::color_write_disabled(),
pp::renderer::gl::color_write_disabled(),
pp::renderer::gl::color_write_disabled());
m_hm_plane.draw_fill();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glColorMask(
pp::renderer::gl::color_write_enabled(),
pp::renderer::gl::color_write_enabled(),
pp::renderer::gl::color_write_enabled(),
pp::renderer::gl::color_write_enabled());
}
m_hm_plane.draw_stroke();
}
@@ -307,23 +323,23 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
{
auto p2d = xy(c) / c.z;
GLint vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
glGetIntegerv(pp::renderer::gl::viewport_query(), vp);
auto aspect_ratio = (float)vp[3] / (float)vp[2];
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glEnable(pp::renderer::gl::blend_state());
glDisable(pp::renderer::gl::depth_test_state());
ShaderManager::use(kShader::Texture);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-1.f, 1.f, -1.f, 1.f) *
//glm::scale(glm::vec3(100)) *
glm::translate(glm::vec3(p2d, 0)) * glm::scale(glm::vec3(.1f * aspect_ratio, .1f, 1.f)));
glActiveTexture(GL_TEXTURE0);
glActiveTexture(pp::renderer::gl::active_texture_unit(0U));
m_sampler_linear.bind(0);
constexpr auto sun_tex = const_hash("data/sun.png");
TextureManager::get(sun_tex).bind();
m_plane.draw_fill();
}
}
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
depth ? glEnable(pp::renderer::gl::depth_test_state()) : glDisable(pp::renderer::gl::depth_test_state());
}
}
@@ -355,11 +371,11 @@ void NodePanelGrid::bake_uvs()
RTT fb;
if (ShaderManager::ext_float32)
{
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
fb.create(m_texture.size().x, m_texture.size().y, -1, pp::renderer::gl::rgba32f_internal_format());
}
else if (ShaderManager::ext_float16)
{
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
fb.create(m_texture.size().x, m_texture.size().y, -1, pp::renderer::gl::rgba16f_internal_format());
}
std::unique_ptr<float[]> data_nor;
@@ -367,8 +383,8 @@ void NodePanelGrid::bake_uvs()
App::I->render_task([&]{
fb.bindFramebuffer();
fb.clear({ 1, 0, 0, 1 });
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(pp::renderer::gl::blend_state());
glDisable(pp::renderer::gl::depth_test_state());
glViewport(0, 0, fb.getWidth(), fb.getHeight());
ShaderManager::use(kShader::BakeUV);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::mat4(1));

View File

@@ -100,6 +100,8 @@ constexpr std::uint32_t gl_pixel_pack_buffer = 0x88EBU;
constexpr std::uint32_t gl_pixel_unpack_buffer = 0x88ECU;
constexpr std::uint32_t gl_stream_read = 0x88E1U;
constexpr std::uint32_t gl_map_read_bit = 0x0001U;
constexpr std::uint8_t gl_boolean_false = 0U;
constexpr std::uint8_t gl_boolean_true = 1U;
[[nodiscard]] bool contains(std::string_view text, std::string_view needle) noexcept
{
@@ -544,6 +546,26 @@ std::uint32_t rgba8_internal_format() noexcept
return gl_rgba8;
}
std::uint32_t rgba16f_internal_format() noexcept
{
return gl_rgba16f;
}
std::uint32_t rgba32f_internal_format() noexcept
{
return gl_rgba32f;
}
std::uint8_t color_write_disabled() noexcept
{
return gl_boolean_false;
}
std::uint8_t color_write_enabled() noexcept
{
return gl_boolean_true;
}
std::uint32_t linear_texture_filter() noexcept
{
return gl_linear;

View File

@@ -111,6 +111,10 @@ struct OpenGlReadbackFormat {
[[nodiscard]] std::uint32_t add_blend_equation() noexcept;
[[nodiscard]] std::uint32_t max_blend_equation() noexcept;
[[nodiscard]] std::uint32_t rgba8_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba16f_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba32f_internal_format() noexcept;
[[nodiscard]] std::uint8_t color_write_disabled() noexcept;
[[nodiscard]] std::uint8_t color_write_enabled() noexcept;
[[nodiscard]] std::uint32_t linear_texture_filter() noexcept;
[[nodiscard]] std::uint32_t linear_mipmap_linear_texture_filter() noexcept;
[[nodiscard]] std::uint32_t nearest_texture_filter() noexcept;

View File

@@ -336,6 +336,10 @@ void maps_app_initialization_parameters(pp::tests::Harness& h)
PP_EXPECT(h, pp::renderer::gl::add_blend_equation() == 0x8006U);
PP_EXPECT(h, pp::renderer::gl::max_blend_equation() == 0x8008U);
PP_EXPECT(h, pp::renderer::gl::rgba8_internal_format() == 0x8058U);
PP_EXPECT(h, pp::renderer::gl::rgba16f_internal_format() == 0x881AU);
PP_EXPECT(h, pp::renderer::gl::rgba32f_internal_format() == 0x8814U);
PP_EXPECT(h, pp::renderer::gl::color_write_disabled() == 0U);
PP_EXPECT(h, pp::renderer::gl::color_write_enabled() == 1U);
PP_EXPECT(h, pp::renderer::gl::linear_texture_filter() == 0x2601U);
PP_EXPECT(h, pp::renderer::gl::linear_mipmap_linear_texture_filter() == 0x2703U);
PP_EXPECT(h, pp::renderer::gl::nearest_texture_filter() == 0x2600U);