Move OpenGL texture upload mapping
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
|
||||
@@ -23,4 +24,6 @@ struct OpenGlCapabilities {
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
|
||||
[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "rtt.h"
|
||||
#include "util.h"
|
||||
#include "app.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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<GLenum>(
|
||||
pp::renderer::gl::texture_upload_type_for_internal_format(static_cast<std::uint32_t>(internal_format)));
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texID);
|
||||
if (tex == -1)
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "texture.h"
|
||||
#include "util.h"
|
||||
#include "app.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
std::map<uint16_t, Texture2D> TextureManager::m_textures;
|
||||
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);
|
||||
//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<GLenum>(
|
||||
pp::renderer::gl::texture_upload_type_for_internal_format(static_cast<std::uint32_t>(internal_format)));
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, ifmt, data);
|
||||
unbind();
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user