Add renderer depth state contract
This commit is contained in:
@@ -158,6 +158,24 @@ pp::foundation::Status RecordingCommandContext::set_blend_state(BlendState state
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::set_depth_state(DepthState state) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
return pp::foundation::Status::invalid_argument("render pass has not begun");
|
||||
}
|
||||
|
||||
const auto status = validate_depth_state(state);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
push_command(commands_, RecordedRenderCommand {
|
||||
.kind = RecordedRenderCommandKind::set_depth_state,
|
||||
.depth_state = state,
|
||||
});
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::bind_shader(IShaderProgram& shader) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
@@ -440,6 +458,8 @@ const char* recorded_render_command_kind_name(RecordedRenderCommandKind kind) no
|
||||
return "set_scissor";
|
||||
case RecordedRenderCommandKind::set_blend_state:
|
||||
return "set_blend_state";
|
||||
case RecordedRenderCommandKind::set_depth_state:
|
||||
return "set_depth_state";
|
||||
case RecordedRenderCommandKind::bind_shader:
|
||||
return "bind_shader";
|
||||
case RecordedRenderCommandKind::bind_texture:
|
||||
|
||||
@@ -12,6 +12,7 @@ enum class RecordedRenderCommandKind : std::uint8_t {
|
||||
set_viewport,
|
||||
set_scissor,
|
||||
set_blend_state,
|
||||
set_depth_state,
|
||||
bind_shader,
|
||||
bind_texture,
|
||||
bind_mesh,
|
||||
@@ -31,6 +32,7 @@ struct RecordedRenderCommand {
|
||||
Viewport viewport {};
|
||||
ScissorRect scissor {};
|
||||
BlendState blend_state {};
|
||||
DepthState depth_state {};
|
||||
MeshDesc mesh_desc {};
|
||||
TextureDesc texture_desc {};
|
||||
std::uint32_t texture_slot = 0;
|
||||
@@ -104,6 +106,7 @@ public:
|
||||
[[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;
|
||||
[[nodiscard]] pp::foundation::Status set_depth_state(DepthState state) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
|
||||
@@ -220,6 +220,28 @@ pp::foundation::Status validate_blend_state(BlendState state) noexcept
|
||||
return validate_blend_op(state.alpha_op);
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_compare_op(CompareOp op) noexcept
|
||||
{
|
||||
switch (op) {
|
||||
case CompareOp::never:
|
||||
case CompareOp::less:
|
||||
case CompareOp::equal:
|
||||
case CompareOp::less_or_equal:
|
||||
case CompareOp::greater:
|
||||
case CompareOp::not_equal:
|
||||
case CompareOp::greater_or_equal:
|
||||
case CompareOp::always:
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
return pp::foundation::Status::invalid_argument("depth compare operation is not supported");
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_depth_state(DepthState state) noexcept
|
||||
{
|
||||
return validate_compare_op(state.compare);
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept
|
||||
{
|
||||
if (desc.vertex_count == 0) {
|
||||
@@ -447,4 +469,28 @@ const char* blend_op_name(BlendOp op) noexcept
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char* compare_op_name(CompareOp op) noexcept
|
||||
{
|
||||
switch (op) {
|
||||
case CompareOp::never:
|
||||
return "never";
|
||||
case CompareOp::less:
|
||||
return "less";
|
||||
case CompareOp::equal:
|
||||
return "equal";
|
||||
case CompareOp::less_or_equal:
|
||||
return "less_or_equal";
|
||||
case CompareOp::greater:
|
||||
return "greater";
|
||||
case CompareOp::not_equal:
|
||||
return "not_equal";
|
||||
case CompareOp::greater_or_equal:
|
||||
return "greater_or_equal";
|
||||
case CompareOp::always:
|
||||
return "always";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,6 +88,17 @@ enum class BlendOp : std::uint8_t {
|
||||
reverse_subtract,
|
||||
};
|
||||
|
||||
enum class CompareOp : std::uint8_t {
|
||||
never,
|
||||
less,
|
||||
equal,
|
||||
less_or_equal,
|
||||
greater,
|
||||
not_equal,
|
||||
greater_or_equal,
|
||||
always,
|
||||
};
|
||||
|
||||
struct BlendState {
|
||||
bool enabled = false;
|
||||
BlendFactor source_color = BlendFactor::one;
|
||||
@@ -102,6 +113,12 @@ struct BlendState {
|
||||
bool write_a = true;
|
||||
};
|
||||
|
||||
struct DepthState {
|
||||
bool test_enabled = false;
|
||||
bool write_enabled = false;
|
||||
CompareOp compare = CompareOp::less_or_equal;
|
||||
};
|
||||
|
||||
struct MeshDesc {
|
||||
std::uint32_t vertex_count = 0;
|
||||
std::uint32_t index_count = 0;
|
||||
@@ -165,6 +182,7 @@ public:
|
||||
[[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;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_depth_state(DepthState state) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
@@ -206,6 +224,8 @@ public:
|
||||
[[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;
|
||||
[[nodiscard]] pp::foundation::Status validate_compare_op(CompareOp op) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_depth_state(DepthState state) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_texture_slot(std::uint32_t slot) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noexcept;
|
||||
@@ -224,5 +244,6 @@ public:
|
||||
[[nodiscard]] const char* blit_filter_name(BlitFilter filter) noexcept;
|
||||
[[nodiscard]] const char* blend_factor_name(BlendFactor factor) noexcept;
|
||||
[[nodiscard]] const char* blend_op_name(BlendOp op) noexcept;
|
||||
[[nodiscard]] const char* compare_op_name(CompareOp op) noexcept;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user