Map renderer texture formats to OpenGL

This commit is contained in:
2026-06-02 18:14:40 +02:00
parent 8c99454bf5
commit dc03491b0d
5 changed files with 75 additions and 2 deletions

View File

@@ -68,6 +68,9 @@ constexpr std::uint32_t gl_rgb8 = 0x8051U;
constexpr std::uint32_t gl_rgba8 = 0x8058U;
constexpr std::uint32_t gl_rgba32f = 0x8814U;
constexpr std::uint32_t gl_rgba16f = 0x881AU;
constexpr std::uint32_t gl_depth_stencil = 0x84F9U;
constexpr std::uint32_t gl_unsigned_int_24_8 = 0x84FAU;
constexpr std::uint32_t gl_depth24_stencil8 = 0x88F0U;
constexpr std::uint32_t gl_texture_2d = 0x0DE1U;
constexpr std::uint32_t gl_renderbuffer = 0x8D41U;
constexpr std::uint32_t gl_depth_component24 = 0x81A6U;
@@ -262,6 +265,35 @@ OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count)
}
}
OpenGlRendererTextureFormat texture_format_for_renderer_format(pp::renderer::TextureFormat format) noexcept
{
switch (format) {
case pp::renderer::TextureFormat::rgba8:
return OpenGlRendererTextureFormat {
.internal_format = gl_rgba8,
.pixel_format = gl_rgba,
.component_type = gl_unsigned_byte,
.bytes_per_pixel = 4U,
};
case pp::renderer::TextureFormat::r8:
return OpenGlRendererTextureFormat {
.internal_format = gl_r8,
.pixel_format = gl_red,
.component_type = gl_unsigned_byte,
.bytes_per_pixel = 1U,
};
case pp::renderer::TextureFormat::depth24_stencil8:
return OpenGlRendererTextureFormat {
.internal_format = gl_depth24_stencil8,
.pixel_format = gl_depth_stencil,
.component_type = gl_unsigned_int_24_8,
.bytes_per_pixel = 4U,
};
default:
return OpenGlRendererTextureFormat {};
}
}
OpenGlReadbackFormat rgba8_readback_format() noexcept
{
return OpenGlReadbackFormat {

View File

@@ -40,6 +40,13 @@ struct OpenGlReadbackFormat {
std::uint32_t bytes_per_pixel = 0;
};
struct OpenGlRendererTextureFormat {
std::uint32_t internal_format = 0;
std::uint32_t pixel_format = 0;
std::uint32_t component_type = 0;
std::uint32_t bytes_per_pixel = 0;
};
struct OpenGlWindowsWglContextConfig {
std::array<std::int32_t, 9> context_attributes {};
std::array<std::int32_t, 15> pixel_format_attributes {};
@@ -59,6 +66,8 @@ struct OpenGlWindowsWglContextConfig {
[[nodiscard]] std::uint32_t unsigned_byte_component_type() noexcept;
[[nodiscard]] std::uint32_t rgba_pixel_format() noexcept;
[[nodiscard]] OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count) noexcept;
[[nodiscard]] OpenGlRendererTextureFormat texture_format_for_renderer_format(
pp::renderer::TextureFormat format) noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba8_readback_format() noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba32f_readback_format() noexcept;
[[nodiscard]] std::uint64_t readback_byte_count(