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

@@ -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;
}
}
}

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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();
});