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