Changed SceneGraph::CompareItems and CompareItems3D to compare the render items based... 14/48914/2
authorChu Hoang <c.hoang@samsung.com>
Thu, 1 Oct 2015 11:35:24 +0000 (12:35 +0100)
committerChu Hoang <c.hoang@samsung.com>
Thu, 1 Oct 2015 13:22:39 +0000 (14:22 +0100)
This is to reduce the number of glBindTexture calls.

Change-Id: Iad24b18c5a42a53a85cdcf9522c5de71e3bf44a2

dali/integration-api/resource-declarations.h
dali/internal/render/renderers/render-new-renderer.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/update/manager/prepare-render-instructions.cpp
dali/internal/update/manager/prepare-render-instructions.h
dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp

index 69dface..16118aa 100644 (file)
@@ -49,6 +49,7 @@ namespace Integration
  * Dali::Internal::ImageFactoryCache::RequestId
  */
 typedef unsigned int ResourceId;
+const ResourceId InvalidResourceId = (ResourceId)-1;
 
 /**
  * Used to inform the current loading status
index 82b68b9..995f515 100644 (file)
@@ -79,10 +79,12 @@ public:
    * @param[in] bufferIndex The buffer index
    * @param[out] sortAttributes
    */
-  void SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const
+  void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
   {
-    sortAttributes.shader = &(mRenderDataProvider->GetShader());
-    sortAttributes.material = &(mRenderDataProvider->GetMaterial());
+    sortAttributes.shader = &( mRenderDataProvider->GetShader() );
+    const SceneGraph::RenderDataProvider::Samplers& samplers = mRenderDataProvider->GetSamplers();
+
+    sortAttributes.textureResourceId = samplers.Empty() ? Integration::InvalidResourceId : samplers[ 0 ]->GetTextureId( bufferIndex );
     sortAttributes.geometry = mRenderGeometry;
   }
 
index 3e9e1d8..90650ef 100644 (file)
@@ -228,10 +228,10 @@ void Renderer::Render( Context& context,
   DoRender( context, textureCache, node, bufferIndex, *program, modelViewMatrix, viewMatrix );
 }
 
-void Renderer::SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const
+void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
 {
   sortAttributes.shader = mShader;
-  sortAttributes.material = NULL;
+  sortAttributes.textureResourceId = Integration::InvalidResourceId;
   sortAttributes.geometry = NULL;
 }
 
index 27c9cfb..642f597 100644 (file)
@@ -127,7 +127,7 @@ public:
    * @param[in] bufferIndex The current update buffer index.
    * @param[out] sortAttributes
    */
-  virtual void SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
+  virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
 
 protected:
   /**
index e4a42db..4089973 100644 (file)
@@ -251,11 +251,11 @@ bool CompareItems( const RendererWithSortAttributes& lhs, const RendererWithSort
   {
     if( lhs.shader == rhs.shader )
     {
-      if( lhs.material == rhs.material )
+      if( lhs.textureResourceId == rhs.textureResourceId )
       {
         return lhs.geometry < rhs.geometry;
       }
-      return lhs.material < rhs.material;
+      return lhs.textureResourceId < rhs.textureResourceId;
     }
     return lhs.shader < rhs.shader;;
   }
@@ -278,11 +278,11 @@ bool CompareItems3D( const RendererWithSortAttributes& lhs, const RendererWithSo
       //If both RenderItems are opaque, sort using shader, then material then geometry
       if( lhs.shader == rhs.shader )
       {
-        if( lhs.material == rhs.material )
+        if( lhs.textureResourceId == rhs.textureResourceId )
         {
           return lhs.geometry < rhs.geometry;
         }
-        return lhs.material < rhs.material;
+        return lhs.textureResourceId < rhs.textureResourceId;
       }
       return lhs.shader < rhs.shader;
     }
@@ -293,11 +293,11 @@ bool CompareItems3D( const RendererWithSortAttributes& lhs, const RendererWithSo
       {
         if( lhs.shader == rhs.shader )
         {
-          if( lhs.material == rhs.material )
+          if( lhs.textureResourceId == rhs.textureResourceId )
           {
             return lhs.geometry < rhs.geometry;
           }
-          return lhs.material < rhs.material;
+          return lhs.textureResourceId < rhs.textureResourceId;
         }
         return lhs.shader < rhs.shader;
       }
@@ -343,7 +343,7 @@ inline void SortColorRenderItems( BufferIndex bufferIndex, RenderList& renderLis
     {
       RenderItem& item = renderList.GetItem( index );
 
-      item.GetRenderer().SetSortAttributes(sortingHelper[ index ]);
+      item.GetRenderer().SetSortAttributes( bufferIndex, sortingHelper[ index ] );
 
       // the default sorting function should get inlined here
       sortingHelper[ index ].zValue = Internal::Layer::ZValue( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex();
@@ -359,7 +359,7 @@ inline void SortColorRenderItems( BufferIndex bufferIndex, RenderList& renderLis
     {
       RenderItem& item = renderList.GetItem( index );
 
-      item.GetRenderer().SetSortAttributes(sortingHelper[ index ]);
+      item.GetRenderer().SetSortAttributes( bufferIndex, sortingHelper[ index ] );
       sortingHelper[ index ].zValue = (*sortFunction)( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex();
 
       // keep the renderitem pointer in the helper so we can quickly reorder items after sort
index abbb0fb..cbae425 100644 (file)
@@ -21,6 +21,7 @@
 // INTERNAL INCLUDES
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/update/manager/sorted-layers.h>
+#include <dali/integration-api/resource-declarations.h>
 
 namespace Dali
 {
@@ -45,7 +46,7 @@ struct RendererWithSortAttributes
   RendererWithSortAttributes()
   : renderItem( NULL ),
     shader(NULL),
-    material(NULL),
+    textureResourceId( Integration::InvalidResourceId ),
     geometry(NULL),
     zValue(0.0f)
   {
@@ -53,9 +54,9 @@ struct RendererWithSortAttributes
 
   RenderItem*                   renderItem;       ///< The render item that is being sorted (includes depth index)
   const Shader*                 shader;           ///< The shader instance
-  const MaterialDataProvider*   material;         ///< The material instance
+  Integration::ResourceId       textureResourceId;///< The first texture resource ID of the sampler instance, is InvalidResourceId if the material doesn't have any samplers
   const RenderGeometry*         geometry;         ///< The geometry instance
-  float                         zValue;           // The zValue of the given renderer (either distance from camera, or a custom calculated value)
+  float                         zValue;           ///< The zValue of the given renderer (either distance from camera, or a custom calculated value)
 };
 
 typedef std::vector< RendererWithSortAttributes > RendererSortingHelper;
index ffcacb0..4ee06c7 100644 (file)
@@ -209,7 +209,7 @@ void RenderableAttachment::SetSortModifier(float modifier)
 void RenderableAttachment::SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes )
 {
   sortAttributes.shader = mShader;
-  sortAttributes.material = NULL;
+  sortAttributes.textureResourceId = Integration::InvalidResourceId;
   sortAttributes.geometry = NULL;
 }