[Tizen] Implement partial update
[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) 2019 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      * @param[in] boundTextures          The textures bound for rendering
62      * @param[in] scissorBox             The damaged rect for partial update
63      */
64     void ProcessRenderInstruction( const SceneGraph::RenderInstruction& instruction,
65                                    Context& context,
66                                    BufferIndex bufferIndex,
67                                    Integration::DepthBufferAvailable depthBufferAvailable,
68                                    Integration::StencilBufferAvailable stencilBufferAvailable,
69                                    Vector<GLuint>& boundTextures,
70                                    int orientation,
71                                    Dali::ClippingBox& scissorBox );
72
73   private:
74
75     /**
76      * @brief Calculate a 2D AABB (axis aligned bounding box) in screen space.
77      * The RenderItems dimensions are translated and a Z value of 0 is assumed for this purpose.
78      * No projection is performed, but rotation on Z is supported.
79      * @param[in] item The RenderItem to generate an AABB for
80      * @return         The generated AABB in screen space
81      */
82     inline Dali::ClippingBox CalculateScreenSpaceAABB( const Dali::Internal::SceneGraph::RenderItem& item );
83
84     /**
85      * @brief Perform any scissor clipping related operations based on the current RenderItem.
86      * This includes:
87      *  - Determining if any action is to be taken (so the method can be exited early if not).
88      *  - If the node is a clipping node, apply the nodes clip intersected with the current/parent scissor clip.
89      *  - If we have gone up the scissor hierarchy, and need to un-apply a scissor clip.
90      *  - Disable scissor clipping completely if it is not needed
91      * @param[in] item     The current RenderItem (about to be rendered)
92      * @param[in] context  The current Context
93      */
94     inline void SetupScissorClipping( const Dali::Internal::SceneGraph::RenderItem& item, Context& context, int orientation );
95
96     /**
97      * @brief Set up the clipping based on the specified clipping settings.
98      * @param[in]     item                     The current RenderItem (about to be rendered)
99      * @param[in]     context                  The context
100      * @param[in/out] usedStencilBuffer        True if the stencil buffer has been used so far within this RenderList. Used by StencilMode::ON.
101      * @param[in/out] lastClippingDepth        The stencil depth of the last renderer drawn. Used by the clipping feature.
102      * @param[in/out] lastClippingId           The clipping ID of the last renderer drawn.   Used by the clipping feature.
103      * @param[in]     stencilBufferAvailable   Whether the stencil buffer is available
104      */
105     inline void SetupClipping( const Dali::Internal::SceneGraph::RenderItem& item,
106                                Context& context,
107                                bool& usedStencilBuffer,
108                                uint32_t& lastClippingDepth,
109                                uint32_t& lastClippingId,
110                                Integration::StencilBufferAvailable stencilBufferAvailable,
111                                int orientation );
112
113     /**
114      * @brief Process a render-list.
115      * @param[in] renderList             The render-list to process.
116      * @param[in] context                The GL context.
117      * @param[in] buffer                 The current render buffer index (previous update buffer)
118      * @param[in] viewMatrix             The view matrix from the appropriate camera.
119      * @param[in] projectionMatrix       The projection matrix from the appropriate camera.
120      * @param[in] depthBufferAvailable   Whether the depth buffer is available
121      * @param[in] stencilBufferAvailable Whether the stencil buffer is available
122      * @param[in] boundTextures          The textures bound for rendering
123      * @param[in] scissorBox             The damaged rect for partial update
124      */
125     inline void ProcessRenderList( const Dali::Internal::SceneGraph::RenderList& renderList,
126                                    Context& context,
127                                    BufferIndex bufferIndex,
128                                    const Matrix& viewMatrix,
129                                    const Matrix& projectionMatrix,
130                                    Integration::DepthBufferAvailable depthBufferAvailable,
131                                    Integration::StencilBufferAvailable stencilBufferAvailable,
132                                    Vector<GLuint>& boundTextures,
133                                    int orientation,
134                                    Dali::ClippingBox& scissorBox );
135
136     // Prevent copying:
137     RenderAlgorithms( RenderAlgorithms& rhs );
138     RenderAlgorithms& operator=( const RenderAlgorithms& rhs );
139
140
141     // Member variables:
142
143     using ScissorStackType = std::vector<Dali::ClippingBox>;      ///< The container type used to maintain the applied scissor hierarchy
144
145     ScissorStackType                        mScissorStack;        ///< Contains the currently applied scissor hierarchy (so we can undo clips)
146     Dali::ClippingBox                       mViewportRectangle;   ///< The viewport dimensions, used to translate AABBs to scissor coordinates
147     bool                                    mHasLayerScissor:1;   ///< Marks if the currently process render instruction has a layer-based clipping region
148 };
149
150 } // namespace Render
151
152 } // namespace Internal
153
154 } // namespace Dali
155
156 #endif // DALI_INTERNAL_RENDER_ALGORITHMS_H