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