523cc14665c74043afa69de062ab16f68b05c8b8
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-algorithms.h
1 #ifndef DALI_INTERNAL_RENDER_ALGORITHMS_H
2 #define DALI_INTERNAL_RENDER_ALGORITHMS_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31 class Context;
32
33 namespace SceneGraph
34 {
35 class RenderInstruction;
36 struct RenderItem;
37 }
38
39 namespace Render
40 {
41
42 /**
43  * @brief The responsibility of the RenderAlgorithms object is to action renders required by a RenderInstruction.
44  */
45 class RenderAlgorithms
46 {
47   public:
48
49     /**
50      * Constructor.
51      */
52     RenderAlgorithms();
53
54     /**
55      * Process a render-instruction.
56      * @param[in] instruction            The render-instruction to process.
57      * @param[in] context                The GL context.
58      * @param[in] bufferIndex            The current render buffer index (previous update buffer)
59      * @param[in] depthBufferAvailable   Whether the depth buffer is available
60      * @param[in] stencilBufferAvailable Whether the stencil buffer is available
61      */
62     void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction,
63                                    Context& context,
64                                    BufferIndex bufferIndex,
65                                    Integration::DepthBufferAvailable depthBufferAvailable,
66                                    Integration::StencilBufferAvailable stencilBufferAvailable );
67
68   private:
69
70     /**
71      * @brief Calculate a 2D AABB (axis aligned bounding box) in screen space.
72      * The RenderItems dimensions are translated and a Z value of 0 is assumed for this purpose.
73      * No projection is performed, but rotation on Z is supported.
74      * @param[in] item The RenderItem to generate an AABB for
75      * @return         The generated AABB in screen space
76      */
77     inline Dali::ClippingBox CalculateScreenSpaceAABB( const Dali::Internal::SceneGraph::RenderItem& item );
78
79     /**
80      * @brief Perform any scissor clipping related operations based on the current RenderItem.
81      * This includes:
82      *  - Determining if any action is to be taken (so the method can be exited early if not).
83      *  - If the node is a clipping node, apply the nodes clip intersected with the current/parent scissor clip.
84      *  - If we have gone up the scissor hierarchy, and need to un-apply a scissor clip.
85      *  - Disable scissor clipping completely if it is not needed
86      * @param[in] item     The current RenderItem (about to be rendered)
87      * @param[in] context  The current Context
88      */
89     inline void SetupScissorClipping( const Dali::Internal::SceneGraph::RenderItem& item, Context& context );
90
91     /**
92      * @brief Set up the clipping based on the specified clipping settings.
93      * @param[in]     item                     The current RenderItem (about to be rendered)
94      * @param[in]     context                  The context
95      * @param[in/out] usedStencilBuffer        True if the stencil buffer has been used so far within this RenderList. Used by StencilMode::ON.
96      * @param[in/out] lastClippingDepth        The stencil depth of the last renderer drawn. Used by the clipping feature.
97      * @param[in/out] lastClippingId           The clipping ID of the last renderer drawn.   Used by the clipping feature.
98      * @param[in]     stencilBufferAvailable   Whether the stencil buffer is available
99      */
100     inline void SetupClipping( const Dali::Internal::SceneGraph::RenderItem& item,
101                                Context& context,
102                                bool& usedStencilBuffer,
103                                uint32_t& lastClippingDepth,
104                                uint32_t& lastClippingId,
105                                Integration::StencilBufferAvailable stencilBufferAvailable );
106
107     /**
108      * @brief Process a render-list.
109      * @param[in] renderList             The render-list to process.
110      * @param[in] context                The GL context.
111      * @param[in] buffer                 The current render buffer index (previous update buffer)
112      * @param[in] viewMatrix             The view matrix from the appropriate camera.
113      * @param[in] projectionMatrix       The projection matrix from the appropriate camera.
114      * @param[in] depthBufferAvailable   Whether the depth buffer is available
115      * @param[in] stencilBufferAvailable Whether the stencil buffer is available
116      */
117     inline void ProcessRenderList( const Dali::Internal::SceneGraph::RenderList& renderList,
118                                    Context& context,
119                                    BufferIndex bufferIndex,
120                                    const Matrix& viewMatrix,
121                                    const Matrix& projectionMatrix,
122                                    Integration::DepthBufferAvailable depthBufferAvailable,
123                                    Integration::StencilBufferAvailable stencilBufferAvailable );
124
125     // Prevent copying:
126     RenderAlgorithms( RenderAlgorithms& rhs );
127     RenderAlgorithms& operator=( const RenderAlgorithms& rhs );
128
129
130     // Member variables:
131
132     using ScissorStackType = std::vector<Dali::ClippingBox>;      ///< The container type used to maintain the applied scissor hierarchy
133
134     ScissorStackType                        mScissorStack;        ///< Contains the currently applied scissor hierarchy (so we can undo clips)
135     Dali::ClippingBox                       mViewportRectangle;   ///< The viewport dimensions, used to translate AABBs to scissor coordinates
136     bool                                    mHasLayerScissor:1;   ///< Marks if the currently process render instruction has a layer-based clipping region
137 };
138
139 } // namespace Render
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // DALI_INTERNAL_RENDER_ALGORITHMS_H