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