From cc33fbdde25cb954aa86111946c6a43a168bc3cc Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 2 Jun 2026 20:35:28 +0200 Subject: [PATCH] Map render pass clear values to OpenGL --- docs/modernization/build-inventory.md | 2 +- docs/modernization/roadmap.md | 2 +- src/renderer_gl/opengl_capabilities.cpp | 14 ++++++++ src/renderer_gl/opengl_capabilities.h | 8 +++++ tests/renderer_gl/capabilities_tests.cpp | 44 ++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 10acc55..bdb28e7 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -201,7 +201,7 @@ Known local toolchain state: framebuffer targets, binding queries, attachment points, and completion status used by `RTT::create` and framebuffer bind/restore paths, plus RTT clear color/depth masks, renderer API render-pass color/depth/stencil - clear-mask mapping, and color-write-mask query tokens. `RTT` no longer + clear-mask and clear-value mapping, and color-write-mask query tokens. `RTT` no longer spells GL enum names directly. It also validates renderer API primitive-topology to OpenGL draw-mode mapping, Shape index-type, fill/stroke primitive-mode, buffer target, static upload usage, diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 560595f..4ff697a 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -455,7 +455,7 @@ render-target texture parameters, texture/renderbuffer targets, depth format, framebuffer targets, binding queries, attachment points, and completion status used by `RTT::create` and framebuffer bind/restore paths, also live in `pp_renderer_gl`. RTT clear color/depth masks, renderer API render-pass -color/depth/stencil clear-mask mapping, and color-write-mask query tokens also +color/depth/stencil clear-mask and clear-value mapping, and color-write-mask query tokens also live in `pp_renderer_gl`. `RTT` no longer spells GL enum names directly. Renderer API primitive-topology to OpenGL draw-mode mapping, mesh index-type and primitive-mode decisions used by legacy `Shape` drawing, plus Shape buffer diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index 4586c37..1fb74e3 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -492,6 +492,20 @@ std::uint32_t clear_mask_for_render_pass(pp::renderer::RenderPassDesc desc) noex return mask; } +OpenGlClearValues clear_values_for_render_pass(pp::renderer::RenderPassDesc desc) noexcept +{ + return OpenGlClearValues { + .color = { + desc.clear_color.r, + desc.clear_color.g, + desc.clear_color.b, + desc.clear_color.a, + }, + .depth = desc.clear_depth, + .stencil = desc.clear_stencil, + }; +} + std::uint32_t color_write_mask_query() noexcept { return gl_color_writemask; diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index b3f0bdd..c6483d6 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -72,6 +72,12 @@ struct OpenGlColorWriteMask { std::uint8_t a = 0; }; +struct OpenGlClearValues { + std::array color {}; + float depth = 1.0F; + std::uint8_t stencil = 0; +}; + struct OpenGlBlendState { std::uint8_t enabled = 0; std::uint32_t source_color_factor = 0; @@ -153,6 +159,8 @@ struct OpenGlWindowsWglContextConfig { [[nodiscard]] std::uint32_t framebuffer_stencil_buffer_mask() noexcept; [[nodiscard]] std::uint32_t clear_mask_for_render_pass( pp::renderer::RenderPassDesc desc) noexcept; +[[nodiscard]] OpenGlClearValues clear_values_for_render_pass( + pp::renderer::RenderPassDesc desc) noexcept; [[nodiscard]] std::uint32_t color_write_mask_query() noexcept; [[nodiscard]] std::uint32_t framebuffer_blit_filter(bool linear) noexcept; [[nodiscard]] OpenGlEnumMapping blit_filter_for_renderer_filter( diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index 3332ab1..3a405e8 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -310,6 +310,49 @@ void maps_render_pass_clear_masks(pp::tests::Harness& h) PP_EXPECT(h, all_buffers == 0x00004500U); } +void maps_render_pass_clear_values(pp::tests::Harness& h) +{ + const auto values = pp::renderer::gl::clear_values_for_render_pass(pp::renderer::RenderPassDesc { + .clear_color_enabled = true, + .clear_color = { + .r = 0.125F, + .g = 0.25F, + .b = 0.5F, + .a = 1.0F, + }, + .clear_depth_enabled = true, + .clear_depth = 0.625F, + .clear_stencil_enabled = true, + .clear_stencil = 7U, + }); + const auto disabled_values = pp::renderer::gl::clear_values_for_render_pass(pp::renderer::RenderPassDesc { + .clear_color_enabled = false, + .clear_color = { + .r = 1.0F, + .g = 0.75F, + .b = 0.5F, + .a = 0.25F, + }, + .clear_depth_enabled = false, + .clear_depth = 0.125F, + .clear_stencil_enabled = false, + .clear_stencil = 13U, + }); + + PP_EXPECT(h, values.color[0] == 0.125F); + PP_EXPECT(h, values.color[1] == 0.25F); + PP_EXPECT(h, values.color[2] == 0.5F); + PP_EXPECT(h, values.color[3] == 1.0F); + PP_EXPECT(h, values.depth == 0.625F); + PP_EXPECT(h, values.stencil == 7U); + PP_EXPECT(h, disabled_values.color[0] == 1.0F); + PP_EXPECT(h, disabled_values.color[1] == 0.75F); + PP_EXPECT(h, disabled_values.color[2] == 0.5F); + PP_EXPECT(h, disabled_values.color[3] == 0.25F); + PP_EXPECT(h, disabled_values.depth == 0.125F); + PP_EXPECT(h, disabled_values.stencil == 13U); +} + void maps_renderer_primitive_topologies_to_draw_modes(pp::tests::Harness& h) { PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_renderer_topology( @@ -963,6 +1006,7 @@ int main() harness.run("maps_framebuffer_render_target_parameters", maps_framebuffer_render_target_parameters); harness.run("maps_framebuffer_blit_parameters", maps_framebuffer_blit_parameters); harness.run("maps_render_pass_clear_masks", maps_render_pass_clear_masks); + harness.run("maps_render_pass_clear_values", maps_render_pass_clear_values); harness.run("maps_renderer_primitive_topologies_to_draw_modes", maps_renderer_primitive_topologies_to_draw_modes); harness.run("maps_shape_index_and_primitive_modes", maps_shape_index_and_primitive_modes); harness.run("maps_panopainter_cube_faces_to_texture_targets", maps_panopainter_cube_faces_to_texture_targets);