Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
DepthStencilState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "spdlog/fmt/fmt.h"
5#include "utils/webgpu.hpp"
6
7namespace Graphic::Utils {
9 public:
10 explicit DepthStencilState(const std::string &name) : name(name) {}
11 ~DepthStencilState() override = default;
12
13 std::vector<ValidationError> validate(void) const override
14 {
15 std::vector<ValidationError> errors;
16 if (this->value.format == wgpu::TextureFormat::Undefined)
17 {
18 errors.emplace_back("Format is not set", fmt::format("DepthStencilState({})", this->name),
20 }
21 if (this->value.depthWriteEnabled && this->value.depthCompare == wgpu::CompareFunction::Undefined)
22 {
23 errors.emplace_back("Depth compare function is not set while depth write is enabled",
24 fmt::format("DepthStencilState({})", this->name), ValidationError::Severity::Error);
25 }
26 return errors;
27 }
28
29 inline DepthStencilState &setCompareFunction(wgpu::CompareFunction func)
30 {
31 this->value.depthCompare = func;
32 return *this;
33 }
34
35 inline DepthStencilState &setDepthWriteEnabled(wgpu::OptionalBool enabled)
36 {
37 this->value.depthWriteEnabled = enabled;
38 return *this;
39 }
40
41 inline DepthStencilState &setFormat(wgpu::TextureFormat format)
42 {
43 this->value.format = format;
44 return *this;
45 }
46
47 inline const wgpu::DepthStencilState &getValue() const { return this->value; }
48
49 private:
50 wgpu::DepthStencilState value = wgpu::DepthStencilState(wgpu::Default);
51 std::string name;
52};
53} // namespace Graphic::Utils
DepthStencilState & setDepthWriteEnabled(wgpu::OptionalBool enabled)
Definition DepthStencilState.hpp:35
wgpu::DepthStencilState value
Definition DepthStencilState.hpp:50
DepthStencilState & setCompareFunction(wgpu::CompareFunction func)
Definition DepthStencilState.hpp:29
DepthStencilState & setFormat(wgpu::TextureFormat format)
Definition DepthStencilState.hpp:41
~DepthStencilState() override=default
std::vector< ValidationError > validate(void) const override
Definition DepthStencilState.hpp:13
DepthStencilState(const std::string &name)
Definition DepthStencilState.hpp:10
std::string name
Definition DepthStencilState.hpp:51
const wgpu::DepthStencilState & getValue() const
Definition DepthStencilState.hpp:47
Definition IValidable.hpp:26
Definition DefaultSampler.hpp:6
constexpr DefaultFlag Default
Definition webgpu.hpp:78
@ Error
Definition IValidable.hpp:14