[dali_1.9.32] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-algorithms.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 94658ea..f5d540c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -194,9 +194,6 @@ inline void SetupDepthBuffer( const RenderItem& item, Context& context, bool dep
     // The depth buffer must be enabled if either reading or writing.
     context.EnableDepthBuffer( true );
 
-    // Set up the depth mask based on our depth write setting.
-    context.DepthMask( enableDepthWrite );
-
     // Look-up the GL depth function from the Dali::DepthFunction enum, and set it.
     context.DepthFunc( DaliDepthToGLDepthTable[ item.mRenderer->GetDepthFunction() ] );
 
@@ -210,8 +207,12 @@ inline void SetupDepthBuffer( const RenderItem& item, Context& context, bool dep
       firstDepthBufferUse = false;
 
       // Note: The buffer will only be cleared if written to since a previous clear.
+      context.DepthMask( true );
       context.Clear( GL_DEPTH_BUFFER_BIT, Context::CHECK_CACHED_VALUES );
     }
+
+    // Set up the depth mask based on our depth write setting.
+    context.DepthMask( enableDepthWrite );
   }
   else
   {
@@ -244,9 +245,9 @@ inline void RenderAlgorithms::SetupScissorClipping( const RenderItem& item, Cont
   // So we know if we are at depth 4 and the stackDepth is 5, that we have gone up.
   // If the depth is the same then we are effectively part of a different sub-tree from the parent, we must also remove the current clip.
   // Note: Stack depth must always be at least 1, as we will have the layer or stage size as the root value.
-  if( ( childStackDepth > 0u ) && ( scissorDepth <= childStackDepth ) )
+  if( ( childStackDepth > 0u ) && ( scissorDepth < childStackDepth ) )
   {
-    while( scissorDepth <= childStackDepth )  // Pop until sibling
+    while( scissorDepth < childStackDepth )
     {
       mScissorStack.pop_back();
       --childStackDepth;
@@ -255,7 +256,7 @@ inline void RenderAlgorithms::SetupScissorClipping( const RenderItem& item, Cont
     // We traversed up the tree, we need to apply a new scissor rectangle (unless we are at the root).
     traversedUpTree = true;
   }
-  else if( clippingNode && childStackDepth > 0u && childStackDepth == scissorDepth ) // case of sibling clip area
+  if( clippingNode && childStackDepth > 0u && childStackDepth == scissorDepth ) // case of sibling clip area
   {
     mScissorStack.pop_back();
     --childStackDepth;
@@ -270,7 +271,7 @@ inline void RenderAlgorithms::SetupScissorClipping( const RenderItem& item, Cont
       // This is a clipping node. We generate the AABB for this node and intersect it with the previous intersection further up the tree.
 
       // Get the AABB bounding box for the current render item.
-      const ClippingBox scissorBox( item.CalculateViewportSpaceAABB( mViewportRectangle.width, mViewportRectangle.height ) );
+      const ClippingBox scissorBox( item.CalculateViewportSpaceAABB( item.mSize, mViewportRectangle.width, mViewportRectangle.height ) );
 
       // Get the AABB for the parent item that we must intersect with.
       const ClippingBox& parentBox( mScissorStack.back() );
@@ -388,7 +389,11 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
                                                  const Matrix& viewMatrix,
                                                  const Matrix& projectionMatrix,
                                                  Integration::DepthBufferAvailable depthBufferAvailable,
-                                                 Integration::StencilBufferAvailable stencilBufferAvailable )
+                                                 Integration::StencilBufferAvailable stencilBufferAvailable,
+                                                 Vector<GLuint>& boundTextures,
+                                                 const RenderInstruction& instruction,
+                                                 const Rect<int>& rootClippingRect
+                                                 )
 {
   DALI_PRINT_RENDER_LIST( renderList );
 
@@ -407,6 +412,22 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
 
   // Setup Scissor testing (for both viewport and per-node scissor)
   mScissorStack.clear();
+
+  // Add root clipping rect (set manually for Render function ny partial update for example)
+  // on the bottom of the stack
+  if (!rootClippingRect.IsEmpty())
+  {
+    context.SetScissorTest( true );
+    context.Scissor( rootClippingRect.x, rootClippingRect.y, rootClippingRect.width, rootClippingRect.height );
+    mScissorStack.push_back( rootClippingRect );
+  }
+  // We are not performing a layer clip and no clipping rect set. Add the viewport as the root scissor rectangle.
+  else if (!renderList.IsClipping())
+  {
+    context.SetScissorTest( false );
+    mScissorStack.push_back( mViewportRectangle );
+  }
+
   if( renderList.IsClipping() )
   {
     context.SetScissorTest( true );
@@ -415,17 +436,12 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
     mScissorStack.push_back( layerScissorBox );
     mHasLayerScissor = true;
   }
-  else
-  {
-    // We are not performing a layer clip. Add the viewport as the root scissor rectangle.
-    context.SetScissorTest( false );
-    mScissorStack.push_back( mViewportRectangle );
-  }
 
   // Loop through all RenderList in the RenderList, set up any prerequisites to render them, then perform the render.
-  for( size_t index( 0u ); index < count; ++index )
+  for( uint32_t index = 0u; index < count; ++index )
   {
     const RenderItem& item = renderList.GetItem( index );
+
     DALI_PRINT_RENDER_ITEM( item );
 
     // Set up clipping based on both the Renderer and Actor APIs.
@@ -444,9 +460,18 @@ inline void RenderAlgorithms::ProcessRenderList( const RenderList& renderList,
         SetupDepthBuffer( item, context, autoDepthTestMode, firstDepthBufferUse );
       }
 
-      // Render the item.
-      item.mRenderer->Render( context, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix,
-                              viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
+      // Depending on whether the renderer has draw commands attached or not the rendering process will
+      // iterate through all the render queues. If there are no draw commands attached, only one
+      // iteration must be done and the default behaviour of the renderer will be executed.
+      // The queues allow to iterate over the same renderer multiple times changing the state of the renderer.
+      // It is similar to the multi-pass rendering.
+      auto const MAX_QUEUE = item.mRenderer->GetDrawCommands().empty() ? 1 : DevelRenderer::RENDER_QUEUE_MAX;
+      for( auto queue = 0u; queue < MAX_QUEUE; ++queue )
+      {
+        // Render the item.
+        item.mRenderer->Render(context, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix,
+                               viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque, boundTextures, instruction, queue);
+      }
     }
   }
 }
@@ -461,7 +486,9 @@ void RenderAlgorithms::ProcessRenderInstruction( const RenderInstruction& instru
                                                  Context& context,
                                                  BufferIndex bufferIndex,
                                                  Integration::DepthBufferAvailable depthBufferAvailable,
-                                                 Integration::StencilBufferAvailable stencilBufferAvailable )
+                                                 Integration::StencilBufferAvailable stencilBufferAvailable,
+                                                 Vector<GLuint>& boundTextures,
+                                                 const Rect<int>& rootClippingRect )
 {
   DALI_PRINT_RENDER_INSTRUCTION( instruction, bufferIndex );
 
@@ -489,7 +516,10 @@ void RenderAlgorithms::ProcessRenderInstruction( const RenderInstruction& instru
                            *viewMatrix,
                            *projectionMatrix,
                             depthBufferAvailable,
-                            stencilBufferAvailable );
+                            stencilBufferAvailable,
+                            boundTextures,
+                            instruction, //added for reflection effect
+                            rootClippingRect );
       }
     }
   }