Move OpenGL texture upload mapping

This commit is contained in:
2026-06-01 17:46:48 +02:00
parent 9ab73a0354
commit 2754df9f46
7 changed files with 56 additions and 11 deletions

View File

@@ -126,7 +126,8 @@ Known local toolchain state:
- `pp_renderer_gl` owns headless OpenGL runtime capability detection consumed - `pp_renderer_gl` owns headless OpenGL runtime capability detection consumed
by the legacy app initialization path; `pp_renderer_gl_capabilities_tests` by the legacy app initialization path; `pp_renderer_gl_capabilities_tests`
validates framebuffer fetch, map-buffer alignment, desktop GL float support, 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 - `windows-msvc-vcpkg-headless` validates manifest install/configure/build/test
for the current headless component matrix; see DEBT-0007 for remaining app for the current headless component matrix; see DEBT-0007 for remaining app
and platform triplet migration. and platform triplet migration.

View File

@@ -387,9 +387,10 @@ readback, trace interface validation, and the canonical PanoPainter shader
catalog now consumed by the legacy OpenGL app initialization path. catalog now consumed by the legacy OpenGL app initialization path.
`pp_renderer_gl` now exists as the first OpenGL backend library and owns pure `pp_renderer_gl` now exists as the first OpenGL backend library and owns pure
OpenGL capability detection for framebuffer fetch, map-buffer alignment, and OpenGL capability detection for framebuffer fetch, map-buffer alignment, and
float texture support. The legacy app delegates extension interpretation to float texture support. It also owns the OpenGL texture upload-type mapping used
that backend library, but the existing renderer classes are not yet fully by legacy `Texture2D` and `RTT` creation. The legacy app delegates extension
behind the renderer interfaces. and upload-format interpretation to that backend library, but the existing
renderer classes are not yet fully behind the renderer interfaces.
Implementation tasks: Implementation tasks:
@@ -628,7 +629,8 @@ Results:
- `pp_renderer_gl_capabilities_tests` passed on default MSVC, vcpkg-headless, - `pp_renderer_gl_capabilities_tests` passed on default MSVC, vcpkg-headless,
and Android arm64 configure/build, covering framebuffer fetch, map-buffer and Android arm64 configure/build, covering framebuffer fetch, map-buffer
alignment, desktop GL core float support, GLES float/half-float extensions, 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 - PowerShell analyze automation returns JSON summaries and includes the shader
validation target. validation target.
- `windows-msvc-vcpkg-headless` configured through the Visual Studio bundled - `windows-msvc-vcpkg-headless` configured through the Visual Studio bundled

View File

@@ -4,6 +4,12 @@ namespace pp::renderer::gl {
namespace { 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 [[nodiscard]] bool contains(std::string_view text, std::string_view needle) noexcept
{ {
return text.find(needle) != std::string_view::npos; return text.find(needle) != std::string_view::npos;
@@ -50,4 +56,16 @@ OpenGlCapabilities detect_opengl_capabilities(
return 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;
}
}
} }

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <cstdint>
#include <span> #include <span>
#include <string_view> #include <string_view>
@@ -23,4 +24,6 @@ struct OpenGlCapabilities {
std::span<const std::string_view> extensions, std::span<const std::string_view> extensions,
OpenGlRuntime runtime) noexcept; OpenGlRuntime runtime) noexcept;
[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept;
} }

View File

@@ -3,6 +3,9 @@
#include "rtt.h" #include "rtt.h"
#include "util.h" #include "util.h"
#include "app.h" #include "app.h"
#include "renderer_gl/opengl_capabilities.h"
#include <cstdint>
RTT& RTT::operator=(RTT&& other) RTT& RTT::operator=(RTT&& other)
{ {
@@ -204,9 +207,8 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
texID = tex; texID = tex;
} }
auto ifmt = GL_UNSIGNED_BYTE; const auto ifmt = static_cast<GLenum>(
if (internal_format == GL_RGBA32F) ifmt = GL_FLOAT; pp::renderer::gl::texture_upload_type_for_internal_format(static_cast<std::uint32_t>(internal_format)));
if (internal_format == GL_RGBA16F) ifmt = GL_HALF_FLOAT;
glBindTexture(GL_TEXTURE_2D, texID); glBindTexture(GL_TEXTURE_2D, texID);
if (tex == -1) if (tex == -1)

View File

@@ -3,6 +3,9 @@
#include "texture.h" #include "texture.h"
#include "util.h" #include "util.h"
#include "app.h" #include "app.h"
#include "renderer_gl/opengl_capabilities.h"
#include <cstdint>
std::map<uint16_t, Texture2D> TextureManager::m_textures; std::map<uint16_t, Texture2D> TextureManager::m_textures;
std::array<int, 6> TextureCube::m_faces_map { std::array<int, 6> TextureCube::m_faces_map {
@@ -176,9 +179,8 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
glGenTextures(1, &m_tex); glGenTextures(1, &m_tex);
//LOG("TEX create %d", m_tex); //LOG("TEX create %d", m_tex);
bind(); bind();
auto ifmt = GL_UNSIGNED_BYTE; const auto ifmt = static_cast<GLenum>(
if (internal_format == GL_RGBA32F) ifmt = GL_FLOAT; pp::renderer::gl::texture_upload_type_for_internal_format(static_cast<std::uint32_t>(internal_format)));
if (internal_format == GL_RGBA16F) ifmt = GL_HALF_FLOAT;
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, ifmt, data); glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, ifmt, data);
unbind(); unbind();
}); });

View File

@@ -2,6 +2,7 @@
#include "test_harness.h" #include "test_harness.h"
#include <array> #include <array>
#include <cstdint>
#include <string_view> #include <string_view>
namespace { namespace {
@@ -68,6 +69,21 @@ 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 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() 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("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("selects_texture_upload_type_from_internal_format", selects_texture_upload_type_from_internal_format);
return harness.finish(); return harness.finish();
} }