Berserk
RHIGraphicsPipeline.hpp
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* This file is part of Berserk Engine project */
3 /* https://github.com/EgorOrachyov/Berserk */
4 /**********************************************************************************/
5 /* MIT License */
6 /* */
7 /* Copyright (c) 2018 - 2021 Egor Orachyov */
8 /* */
9 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
10 /* of this software and associated documentation files (the "Software"), to deal */
11 /* in the Software without restriction, including without limitation the rights */
12 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13 /* copies of the Software, and to permit persons to whom the Software is */
14 /* furnished to do so, subject to the following conditions: */
15 /* */
16 /* The above copyright notice and this permission notice shall be included in all */
17 /* copies or substantial portions of the Software. */
18 /* */
19 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25 /* SOFTWARE. */
26 /**********************************************************************************/
27 
28 #ifndef BERSERK_RHIGRAPHICSPIPELINE_HPP
29 #define BERSERK_RHIGRAPHICSPIPELINE_HPP
30 
31 #include <core/Config.hpp>
32 #include <core/Typedefs.hpp>
33 #include <rhi/RHIRenderPass.hpp>
34 #include <rhi/RHIResource.hpp>
35 #include <rhi/RHIShader.hpp>
37 
38 #include <vector>
39 
41 
56 
58  Memory::Set(this, 0x0, sizeof(RHIRasterState));
62  lineWidth = 1;
63  }
64 
65  bool operator==(const RHIRasterState &other) const {
66  return mode == other.mode &&
67  cullMode == other.cullMode &&
68  frontFace == other.frontFace &&
69  lineWidth == other.lineWidth;
70  }
71 };
72 
79  bool depthEnable : 1;
80  bool depthWrite : 1;
81  bool stencilEnable : 1;
89 
91  Memory::Set(this, 0x0, sizeof(RHIDepthStencilState));
93  depthEnable = false;
94  depthWrite = false;
95  stencilEnable = false;
96  writeMask = 0;
97  referenceValue = 0;
98  compareMask = 0;
103  }
104 
105  bool operator==(const RHIDepthStencilState &other) const {
106  return depthCompare == other.depthCompare &&
107  depthEnable == other.depthEnable &&
108  depthWrite == other.depthWrite &&
109  stencilEnable == other.stencilEnable &&
110  writeMask == other.writeMask &&
111  referenceValue == other.referenceValue &&
112  compareMask == other.compareMask &&
113  sfail == other.sfail &&
114  dfail == other.dfail &&
115  dpass == other.dpass &&
117  }
118 
121 
123  dss.depthEnable = true;
124  dss.depthWrite = depthWrite;
125 
126  return dss;
127  }
128 };
129 
135  bool enable : 1;
142 
144  Memory::Set(this, 0x0, sizeof(RHIBlendAttachment));
145  enable = false;
152  }
153 
154  bool operator==(const RHIBlendAttachment &other) const {
155  return (enable == false && other.enable == false) ||
156  (enable == other.enable &&
157  alphaBlendOp == other.alphaBlendOp &&
158  colorBlendOp == other.colorBlendOp &&
163  }
164 };
165 
171  std::vector<RHIBlendAttachment> attachments;
172 
173  bool operator==(const RHIBlendState &other) const {
174  if (attachments.size() != other.attachments.size())
175  return false;
176 
177  for (size_t i = 0; i < attachments.size(); i++) {
178  if (!(attachments[i] == other.attachments[i]))
179  return false;
180  }
181 
182  return true;
183  }
184 
186  RHIBlendState bs;
187  bs.attachments.resize(attachments);
188 
189  for (uint32 i = 0; i < attachments; i++) {
190  auto &attachment = bs.attachments[i];
191  attachment.enable = true;
192  attachment.alphaBlendOp = RHIBlendOperation::Add;
193  attachment.colorBlendOp = RHIBlendOperation::Add;
194  attachment.srcAlphaBlendFactor = RHIBlendFactor::SrcAlpha;
195  attachment.srcColorBlendFactor = RHIBlendFactor::SrcAlpha;
196  attachment.dstAlphaBlendFactor = RHIBlendFactor::OneMinusSrcAlpha;
197  attachment.dstColorBlendFactor = RHIBlendFactor::OneMinusSrcAlpha;
198  }
199 
200  return bs;
201  }
202 };
203 
209 public:
217 };
218 
224 public:
225  BRK_API ~RHIGraphicsPipeline() override = default;
226 
228  const RHIGraphicsPipelineDesc &GetDesc() const { return mDesc; }
229 
230 protected:
233 };
234 
240 
241 #endif//BERSERK_RHIGRAPHICSPIPELINE_HPP
#define BRK_NS_END
Definition: Config.hpp:48
#define BRK_API
Definition: Config.hpp:32
std::uint8_t uint8
Definition: Typedefs.hpp:38
std::uint32_t uint32
Definition: Typedefs.hpp:44
static void Set(void *destination, int value, size_t sizeInBytes)
Definition: Memory.hpp:71
Graphics pipeline descriptor.
Definition: RHIGraphicsPipeline.hpp:208
Ref< RHIRenderPass > renderPass
Definition: RHIGraphicsPipeline.hpp:216
RHIPrimitivesType primitivesType
Definition: RHIGraphicsPipeline.hpp:213
RHIDepthStencilState depthStencilState
Definition: RHIGraphicsPipeline.hpp:210
RHIRasterState rasterState
Definition: RHIGraphicsPipeline.hpp:211
RHIBlendState blendState
Definition: RHIGraphicsPipeline.hpp:212
Ref< RHIShader > shader
Definition: RHIGraphicsPipeline.hpp:214
Ref< RHIVertexDeclaration > declaration
Definition: RHIGraphicsPipeline.hpp:215
Graphics pipeline.
Definition: RHIGraphicsPipeline.hpp:223
RHIGraphicsPipelineDesc mDesc
Definition: RHIGraphicsPipeline.hpp:232
BRK_API ~RHIGraphicsPipeline() override=default
const RHIGraphicsPipelineDesc & GetDesc() const
Definition: RHIGraphicsPipeline.hpp:228
Base class for RHI resource.
Definition: RHIResource.hpp:55
RHIPolygonFrontFace
Definition: RHIDefs.hpp:241
RHIBlendOperation
Definition: RHIDefs.hpp:289
RHIOperation
Definition: RHIDefs.hpp:257
RHIPolygonMode
Definition: RHIDefs.hpp:227
RHICompareFunction
Definition: RHIDefs.hpp:246
RHIPolygonCullMode
Definition: RHIDefs.hpp:233
RHIBlendFactor
Definition: RHIDefs.hpp:266
RHIPrimitivesType
Definition: RHIDefs.hpp:220
Definition: GLDevice.cpp:46
RHI single blend attachment descriptor.
Definition: RHIGraphicsPipeline.hpp:134
RHIBlendOperation colorBlendOp
Definition: RHIGraphicsPipeline.hpp:137
RHIBlendAttachment()
Definition: RHIGraphicsPipeline.hpp:143
bool operator==(const RHIBlendAttachment &other) const
Definition: RHIGraphicsPipeline.hpp:154
RHIBlendFactor srcAlphaBlendFactor
Definition: RHIGraphicsPipeline.hpp:138
RHIBlendOperation alphaBlendOp
Definition: RHIGraphicsPipeline.hpp:136
RHIBlendFactor srcColorBlendFactor
Definition: RHIGraphicsPipeline.hpp:139
bool enable
Definition: RHIGraphicsPipeline.hpp:135
RHIBlendFactor dstColorBlendFactor
Definition: RHIGraphicsPipeline.hpp:141
RHIBlendFactor dstAlphaBlendFactor
Definition: RHIGraphicsPipeline.hpp:140
RHI blend state descriptor.
Definition: RHIGraphicsPipeline.hpp:170
static RHIBlendState CreateBlendState(uint32 attachments)
Definition: RHIGraphicsPipeline.hpp:185
bool operator==(const RHIBlendState &other) const
Definition: RHIGraphicsPipeline.hpp:173
std::vector< RHIBlendAttachment > attachments
Definition: RHIGraphicsPipeline.hpp:171
RHI depth stencil state descriptor.
Definition: RHIGraphicsPipeline.hpp:77
bool depthWrite
Definition: RHIGraphicsPipeline.hpp:80
RHIOperation sfail
Definition: RHIGraphicsPipeline.hpp:85
RHICompareFunction depthCompare
Definition: RHIGraphicsPipeline.hpp:78
bool stencilEnable
Definition: RHIGraphicsPipeline.hpp:81
bool depthEnable
Definition: RHIGraphicsPipeline.hpp:79
uint8 writeMask
Definition: RHIGraphicsPipeline.hpp:82
uint8 compareMask
Definition: RHIGraphicsPipeline.hpp:84
RHIOperation dfail
Definition: RHIGraphicsPipeline.hpp:86
bool operator==(const RHIDepthStencilState &other) const
Definition: RHIGraphicsPipeline.hpp:105
uint8 referenceValue
Definition: RHIGraphicsPipeline.hpp:83
RHIOperation dpass
Definition: RHIGraphicsPipeline.hpp:87
RHICompareFunction compareFunction
Definition: RHIGraphicsPipeline.hpp:88
static RHIDepthStencilState CreateDepthState(bool depthWrite=true)
Definition: RHIGraphicsPipeline.hpp:119
RHIDepthStencilState()
Definition: RHIGraphicsPipeline.hpp:90
RHI raster state descriptor.
Definition: RHIGraphicsPipeline.hpp:51
RHIPolygonCullMode cullMode
Definition: RHIGraphicsPipeline.hpp:53
bool operator==(const RHIRasterState &other) const
Definition: RHIGraphicsPipeline.hpp:65
RHIRasterState()
Definition: RHIGraphicsPipeline.hpp:57
uint8 lineWidth
Definition: RHIGraphicsPipeline.hpp:55
RHIPolygonFrontFace frontFace
Definition: RHIGraphicsPipeline.hpp:54
RHIPolygonMode mode
Definition: RHIGraphicsPipeline.hpp:52