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