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 SetTopology(Topology topo)31 void SetTopology(Topology topo) { topology_ = topo; } GetTopology()32 Topology GetTopology() const { return topology_; } 33 SetPolygonMode(PolygonMode mode)34 void SetPolygonMode(PolygonMode mode) { polygon_mode_ = mode; } GetPolygonMode()35 PolygonMode GetPolygonMode() const { return polygon_mode_; } 36 SetCullMode(CullMode mode)37 void SetCullMode(CullMode mode) { cull_mode_ = mode; } GetCullMode()38 CullMode GetCullMode() const { return cull_mode_; } 39 SetFrontFace(FrontFace face)40 void SetFrontFace(FrontFace face) { front_face_ = face; } GetFrontFace()41 FrontFace GetFrontFace() const { return front_face_; } 42 SetDepthCompareOp(CompareOp op)43 void SetDepthCompareOp(CompareOp op) { depth_compare_op_ = op; } GetDepthCompareOp()44 CompareOp GetDepthCompareOp() const { return depth_compare_op_; } 45 SetColorWriteMask(uint8_t mask)46 void SetColorWriteMask(uint8_t mask) { color_write_mask_ = mask; } GetColorWriteMask()47 uint8_t GetColorWriteMask() const { return color_write_mask_; } 48 SetFrontFailOp(StencilOp op)49 void SetFrontFailOp(StencilOp op) { front_fail_op_ = op; } GetFrontFailOp()50 StencilOp GetFrontFailOp() const { return front_fail_op_; } 51 SetFrontPassOp(StencilOp op)52 void SetFrontPassOp(StencilOp op) { front_pass_op_ = op; } GetFrontPassOp()53 StencilOp GetFrontPassOp() const { return front_pass_op_; } 54 SetFrontDepthFailOp(StencilOp op)55 void SetFrontDepthFailOp(StencilOp op) { front_depth_fail_op_ = op; } GetFrontDepthFailOp()56 StencilOp GetFrontDepthFailOp() const { return front_depth_fail_op_; } 57 SetFrontCompareOp(CompareOp op)58 void SetFrontCompareOp(CompareOp op) { front_compare_op_ = op; } GetFrontCompareOp()59 CompareOp GetFrontCompareOp() const { return front_compare_op_; } 60 SetFrontCompareMask(uint32_t mask)61 void SetFrontCompareMask(uint32_t mask) { front_compare_mask_ = mask; } GetFrontCompareMask()62 uint32_t GetFrontCompareMask() const { return front_compare_mask_; } 63 SetFrontWriteMask(uint32_t mask)64 void SetFrontWriteMask(uint32_t mask) { front_write_mask_ = mask; } GetFrontWriteMask()65 uint32_t GetFrontWriteMask() const { return front_write_mask_; } 66 SetFrontReference(uint32_t ref)67 void SetFrontReference(uint32_t ref) { front_reference_ = ref; } GetFrontReference()68 uint32_t GetFrontReference() const { return front_reference_; } 69 SetBackFailOp(StencilOp op)70 void SetBackFailOp(StencilOp op) { back_fail_op_ = op; } GetBackFailOp()71 StencilOp GetBackFailOp() const { return back_fail_op_; } 72 SetBackPassOp(StencilOp op)73 void SetBackPassOp(StencilOp op) { back_pass_op_ = op; } GetBackPassOp()74 StencilOp GetBackPassOp() const { return back_pass_op_; } 75 SetBackDepthFailOp(StencilOp op)76 void SetBackDepthFailOp(StencilOp op) { back_depth_fail_op_ = op; } GetBackDepthFailOp()77 StencilOp GetBackDepthFailOp() const { return back_depth_fail_op_; } 78 SetBackCompareOp(CompareOp op)79 void SetBackCompareOp(CompareOp op) { back_compare_op_ = op; } GetBackCompareOp()80 CompareOp GetBackCompareOp() const { return back_compare_op_; } 81 SetBackCompareMask(uint32_t mask)82 void SetBackCompareMask(uint32_t mask) { back_compare_mask_ = mask; } GetBackCompareMask()83 uint32_t GetBackCompareMask() const { return back_compare_mask_; } 84 SetBackWriteMask(uint32_t mask)85 void SetBackWriteMask(uint32_t mask) { back_write_mask_ = mask; } GetBackWriteMask()86 uint32_t GetBackWriteMask() const { return back_write_mask_; } 87 SetBackReference(uint32_t ref)88 void SetBackReference(uint32_t ref) { back_reference_ = ref; } GetBackReference()89 uint32_t GetBackReference() const { return back_reference_; } 90 SetLineWidth(float width)91 void SetLineWidth(float width) { line_width_ = width; } GetLineWidth()92 float GetLineWidth() const { return line_width_; } 93 SetEnableBlend(bool v)94 void SetEnableBlend(bool v) { enable_blend_ = v; } GetEnableBlend()95 bool GetEnableBlend() const { return enable_blend_; } 96 SetEnableDepthTest(bool v)97 void SetEnableDepthTest(bool v) { enable_depth_test_ = v; } GetEnableDepthTest()98 bool GetEnableDepthTest() const { return enable_depth_test_; } 99 SetEnableDepthWrite(bool v)100 void SetEnableDepthWrite(bool v) { enable_depth_write_ = v; } GetEnableDepthWrite()101 bool GetEnableDepthWrite() const { return enable_depth_write_; } 102 SetEnableStencilTest(bool v)103 void SetEnableStencilTest(bool v) { enable_stencil_test_ = v; } GetEnableStencilTest()104 bool GetEnableStencilTest() const { return enable_stencil_test_; } 105 SetEnablePrimitiveRestart(bool v)106 void SetEnablePrimitiveRestart(bool v) { enable_primitive_restart_ = v; } GetEnablePrimitiveRestart()107 bool GetEnablePrimitiveRestart() const { return enable_primitive_restart_; } 108 SetEnableDepthClamp(bool v)109 void SetEnableDepthClamp(bool v) { enable_depth_clamp_ = v; } GetEnableDepthClamp()110 bool GetEnableDepthClamp() const { return enable_depth_clamp_; } 111 SetEnableRasterizerDiscard(bool v)112 void SetEnableRasterizerDiscard(bool v) { enable_rasterizer_discard_ = v; } GetEnableRasterizerDiscard()113 bool GetEnableRasterizerDiscard() const { return enable_rasterizer_discard_; } 114 SetEnableDepthBias(bool v)115 void SetEnableDepthBias(bool v) { enable_depth_bias_ = v; } GetEnableDepthBias()116 bool GetEnableDepthBias() const { return enable_depth_bias_; } 117 SetEnableLogicOp(bool v)118 void SetEnableLogicOp(bool v) { enable_logic_op_ = v; } GetEnableLogicOp()119 bool GetEnableLogicOp() const { return enable_logic_op_; } 120 SetEnableDepthBoundsTest(bool v)121 void SetEnableDepthBoundsTest(bool v) { enable_depth_bounds_test_ = v; } GetEnableDepthBoundsTest()122 bool GetEnableDepthBoundsTest() const { return enable_depth_bounds_test_; } 123 SetDepthBiasConstantFactor(float f)124 void SetDepthBiasConstantFactor(float f) { depth_bias_constant_factor_ = f; } GetDepthBiasConstantFactor()125 float GetDepthBiasConstantFactor() const { 126 return depth_bias_constant_factor_; 127 } 128 SetDepthBiasClamp(float f)129 void SetDepthBiasClamp(float f) { depth_bias_clamp_ = f; } GetDepthBiasClamp()130 float GetDepthBiasClamp() const { return depth_bias_clamp_; } 131 SetDepthBiasSlopeFactor(float f)132 void SetDepthBiasSlopeFactor(float f) { depth_bias_slope_factor_ = f; } GetDepthBiasSlopeFactor()133 float GetDepthBiasSlopeFactor() const { return depth_bias_slope_factor_; } 134 SetMinDepthBounds(float f)135 void SetMinDepthBounds(float f) { min_depth_bounds_ = f; } GetMinDepthBounds()136 float GetMinDepthBounds() const { return min_depth_bounds_; } 137 SetMaxDepthBounds(float f)138 void SetMaxDepthBounds(float f) { max_depth_bounds_ = f; } GetMaxDepthBounds()139 float GetMaxDepthBounds() const { return max_depth_bounds_; } 140 SetLogicOp(LogicOp op)141 void SetLogicOp(LogicOp op) { logic_op_ = op; } GetLogicOp()142 LogicOp GetLogicOp() const { return logic_op_; } 143 SetSrcColorBlendFactor(BlendFactor f)144 void SetSrcColorBlendFactor(BlendFactor f) { src_color_blend_factor_ = f; } GetSrcColorBlendFactor()145 BlendFactor GetSrcColorBlendFactor() const { return src_color_blend_factor_; } 146 SetDstColorBlendFactor(BlendFactor f)147 void SetDstColorBlendFactor(BlendFactor f) { dst_color_blend_factor_ = f; } GetDstColorBlendFactor()148 BlendFactor GetDstColorBlendFactor() const { return dst_color_blend_factor_; } 149 SetSrcAlphaBlendFactor(BlendFactor f)150 void SetSrcAlphaBlendFactor(BlendFactor f) { src_alpha_blend_factor_ = f; } GetSrcAlphaBlendFactor()151 BlendFactor GetSrcAlphaBlendFactor() const { return src_alpha_blend_factor_; } 152 SetDstAlphaBlendFactor(BlendFactor f)153 void SetDstAlphaBlendFactor(BlendFactor f) { dst_alpha_blend_factor_ = f; } GetDstAlphaBlendFactor()154 BlendFactor GetDstAlphaBlendFactor() const { return dst_alpha_blend_factor_; } 155 SetColorBlendOp(BlendOp op)156 void SetColorBlendOp(BlendOp op) { color_blend_op_ = op; } GetColorBlendOp()157 BlendOp GetColorBlendOp() const { return color_blend_op_; } 158 SetAlphaBlendOp(BlendOp op)159 void SetAlphaBlendOp(BlendOp op) { alpha_blend_op_ = op; } GetAlphaBlendOp()160 BlendOp GetAlphaBlendOp() const { return alpha_blend_op_; } 161 162 private: 163 StencilOp front_fail_op_ = StencilOp::kKeep; 164 StencilOp front_pass_op_ = StencilOp::kKeep; 165 StencilOp front_depth_fail_op_ = StencilOp::kKeep; 166 CompareOp front_compare_op_ = CompareOp::kAlways; 167 168 StencilOp back_fail_op_ = StencilOp::kKeep; 169 StencilOp back_pass_op_ = StencilOp::kKeep; 170 StencilOp back_depth_fail_op_ = StencilOp::kKeep; 171 CompareOp back_compare_op_ = CompareOp::kAlways; 172 173 Topology topology_ = Topology::kTriangleStrip; 174 PolygonMode polygon_mode_ = PolygonMode::kFill; 175 CullMode cull_mode_ = CullMode::kNone; 176 FrontFace front_face_ = FrontFace::kCounterClockwise; 177 CompareOp depth_compare_op_ = CompareOp::kAlways; 178 LogicOp logic_op_ = LogicOp::kClear; 179 BlendFactor src_color_blend_factor_ = BlendFactor::kOne; 180 BlendFactor dst_color_blend_factor_ = BlendFactor::kZero; 181 BlendFactor src_alpha_blend_factor_ = BlendFactor::kOne; 182 BlendFactor dst_alpha_blend_factor_ = BlendFactor::kZero; 183 BlendOp color_blend_op_ = BlendOp::kAdd; 184 BlendOp alpha_blend_op_ = BlendOp::kAdd; 185 186 uint32_t front_compare_mask_ = std::numeric_limits<uint32_t>::max(); 187 uint32_t front_write_mask_ = std::numeric_limits<uint32_t>::max(); 188 uint32_t front_reference_ = 0; 189 190 uint32_t back_compare_mask_ = std::numeric_limits<uint32_t>::max(); 191 uint32_t back_write_mask_ = std::numeric_limits<uint32_t>::max(); 192 uint32_t back_reference_ = 0; 193 194 uint8_t color_write_mask_ = 195 kColorMaskR | kColorMaskG | kColorMaskB | kColorMaskA; 196 197 bool enable_blend_ = false; 198 bool enable_depth_test_ = false; 199 bool enable_depth_write_ = false; 200 bool enable_depth_clamp_ = false; 201 bool enable_depth_bias_ = false; 202 bool enable_depth_bounds_test_ = false; 203 bool enable_stencil_test_ = false; 204 bool enable_primitive_restart_ = false; 205 bool enable_rasterizer_discard_ = false; 206 bool enable_logic_op_ = false; 207 208 float line_width_ = 1.0f; 209 float depth_bias_constant_factor_ = 0.0f; 210 float depth_bias_clamp_ = 0.0f; 211 float depth_bias_slope_factor_ = 0.0f; 212 float min_depth_bounds_ = 0.0f; 213 float max_depth_bounds_ = 0.0f; 214 }; 215 216 } // namespace amber 217 218 #endif // SRC_PIPELINE_DATA_H_ 219