Expand renderer API interfaces

This commit is contained in:
2026-06-01 08:15:21 +02:00
parent 93d8aaaffd
commit 6604f30ef3
4 changed files with 332 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
#include "renderer_api/renderer_api.h"
#include <cmath>
#include <limits>
namespace pp::renderer {
@@ -66,6 +67,62 @@ pp::foundation::Result<std::uint64_t> texture_byte_size(TextureDesc desc) noexce
return pp::foundation::Result<std::uint64_t>::success(bytes);
}
pp::foundation::Status validate_viewport(Viewport viewport, Extent2D target_extent) noexcept
{
const auto extent_status = validate_extent(target_extent);
if (!extent_status.ok()) {
return extent_status;
}
if (viewport.x < 0 || viewport.y < 0) {
return pp::foundation::Status::invalid_argument("viewport origin must be non-negative");
}
if (viewport.width == 0 || viewport.height == 0) {
return pp::foundation::Status::invalid_argument("viewport size must be greater than zero");
}
if (!std::isfinite(viewport.min_depth) || !std::isfinite(viewport.max_depth)) {
return pp::foundation::Status::invalid_argument("viewport depth range must be finite");
}
if (viewport.min_depth < 0.0F || viewport.max_depth > 1.0F || viewport.min_depth > viewport.max_depth) {
return pp::foundation::Status::out_of_range("viewport depth range must be within 0..1 and ordered");
}
const auto x = static_cast<std::uint32_t>(viewport.x);
const auto y = static_cast<std::uint32_t>(viewport.y);
if (x > target_extent.width || y > target_extent.height) {
return pp::foundation::Status::out_of_range("viewport origin is outside the render target");
}
if (viewport.width > target_extent.width - x || viewport.height > target_extent.height - y) {
return pp::foundation::Status::out_of_range("viewport exceeds render target bounds");
}
return pp::foundation::Status::success();
}
pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept
{
if (desc.vertex_count == 0) {
return pp::foundation::Status::invalid_argument("mesh must contain at least one vertex");
}
if (desc.vertex_count > max_mesh_vertices || desc.index_count > max_mesh_vertices) {
return pp::foundation::Status::out_of_range("mesh vertex or index count exceeds the configured limit");
}
switch (desc.topology) {
case PrimitiveTopology::triangles:
case PrimitiveTopology::triangle_strip:
case PrimitiveTopology::lines:
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("mesh topology is not supported");
}
pp::foundation::Status validate_readback_region(TextureDesc desc, ReadbackRegion region) noexcept
{
const auto extent_status = validate_extent(desc.extent);
@@ -102,4 +159,18 @@ const char* texture_format_name(TextureFormat format) noexcept
return "unknown";
}
const char* primitive_topology_name(PrimitiveTopology topology) noexcept
{
switch (topology) {
case PrimitiveTopology::triangles:
return "triangles";
case PrimitiveTopology::triangle_strip:
return "triangle_strip";
case PrimitiveTopology::lines:
return "lines";
}
return "unknown";
}
}