1 #ifndef DALI_SCENE3D_LOADER_RENDERER_STATE_H
2 #define DALI_SCENE3D_LOADER_RENDERER_STATE_H
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/public-api/rendering/renderer.h>
24 #include <dali-scene3d/public-api/api.h>
26 namespace Dali::Scene3D::Loader
29 * @brief Contains values for comparison functions used in depth and stencil testing.
30 * @note Relative order of members must match DepthFunction::Type and StencilFunction::Type.
32 struct DALI_SCENE3D_API Comparison
36 OMIT, // not specified; will not be set.
47 Comparison() = delete;
51 * @brief Determines the blend factor used.
52 * @note Relative order of members must match BlendFactor::Type.
54 struct DALI_SCENE3D_API BlendFactor
58 OMIT, // not specified - will not be updated
60 ONE, // default for source alpha
63 SRC_ALPHA, // default for source RGB
64 ONE_MINUS_SRC_ALPHA, // default for destination RGB and destination alpha
71 ONE_MINUS_CONSTANT_COLOR,
73 ONE_MINUS_CONSTANT_ALPHA,
76 BlendFactor() = delete;
80 * @brief Determines which buffers shall the Renderer write into.
81 * @note Relative order of members must match RenderMode::Type.
83 struct DALI_SCENE3D_API BufferMode
87 OMIT, ///< not specified - will not be updated
88 NONE, ///< Don’t write to either color or stencil buffer (But will potentially render to depth buffer).
89 AUTO, ///< Writes are managed by the Actor Clipping API. This is DALi's default.
90 COLOR, ///< Ignore stencil properties. Write to the color buffer.
91 STENCIL, ///< Use the stencil properties. Do not write to the color buffer.
92 COLOR_STENCIL ///< Use the stencil properties AND Write to the color buffer.
95 BufferMode() = delete;
99 * @brief Contains values and functionality for configuring Renderers.
101 namespace RendererState
103 using Type = uint32_t; // 8 bits reserved for flags, 4 * 4 bit for blend factors, 4 bits for depth function
105 enum DALI_SCENE3D_API Value : Type
117 DEPTH_FUNCTION_SHIFT = 6,
118 DEPTH_FUNCTION_BITS = 4,
119 DEPTH_FUNCTION_MASK = ((1 << DEPTH_FUNCTION_BITS) - 1) << DEPTH_FUNCTION_SHIFT,
121 BLEND_FACTOR_BASE_SHIFT = DEPTH_FUNCTION_SHIFT + DEPTH_FUNCTION_BITS,
122 BLEND_FACTOR_ITEM_BITS = 4,
123 BLEND_FACTOR_ITEMS = 4,
124 BLEND_FACTOR_BITS = BLEND_FACTOR_ITEM_BITS * BLEND_FACTOR_ITEMS,
125 BLEND_FACTOR_MASK = ((1 << BLEND_FACTOR_BITS) - 1) << BLEND_FACTOR_BASE_SHIFT,
126 BLEND_FACTOR_ITEM_MASK = (1 << BLEND_FACTOR_ITEM_BITS) - 1, // after rshifting by BLEND_FACTOR_BASE_SHIFT
128 // Buffer mode is DALi's RenderMode, just to avoid too much conflation.
129 BUFFER_MODE_BITS = 3u,
130 BUFFER_MODE_SHIFT = 32u - BUFFER_MODE_BITS, // from end
131 BUFFER_MODE_MASK = ((1u << BUFFER_MODE_BITS) - 1u) << BUFFER_MODE_SHIFT,
133 DEFAULT = DEPTH_WRITE | DEPTH_TEST | CULL_BACK | (Comparison::LESS_EQUAL << DEPTH_FUNCTION_SHIFT),
137 * @brief Encodes the given blend factors into a RenderMode value, maskable into other options,
138 * passable into ApplyRenderMode().
140 inline DALI_SCENE3D_API constexpr uint32_t FromBlendFactors(BlendFactor::Type srcRgb, BlendFactor::Type destRgb, BlendFactor::Type srcAlpha, BlendFactor::Type destAlpha)
142 return (srcRgb | (destRgb << BLEND_FACTOR_ITEM_BITS) | (srcAlpha << (BLEND_FACTOR_ITEM_BITS * 2)) |
143 (destAlpha << (BLEND_FACTOR_ITEM_BITS * 3)))
144 << BLEND_FACTOR_BASE_SHIFT;
148 * @brief Applies the settings encoded in @a rendererState, to a @a renderer.
149 * @note Depth function is only set if not Comparison::OMIT.
150 * @note Blend factors are only set if not BlendFactor::OMIT.
151 * @note Buffer mode is only set is not BufferMode::OMIT.
153 DALI_SCENE3D_API void Apply(Type rendererState, Renderer& renderer);
155 } // namespace RendererState
157 } // namespace Dali::Scene3D::Loader
159 #endif //DALI_SCENE3D_LOADER_RENDERER_STATE_H