Route cube textures and samplers through renderer GL

This commit is contained in:
2026-06-03 06:46:06 +02:00
parent 779d6b0387
commit f20595aff6
6 changed files with 714 additions and 59 deletions

View File

@@ -480,6 +480,65 @@ pp::foundation::Status delete_opengl_texture_2d(
return pp::foundation::Status::success();
}
pp::foundation::Status delete_opengl_texture_objects(
std::span<const std::uint32_t> texture_ids,
OpenGlTexture2DDeleteDispatch dispatch) noexcept
{
if (dispatch.delete_textures == nullptr) {
return pp::foundation::Status::invalid_argument("OpenGL texture delete dispatch callback must not be null");
}
if (texture_ids.empty()) {
return pp::foundation::Status::success();
}
dispatch.delete_textures(static_cast<std::uint32_t>(texture_ids.size()), texture_ids.data());
return pp::foundation::Status::success();
}
pp::foundation::Result<std::uint32_t> allocate_opengl_texture_cube(
OpenGlTextureCubeAllocation allocation,
OpenGlTextureCubeAllocationDispatch dispatch) noexcept
{
if (dispatch.gen_textures == nullptr
|| dispatch.bind_texture == nullptr
|| dispatch.tex_image_2d == nullptr) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::invalid_argument(
"OpenGL cube texture allocation dispatch callbacks must not be null"));
}
if (allocation.resolution <= 0
|| allocation.internal_format == 0
|| allocation.pixel_format == 0U
|| allocation.component_type == 0U) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::invalid_argument("OpenGL cube texture allocation parameters are invalid"));
}
std::uint32_t texture_id = 0U;
dispatch.gen_textures(1U, &texture_id);
if (texture_id == 0U) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::out_of_range("OpenGL cube texture allocation returned id 0"));
}
dispatch.bind_texture(texture_cube_map_target(), texture_id);
for (std::uint32_t face_index = 0U; face_index < 6U; ++face_index) {
dispatch.tex_image_2d(
cube_map_allocation_face_texture_target(face_index),
0,
allocation.internal_format,
allocation.resolution,
allocation.resolution,
0,
allocation.pixel_format,
allocation.component_type,
nullptr);
}
return pp::foundation::Result<std::uint32_t>::success(texture_id);
}
pp::foundation::Status bind_opengl_texture_2d(
std::uint32_t texture_id,
OpenGlTexture2DBindDispatch dispatch) noexcept
@@ -492,6 +551,18 @@ pp::foundation::Status bind_opengl_texture_2d(
return pp::foundation::Status::success();
}
pp::foundation::Status bind_opengl_texture_cube(
std::uint32_t texture_id,
OpenGlTexture2DBindDispatch dispatch) noexcept
{
if (dispatch.bind_texture == nullptr) {
return pp::foundation::Status::invalid_argument("OpenGL cube texture bind dispatch callback must not be null");
}
dispatch.bind_texture(texture_cube_map_target(), texture_id);
return pp::foundation::Status::success();
}
pp::foundation::Status update_opengl_texture_2d(
OpenGlTexture2DUpdate update,
OpenGlTexture2DUpdateDispatch dispatch) noexcept
@@ -714,6 +785,104 @@ pp::foundation::Status restore_opengl_framebuffer_binding(
return pp::foundation::Status::success();
}
pp::foundation::Result<std::uint32_t> create_opengl_sampler(
std::span<const OpenGlTextureParameter> parameters,
OpenGlSamplerCreateDispatch dispatch) noexcept
{
if (dispatch.gen_samplers == nullptr || dispatch.sampler_parameter_i == nullptr) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::invalid_argument("OpenGL sampler create dispatch callbacks must not be null"));
}
if (parameters.empty()) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::invalid_argument("OpenGL sampler parameters are invalid"));
}
for (const auto parameter : parameters) {
if (parameter.name == 0U) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::invalid_argument("OpenGL sampler parameter name is invalid"));
}
}
std::uint32_t sampler_id = 0U;
dispatch.gen_samplers(1U, &sampler_id);
if (sampler_id == 0U) {
return pp::foundation::Result<std::uint32_t>::failure(
pp::foundation::Status::out_of_range("OpenGL sampler allocation returned id 0"));
}
const auto status = set_opengl_sampler_parameters(
sampler_id,
parameters,
OpenGlSamplerParameterDispatch {
.sampler_parameter_i = dispatch.sampler_parameter_i,
});
if (!status.ok()) {
return pp::foundation::Result<std::uint32_t>::failure(status);
}
return pp::foundation::Result<std::uint32_t>::success(sampler_id);
}
pp::foundation::Status set_opengl_sampler_parameters(
std::uint32_t sampler_id,
std::span<const OpenGlTextureParameter> parameters,
OpenGlSamplerParameterDispatch dispatch) noexcept
{
if (dispatch.sampler_parameter_i == nullptr) {
return pp::foundation::Status::invalid_argument("OpenGL sampler parameter dispatch callback must not be null");
}
if (sampler_id == 0U || parameters.empty()) {
return pp::foundation::Status::invalid_argument("OpenGL sampler parameters are invalid");
}
for (const auto parameter : parameters) {
if (parameter.name == 0U) {
return pp::foundation::Status::invalid_argument("OpenGL sampler parameter name is invalid");
}
dispatch.sampler_parameter_i(
sampler_id,
parameter.name,
static_cast<std::int32_t>(parameter.value));
}
return pp::foundation::Status::success();
}
pp::foundation::Status set_opengl_sampler_border_color(
std::uint32_t sampler_id,
std::uint32_t parameter,
const float* rgba,
OpenGlSamplerBorderDispatch dispatch) noexcept
{
if (dispatch.sampler_parameter_fv == nullptr) {
return pp::foundation::Status::invalid_argument(
"OpenGL sampler border color dispatch callback must not be null");
}
if (sampler_id == 0U || parameter == 0U || rgba == nullptr) {
return pp::foundation::Status::invalid_argument("OpenGL sampler border color parameters are invalid");
}
dispatch.sampler_parameter_fv(sampler_id, parameter, rgba);
return pp::foundation::Status::success();
}
pp::foundation::Status bind_opengl_sampler_object(
std::uint32_t unit,
std::uint32_t sampler_id,
OpenGlSamplerBindDispatch dispatch) noexcept
{
if (dispatch.bind_sampler == nullptr) {
return pp::foundation::Status::invalid_argument("OpenGL sampler bind dispatch callback must not be null");
}
dispatch.bind_sampler(unit, sampler_id);
return pp::foundation::Status::success();
}
std::uint32_t extension_count_query() noexcept
{
return gl_num_extensions;

View File

@@ -119,6 +119,13 @@ struct OpenGlTexture2DAllocation {
const void* data = nullptr;
};
struct OpenGlTextureCubeAllocation {
std::int32_t resolution = 0;
std::int32_t internal_format = 0;
std::uint32_t pixel_format = 0;
std::uint32_t component_type = 0;
};
struct OpenGlTexture2DUpdate {
std::uint32_t texture_id = 0;
std::int32_t width = 0;
@@ -216,6 +223,14 @@ using OpenGlUseProgramFn = void (*)(std::uint32_t program) noexcept;
using OpenGlBindFramebufferFn = void (*)(std::uint32_t target, std::uint32_t framebuffer) noexcept;
using OpenGlBindTextureFn = void (*)(std::uint32_t target, std::uint32_t texture) noexcept;
using OpenGlBindSamplerFn = void (*)(std::uint32_t unit, std::uint32_t sampler) noexcept;
using OpenGlSamplerParameteriFn = void (*)(
std::uint32_t sampler,
std::uint32_t parameter,
std::int32_t value) noexcept;
using OpenGlSamplerParameterfvFn = void (*)(
std::uint32_t sampler,
std::uint32_t parameter,
const float* values) noexcept;
using OpenGlGenObjectsFn = void (*)(std::uint32_t count, std::uint32_t* ids) noexcept;
using OpenGlDeleteObjectsFn = void (*)(std::uint32_t count, const std::uint32_t* ids) noexcept;
using OpenGlTexImage2DFn = void (*)(
@@ -349,6 +364,12 @@ struct OpenGlTexture2DDeleteDispatch {
OpenGlDeleteObjectsFn delete_textures = nullptr;
};
struct OpenGlTextureCubeAllocationDispatch {
OpenGlGenObjectsFn gen_textures = nullptr;
OpenGlBindTextureFn bind_texture = nullptr;
OpenGlTexImage2DFn tex_image_2d = nullptr;
};
struct OpenGlTexture2DBindDispatch {
OpenGlBindTextureFn bind_texture = nullptr;
};
@@ -395,6 +416,23 @@ struct OpenGlFramebufferRestoreDispatch {
OpenGlBindFramebufferFn bind_framebuffer = nullptr;
};
struct OpenGlSamplerCreateDispatch {
OpenGlGenObjectsFn gen_samplers = nullptr;
OpenGlSamplerParameteriFn sampler_parameter_i = nullptr;
};
struct OpenGlSamplerParameterDispatch {
OpenGlSamplerParameteriFn sampler_parameter_i = nullptr;
};
struct OpenGlSamplerBorderDispatch {
OpenGlSamplerParameterfvFn sampler_parameter_fv = nullptr;
};
struct OpenGlSamplerBindDispatch {
OpenGlBindSamplerFn bind_sampler = nullptr;
};
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
std::span<const std::string_view> extensions,
OpenGlRuntime runtime) noexcept;
@@ -433,9 +471,18 @@ struct OpenGlFramebufferRestoreDispatch {
[[nodiscard]] pp::foundation::Status delete_opengl_texture_2d(
std::uint32_t texture_id,
OpenGlTexture2DDeleteDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status delete_opengl_texture_objects(
std::span<const std::uint32_t> texture_ids,
OpenGlTexture2DDeleteDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Result<std::uint32_t> allocate_opengl_texture_cube(
OpenGlTextureCubeAllocation allocation,
OpenGlTextureCubeAllocationDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status bind_opengl_texture_2d(
std::uint32_t texture_id,
OpenGlTexture2DBindDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status bind_opengl_texture_cube(
std::uint32_t texture_id,
OpenGlTexture2DBindDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status update_opengl_texture_2d(
OpenGlTexture2DUpdate update,
OpenGlTexture2DUpdateDispatch dispatch) noexcept;
@@ -457,6 +504,22 @@ struct OpenGlFramebufferRestoreDispatch {
[[nodiscard]] pp::foundation::Status restore_opengl_framebuffer_binding(
OpenGlFramebufferBindingState binding,
OpenGlFramebufferRestoreDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Result<std::uint32_t> create_opengl_sampler(
std::span<const OpenGlTextureParameter> parameters,
OpenGlSamplerCreateDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status set_opengl_sampler_parameters(
std::uint32_t sampler_id,
std::span<const OpenGlTextureParameter> parameters,
OpenGlSamplerParameterDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status set_opengl_sampler_border_color(
std::uint32_t sampler_id,
std::uint32_t parameter,
const float* rgba,
OpenGlSamplerBorderDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status bind_opengl_sampler_object(
std::uint32_t unit,
std::uint32_t sampler_id,
OpenGlSamplerBindDispatch dispatch) noexcept;
[[nodiscard]] std::uint32_t extension_count_query() noexcept;
[[nodiscard]] std::uint32_t extension_string_name() noexcept;