Add renderer render pass clear contract
This commit is contained in:
@@ -94,7 +94,7 @@ RecordingCommandContext::RecordingCommandContext(std::vector<RecordedRenderComma
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::begin_render_pass(
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept
|
||||
RenderPassDesc desc) noexcept
|
||||
{
|
||||
if (in_render_pass_) {
|
||||
return pp::foundation::Status::invalid_argument("render pass is already active");
|
||||
@@ -110,6 +110,11 @@ pp::foundation::Status RecordingCommandContext::begin_render_pass(
|
||||
return size_status.status();
|
||||
}
|
||||
|
||||
const auto render_pass_status = validate_render_pass_desc(desc);
|
||||
if (!render_pass_status.ok()) {
|
||||
return render_pass_status;
|
||||
}
|
||||
|
||||
in_render_pass_ = true;
|
||||
shader_bound_ = false;
|
||||
mesh_bound_ = false;
|
||||
@@ -117,7 +122,12 @@ pp::foundation::Status RecordingCommandContext::begin_render_pass(
|
||||
push_command(commands_, RecordedRenderCommand {
|
||||
.kind = RecordedRenderCommandKind::begin_render_pass,
|
||||
.target_desc = active_target_,
|
||||
.clear_color = clear_color,
|
||||
.clear_color_enabled = desc.clear_color_enabled,
|
||||
.clear_color = desc.clear_color,
|
||||
.clear_depth_enabled = desc.clear_depth_enabled,
|
||||
.clear_depth = desc.clear_depth,
|
||||
.clear_stencil_enabled = desc.clear_stencil_enabled,
|
||||
.clear_stencil = desc.clear_stencil,
|
||||
});
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,12 @@ enum class RecordedRenderCommandKind : std::uint8_t {
|
||||
struct RecordedRenderCommand {
|
||||
RecordedRenderCommandKind kind = RecordedRenderCommandKind::draw;
|
||||
TextureDesc target_desc {};
|
||||
bool clear_color_enabled = false;
|
||||
ClearColor clear_color {};
|
||||
bool clear_depth_enabled = false;
|
||||
float clear_depth = 1.0F;
|
||||
bool clear_stencil_enabled = false;
|
||||
std::uint8_t clear_stencil = 0;
|
||||
Viewport viewport {};
|
||||
ScissorRect scissor {};
|
||||
BlendState blend_state {};
|
||||
@@ -107,7 +112,7 @@ public:
|
||||
|
||||
[[nodiscard]] pp::foundation::Status begin_render_pass(
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept override;
|
||||
RenderPassDesc desc) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_viewport(Viewport viewport) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_scissor(ScissorRect scissor) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_blend_state(BlendState state) noexcept override;
|
||||
|
||||
@@ -163,6 +163,27 @@ pp::foundation::Status validate_scissor(ScissorRect scissor, Extent2D target_ext
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_render_pass_desc(RenderPassDesc desc) noexcept
|
||||
{
|
||||
if (desc.clear_color_enabled
|
||||
&& (!std::isfinite(desc.clear_color.r)
|
||||
|| !std::isfinite(desc.clear_color.g)
|
||||
|| !std::isfinite(desc.clear_color.b)
|
||||
|| !std::isfinite(desc.clear_color.a))) {
|
||||
return pp::foundation::Status::invalid_argument("render pass clear color must be finite");
|
||||
}
|
||||
|
||||
if (desc.clear_depth_enabled && !std::isfinite(desc.clear_depth)) {
|
||||
return pp::foundation::Status::invalid_argument("render pass clear depth must be finite");
|
||||
}
|
||||
|
||||
if (desc.clear_depth_enabled && (desc.clear_depth < 0.0F || desc.clear_depth > 1.0F)) {
|
||||
return pp::foundation::Status::out_of_range("render pass clear depth must be within 0..1");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_blend_factor(BlendFactor factor) noexcept
|
||||
{
|
||||
switch (factor) {
|
||||
|
||||
@@ -64,6 +64,15 @@ struct ClearColor {
|
||||
float a = 0.0F;
|
||||
};
|
||||
|
||||
struct RenderPassDesc {
|
||||
bool clear_color_enabled = true;
|
||||
ClearColor clear_color;
|
||||
bool clear_depth_enabled = false;
|
||||
float clear_depth = 1.0F;
|
||||
bool clear_stencil_enabled = false;
|
||||
std::uint8_t clear_stencil = 0;
|
||||
};
|
||||
|
||||
enum class PrimitiveTopology : std::uint8_t {
|
||||
triangles,
|
||||
triangle_strip,
|
||||
@@ -201,7 +210,7 @@ public:
|
||||
virtual ~ICommandContext() = default;
|
||||
[[nodiscard]] virtual pp::foundation::Status begin_render_pass(
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept = 0;
|
||||
RenderPassDesc desc) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_viewport(Viewport viewport) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_scissor(ScissorRect scissor) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_blend_state(BlendState state) noexcept = 0;
|
||||
@@ -260,6 +269,7 @@ public:
|
||||
[[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_scissor(ScissorRect scissor, Extent2D target_extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_render_pass_desc(RenderPassDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_factor(BlendFactor factor) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_op(BlendOp op) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_state(BlendState state) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user