Expand renderer API interfaces
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace pp::renderer {
|
||||
|
||||
constexpr std::uint32_t max_texture_dimension = 32768;
|
||||
constexpr std::uint32_t max_mesh_vertices = 16777216;
|
||||
constexpr std::uint64_t max_texture_bytes = 1024ULL * 1024ULL * 1024ULL;
|
||||
|
||||
enum class TextureFormat : std::uint8_t {
|
||||
@@ -33,12 +35,70 @@ struct ReadbackRegion {
|
||||
std::uint32_t height = 0;
|
||||
};
|
||||
|
||||
struct Viewport {
|
||||
std::int32_t x = 0;
|
||||
std::int32_t y = 0;
|
||||
std::uint32_t width = 0;
|
||||
std::uint32_t height = 0;
|
||||
float min_depth = 0.0F;
|
||||
float max_depth = 1.0F;
|
||||
};
|
||||
|
||||
struct ClearColor {
|
||||
float r = 0.0F;
|
||||
float g = 0.0F;
|
||||
float b = 0.0F;
|
||||
float a = 0.0F;
|
||||
};
|
||||
|
||||
enum class PrimitiveTopology : std::uint8_t {
|
||||
triangles,
|
||||
triangle_strip,
|
||||
lines,
|
||||
};
|
||||
|
||||
struct MeshDesc {
|
||||
std::uint32_t vertex_count = 0;
|
||||
std::uint32_t index_count = 0;
|
||||
PrimitiveTopology topology = PrimitiveTopology::triangles;
|
||||
};
|
||||
|
||||
struct ShaderStageSource {
|
||||
const char* entry_point = "main";
|
||||
const char* source = nullptr;
|
||||
std::size_t source_size = 0;
|
||||
};
|
||||
|
||||
struct ShaderProgramDesc {
|
||||
const char* debug_name = "";
|
||||
ShaderStageSource vertex;
|
||||
ShaderStageSource fragment;
|
||||
};
|
||||
|
||||
class ITexture2D {
|
||||
public:
|
||||
virtual ~ITexture2D() = default;
|
||||
[[nodiscard]] virtual TextureDesc desc() const noexcept = 0;
|
||||
};
|
||||
|
||||
class IRenderTarget {
|
||||
public:
|
||||
virtual ~IRenderTarget() = default;
|
||||
[[nodiscard]] virtual TextureDesc color_desc() const noexcept = 0;
|
||||
};
|
||||
|
||||
class IShaderProgram {
|
||||
public:
|
||||
virtual ~IShaderProgram() = default;
|
||||
[[nodiscard]] virtual const char* debug_name() const noexcept = 0;
|
||||
};
|
||||
|
||||
class IMesh {
|
||||
public:
|
||||
virtual ~IMesh() = default;
|
||||
[[nodiscard]] virtual MeshDesc desc() const noexcept = 0;
|
||||
};
|
||||
|
||||
class IReadbackBuffer {
|
||||
public:
|
||||
virtual ~IReadbackBuffer() = default;
|
||||
@@ -51,10 +111,34 @@ public:
|
||||
virtual void marker(const char* component, const char* name) noexcept = 0;
|
||||
};
|
||||
|
||||
class ICommandContext {
|
||||
public:
|
||||
virtual ~ICommandContext() = default;
|
||||
[[nodiscard]] virtual pp::foundation::Status begin_render_pass(
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_viewport(Viewport viewport) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_mesh(IMesh& mesh) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status draw() noexcept = 0;
|
||||
virtual void end_render_pass() noexcept = 0;
|
||||
};
|
||||
|
||||
class IRenderDevice {
|
||||
public:
|
||||
virtual ~IRenderDevice() = default;
|
||||
[[nodiscard]] virtual const char* backend_name() const noexcept = 0;
|
||||
[[nodiscard]] virtual ICommandContext& immediate_context() noexcept = 0;
|
||||
[[nodiscard]] virtual IRenderTrace* trace() noexcept = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::uint32_t bytes_per_pixel(TextureFormat format) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_extent(Extent2D extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_viewport(Viewport viewport, Extent2D target_extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Result<std::uint64_t> texture_byte_size(TextureDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_readback_region(TextureDesc desc, ReadbackRegion region) noexcept;
|
||||
[[nodiscard]] const char* texture_format_name(TextureFormat format) noexcept;
|
||||
[[nodiscard]] const char* primitive_topology_name(PrimitiveTopology topology) noexcept;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user