From 2754df9f460fda0c8d5a1e3efe654fa579b47d29 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 1 Jun 2026 17:46:48 +0200 Subject: [PATCH] Move OpenGL texture upload mapping --- docs/modernization/build-inventory.md | 3 ++- docs/modernization/roadmap.md | 10 ++++++---- src/renderer_gl/opengl_capabilities.cpp | 18 ++++++++++++++++++ src/renderer_gl/opengl_capabilities.h | 3 +++ src/rtt.cpp | 8 +++++--- src/texture.cpp | 8 +++++--- tests/renderer_gl/capabilities_tests.cpp | 17 +++++++++++++++++ 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index c5e71b5..3a24cff 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -126,7 +126,8 @@ Known local toolchain state: - `pp_renderer_gl` owns headless OpenGL runtime capability detection consumed by the legacy app initialization path; `pp_renderer_gl_capabilities_tests` validates framebuffer fetch, map-buffer alignment, desktop GL float support, - GLES float/half-float extensions, and WebGL exclusion behavior. + GLES float/half-float extensions, WebGL exclusion behavior, and the + upload-type mapping used by legacy `Texture2D` and `RTT` creation. - `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 be7c5c2..f5bee89 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -387,9 +387,10 @@ readback, trace interface validation, and the canonical PanoPainter shader catalog now consumed by the legacy OpenGL app initialization path. `pp_renderer_gl` now exists as the first OpenGL backend library and owns pure OpenGL capability detection for framebuffer fetch, map-buffer alignment, and -float texture support. The legacy app delegates extension interpretation to -that backend library, but the existing renderer classes are not yet fully -behind the renderer interfaces. +float texture support. It also owns the OpenGL texture upload-type mapping used +by legacy `Texture2D` and `RTT` creation. The legacy app delegates extension +and upload-format interpretation to that backend library, but the existing +renderer classes are not yet fully behind the renderer interfaces. Implementation tasks: @@ -628,7 +629,8 @@ Results: - `pp_renderer_gl_capabilities_tests` passed on default MSVC, vcpkg-headless, and Android arm64 configure/build, covering framebuffer fetch, map-buffer alignment, desktop GL core float support, GLES float/half-float extensions, - and WebGL exclusion behavior. + WebGL exclusion behavior, and upload types for RGBA8/RGBA16F/RGBA32F + internal formats. - PowerShell analyze automation returns JSON summaries and includes the shader validation target. - `windows-msvc-vcpkg-headless` configured through the Visual Studio bundled diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index 43e9b0c..6f0bbb8 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -4,6 +4,12 @@ namespace pp::renderer::gl { namespace { +constexpr std::uint32_t gl_unsigned_byte = 0x1401U; +constexpr std::uint32_t gl_float = 0x1406U; +constexpr std::uint32_t gl_half_float = 0x140BU; +constexpr std::uint32_t gl_rgba32f = 0x8814U; +constexpr std::uint32_t gl_rgba16f = 0x881AU; + [[nodiscard]] bool contains(std::string_view text, std::string_view needle) noexcept { return text.find(needle) != std::string_view::npos; @@ -50,4 +56,16 @@ OpenGlCapabilities detect_opengl_capabilities( return capabilities; } +std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept +{ + switch (internal_format) { + case gl_rgba32f: + return gl_float; + case gl_rgba16f: + return gl_half_float; + default: + return gl_unsigned_byte; + } +} + } diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index d429c51..4c6114b 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -23,4 +24,6 @@ struct OpenGlCapabilities { std::span extensions, OpenGlRuntime runtime) noexcept; +[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept; + } diff --git a/src/rtt.cpp b/src/rtt.cpp index b4e1ef3..8384a41 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -3,6 +3,9 @@ #include "rtt.h" #include "util.h" #include "app.h" +#include "renderer_gl/opengl_capabilities.h" + +#include RTT& RTT::operator=(RTT&& other) { @@ -204,9 +207,8 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format, texID = tex; } - auto ifmt = GL_UNSIGNED_BYTE; - if (internal_format == GL_RGBA32F) ifmt = GL_FLOAT; - if (internal_format == GL_RGBA16F) ifmt = GL_HALF_FLOAT; + const auto ifmt = static_cast( + pp::renderer::gl::texture_upload_type_for_internal_format(static_cast(internal_format))); glBindTexture(GL_TEXTURE_2D, texID); if (tex == -1) diff --git a/src/texture.cpp b/src/texture.cpp index 167ba37..d1ab740 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -3,6 +3,9 @@ #include "texture.h" #include "util.h" #include "app.h" +#include "renderer_gl/opengl_capabilities.h" + +#include std::map TextureManager::m_textures; std::array TextureCube::m_faces_map { @@ -176,9 +179,8 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma glGenTextures(1, &m_tex); //LOG("TEX create %d", m_tex); bind(); - auto ifmt = GL_UNSIGNED_BYTE; - if (internal_format == GL_RGBA32F) ifmt = GL_FLOAT; - if (internal_format == GL_RGBA16F) ifmt = GL_HALF_FLOAT; + const auto ifmt = static_cast( + pp::renderer::gl::texture_upload_type_for_internal_format(static_cast(internal_format))); glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, ifmt, data); unbind(); }); diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index 635b5a0..bd6e40e 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -2,6 +2,7 @@ #include "test_harness.h" #include +#include #include namespace { @@ -68,6 +69,21 @@ void ignores_gles_texture_extensions_for_webgl_runtime(pp::tests::Harness& h) PP_EXPECT(h, !capabilities.float16_textures); } +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_float = 0x1406U; + constexpr std::uint32_t gl_half_float = 0x140BU; + constexpr std::uint32_t gl_rgba8 = 0x8058U; + constexpr std::uint32_t gl_rgba32f = 0x8814U; + constexpr std::uint32_t gl_rgba16f = 0x881AU; + + PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba8) == gl_unsigned_byte); + PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba32f) == gl_float); + PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba16f) == gl_half_float); + PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(0U) == gl_unsigned_byte); +} + } int main() @@ -77,5 +93,6 @@ 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("selects_texture_upload_type_from_internal_format", selects_texture_upload_type_from_internal_format); return harness.finish(); }