1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_PIPELINE_DATA_H_
16 #define SRC_PIPELINE_DATA_H_
17 
18 #include <limits>
19 
20 #include "src/command_data.h"
21 
22 namespace amber {
23 
24 /// Stores information used to configure a pipeline.
25 class PipelineData {
26  public:
27   PipelineData();
28   ~PipelineData();
29   PipelineData(const PipelineData&);
30 
31   PipelineData& operator=(const PipelineData&) = default;
32 
SetTopology(Topology topo)33   void SetTopology(Topology topo) { topology_ = topo; }
GetTopology()34   Topology GetTopology() const { return topology_; }
35 
SetPolygonMode(PolygonMode mode)36   void SetPolygonMode(PolygonMode mode) { polygon_mode_ = mode; }
GetPolygonMode()37   PolygonMode GetPolygonMode() const { return polygon_mode_; }
38 
SetCullMode(CullMode mode)39   void SetCullMode(CullMode mode) { cull_mode_ = mode; }
GetCullMode()40   CullMode GetCullMode() const { return cull_mode_; }
41 
SetFrontFace(FrontFace face)42   void SetFrontFace(FrontFace face) { front_face_ = face; }
GetFrontFace()43   FrontFace GetFrontFace() const { return front_face_; }
44 
SetDepthCompareOp(CompareOp op)45   void SetDepthCompareOp(CompareOp op) { depth_compare_op_ = op; }
GetDepthCompareOp()46   CompareOp GetDepthCompareOp() const { return depth_compare_op_; }
47 
SetColorWriteMask(uint8_t mask)48   void SetColorWriteMask(uint8_t mask) { color_write_mask_ = mask; }
GetColorWriteMask()49   uint8_t GetColorWriteMask() const { return color_write_mask_; }
50 
SetFrontFailOp(StencilOp op)51   void SetFrontFailOp(StencilOp op) { front_fail_op_ = op; }
GetFrontFailOp()52   StencilOp GetFrontFailOp() const { return front_fail_op_; }
53 
SetFrontPassOp(StencilOp op)54   void SetFrontPassOp(StencilOp op) { front_pass_op_ = op; }
GetFrontPassOp()55   StencilOp GetFrontPassOp() const { return front_pass_op_; }
56 
SetFrontDepthFailOp(StencilOp op)57   void SetFrontDepthFailOp(StencilOp op) { front_depth_fail_op_ = op; }
GetFrontDepthFailOp()58   StencilOp GetFrontDepthFailOp() const { return front_depth_fail_op_; }
59 
SetFrontCompareOp(CompareOp op)60   void SetFrontCompareOp(CompareOp op) { front_compare_op_ = op; }
GetFrontCompareOp()61   CompareOp GetFrontCompareOp() const { return front_compare_op_; }
62 
SetFrontCompareMask(uint32_t mask)63   void SetFrontCompareMask(uint32_t mask) { front_compare_mask_ = mask; }
GetFrontCompareMask()64   uint32_t GetFrontCompareMask() const { return front_compare_mask_; }
65 
SetFrontWriteMask(uint32_t mask)66   void SetFrontWriteMask(uint32_t mask) { front_write_mask_ = mask; }
GetFrontWriteMask()67   uint32_t GetFrontWriteMask() const { return front_write_mask_; }
68 
SetFrontReference(uint32_t ref)69   void SetFrontReference(uint32_t ref) { front_reference_ = ref; }
GetFrontReference()70   uint32_t GetFrontReference() const { return front_reference_; }
71 
SetBackFailOp(StencilOp op)72   void SetBackFailOp(StencilOp op) { back_fail_op_ = op; }
GetBackFailOp()73   StencilOp GetBackFailOp() const { return back_fail_op_; }
74 
SetBackPassOp(StencilOp op)75   void SetBackPassOp(StencilOp op) { back_pass_op_ = op; }
GetBackPassOp()76   StencilOp GetBackPassOp() const { return back_pass_op_; }
77 
SetBackDepthFailOp(StencilOp op)78   void SetBackDepthFailOp(StencilOp op) { back_depth_fail_op_ = op; }
GetBackDepthFailOp()79   StencilOp GetBackDepthFailOp() const { return back_depth_fail_op_; }
80 
SetBackCompareOp(CompareOp op)81   void SetBackCompareOp(CompareOp op) { back_compare_op_ = op; }
GetBackCompareOp()82   CompareOp GetBackCompareOp() const { return back_compare_op_; }
83 
SetBackCompareMask(uint32_t mask)84   void SetBackCompareMask(uint32_t mask) { back_compare_mask_ = mask; }
GetBackCompareMask()85   uint32_t GetBackCompareMask() const { return back_compare_mask_; }
86 
SetBackWriteMask(uint32_t mask)87   void SetBackWriteMask(uint32_t mask) { back_write_mask_ = mask; }
GetBackWriteMask()88   uint32_t GetBackWriteMask() const { return back_write_mask_; }
89 
SetBackReference(uint32_t ref)90   void SetBackReference(uint32_t ref) { back_reference_ = ref; }
GetBackReference()91   uint32_t GetBackReference() const { return back_reference_; }
92 
SetLineWidth(float width)93   void SetLineWidth(float width) { line_width_ = width; }
GetLineWidth()94   float GetLineWidth() const { return line_width_; }
95 
SetEnableBlend(bool v)96   void SetEnableBlend(bool v) { enable_blend_ = v; }
GetEnableBlend()97   bool GetEnableBlend() const { return enable_blend_; }
98 
SetEnableDepthTest(bool v)99   void SetEnableDepthTest(bool v) { enable_depth_test_ = v; }
GetEnableDepthTest()100   bool GetEnableDepthTest() const { return enable_depth_test_; }
101 
SetEnableDepthWrite(bool v)102   void SetEnableDepthWrite(bool v) { enable_depth_write_ = v; }
GetEnableDepthWrite()103   bool GetEnableDepthWrite() const { return enable_depth_write_; }
104 
SetEnableStencilTest(bool v)105   void SetEnableStencilTest(bool v) { enable_stencil_test_ = v; }
GetEnableStencilTest()106   bool GetEnableStencilTest() const { return enable_stencil_test_; }
107 
SetEnablePrimitiveRestart(bool v)108   void SetEnablePrimitiveRestart(bool v) { enable_primitive_restart_ = v; }
GetEnablePrimitiveRestart()109   bool GetEnablePrimitiveRestart() const { return enable_primitive_restart_; }
110 
SetEnableDepthClamp(bool v)111   void SetEnableDepthClamp(bool v) { enable_depth_clamp_ = v; }
GetEnableDepthClamp()112   bool GetEnableDepthClamp() const { return enable_depth_clamp_; }
113 
SetEnableRasterizerDiscard(bool v)114   void SetEnableRasterizerDiscard(bool v) { enable_rasterizer_discard_ = v; }
GetEnableRasterizerDiscard()115   bool GetEnableRasterizerDiscard() const { return enable_rasterizer_discard_; }
116 
SetEnableDepthBias(bool v)117   void SetEnableDepthBias(bool v) { enable_depth_bias_ = v; }
GetEnableDepthBias()118   bool GetEnableDepthBias() const { return enable_depth_bias_; }
119 
SetEnableLogicOp(bool v)120   void SetEnableLogicOp(bool v) { enable_logic_op_ = v; }
GetEnableLogicOp()121   bool GetEnableLogicOp() const { return enable_logic_op_; }
122 
SetEnableDepthBoundsTest(bool v)123   void SetEnableDepthBoundsTest(bool v) { enable_depth_bounds_test_ = v; }
GetEnableDepthBoundsTest()124   bool GetEnableDepthBoundsTest() const { return enable_depth_bounds_test_; }
125 
SetDepthBiasConstantFactor(float f)126   void SetDepthBiasConstantFactor(float f) { depth_bias_constant_factor_ = f; }
GetDepthBiasConstantFactor()127   float GetDepthBiasConstantFactor() const {
128     return depth_bias_constant_factor_;
129   }
130 
SetDepthBiasClamp(float f)131   void SetDepthBiasClamp(float f) { depth_bias_clamp_ = f; }
GetDepthBiasClamp()132   float GetDepthBiasClamp() const { return depth_bias_clamp_; }
133 
SetDepthBiasSlopeFactor(float f)134   void SetDepthBiasSlopeFactor(float f) { depth_bias_slope_factor_ = f; }
GetDepthBiasSlopeFactor()135   float GetDepthBiasSlopeFactor() const { return depth_bias_slope_factor_; }
136 
SetMinDepthBounds(float f)137   void SetMinDepthBounds(float f) { min_depth_bounds_ = f; }
GetMinDepthBounds()138   float GetMinDepthBounds() const { return min_depth_bounds_; }
139 
SetMaxDepthBounds(float f)140   void SetMaxDepthBounds(float f) { max_depth_bounds_ = f; }
GetMaxDepthBounds()141   float GetMaxDepthBounds() const { return max_depth_bounds_; }
142 
SetLogicOp(LogicOp op)143   void SetLogicOp(LogicOp op) { logic_op_ = op; }
GetLogicOp()144   LogicOp GetLogicOp() const { return logic_op_; }
145 
SetSrcColorBlendFactor(BlendFactor f)146   void SetSrcColorBlendFactor(BlendFactor f) { src_color_blend_factor_ = f; }
GetSrcColorBlendFactor()147   BlendFactor GetSrcColorBlendFactor() const { return src_color_blend_factor_; }
148 
SetDstColorBlendFactor(BlendFactor f)149   void SetDstColorBlendFactor(BlendFactor f) { dst_color_blend_factor_ = f; }
GetDstColorBlendFactor()150   BlendFactor GetDstColorBlendFactor() const { return dst_color_blend_factor_; }
151 
SetSrcAlphaBlendFactor(BlendFactor f)152   void SetSrcAlphaBlendFactor(BlendFactor f) { src_alpha_blend_factor_ = f; }
GetSrcAlphaBlendFactor()153   BlendFactor GetSrcAlphaBlendFactor() const { return src_alpha_blend_factor_; }
154 
SetDstAlphaBlendFactor(BlendFactor f)155   void SetDstAlphaBlendFactor(BlendFactor f) { dst_alpha_blend_factor_ = f; }
GetDstAlphaBlendFactor()156   BlendFactor GetDstAlphaBlendFactor() const { return dst_alpha_blend_factor_; }
157 
SetColorBlendOp(BlendOp op)158   void SetColorBlendOp(BlendOp op) { color_blend_op_ = op; }
GetColorBlendOp()159   BlendOp GetColorBlendOp() const { return color_blend_op_; }
160 
SetAlphaBlendOp(BlendOp op)161   void SetAlphaBlendOp(BlendOp op) { alpha_blend_op_ = op; }
GetAlphaBlendOp()162   BlendOp GetAlphaBlendOp() const { return alpha_blend_op_; }
163 
164  private:
165   StencilOp front_fail_op_ = StencilOp::kKeep;
166   StencilOp front_pass_op_ = StencilOp::kKeep;
167   StencilOp front_depth_fail_op_ = StencilOp::kKeep;
168   CompareOp front_compare_op_ = CompareOp::kAlways;
169 
170   StencilOp back_fail_op_ = StencilOp::kKeep;
171   StencilOp back_pass_op_ = StencilOp::kKeep;
172   StencilOp back_depth_fail_op_ = StencilOp::kKeep;
173   CompareOp back_compare_op_ = CompareOp::kAlways;
174 
175   Topology topology_ = Topology::kTriangleStrip;
176   PolygonMode polygon_mode_ = PolygonMode::kFill;
177   CullMode cull_mode_ = CullMode::kNone;
178   FrontFace front_face_ = FrontFace::kCounterClockwise;
179   CompareOp depth_compare_op_ = CompareOp::kAlways;
180   LogicOp logic_op_ = LogicOp::kClear;
181   BlendFactor src_color_blend_factor_ = BlendFactor::kOne;
182   BlendFactor dst_color_blend_factor_ = BlendFactor::kZero;
183   BlendFactor src_alpha_blend_factor_ = BlendFactor::kOne;
184   BlendFactor dst_alpha_blend_factor_ = BlendFactor::kZero;
185   BlendOp color_blend_op_ = BlendOp::kAdd;
186   BlendOp alpha_blend_op_ = BlendOp::kAdd;
187 
188   uint32_t front_compare_mask_ = std::numeric_limits<uint32_t>::max();
189   uint32_t front_write_mask_ = std::numeric_limits<uint32_t>::max();
190   uint32_t front_reference_ = 0;
191 
192   uint32_t back_compare_mask_ = std::numeric_limits<uint32_t>::max();
193   uint32_t back_write_mask_ = std::numeric_limits<uint32_t>::max();
194   uint32_t back_reference_ = 0;
195 
196   uint8_t color_write_mask_ =
197       kColorMaskR | kColorMaskG | kColorMaskB | kColorMaskA;
198 
199   bool enable_blend_ = false;
200   bool enable_depth_test_ = false;
201   bool enable_depth_write_ = false;
202   bool enable_depth_clamp_ = false;
203   bool enable_depth_bias_ = false;
204   bool enable_depth_bounds_test_ = false;
205   bool enable_stencil_test_ = false;
206   bool enable_primitive_restart_ = false;
207   bool enable_rasterizer_discard_ = false;
208   bool enable_logic_op_ = false;
209 
210   float line_width_ = 1.0f;
211   float depth_bias_constant_factor_ = 0.0f;
212   float depth_bias_clamp_ = 0.0f;
213   float depth_bias_slope_factor_ = 0.0f;
214   float min_depth_bounds_ = 0.0f;
215   float max_depth_bounds_ = 0.0f;
216 };
217 
218 }  // namespace amber
219 
220 #endif  // SRC_PIPELINE_DATA_H_
221