[dali_1.2.27] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / render-instruction-processor.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_PROCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2016 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/update/manager/sorted-layers.h>
24 #include <dali/integration-api/resource-declarations.h>
25 #include <dali/public-api/common/dali-vector.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Render
34 {
35 class Geometry;
36 }
37
38 namespace SceneGraph
39 {
40
41 class RenderTracker;
42 struct RenderItem;
43 class Shader;
44 struct RenderList;
45 class RenderTask;
46 class RenderInstructionContainer;
47
48
49 /**
50  * @brief This class handles the sorting and preparation of Renderers for each layer.
51  */
52 class RenderInstructionProcessor
53 {
54 public:
55
56   /**
57    * @brief Constructor.
58    */
59   RenderInstructionProcessor();
60
61   /**
62    * @brief Destructor.
63    */
64   ~RenderInstructionProcessor();
65
66   /**
67    * @brief Structure to store information for sorting the renderers.
68    * (Note, depthIndex is stored within the renderItem).
69    */
70   struct SortAttributes
71   {
72     SortAttributes()
73     : renderItem( NULL ),
74       shader( NULL ),
75       textureSet( NULL ),
76       geometry( NULL ),
77       zValue( 0.0f )
78     {
79     }
80
81     RenderItem*             renderItem;        ///< The render item that is being sorted (includes depth index)
82     const Shader*           shader;            ///< The shader instance
83     const void*             textureSet;        ///< The textureSet instance
84     const Render::Geometry* geometry;          ///< The geometry instance
85     float                   zValue;            ///< The Z value of the given renderer (either distance from camera, or a custom calculated value)
86   };
87
88
89   /**
90    * @brief Sorts and prepares the list of opaque/transparent Renderers for each layer.
91    * Whilst iterating through each layer, update the RenderItems ModelView matrices
92    *
93    * The opaque and transparent render lists are sorted first by depth
94    * index, then by Z (for transparent only), then by shader, texture
95    * and geometry. The render algorithm should then work through both
96    * lists simultaneously, working through opaque then transparent
97    * items at each depth index, resetting the flags appropriately.
98    *
99    * @param[in]  updateBufferIndex The current update buffer index.
100    * @param[in]  sortedLayers      The layers containing lists of opaque/transparent renderables.
101    * @param[in]  renderTask        The rendering task information.
102    * @param[in]  cull              Whether frustum culling is enabled or not
103    * @param[in]  hasClippingNodes  Whether any clipping nodes exist within this layer, to optimize sorting if not
104    * @param[out] instructions      The rendering instructions for the next frame.
105    */
106   void Prepare( BufferIndex updateBufferIndex,
107                 SortedLayerPointers& sortedLayers,
108                 RenderTask& renderTask,
109                 bool cull,
110                 bool hasClippingNodes,
111                 RenderInstructionContainer& instructions );
112
113 private:
114
115   /**
116    * Undefine copy and assignment operators.
117    */
118   RenderInstructionProcessor( const RenderInstructionProcessor& renderInstructionProcessor );             ///< No definition
119   RenderInstructionProcessor& operator=( const RenderInstructionProcessor& renderInstructionProcessor );  ///< No definition
120
121 private:
122
123   /**
124    * @brief Sort render items
125    * @param bufferIndex The buffer to read from
126    * @param renderList to sort
127    * @param layer where the Renderers are from
128    * @param respectClippingOrder Sort with the correct clipping hierarchy.
129    */
130   inline void SortRenderItems( BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder );
131
132   /// Sort comparitor function pointer type.
133   typedef bool ( *ComparitorPointer )( const SortAttributes& lhs, const SortAttributes& rhs );
134   typedef std::vector< SortAttributes > SortingHelper;
135
136   Dali::Vector< ComparitorPointer > mSortComparitors;       ///< Contains all sort comparitors, used for quick look-up
137   RenderInstructionProcessor::SortingHelper mSortingHelper; ///< Helper used to sort Renderers
138
139 };
140
141
142 } // namespace SceneGraph
143
144 } // namespace Internal
145
146 } // namespace Dali
147
148 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_PROCESSOR_H