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