From 11c7d87330b00e07c0b39ee3eaaff95e6fedf711 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 4 Jun 2026 19:28:34 +0200 Subject: [PATCH] Move OpenGL runtime classification into renderer backend --- CMakeLists.txt | 11 +++++++++++ docs/modernization/build-inventory.md | 4 ++++ docs/modernization/roadmap.md | 4 ++++ src/app_shaders.cpp | 23 +++++++---------------- src/renderer_gl/opengl_capabilities.cpp | 15 +++++++++++++++ src/renderer_gl/opengl_capabilities.h | 1 + tests/renderer_gl/capabilities_tests.cpp | 11 +++++++++++ 7 files changed, 53 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 191203e..7c39fd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,17 @@ if(PP_ENABLE_OPENGL) pp_project_options PRIVATE pp_project_warnings) + if(EMSCRIPTEN) + target_compile_definitions(pp_renderer_gl PRIVATE + PP_RENDERER_GL_RUNTIME_GLES=1 + PP_RENDERER_GL_RUNTIME_WEB=1) + elseif(ANDROID OR CMAKE_SYSTEM_NAME STREQUAL "iOS") + target_compile_definitions(pp_renderer_gl PRIVATE + PP_RENDERER_GL_RUNTIME_GLES=1) + else() + target_compile_definitions(pp_renderer_gl PRIVATE + PP_RENDERER_GL_RUNTIME_DESKTOP=1) + endif() endif() add_library(pp_paint_renderer STATIC diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 616a884..7862013 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -788,6 +788,10 @@ Known warnings after the current CMake app build: the retained OpenGL runtime classes still include legacy app/engine headers and are still consumed directly by canvas and UI classes. It should become a normal backend library once those call sites depend on `pp_renderer_api`. + `pp_renderer_gl` now owns OpenGL runtime build-target classification through + CMake target compile definitions and `opengl_runtime_for_current_build()`, + so app shader startup asks the backend for desktop GL/GLES/WebGL policy + instead of carrying local platform branches. - `pp_legacy_ui_core` is an object-library containment boundary because the retained base `Node` controls still depend on legacy renderer and app headers. It should shrink as layout parsing, colors, generic controls, and diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 1622ad9..5ccf257 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -672,6 +672,10 @@ Default canvas allocation size now dispatches through `PlatformServices`, so 1536 and WebGL 512 defaults without carrying the old `CANVAS_RES` platform macro in `canvas.h`; DEBT-0057 tracks moving the retained WebGL policy branch out of the legacy fallback when the Web shell owns injected services. +OpenGL runtime build-target classification now lives in `pp_renderer_gl` +through CMake-owned compile definitions and +`opengl_runtime_for_current_build()`, so `app_shaders.cpp` no longer decides +desktop GL/GLES/WebGL capability policy with local platform branches. Prepared-file save/download handoff is now also part of the service contract, so iOS/Web export completion routes through `PlatformServices` after the app writes the temporary/exported payload. diff --git a/src/app_shaders.cpp b/src/app_shaders.cpp index 51bb2cc..53e603e 100644 --- a/src/app_shaders.cpp +++ b/src/app_shaders.cpp @@ -50,16 +50,7 @@ void App::initShaders() LOG("EXT: %s", extension_storage.back().c_str()); } - pp::renderer::gl::OpenGlRuntime runtime; -#if __GL__ - runtime.desktop_gl = true; -#endif -#if __GLES__ - runtime.gles = true; -#endif -#if __WEB__ - runtime.web = true; -#endif + const auto runtime = pp::renderer::gl::opengl_runtime_for_current_build(); const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(extension_views, runtime); ShaderManager::ext_framebuffer_fetch = capabilities.framebuffer_fetch; ShaderManager::ext_map_aligned = capabilities.map_buffer_alignment; @@ -69,12 +60,12 @@ void App::initShaders() ShaderManager::set_render_device_features(pp::renderer::gl::render_device_features(capabilities)); }); -#if __GL__ - // In OpenGL 3.3 these should be already available - ShaderManager::ext_float32_linear = true; - ShaderManager::ext_float32 = true; - ShaderManager::ext_float16 = true; -#endif + if (pp::renderer::gl::opengl_runtime_for_current_build().desktop_gl) { + // In OpenGL 3.3 these should be already available. + ShaderManager::ext_float32_linear = true; + ShaderManager::ext_float32 = true; + ShaderManager::ext_float16 = true; + } ShaderManager::set_render_device_features( pp::renderer::gl::render_device_features(shader_manager_capabilities())); diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index 5c892d2..5569a74 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -201,6 +201,21 @@ OpenGlCapabilities detect_opengl_capabilities( return capabilities; } +OpenGlRuntime opengl_runtime_for_current_build() noexcept +{ + OpenGlRuntime runtime; +#if defined(PP_RENDERER_GL_RUNTIME_DESKTOP) + runtime.desktop_gl = true; +#endif +#if defined(PP_RENDERER_GL_RUNTIME_GLES) + runtime.gles = true; +#endif +#if defined(PP_RENDERER_GL_RUNTIME_WEB) + runtime.web = true; +#endif + return runtime; +} + pp::renderer::RenderDeviceFeatures render_device_features(OpenGlCapabilities capabilities) noexcept { return pp::renderer::RenderDeviceFeatures { diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index e56a56e..3f9bcea 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -678,6 +678,7 @@ struct OpenGlMeshDeleteDispatch { [[nodiscard]] OpenGlCapabilities detect_opengl_capabilities( std::span extensions, OpenGlRuntime runtime) noexcept; +[[nodiscard]] OpenGlRuntime opengl_runtime_for_current_build() noexcept; [[nodiscard]] pp::renderer::RenderDeviceFeatures render_device_features( OpenGlCapabilities capabilities) noexcept; [[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept; diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index d975fad..74659d3 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -1035,6 +1035,16 @@ void ignores_gles_texture_extensions_for_webgl_runtime(pp::tests::Harness& h) PP_EXPECT(h, !capabilities.float16_textures); } +void classifies_current_build_opengl_runtime(pp::tests::Harness& h) +{ + const auto runtime = pp::renderer::gl::opengl_runtime_for_current_build(); + + PP_EXPECT(h, runtime.desktop_gl || runtime.gles); + PP_EXPECT(h, !(runtime.desktop_gl && runtime.gles)); + if (runtime.web) + PP_EXPECT(h, runtime.gles); +} + void selects_texture_upload_type_from_internal_format(pp::tests::Harness& h) { constexpr std::uint32_t gl_unsigned_byte = 0x1401U; @@ -4092,6 +4102,7 @@ int main() harness.run("treats_desktop_gl_float_rendering_as_core", treats_desktop_gl_float_rendering_as_core); harness.run("detects_gles_texture_float_extensions", detects_gles_texture_float_extensions); harness.run("ignores_gles_texture_extensions_for_webgl_runtime", ignores_gles_texture_extensions_for_webgl_runtime); + harness.run("classifies_current_build_opengl_runtime", classifies_current_build_opengl_runtime); harness.run("selects_texture_upload_type_from_internal_format", selects_texture_upload_type_from_internal_format); harness.run("maps_image_channel_count_to_texture_format", maps_image_channel_count_to_texture_format); harness.run("maps_renderer_texture_formats_to_opengl_tokens", maps_renderer_texture_formats_to_opengl_tokens);