From: Chu Hoang Date: Thu, 1 Oct 2015 11:35:24 +0000 (+0100) Subject: Changed SceneGraph::CompareItems and CompareItems3D to compare the render items based... X-Git-Tag: dali_1.1.5~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73ab81d3c98d1e706be2aa7c32bd51212c56243e;p=platform%2Fcore%2Fuifw%2Fdali-core.git Changed SceneGraph::CompareItems and CompareItems3D to compare the render items based on textureId instead of material. This is to reduce the number of glBindTexture calls. Change-Id: Iad24b18c5a42a53a85cdcf9522c5de71e3bf44a2 --- diff --git a/dali/integration-api/resource-declarations.h b/dali/integration-api/resource-declarations.h index 69dface..16118aa 100644 --- a/dali/integration-api/resource-declarations.h +++ b/dali/integration-api/resource-declarations.h @@ -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 diff --git a/dali/internal/render/renderers/render-new-renderer.h b/dali/internal/render/renderers/render-new-renderer.h index 82b68b9..995f515 100644 --- a/dali/internal/render/renderers/render-new-renderer.h +++ b/dali/internal/render/renderers/render-new-renderer.h @@ -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; } diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 3e9e1d8..90650ef 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -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; } diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index 27c9cfb..642f597 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -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: /** diff --git a/dali/internal/update/manager/prepare-render-instructions.cpp b/dali/internal/update/manager/prepare-render-instructions.cpp index e4a42db..4089973 100644 --- a/dali/internal/update/manager/prepare-render-instructions.cpp +++ b/dali/internal/update/manager/prepare-render-instructions.cpp @@ -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 diff --git a/dali/internal/update/manager/prepare-render-instructions.h b/dali/internal/update/manager/prepare-render-instructions.h index abbb0fb..cbae425 100644 --- a/dali/internal/update/manager/prepare-render-instructions.h +++ b/dali/internal/update/manager/prepare-render-instructions.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include 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; diff --git a/dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp b/dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp index ffcacb0..4ee06c7 100644 --- a/dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp +++ b/dali/internal/update/node-attachments/scene-graph-renderable-attachment.cpp @@ -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; }