Merge "RenderItem clean-up" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-algorithms.cpp
index 95785de..879dba8 100644 (file)
@@ -23,7 +23,7 @@
 #include <dali/internal/render/common/render-list.h>
 #include <dali/internal/render/common/render-instruction.h>
 #include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
 
 using Dali::Internal::SceneGraph::RenderItem;
 using Dali::Internal::SceneGraph::RenderList;
@@ -70,20 +70,24 @@ inline void SetRenderFlags( const RenderList& renderList, Context& context )
 {
   const unsigned int renderFlags = renderList.GetFlags();
 
-  bool enableDepthBuffer = ( ( renderFlags & RenderList::DEPTH_BUFFER_ENABLED ) != 0u );
-  bool depthMask         = ( ( renderFlags & RenderList::DEPTH_WRITE ) != 0u );
+  if( ( renderFlags & RenderList::DEPTH_BUFFER_ENABLED ) != 0u )
+  {
+    //Enable depth testing
+    context.EnableDepthBuffer( true );
+  }
+  else
+  {
+    //Disable depth test and depth write
+    context.EnableDepthBuffer( false );
+    context.DepthMask( false );
+  }
 
   GLbitfield clearMask   = ( renderFlags & RenderList::DEPTH_CLEAR ) ? GL_DEPTH_BUFFER_BIT : 0u;
 
-  context.EnableDepthBuffer( enableDepthBuffer );
-  context.DepthMask( depthMask );
-
   // Stencil enabled, writing, and clearing...
   const bool enableStencilBuffer( renderFlags & RenderList::STENCIL_BUFFER_ENABLED );
   const bool enableStencilWrite( renderFlags & RenderList::STENCIL_WRITE );
-
   context.EnableStencilBuffer( enableStencilBuffer );
-
   if( enableStencilBuffer )
   {
     context.StencilFunc( (enableStencilWrite ? GL_ALWAYS : GL_EQUAL), 1, 0xFF );
@@ -111,10 +115,8 @@ inline void SetRenderFlags( const RenderList& renderList, Context& context )
  * @param[in] context The GL context.
  * @param[in] defaultShader The default shader to use.
  * @param[in] buffer The current render buffer index (previous update buffer)
- * @param[in] frameTime The elapsed time between the last two updates.
  * @param[in] viewMatrix The view matrix from the appropriate camera.
  * @param[in] projectionMatrix The projection matrix from the appropriate camera.
- * @param[in] cullMode True if the renderers should be subjected to clipspace culling
  */
 inline void ProcessRenderList(
   const RenderList& renderList,
@@ -122,169 +124,65 @@ inline void ProcessRenderList(
   SceneGraph::TextureCache& textureCache,
   SceneGraph::Shader& defaultShader,
   BufferIndex bufferIndex,
-  float frameTime,
   const Matrix& viewMatrix,
-  const Matrix& projectionMatrix,
-  bool cullMode )
+  const Matrix& projectionMatrix )
 {
   DALI_PRINT_RENDER_LIST( renderList );
 
   SetScissorTest( renderList, context );
   SetRenderFlags( renderList, context );
 
-  size_t count = renderList.Count();
-  for ( size_t index = 0; index < count; ++index )
+  if( renderList.HasColorRenderItems() )
   {
-    const RenderItem& item = renderList.GetItem( index );
+    bool depthBufferEnabled = ( ( renderList.GetFlags() & RenderList::DEPTH_BUFFER_ENABLED ) != 0u );
+    size_t count = renderList.Count();
 
-    DALI_PRINT_RENDER_ITEM( item );
-
-    SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
-    const Matrix& modelViewMatrix = item.GetModelViewMatrix();
-
-    renderer->Render( context, textureCache, bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
-  }
-}
-
-/**
- * Render items from the currentIndex until the depth index changes.
- * Leaves currentIndex pointing at the
- *
- * @param[in] renderList The render-list to process.
- * @param[in] context The GL context.
- * @param[in] defaultShader The default shader to use.
- * @param[in] buffer The current render buffer index (previous update buffer)
- * @param[in] frameTime The elapsed time between the last two updates.
- * @param[in] viewMatrix The view matrix from the appropriate camera.
- * @param[in] projectionMatrix The projection matrix from the appropriate camera.
- * @param[in] cullMode True if the renderers should be subjected to clipspace culling
- * @param[in] depthIndex The current depth index
- * @param[inout] currentIndex On entry, the index in the render list of the first item at the given depth index. On exit, the index of the first item at the next depth index.
- */
-inline void RenderItemsAtDepthIndex(
-  const RenderList&         renderList,
-  Context&                  context,
-  SceneGraph::TextureCache& textureCache,
-  SceneGraph::Shader&       defaultShader,
-  BufferIndex               bufferIndex,
-  float                     frameTime,
-  const Matrix&             viewMatrix,
-  const Matrix&             projectionMatrix,
-  bool                      cullMode,
-  int                       depthIndex,
-  size_t&                   currentIndex ) // Out parameter
-{
-  const size_t count = renderList.Count();
-
-  // Don't initialise currentIndex. Ever.
-  for( ; currentIndex < count ; currentIndex++ )
-  {
-    const RenderItem& renderItem = renderList.GetItem( currentIndex );
-    DALI_PRINT_RENDER_ITEM( renderItem );
-
-    if( renderItem.GetDepthIndex() == depthIndex )
+    if( depthBufferEnabled )
     {
-      SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( renderItem.GetRenderer() );
-      const Matrix& modelViewMatrix = renderItem.GetModelViewMatrix();
-      renderer->Render( context, textureCache, bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
+      for ( size_t index = 0; index < count; ++index )
+      {
+        const RenderItem& item = renderList.GetItem( index );
+        DALI_PRINT_RENDER_ITEM( item );
 
+        DepthWriteMode::Type depthWriteMode = item.mRenderer->GetDepthWriteMode();
+        context.DepthMask( ( depthWriteMode == DepthWriteMode::AUTO && item.mIsOpaque ) ||
+                           ( depthWriteMode == DepthWriteMode::ON ) );
+
+        item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
+                                item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
+      }
     }
     else
     {
-      break; // Stop iterating when we reach a new depth index
+      for ( size_t index = 0; index < count; ++index )
+      {
+        const RenderItem& item = renderList.GetItem( index );
+        DALI_PRINT_RENDER_ITEM( item );
+        item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
+                                item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
+      }
     }
   }
-}
-
-
-/**
- * Process two interleaved render-lists.
- *
- * For each depth index, it will set the flags for the first list,
- * render items in the first list, set flags for the second list and
- * render items from the second list.
- *
- * @param[in] renderList1 The first render-list to process.
- * @param[in] renderList2 The second render-list to process.
- * @param[in] context The GL context.
- * @param[in] defaultShader The default shader to use.
- * @param[in] buffer The current render buffer index (previous update buffer)
- * @param[in] frameTime The elapsed time between the last two updates.
- * @param[in] viewMatrix The view matrix from the appropriate camera.
- * @param[in] projectionMatrix The projection matrix from the appropriate camera.
- * @param[in] cullMode True if the renderers should be subjected to clipspace culling
- */
-
-inline void ProcessInterleavedRenderLists(
-  const RenderList&         renderList1,
-  const RenderList&         renderList2,
-  Context&                  context,
-  SceneGraph::TextureCache& textureCache,
-  SceneGraph::Shader&       defaultShader,
-  BufferIndex               bufferIndex,
-  float                     frameTime,
-  const Matrix&             viewMatrix,
-  const Matrix&             projectionMatrix,
-  bool                      cullMode )
-{
-
-  SetScissorTest( renderList1, context ); // Scissor settings are identical for both lists
-  size_t count1 = renderList1.Count();
-  size_t count2 = renderList2.Count();
-  size_t index1 = 0;
-  size_t index2 = 0;
-
-  int depthIndex=renderList1.GetItem( 0 ).GetDepthIndex();
-
-  while( index1 < count1 || index2 < count2 )
+  else
   {
-    if( index1 < count1 && index2 < count2 )
-    {
-      // Take the lowest depth index in both lists
-      depthIndex = std::min( renderList1.GetItem( index1 ).GetDepthIndex(),
-                             renderList2.GetItem( index2 ).GetDepthIndex() );
-    }
-    else if( index1 < count1 )
+    size_t count = renderList.Count();
+    for ( size_t index = 0; index < count; ++index )
     {
-      // Items left only in list 1
-      depthIndex = renderList1.GetItem( index1 ).GetDepthIndex();
-    }
-    else // index2 < count2
-    {
-      // Items left only in list 2
-      depthIndex = renderList2.GetItem( index2 ).GetDepthIndex();
-    }
+      const RenderItem& item = renderList.GetItem( index );
+      DALI_PRINT_RENDER_ITEM( item );
 
-    // Between each successive depth index, reset the flags.
-    SetRenderFlags( renderList1, context );
-
-    // Find and render items in the first list that correspond to the current depth index
-    if( index1 < count1 )
-    {
-      RenderItemsAtDepthIndex( renderList1, context, textureCache, defaultShader,
-                               bufferIndex, frameTime, viewMatrix, projectionMatrix,
-                               cullMode, depthIndex,
-                               index1 ); // Out parameter
+      item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader,
+                              item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque );
     }
 
-    SetRenderFlags( renderList2, context );
-    if( index2 < count2 )
-    {
-      RenderItemsAtDepthIndex( renderList2, context, textureCache, defaultShader,
-                               bufferIndex, frameTime, viewMatrix, projectionMatrix,
-                               cullMode, depthIndex,
-                               index2 ); // Out parameter
-    }
   }
 }
 
-
 void ProcessRenderInstruction( const RenderInstruction& instruction,
                                Context& context,
                                SceneGraph::TextureCache& textureCache,
                                SceneGraph::Shader& defaultShader,
-                               BufferIndex bufferIndex,
-                               float frameTime )
+                               BufferIndex bufferIndex )
 {
   DALI_PRINT_RENDER_INSTRUCTION( instruction, bufferIndex );
 
@@ -308,26 +206,7 @@ void ProcessRenderInstruction( const RenderInstruction& instruction,
       if(  renderList &&
           !renderList->IsEmpty() )
       {
-        if( renderList->GetInterleave() &&
-            index < count-1 &&
-            instruction.GetRenderList(index+1)->GetInterleave() )
-        {
-          ProcessInterleavedRenderLists( *renderList,
-                                         *(instruction.GetRenderList(index+1)),
-                                         context,
-                                         textureCache,
-                                         defaultShader,
-                                         bufferIndex,
-                                         frameTime,
-                                         *viewMatrix,
-                                         *projectionMatrix,
-                                         instruction.mCullMode );
-          index++; // Skip over next render list
-        }
-        else
-        {
-          ProcessRenderList( *renderList, context, textureCache, defaultShader, bufferIndex, frameTime, *viewMatrix, *projectionMatrix, instruction.mCullMode );
-        }
+        ProcessRenderList( *renderList, context, textureCache, defaultShader, bufferIndex, *viewMatrix, *projectionMatrix );
       }
     }
   }