1 #ifndef DALI_INTERNAL_RENDER_ALGORITHMS_H
2 #define DALI_INTERNAL_RENDER_ALGORITHMS_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/core-enumerations.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/render/common/render-list.h>
32 class RenderInstruction;
34 } // namespace SceneGraph
39 * @brief The responsibility of the RenderAlgorithms object is to action renders required by a RenderInstruction.
41 class RenderAlgorithms
47 * @param[in] graphicsController The graphics controller
49 explicit RenderAlgorithms(Graphics::Controller& graphicsController);
51 RenderAlgorithms(RenderAlgorithms& rhs) = delete; // Prevent copying
53 RenderAlgorithms& operator=(const RenderAlgorithms& rhs) = delete; // Prevent Copying
55 * Process a render-instruction.
56 * @param[in] instruction The render-instruction to process.
57 * @param[in] bufferIndex The current render buffer index (previous update buffer)
58 * @param[in] depthBufferAvailable Whether the depth buffer is available
59 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
60 * @param[in] viewport The viewport for drawing
61 * @param[in] rootClippingRect The clipping rectangle
62 * @param[in] orientation The Scene's surface orientation.
63 * @param[in] sceneSize The Scene's surface size.
65 void ProcessRenderInstruction(const SceneGraph::RenderInstruction& instruction,
66 BufferIndex bufferIndex,
67 Integration::DepthBufferAvailable depthBufferAvailable,
68 Integration::StencilBufferAvailable stencilBufferAvailable,
69 const Rect<int32_t>& viewport,
70 const Rect<int>& rootClippingRect,
72 const Uint16Pair& sceneSize);
75 * Resets main command buffer (per scene)
77 void ResetCommandBuffer();
80 * Submits main command buffer (per scene)
82 void SubmitCommandBuffer();
85 * Returns main command buffer
87 * 'Main' command buffer exists per each scene and it is used
88 * to bake all render instructions for the scene.
90 * @return main command buffer
92 [[nodiscard]] Graphics::CommandBuffer* GetMainCommandBuffer() const
94 return mGraphicsCommandBuffer.get();
99 * @brief Calculate a 2D AABB (axis aligned bounding box) in screen space.
100 * The RenderItems dimensions are translated and a Z value of 0 is assumed for this purpose.
101 * No projection is performed, but rotation on Z is supported.
102 * @param[in] item The RenderItem to generate an AABB for
103 * @return The generated AABB in screen space
105 inline Dali::ClippingBox CalculateScreenSpaceAABB(const Dali::Internal::SceneGraph::RenderItem& item);
108 * @brief Perform any scissor clipping related operations based on the current RenderItem.
110 * - Determining if any action is to be taken (so the method can be exited early if not).
111 * - If the node is a clipping node, apply the nodes clip intersected with the current/parent scissor clip.
112 * - If we have gone up the scissor hierarchy, and need to un-apply a scissor clip.
113 * - Disable scissor clipping completely if it is not needed
114 * @param[in] item The current RenderItem (about to be rendered)
115 * @param[in] commandBuffer The command buffer to write into
117 * @param[in] instruction The render-instruction to process.
118 * @param[in] orientation The Scene's surface orientation.
120 inline void SetupScissorClipping(
121 const Dali::Internal::SceneGraph::RenderItem& item,
122 Graphics::CommandBuffer& commandBuffer,
123 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
127 * @brief Set up the clipping based on the specified clipping settings.
128 * @param[in] item The current RenderItem (about to be rendered)
129 * @param[in,out] commandBuffer The command buffer to write commands to
130 * @param[in/out] usedStencilBuffer True if the stencil buffer has been used so far within this RenderList. Used by StencilMode::ON.
131 * @param[in/out] lastClippingDepth The stencil depth of the last renderer drawn. Used by the clipping feature.
132 * @param[in/out] lastClippingId The clipping ID of the last renderer drawn. Used by the clipping feature.
133 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
134 * @param[in] instruction The render-instruction to process.
135 * @param[in] orientation The Scene's surface orientation.
137 inline void SetupClipping(const Dali::Internal::SceneGraph::RenderItem& item,
138 Graphics::CommandBuffer& commandBuffer,
139 bool& usedStencilBuffer,
140 uint32_t& lastClippingDepth,
141 uint32_t& lastClippingId,
142 Integration::StencilBufferAvailable stencilBufferAvailable,
143 const Dali::Internal::SceneGraph::RenderInstruction& instruction,
147 * @brief Process a render-list.
148 * @param[in] renderList The render-list to process.
149 * @param[in] buffer The current render buffer index (previous update buffer)
150 * @param[in] viewMatrix The view matrix from the appropriate camera.
151 * @param[in] projectionMatrix The projection matrix from the appropriate camera.
152 * @param[in] depthBufferAvailable Whether the depth buffer is available
153 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
154 * @param[in] viewport The Viewport
155 * @param[in] rootClippingRect The root clipping rectangle
156 * @param[in] orientation The Scene's surface orientation
157 * @param[in] sceneSize The Scene's surface size.
159 inline void ProcessRenderList(const Dali::Internal::SceneGraph::RenderList& renderList,
160 BufferIndex bufferIndex,
161 const Matrix& viewMatrix,
162 const Matrix& projectionMatrix,
163 Integration::DepthBufferAvailable depthBufferAvailable,
164 Integration::StencilBufferAvailable stencilBufferAvailable,
165 const Dali::Internal::SceneGraph::RenderInstruction& instruction, // in the case of reflection, things like CullFace need to be adjusted for reflection world
166 const Rect<int32_t>& viewport,
167 const Rect<int>& rootClippingRect,
169 const Uint16Pair& sceneSize);
173 using ScissorStackType = std::vector<Dali::ClippingBox>; ///< The container type used to maintain the applied scissor hierarchy
175 Graphics::Controller& mGraphicsController;
176 Graphics::UniquePtr<Graphics::CommandBuffer> mGraphicsCommandBuffer{};
178 std::vector<Graphics::CommandBuffer*> mGraphicsRenderItemCommandBuffers{}; ///< Collection of command buffers issuing single draw call
180 ScissorStackType mScissorStack; ///< Contains the currently applied scissor hierarchy (so we can undo clips)
181 Dali::ClippingBox mViewportRectangle; ///< The viewport dimensions, used to translate AABBs to scissor coordinates
182 bool mHasLayerScissor : 1; ///< Marks if the currently process render instruction has a layer-based clipping region
185 } // namespace Render
187 } // namespace Internal
191 #endif // DALI_INTERNAL_RENDER_ALGORITHMS_H