Move OpenGL runtime classification into renderer backend

This commit is contained in:
2026-06-04 19:28:34 +02:00
parent 0489c4229e
commit 11c7d87330
7 changed files with 53 additions and 16 deletions

View File

@@ -180,6 +180,17 @@ if(PP_ENABLE_OPENGL)
pp_project_options pp_project_options
PRIVATE PRIVATE
pp_project_warnings) 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() endif()
add_library(pp_paint_renderer STATIC add_library(pp_paint_renderer STATIC

View File

@@ -788,6 +788,10 @@ Known warnings after the current CMake app build:
the retained OpenGL runtime classes still include legacy app/engine headers 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 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`. 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 - `pp_legacy_ui_core` is an object-library containment boundary because the
retained base `Node` controls still depend on legacy renderer and app retained base `Node` controls still depend on legacy renderer and app
headers. It should shrink as layout parsing, colors, generic controls, and headers. It should shrink as layout parsing, colors, generic controls, and

View File

@@ -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 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 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. 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, Prepared-file save/download handoff is now also part of the service contract,
so iOS/Web export completion routes through `PlatformServices` after the app so iOS/Web export completion routes through `PlatformServices` after the app
writes the temporary/exported payload. writes the temporary/exported payload.

View File

@@ -50,16 +50,7 @@ void App::initShaders()
LOG("EXT: %s", extension_storage.back().c_str()); LOG("EXT: %s", extension_storage.back().c_str());
} }
pp::renderer::gl::OpenGlRuntime runtime; const auto runtime = pp::renderer::gl::opengl_runtime_for_current_build();
#if __GL__
runtime.desktop_gl = true;
#endif
#if __GLES__
runtime.gles = true;
#endif
#if __WEB__
runtime.web = true;
#endif
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(extension_views, runtime); const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(extension_views, runtime);
ShaderManager::ext_framebuffer_fetch = capabilities.framebuffer_fetch; ShaderManager::ext_framebuffer_fetch = capabilities.framebuffer_fetch;
ShaderManager::ext_map_aligned = capabilities.map_buffer_alignment; 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)); ShaderManager::set_render_device_features(pp::renderer::gl::render_device_features(capabilities));
}); });
#if __GL__ if (pp::renderer::gl::opengl_runtime_for_current_build().desktop_gl) {
// In OpenGL 3.3 these should be already available // In OpenGL 3.3 these should be already available.
ShaderManager::ext_float32_linear = true; ShaderManager::ext_float32_linear = true;
ShaderManager::ext_float32 = true; ShaderManager::ext_float32 = true;
ShaderManager::ext_float16 = true; ShaderManager::ext_float16 = true;
#endif }
ShaderManager::set_render_device_features( ShaderManager::set_render_device_features(
pp::renderer::gl::render_device_features(shader_manager_capabilities())); pp::renderer::gl::render_device_features(shader_manager_capabilities()));

View File

@@ -201,6 +201,21 @@ OpenGlCapabilities detect_opengl_capabilities(
return 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 pp::renderer::RenderDeviceFeatures render_device_features(OpenGlCapabilities capabilities) noexcept
{ {
return pp::renderer::RenderDeviceFeatures { return pp::renderer::RenderDeviceFeatures {

View File

@@ -678,6 +678,7 @@ struct OpenGlMeshDeleteDispatch {
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities( [[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
std::span<const std::string_view> extensions, std::span<const std::string_view> extensions,
OpenGlRuntime runtime) noexcept; OpenGlRuntime runtime) noexcept;
[[nodiscard]] OpenGlRuntime opengl_runtime_for_current_build() noexcept;
[[nodiscard]] pp::renderer::RenderDeviceFeatures render_device_features( [[nodiscard]] pp::renderer::RenderDeviceFeatures render_device_features(
OpenGlCapabilities capabilities) noexcept; OpenGlCapabilities capabilities) noexcept;
[[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept; [[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept;

View File

@@ -1035,6 +1035,16 @@ void ignores_gles_texture_extensions_for_webgl_runtime(pp::tests::Harness& h)
PP_EXPECT(h, !capabilities.float16_textures); 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) void selects_texture_upload_type_from_internal_format(pp::tests::Harness& h)
{ {
constexpr std::uint32_t gl_unsigned_byte = 0x1401U; 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("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("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("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("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_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); harness.run("maps_renderer_texture_formats_to_opengl_tokens", maps_renderer_texture_formats_to_opengl_tokens);