Use TextureSet instead when sorting render items. 44/113744/3
authorFrancisco Santos <f1.santos@samsung.com>
Wed, 8 Feb 2017 14:46:34 +0000 (14:46 +0000)
committerFrancisco Santos <f1.santos@samsung.com>
Wed, 8 Feb 2017 17:02:05 +0000 (17:02 +0000)
Change-Id: Id03460a0e99bca4c914a5f28ff397d570034dcba

automated-tests/src/dali/utc-Dali-TextureSet.cpp
dali/internal/render/common/render-item.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/update/manager/render-instruction-processor.cpp
dali/internal/update/manager/render-instruction-processor.h

index 4811fe7..c8d91b9 100644 (file)
 #include <mesh-builder.h>
 
 using namespace Dali;
+
+namespace
+{
+
+enum SetSampler
+{
+  SET_SAMPLER,
+  DONT_SET_SAMPLER
+};
+
+Actor CreateActor( SetSampler setSamplerOption )
+{
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+
+  Shader shader = CreateShader();
+  TextureSet textureSet = CreateTextureSet();
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  textureSet.SetTexture( 0u, texture );
+  if( setSamplerOption == SET_SAMPLER )
+  {
+    textureSet.SetSampler( 0u, sampler );
+  }
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, shader );
+  renderer.SetTextures( textureSet );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  return actor;
+}
+
+} // namespace
+
+
 void texture_set_test_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -108,20 +148,7 @@ int UtcDaliTextureSetTexture01(void)
 {
   TestApplication application;
 
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
-
-  Shader shader = CreateShader();
-  TextureSet textureSet = CreateTextureSet();
-  textureSet.SetTexture( 0u, texture );
-
-  Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, shader );
-  renderer.SetTextures( textureSet );
-
-  Actor actor = Actor::New();
-  actor.AddRenderer(renderer);
-  actor.SetParentOrigin( ParentOrigin::CENTER );
-  actor.SetSize(400, 400);
+  Actor actor = CreateActor( DONT_SET_SAMPLER );
 
   Stage::GetCurrent().Add( actor );
 
@@ -151,26 +178,42 @@ int UtcDaliTextureSetTexture02(void)
 {
   TestApplication application;
 
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+  Actor actor = CreateActor(SET_SAMPLER);
 
-  Shader shader = CreateShader();
-  TextureSet textureSet = CreateTextureSet();
+  Stage::GetCurrent().Add( actor );
 
-  Sampler sampler = Sampler::New();
-  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
-  textureSet.SetTexture( 0u, texture );
-  textureSet.SetSampler( 0u, sampler );
+  TestGlAbstraction& gl = application.GetGlAbstraction();
 
-  Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, shader );
-  renderer.SetTextures( textureSet );
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
 
-  Actor actor = Actor::New();
-  actor.AddRenderer(renderer);
-  actor.SetParentOrigin( ParentOrigin::CENTER );
-  actor.SetSize(400, 400);
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
 
-  Stage::GetCurrent().Add( actor );
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are four calls to TexParameteri when the texture is first created
+  // Texture minification and magnification filters are now different than default so
+  //there should have been two extra TexParameteri calls to set the new filter mode
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetMultiple(void)
+{
+  TestApplication application;
+
+  Actor actor1 = CreateActor(SET_SAMPLER);
+  Actor actor2 = CreateActor(SET_SAMPLER);
+
+  Stage::GetCurrent().Add( actor1 );
+  Stage::GetCurrent().Add( actor2 );
 
   TestGlAbstraction& gl = application.GetGlAbstraction();
 
@@ -187,13 +230,14 @@ int UtcDaliTextureSetTexture02(void)
   texParameterTrace.Enable( false );
 
   // Verify gl state
-  // There are four calls to TexParameteri when the texture is first created
+  // For each actor there are four calls to TexParameteri when the texture is first created
   // Texture minification and magnification filters are now different than default so
   //there should have been two extra TexParameteri calls to set the new filter mode
-  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
 
   END_TEST;
 }
+
 int UtcDaliTextureSetSetSampler(void)
 {
   TestApplication application;
index 425d8a3..156272c 100644 (file)
@@ -67,6 +67,7 @@ struct RenderItem
   Vector3           mSize;
   Render::Renderer* mRenderer;
   Node*             mNode;
+  const void*       mTextureSet;        //< Used only for sorting
 
   mutable Render::Geometry* mBatchRenderGeometry;
 
index 1fff9e1..685c353 100644 (file)
@@ -605,7 +605,8 @@ void Renderer::Render( Context& context,
   }
 }
 
-void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const
+void Renderer::SetSortAttributes( BufferIndex bufferIndex,
+                                  SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const
 {
   sortAttributes.shader = &( mRenderDataProvider->GetShader() );
   sortAttributes.geometry = mGeometry;
index d6a1fa5..b361c92 100644 (file)
@@ -56,8 +56,28 @@ namespace
 {
 
 /**
+ * Function which compares render items by shader/textureSet/geometry
+ * @param[in] lhs Left hand side item
+ * @param[in] rhs Right hand side item
+ * @return True if left item is greater than right
+ */
+bool PartialCompareItems( const RenderInstructionProcessor::SortAttributes& lhs,
+                          const RenderInstructionProcessor::SortAttributes& rhs )
+{
+  if( lhs.shader == rhs.shader )
+  {
+    if( lhs.textureSet == rhs.textureSet )
+    {
+      return lhs.geometry < rhs.geometry;
+    }
+    return lhs.textureSet < rhs.textureSet;
+  }
+  return lhs.shader < rhs.shader;
+}
+
+/**
  * Function which sorts render items by depth index then by instance
- * ptrs of shader/geometry/material.
+ * ptrs of shader/textureSet/geometry.
  * @param[in] lhs Left hand side item
  * @param[in] rhs Right hand side item
  * @return True if left item is greater than right
@@ -68,15 +88,7 @@ bool CompareItems( const RenderInstructionProcessor::SortAttributes& lhs, const
   // encapsulates the same data (e.g. the middle-order bits of the ptrs).
   if( lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex )
   {
-    if( lhs.shader == rhs.shader )
-    {
-      if( lhs.textureResourceId == rhs.textureResourceId )
-      {
-        return lhs.geometry < rhs.geometry;
-      }
-      return lhs.textureResourceId < rhs.textureResourceId;
-    }
-    return lhs.shader < rhs.shader;
+    return PartialCompareItems(lhs, rhs);
   }
   return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex;
 }
@@ -114,30 +126,14 @@ bool CompareItems3D( const RenderInstructionProcessor::SortAttributes& lhs, cons
     if( lhsIsOpaque )
     {
       // If both RenderItems are opaque, sort using shader, then material then geometry.
-      if( lhs.shader == rhs.shader )
-      {
-        if( lhs.textureResourceId == rhs.textureResourceId )
-        {
-          return lhs.geometry < rhs.geometry;
-        }
-        return lhs.textureResourceId < rhs.textureResourceId;
-      }
-      return lhs.shader < rhs.shader;
+      return PartialCompareItems( lhs, rhs );
     }
     else
     {
       // If both RenderItems are transparent, sort using Z, then shader, then material, then geometry.
       if( Equals( lhs.zValue, rhs.zValue ) )
       {
-        if( lhs.shader == rhs.shader )
-        {
-          if( lhs.textureResourceId == rhs.textureResourceId )
-          {
-            return lhs.geometry < rhs.geometry;
-          }
-          return lhs.textureResourceId < rhs.textureResourceId;
-        }
-        return lhs.shader < rhs.shader;
+        return PartialCompareItems( lhs, rhs );
       }
       return lhs.zValue > rhs.zValue;
     }
@@ -219,6 +215,7 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
       RenderItem& item = renderList.GetNextFreeItem();
       item.mRenderer = &renderable.mRenderer->GetRenderer();
       item.mNode = renderable.mNode;
+      item.mTextureSet = renderable.mRenderer->GetTextures();
       item.mIsOpaque = ( opacity == Renderer::OPAQUE );
       item.mDepthIndex = renderable.mRenderer->GetDepthIndex();
 
@@ -366,6 +363,9 @@ inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex
 
       item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] );
 
+      // texture set
+      mSortingHelper[ index ].textureSet = item.mTextureSet;
+
       // The default sorting function should get inlined here.
       mSortingHelper[ index ].zValue = Internal::Layer::ZValue( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex;
 
@@ -381,6 +381,11 @@ inline void RenderInstructionProcessor::SortRenderItems( BufferIndex bufferIndex
       RenderItem& item = renderList.GetItem( index );
 
       item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] );
+
+      // texture set
+      mSortingHelper[ index ].textureSet = item.mTextureSet;
+
+
       mSortingHelper[ index ].zValue = (*sortFunction)( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex;
 
       // Keep the RenderItem pointer in the helper so we can quickly reorder items after sort.
index d864b90..2127d3b 100644 (file)
@@ -73,7 +73,7 @@ public:
     SortAttributes()
     : renderItem( NULL ),
       shader( NULL ),
-      textureResourceId( Integration::InvalidResourceId ),
+      textureSet( NULL ),
       geometry( NULL ),
       zValue( 0.0f )
     {
@@ -81,7 +81,7 @@ public:
 
     RenderItem*             renderItem;        ///< The render item that is being sorted (includes depth index)
     const Shader*           shader;            ///< The shader instance
-    Integration::ResourceId textureResourceId; ///< The first texture resource ID of the texture set instance, is InvalidResourceId if the texture set doesn't have any textures
+    const void*             textureSet;        ///< The textureSet instance
     const Render::Geometry* geometry;          ///< The geometry instance
     float                   zValue;            ///< The Z value of the given renderer (either distance from camera, or a custom calculated value)
   };