Route cube textures and samplers through renderer GL
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user