Optimize blending requirement resolution 56/50756/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 30 Oct 2015 15:36:12 +0000 (15:36 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 2 Nov 2015 11:36:41 +0000 (11:36 +0000)
- dont iterate through list of textures but store one bool per material
- stop copying bitmap metadata objects

Change-Id: I1a55a3be1cabafec68b75f3d65704c52616d6ea0

dali/internal/event/rendering/material-impl.h
dali/internal/render/renderers/render-new-renderer.cpp
dali/internal/update/common/uniform-map.h
dali/internal/update/rendering/scene-graph-material.cpp
dali/internal/update/rendering/scene-graph-material.h
dali/internal/update/rendering/scene-graph-renderer.cpp

index b5deaad..e3dbc4f 100644 (file)
@@ -318,7 +318,7 @@ private: // Data
   Dali::Material::FaceCullingMode mFaceCullingMode; ///< Local copy of face culling mode
   BlendingMode::Type mBlendingMode;                 ///< Local copy of blending mode
   BlendingOptions mBlendingOptions;                 ///< Local copy of blending options bitmask
-  Vector4* mBlendColor;                             ///< Local copy of blend color, pointer only as its raraly used
+  Vector4* mBlendColor;                             ///< Local copy of blend color, pointer only as its rarely used
   bool mOnStage;
 
 };
index 90d2c3e..19ecad2 100644 (file)
@@ -109,6 +109,10 @@ void NewRenderer::DoSetBlending( Context& context )
   {
     context.SetCustomBlendColor( *blendColor );
   }
+  else
+  {
+    context.SetDefaultBlendColor();
+  }
 
   const BlendingOptions& blending = material.GetBlendingOptions();
   // Set blend source & destination factors
index f78ab3a..8ca4246 100644 (file)
@@ -64,7 +64,7 @@ public:
 /**
  * The UniformMap class is used to map uniform names to property values. It is available
  * in all of the classes responsible for rendering:
- * Actor, Renderer, Geometry, PropertyBuffer, Material, Sampler, Shader.
+ * Actor, Renderer, Geometry, Material, Shader.
  *
  * It can be observed for changes to the mapping table.
  */
index a67de19..3e01a91 100644 (file)
@@ -37,12 +37,12 @@ Material::Material()
   mSamplers(),
   mTextureId(),
   mUniformName(),
-  mIsFullyOpaque(),
   mConnectionObservers(),
   mFaceCullingMode( Dali::Material::NONE ),
   mBlendingMode( Dali::BlendingMode::AUTO ),
   mBlendingOptions(), // initializes to defaults
-  mBlendPolicy( OPAQUE )
+  mBlendPolicy( OPAQUE ),
+  mTexturesRequireBlending( false )
 {
   // Observe own property-owner's uniform map
   AddUniformMapObserver( *this );
@@ -96,31 +96,20 @@ void Material::PrepareRender( BufferIndex bufferIndex )
     }
     case BlendingMode::AUTO:
     {
-      bool opaque = true;
-
       // @todo: Change hints for new SceneGraphShader:
       // If shader hint OUTPUT_IS_OPAQUE is enabled, set policy to ALWAYS_OPAQUE
       // If shader hint OUTPUT_IS_TRANSPARENT is enabled, set policy to ALWAYS_TRANSPARENT
       // else test remainder, and set policy to either ALWAYS_TRANSPARENT or USE_ACTOR_COLOR
 
-      if( mShader->GeometryHintEnabled( Dali::ShaderEffect::HINT_BLENDING ) )
+      if( mTexturesRequireBlending ||
+          mShader->GeometryHintEnabled( Dali::ShaderEffect::HINT_BLENDING ) )
       {
-        opaque = false;
+        mBlendPolicy = Material::TRANSPARENT;
       }
-
-      if( opaque )
+      else
       {
-        size_t textureCount( GetTextureCount() );
-        for( unsigned int i(0); i<textureCount; ++i )
-        {
-          if( !mIsFullyOpaque[i] )
-          {
-            opaque = false;
-          }
-        }
+        mBlendPolicy = Material::USE_ACTOR_COLOR;
       }
-
-      mBlendPolicy = opaque ? Material::USE_ACTOR_COLOR : Material::TRANSPARENT;
     }
   }
 }
@@ -162,7 +151,6 @@ void Material::AddTexture( const std::string& name, ResourceId id, Render::Sampl
   mTextureId.PushBack( id );
   mUniformName.push_back( name );
   mSamplers.PushBack( sampler );
-  mIsFullyOpaque.PushBack( false );
 
   mConnectionObservers.ConnectionsChanged(*this);
 }
@@ -172,7 +160,6 @@ void Material::RemoveTexture( size_t index )
   mTextureId.Erase( mTextureId.Begin()+index );
   mUniformName.erase( mUniformName.begin() + index );
   mSamplers.Erase( mSamplers.Begin()+index );
-  mIsFullyOpaque.Erase( mIsFullyOpaque.Begin()+index );
   mConnectionObservers.ConnectionsChanged( *this );
 }
 
@@ -229,6 +216,11 @@ void Material::ConnectedUniformMapChanged( )
   mConnectionObservers.ConnectedUniformMapChanged();
 }
 
+void Material::SetTexturesRequireBlending( bool texturesRequireBlending )
+{
+  mTexturesRequireBlending = texturesRequireBlending;
+}
+
 } // namespace SceneGraph
 
 } // namespace Internal
index 16a769d..e8b4914 100644 (file)
@@ -255,26 +255,26 @@ public: // ConnectionChangePropagator::Observer
    */
   virtual void ConnectedUniformMapChanged();
 
-public: // PropertyOwner implementation
+public:
 
-  void SetIsFullyOpaque( size_t index, bool isFullyOpaque )
-  {
-    mIsFullyOpaque[index] = isFullyOpaque;
-  }
+  /**
+   * @param texturesRequireBlending, true if any of the textures requires blending
+   */
+  void SetTexturesRequireBlending( bool texturesRequireBlending );
 
 private: // Data
 
-  Shader*                     mShader;
-  Vector4*                    mBlendColor; // not double buffered as its not animateable and not frequently changed
-  Vector< Render::Sampler* >  mSamplers; // Not owned
-  Vector< ResourceId >        mTextureId;
-  std::vector< std::string >  mUniformName;
-  Vector< bool >              mIsFullyOpaque;
-  ConnectionChangePropagator  mConnectionObservers;
-  Dali::Material::FaceCullingMode  mFaceCullingMode; // not double buffered as its not animateable and not frequently changed
-  BlendingMode::Type          mBlendingMode; // not double buffered as its not animateable and not frequently changed
-  BlendingOptions             mBlendingOptions; // not double buffered as its not animateable and not frequently changed
-  BlendPolicy                 mBlendPolicy; ///< The blend policy as determined by PrepareRender
+  Shader*                         mShader;
+  Vector4*                        mBlendColor; // not double buffered as its not animateable and not frequently changed
+  Vector< Render::Sampler* >      mSamplers; // Not owned
+  Vector< ResourceId >            mTextureId;
+  std::vector< std::string >      mUniformName;
+  ConnectionChangePropagator      mConnectionObservers;
+  Dali::Material::FaceCullingMode mFaceCullingMode; // not double buffered as its not animateable and not frequently changed
+  BlendingMode::Type              mBlendingMode; // not double buffered as its not animateable and not frequently changed
+  BlendingOptions                 mBlendingOptions; // not double buffered as its not animateable and not frequently changed
+  BlendPolicy                     mBlendPolicy; ///< The blend policy as determined by PrepareRender
+  bool                            mTexturesRequireBlending;
 
 };
 
index d7dce43..eeb0bbb 100644 (file)
@@ -322,7 +322,6 @@ void Renderer::PrepareResources( BufferIndex updateBufferIndex, ResourceManager&
   CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
   mResourcesReady = false;
 
-
   mFinishedResourceAcquisition = false;
 
   // Can only be considered ready when all the scene graph objects are connected to the renderer
@@ -334,57 +333,64 @@ void Renderer::PrepareResources( BufferIndex updateBufferIndex, ResourceManager&
     unsigned int frameBufferCount = 0;
 
     size_t textureCount( mMaterial->GetTextureCount() );
-    for( unsigned int i(0); i<textureCount; ++i )
+    if( textureCount > 0 )
     {
-      ResourceId textureId = mMaterial->GetTextureId(i);
-      BitmapMetadata metaData = resourceManager.GetBitmapMetadata( textureId );
-
-      mMaterial->SetIsFullyOpaque( i, metaData.IsFullyOpaque() );
-
-      switch( completeStatusManager.GetStatus( textureId ) )
+      unsigned int opaqueCount = 0;
+      for( unsigned int i(0); i<textureCount; ++i )
       {
-        case CompleteStatusManager::NOT_READY:
+        ResourceId textureId = mMaterial->GetTextureId(i);
+        BitmapMetadata metaData = resourceManager.GetBitmapMetadata( textureId );
+        if( metaData.IsFullyOpaque() )
         {
-          if( metaData.GetIsFramebuffer() )
-          {
-            frameBufferCount++;
-          }
-          if( completeStatusManager.FindResourceTracker(textureId) != NULL )
+          ++opaqueCount;
+        }
+
+        switch( completeStatusManager.GetStatus( textureId ) )
+        {
+          case CompleteStatusManager::NOT_READY:
           {
-            bool found = false;
-            std::size_t numTrackedResources = mTrackedResources.Count();
-            for( size_t i=0; i < numTrackedResources; ++i )
+          if( metaData.GetIsFramebuffer() )
             {
-              if(mTrackedResources[i] == textureId)
+              frameBufferCount++;
+            }
+            if( completeStatusManager.FindResourceTracker(textureId) != NULL )
+            {
+              bool found = false;
+              std::size_t numTrackedResources = mTrackedResources.Count();
+              for( size_t i=0; i < numTrackedResources; ++i )
+              {
+                if(mTrackedResources[i] == textureId)
+                {
+                  found = true;
+                  break;
+                }
+              }
+              if( ! found )
               {
-                found = true;
-                break;
+                mTrackedResources.PushBack( textureId );
               }
             }
-            if( ! found )
+            else
             {
-              mTrackedResources.PushBack( textureId );
+              mHasUntrackedResources = true;
             }
           }
-          else
+          break;
+
+          case CompleteStatusManager::COMPLETE:
           {
-            mHasUntrackedResources = true;
+            completeCount++;
           }
-        }
-        break;
-
-        case CompleteStatusManager::COMPLETE:
-        {
-          completeCount++;
-        }
-        break;
+          break;
 
-        case CompleteStatusManager::NEVER:
-        {
-          neverCount++;
+          case CompleteStatusManager::NEVER:
+          {
+            neverCount++;
+          }
+          break;
         }
-        break;
       }
+      mMaterial->SetTexturesRequireBlending( opaqueCount != textureCount );
     }
 
     // We are ready if all samplers are complete, or those that aren't are framebuffers