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