25d6e97d6e7a750f4c0ebe9d75cf3d25c4e51de6
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / render-instruction-processor.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/render-instruction-processor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/common/matrix-utils.h>
24 #include <dali/internal/event/actors/layer-impl.h> // for the default sorting function
25 #include <dali/internal/render/common/render-instruction-container.h>
26 #include <dali/internal/render/common/render-instruction.h>
27 #include <dali/internal/render/common/render-item.h>
28 #include <dali/internal/render/common/render-tracker.h>
29 #include <dali/internal/render/renderers/render-renderer.h>
30 #include <dali/internal/render/shaders/render-shader.h>
31 #include <dali/internal/update/manager/sorted-layers.h>
32 #include <dali/internal/update/nodes/partial-rendering-data.h>
33 #include <dali/internal/update/nodes/scene-graph-layer.h>
34 #include <dali/internal/update/render-tasks/scene-graph-render-task.h>
35 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
36 #include <dali/public-api/actors/layer.h>
37
38 namespace
39 {
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gRenderListLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_RENDER_LISTS");
42 #endif
43 } // namespace
44
45 namespace Dali
46 {
47 namespace Internal
48 {
49 namespace SceneGraph
50 {
51 namespace
52 {
53 /**
54  * Function which compares render items by shader/textureSet/geometry
55  * @param[in] lhs Left hand side item
56  * @param[in] rhs Right hand side item
57  * @return True if left item is greater than right
58  */
59 inline bool PartialCompareItems(const RenderInstructionProcessor::SortAttributes& lhs,
60                                 const RenderInstructionProcessor::SortAttributes& rhs)
61 {
62   if(lhs.shader == rhs.shader)
63   {
64     if(lhs.textureSet == rhs.textureSet)
65     {
66       return lhs.geometry < rhs.geometry;
67     }
68     return lhs.textureSet < rhs.textureSet;
69   }
70   return lhs.shader < rhs.shader;
71 }
72
73 /**
74  * Function which sorts render items by depth index then by instance
75  * ptrs of shader/textureSet/geometry.
76  * @param[in] lhs Left hand side item
77  * @param[in] rhs Right hand side item
78  * @return True if left item is greater than right
79  */
80 bool CompareItems(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
81 {
82   // @todo Consider replacing all these sortAttributes with a single long int that
83   // encapsulates the same data (e.g. the middle-order bits of the ptrs).
84   if(lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex)
85   {
86     return PartialCompareItems(lhs, rhs);
87   }
88   return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex;
89 }
90
91 /**
92  * Function which sorts the render items by Z function, then
93  * by instance ptrs of shader / geometry / material.
94  * @param[in] lhs Left hand side item
95  * @param[in] rhs Right hand side item
96  * @return True if left item is greater than right
97  */
98 bool CompareItems3D(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
99 {
100   const bool lhsIsOpaque = lhs.renderItem->mIsOpaque;
101   if(lhsIsOpaque == rhs.renderItem->mIsOpaque)
102   {
103     if(lhsIsOpaque)
104     {
105       // If both RenderItems are opaque, sort using shader, then material then geometry.
106       return PartialCompareItems(lhs, rhs);
107     }
108     else
109     {
110       // If both RenderItems are transparent, sort using Z, then shader, then material, then geometry.
111       if(Equals(lhs.zValue, rhs.zValue))
112       {
113         return PartialCompareItems(lhs, rhs);
114       }
115       return lhs.zValue > rhs.zValue;
116     }
117   }
118   else
119   {
120     return lhsIsOpaque;
121   }
122 }
123
124 /**
125  * Function which sorts render items by clipping hierarchy, then Z function and instance ptrs of shader / geometry / material.
126  * @param[in] lhs Left hand side item
127  * @param[in] rhs Right hand side item
128  * @return True if left item is greater than right
129  */
130 bool CompareItems3DWithClipping(const RenderInstructionProcessor::SortAttributes& lhs, const RenderInstructionProcessor::SortAttributes& rhs)
131 {
132   // Items must be sorted in order of clipping first, otherwise incorrect clipping regions could be used.
133   if(lhs.renderItem->mNode->mClippingSortModifier == rhs.renderItem->mNode->mClippingSortModifier)
134   {
135     return CompareItems3D(lhs, rhs);
136   }
137
138   return lhs.renderItem->mNode->mClippingSortModifier < rhs.renderItem->mNode->mClippingSortModifier;
139 }
140
141 /**
142  * Set the update area of the node
143  * @param[in] node The node of the renderer
144  * @param[in] isLayer3d Whether we are processing a 3D layer or not
145  * @param[in,out] nodeWorldMatrix The world matrix of the node
146  * @param[in,out] nodeSize The size of the node
147  * @param[in,out] nodeUpdateArea The update area of the node
148  *
149  * @return True if node use it's own UpdateAreaHint, or z transform occured. False if we use nodeUpdateArea equal with Vector4(0, 0, nodeSize.width, nodeSize.height).
150  */
151 inline bool SetNodeUpdateArea(Node* node, bool isLayer3d, Matrix& nodeWorldMatrix, Vector3& nodeSize, Vector4& nodeUpdateArea)
152 {
153   node->GetWorldMatrixAndSize(nodeWorldMatrix, nodeSize);
154
155   if(node->GetUpdateAreaHint() == Vector4::ZERO)
156   {
157     if(isLayer3d)
158     {
159       return true;
160     }
161     // RenderItem::CalculateViewportSpaceAABB cannot cope with z transform
162     // I don't use item.mModelMatrix.GetTransformComponents() for z transform, would be too slow
163     Vector3 zaxis = nodeWorldMatrix.GetZAxis();
164     if(EqualsZero(zaxis.x) && EqualsZero(zaxis.y))
165     {
166       nodeUpdateArea = Vector4(0.0f, 0.0f, nodeSize.width, nodeSize.height);
167       return false;
168     }
169     // Keep nodeUpdateArea as Vector4::ZERO, and return true.
170     return true;
171   }
172   else
173   {
174     nodeUpdateArea = node->GetUpdateAreaHint();
175     return true;
176   }
177 }
178
179 /**
180  * Add a renderer to the list
181  * @param updateBufferIndex to read the model matrix from
182  * @param renderList to add the item to
183  * @param renderable Node-Renderer pair
184  * @param viewMatrix used to calculate modelview matrix for the item
185  * @param camera The camera used to render
186  * @param isLayer3d Whether we are processing a 3D layer or not
187  * @param viewportSet Whether the viewport is set or not
188  * @param viewport The viewport
189  * @param cull Whether frustum culling is enabled or not
190  */
191 inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
192                                     RenderList&               renderList,
193                                     Renderable&               renderable,
194                                     const Matrix&             viewMatrix,
195                                     const SceneGraph::Camera& camera,
196                                     bool                      isLayer3d,
197                                     bool                      viewportSet,
198                                     const Viewport&           viewport,
199                                     bool                      cull)
200 {
201   bool    inside(true);
202   Node*   node = renderable.mNode;
203   Matrix  nodeWorldMatrix(false);
204   Vector3 nodeSize;
205   Vector4 nodeUpdateArea;
206   bool    nodeUpdateAreaSet(false);
207   Matrix  nodeModelViewMatrix(false);
208   bool    nodeModelViewMatrixSet(false);
209
210   // Don't cull items which have render callback
211   bool hasRenderCallback = (renderable.mRenderer && renderable.mRenderer->GetRenderCallback());
212
213   if(cull && renderable.mRenderer && !hasRenderCallback && !renderable.mRenderer->GetShader().HintEnabled(Dali::Shader::Hint::MODIFIES_GEOMETRY) && node->GetClippingMode() == ClippingMode::DISABLED)
214   {
215     const Vector4& boundingSphere = node->GetBoundingSphere();
216     inside                        = (boundingSphere.w > Math::MACHINE_EPSILON_1000) &&
217              (camera.CheckSphereInFrustum(updateBufferIndex, Vector3(boundingSphere), boundingSphere.w));
218
219     if(inside && !isLayer3d && viewportSet)
220     {
221       SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
222       nodeUpdateAreaSet = true;
223
224       const Vector3& scale = nodeWorldMatrix.GetScale();
225       const Vector3& size  = Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f) * scale;
226
227       if(size.LengthSquared() > Math::MACHINE_EPSILON_1000)
228       {
229         MatrixUtils::MultiplyTransformMatrix(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
230         nodeModelViewMatrixSet = true;
231
232         // Assume actors are at z=0, compute AABB in view space & test rect intersection
233         // against z=0 plane boundaries for frustum. (NOT viewport). This should take into account
234         // magnification due to FOV etc.
235
236         // TODO : Below logic might need to refactor it.
237         // If camera is Perspective, we need to calculate clipping box by FoV. Currently, we just believe default camera setup OrthographicSize well.
238         //  - If then, It must use math calculate like tan(fov) internally. So, we might need calculate it only one times, and cache.
239         ClippingBox boundingBox = RenderItem::CalculateTransformSpaceAABB(nodeModelViewMatrix, Vector3(nodeUpdateArea.x, nodeUpdateArea.y, 0.0f), Vector3(nodeUpdateArea.z, nodeUpdateArea.w, 0.0f));
240         ClippingBox clippingBox = camera.GetOrthographicClippingBox(updateBufferIndex);
241         inside                  = clippingBox.Intersects(boundingBox);
242       }
243     }
244     /*
245      * Note, the API Camera::CheckAABBInFrustum() can be used to test if a bounding box is (partially/fully) inside the view frustum.
246      */
247   }
248
249   if(inside)
250   {
251     bool skipRender(false);
252     bool isOpaque = true;
253     if(!hasRenderCallback)
254     {
255       Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType(updateBufferIndex, *node) : Renderer::OPAQUE;
256
257       // We can skip render when node is not clipping and transparent
258       skipRender = (opacityType == Renderer::TRANSPARENT && node->GetClippingMode() == ClippingMode::DISABLED);
259
260       isOpaque = (opacityType == Renderer::OPAQUE);
261     }
262
263     if(!skipRender)
264     {
265       // Get the next free RenderItem.
266       RenderItem& item = renderList.GetNextFreeItem();
267
268       item.mNode       = node;
269       item.mIsOpaque   = isOpaque;
270       item.mDepthIndex = isLayer3d ? 0 : node->GetDepthIndex();
271
272       if(DALI_LIKELY(renderable.mRenderer))
273       {
274         item.mRenderer   = renderable.mRenderer->GetRenderer();
275         item.mTextureSet = renderable.mRenderer->GetTextureSet();
276         item.mDepthIndex += renderable.mRenderer->GetDepthIndex();
277       }
278       else
279       {
280         item.mRenderer = Render::RendererKey{};
281       }
282
283       item.mIsUpdated |= isLayer3d;
284
285       if(!nodeUpdateAreaSet)
286       {
287         SetNodeUpdateArea(node, isLayer3d, nodeWorldMatrix, nodeSize, nodeUpdateArea);
288       }
289
290       item.mSize        = nodeSize;
291       item.mUpdateArea  = nodeUpdateArea;
292       item.mModelMatrix = nodeWorldMatrix;
293
294       if(!nodeModelViewMatrixSet)
295       {
296         MatrixUtils::MultiplyTransformMatrix(nodeModelViewMatrix, nodeWorldMatrix, viewMatrix);
297       }
298       item.mModelViewMatrix = nodeModelViewMatrix;
299
300       PartialRenderingData partialRenderingData;
301       partialRenderingData.color               = node->GetWorldColor(updateBufferIndex);
302       partialRenderingData.matrix              = item.mModelViewMatrix;
303       partialRenderingData.updatedPositionSize = item.mUpdateArea;
304       partialRenderingData.size                = item.mSize;
305
306       auto& nodePartialRenderingData = node->GetPartialRenderingData();
307       item.mIsUpdated                = nodePartialRenderingData.IsUpdated(partialRenderingData) || item.mIsUpdated;
308
309       nodePartialRenderingData.Update(partialRenderingData);
310     }
311     else
312     {
313       // Mark as not rendered
314       auto& nodePartialRenderingData     = node->GetPartialRenderingData();
315       nodePartialRenderingData.mRendered = false;
316     }
317
318     node->SetCulled(updateBufferIndex, false);
319   }
320   else
321   {
322     // Mark as not rendered
323     auto& nodePartialRenderingData     = node->GetPartialRenderingData();
324     nodePartialRenderingData.mRendered = false;
325
326     node->SetCulled(updateBufferIndex, true);
327   }
328 }
329
330 /**
331  * Add all renderers to the list
332  * @param updateBufferIndex to read the model matrix from
333  * @param renderList to add the items to
334  * @param renderers to render
335  * NodeRendererContainer Node-Renderer pairs
336  * @param viewMatrix used to calculate modelview matrix for the items
337  * @param camera The camera used to render
338  * @param isLayer3d Whether we are processing a 3D layer or not
339  * @param cull Whether frustum culling is enabled or not
340  */
341 inline void AddRenderersToRenderList(BufferIndex               updateBufferIndex,
342                                      RenderList&               renderList,
343                                      RenderableContainer&      renderers,
344                                      const Matrix&             viewMatrix,
345                                      const SceneGraph::Camera& camera,
346                                      bool                      isLayer3d,
347                                      bool                      viewportSet,
348                                      const Viewport&           viewport,
349                                      bool                      cull)
350 {
351   DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
352
353   for(auto&& renderer : renderers)
354   {
355     AddRendererToRenderList(updateBufferIndex,
356                             renderList,
357                             renderer,
358                             viewMatrix,
359                             camera,
360                             isLayer3d,
361                             viewportSet,
362                             viewport,
363                             cull);
364   }
365 }
366
367 /**
368  * Try to reuse cached RenderItems from the RenderList
369  * This avoids recalculating the model view matrices in case this part of the scene was static
370  * An example case is a toolbar layer that rarely changes or a popup on top of the rest of the stage
371  * @param layer that is being processed
372  * @param renderList that is cached from frame N-1
373  * @param renderables list of renderables
374  */
375 inline bool TryReuseCachedRenderers(Layer&               layer,
376                                     RenderList&          renderList,
377                                     RenderableContainer& renderables)
378 {
379   bool     retValue        = false;
380   uint32_t renderableCount = static_cast<uint32_t>(renderables.Size());
381   // Check that the cached list originates from this layer and that the counts match
382   if((renderList.GetSourceLayer() == &layer) &&
383      (renderList.GetCachedItemCount() == renderableCount))
384   {
385     // Check that all the same renderers are there. This gives us additional security in avoiding rendering the wrong things.
386     // Render list is sorted so at this stage renderers may be in different order.
387     // Therefore we check a combined sum of all renderer addresses.
388     size_t checkSumNew = 0;
389     size_t checkSumOld = 0;
390     //@todo just use keys, don't deref.
391     for(uint32_t index = 0; index < renderableCount; ++index)
392     {
393       if(DALI_LIKELY(renderables[index].mRenderer))
394       {
395         Render::RendererKey renderer = renderables[index].mRenderer->GetRenderer();
396         checkSumNew += renderer.Value();
397       }
398       if(DALI_LIKELY(renderList.GetItem(index).mRenderer))
399       {
400         checkSumOld += renderList.GetItem(index).mRenderer.Value();
401       }
402     }
403     if(checkSumNew == checkSumOld)
404     {
405       // tell list to reuse its existing items
406       renderList.ReuseCachedItems();
407       retValue = true;
408     }
409   }
410
411   return retValue;
412 }
413
414 inline bool SetupRenderList(RenderableContainer& renderables,
415                             Layer&               layer,
416                             RenderInstruction&   instruction,
417                             bool                 tryReuseRenderList,
418                             RenderList**         renderList)
419 {
420   *renderList = &(instruction.GetNextFreeRenderList(renderables.Size()));
421   (*renderList)->SetClipping(layer.IsClipping(), layer.GetClippingBox());
422   (*renderList)->SetSourceLayer(&layer);
423
424   // Try to reuse cached RenderItems from last time around.
425   return (tryReuseRenderList && TryReuseCachedRenderers(layer, **renderList, renderables));
426 }
427
428 } // Anonymous namespace.
429
430 RenderInstructionProcessor::RenderInstructionProcessor()
431 : mSortingHelper()
432 {
433   // Set up a container of comparators for fast run-time selection.
434   mSortComparitors.Reserve(3u);
435
436   mSortComparitors.PushBack(CompareItems);
437   mSortComparitors.PushBack(CompareItems3D);
438   mSortComparitors.PushBack(CompareItems3DWithClipping);
439 }
440
441 RenderInstructionProcessor::~RenderInstructionProcessor() = default;
442
443 inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex, RenderList& renderList, Layer& layer, bool respectClippingOrder, bool isOrthographicCamera)
444 {
445   const uint32_t renderableCount = static_cast<uint32_t>(renderList.Count());
446   // Reserve space if needed.
447   const uint32_t oldcapacity = static_cast<uint32_t>(mSortingHelper.size());
448   if(oldcapacity < renderableCount)
449   {
450     mSortingHelper.reserve(renderableCount);
451     // Add real objects (reserve does not construct objects).
452     mSortingHelper.insert(mSortingHelper.begin() + oldcapacity,
453                           (renderableCount - oldcapacity),
454                           RenderInstructionProcessor::SortAttributes());
455   }
456   else
457   {
458     // Clear extra elements from helper, does not decrease capability.
459     mSortingHelper.resize(renderableCount);
460   }
461
462   // Calculate the sorting value, once per item by calling the layers sort function.
463   // Using an if and two for-loops rather than if inside for as its better for branch prediction.
464
465   // List of zValue calculating functions.
466   const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = {
467     [](const Vector3& position) { return position.z; },
468     [](const Vector3& position) { return position.LengthSquared(); },
469     layer.GetSortFunction(),
470   };
471
472   // Determine whether we need to use zValue as Euclidean distance or translatoin's z value.
473   // If layer is LAYER_UI or camera is OrthographicProjection mode, we don't need to calculate
474   // renderItem's distance from camera.
475
476   // Here we determine which zValue SortFunctionType (of the 3) to use.
477   //   0 is position z value : Default LAYER_UI or Orthographic camera
478   //   1 is distance square value : Default LAYER_3D and Perspective camera
479   //   2 is user defined function.
480   const int zValueFunctionIndex = layer.UsesDefaultSortFunction() ? ((layer.GetBehavior() == Dali::Layer::LAYER_UI || isOrthographicCamera) ? 0 : 1) : 2;
481
482   for(uint32_t index = 0; index < renderableCount; ++index)
483   {
484     RenderItemKey itemKey = renderList.GetItemKey(index);
485     RenderItem&   item    = *itemKey.Get();
486     if(DALI_LIKELY(item.mRenderer))
487     {
488       item.mRenderer->SetSortAttributes(mSortingHelper[index]);
489     }
490
491     // texture set
492     mSortingHelper[index].textureSet = item.mTextureSet;
493
494     mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
495
496     // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
497     mSortingHelper[index].renderItem = itemKey;
498   }
499
500   // Here we determine which comparitor (of the 3) to use.
501   //   0 is LAYER_UI
502   //   1 is LAYER_3D
503   //   2 is LAYER_3D + Clipping
504   const unsigned int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
505
506   std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
507
508   // Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper.
509   DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "Sorted Transparent List:\n");
510   RenderItemContainer::Iterator renderListIter = renderList.GetContainer().Begin();
511   for(uint32_t index = 0; index < renderableCount; ++index, ++renderListIter)
512   {
513     *renderListIter = mSortingHelper[index].renderItem;
514     DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "  sortedList[%d] = node : %x renderer : %x\n", index, mSortingHelper[index].renderItem->mNode, mSortingHelper[index].renderItem->mRenderer.Get());
515   }
516 }
517
518 void RenderInstructionProcessor::Prepare(BufferIndex                 updateBufferIndex,
519                                          SortedLayerPointers&        sortedLayers,
520                                          RenderTask&                 renderTask,
521                                          bool                        cull,
522                                          bool                        hasClippingNodes,
523                                          RenderInstructionContainer& instructions)
524 {
525   // Retrieve the RenderInstruction buffer from the RenderInstructionContainer
526   // then populate with instructions.
527   RenderInstruction& instruction             = renderTask.PrepareRenderInstruction(updateBufferIndex);
528   bool               viewMatrixHasNotChanged = !renderTask.ViewMatrixUpdated();
529   bool               isRenderListAdded       = false;
530   bool               isRootLayerDirty        = false;
531
532   const Matrix&             viewMatrix           = renderTask.GetViewMatrix(updateBufferIndex);
533   const SceneGraph::Camera& camera               = renderTask.GetCamera();
534   const bool                isOrthographicCamera = camera.mProjectionMode == Dali::Camera::ProjectionMode::ORTHOGRAPHIC_PROJECTION;
535
536   Viewport viewport;
537   bool     viewportSet = renderTask.QueryViewport(updateBufferIndex, viewport);
538
539   const SortedLayersIter endIter = sortedLayers.end();
540   for(SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter)
541   {
542     Layer&      layer = **iter;
543     const bool  tryReuseRenderList(viewMatrixHasNotChanged && layer.CanReuseRenderers(&camera));
544     const bool  isLayer3D  = layer.GetBehavior() == Dali::Layer::LAYER_3D;
545     RenderList* renderList = nullptr;
546
547     if(layer.IsRoot() && (layer.GetDirtyFlags() != NodePropertyFlags::NOTHING))
548     {
549       // If root-layer & dirty, i.e. a property has changed or a child has been deleted, then we need to ensure we render once more
550       isRootLayerDirty = true;
551     }
552
553     if(!layer.colorRenderables.Empty())
554     {
555       RenderableContainer& renderables = layer.colorRenderables;
556
557       if(!SetupRenderList(renderables, layer, instruction, tryReuseRenderList, &renderList))
558       {
559         renderList->SetHasColorRenderItems(true);
560         AddRenderersToRenderList(updateBufferIndex,
561                                  *renderList,
562                                  renderables,
563                                  viewMatrix,
564                                  camera,
565                                  isLayer3D,
566                                  viewportSet,
567                                  viewport,
568                                  cull);
569
570         // We only use the clipping version of the sort comparitor if any clipping nodes exist within the RenderList.
571         SortRenderItems(updateBufferIndex, *renderList, layer, hasClippingNodes, isOrthographicCamera);
572       }
573       else
574       {
575         renderList->SetHasColorRenderItems(true);
576       }
577
578       isRenderListAdded = true;
579     }
580
581     if(!layer.overlayRenderables.Empty())
582     {
583       RenderableContainer& renderables = layer.overlayRenderables;
584
585       if(!SetupRenderList(renderables, layer, instruction, tryReuseRenderList, &renderList))
586       {
587         renderList->SetHasColorRenderItems(false);
588         AddRenderersToRenderList(updateBufferIndex,
589                                  *renderList,
590                                  renderables,
591                                  viewMatrix,
592                                  camera,
593                                  isLayer3D,
594                                  viewportSet,
595                                  viewport,
596                                  cull);
597
598         // Clipping hierarchy is irrelevant when sorting overlay items, so we specify using the non-clipping version of the sort comparitor.
599         SortRenderItems(updateBufferIndex, *renderList, layer, false, isOrthographicCamera);
600       }
601       else
602       {
603         renderList->SetHasColorRenderItems(false);
604       }
605
606       isRenderListAdded = true;
607     }
608   }
609
610   // Inform the render instruction that all renderers have been added and this frame is complete.
611   instruction.UpdateCompleted();
612
613   if(isRenderListAdded || instruction.mIsClearColorSet || isRootLayerDirty)
614   {
615     instructions.PushBack(updateBufferIndex, &instruction);
616   }
617 }
618
619 } // namespace SceneGraph
620
621 } // namespace Internal
622
623 } // namespace Dali