From ef965273f67a17ef2120cf3f0f1072ea0e56878c Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Fri, 6 May 2016 14:50:26 +0100 Subject: [PATCH] RenderItem clean-up Change-Id: I9ea1d07be806414ba3cb56aebe8b13021329adc0 --- .../render/common/render-algorithms.cpp | 14 ++- dali/internal/render/common/render-debug.cpp | 2 +- dali/internal/render/common/render-debug.h | 2 +- dali/internal/render/common/render-item.cpp | 44 +------ dali/internal/render/common/render-item.h | 111 ++---------------- dali/internal/render/common/render-list.h | 5 +- .../render/renderers/render-renderer.cpp | 3 +- .../render/renderers/render-renderer.h | 1 + .../manager/prepare-render-instructions.cpp | 34 +++--- .../manager/prepare-render-instructions.h | 2 +- .../update/manager/transform-manager.cpp | 4 +- .../update/manager/transform-manager.h | 4 +- dali/internal/update/nodes/node.h | 8 +- 13 files changed, 51 insertions(+), 183 deletions(-) diff --git a/dali/internal/render/common/render-algorithms.cpp b/dali/internal/render/common/render-algorithms.cpp index 255af8dc5..879dba82e 100644 --- a/dali/internal/render/common/render-algorithms.cpp +++ b/dali/internal/render/common/render-algorithms.cpp @@ -144,12 +144,12 @@ inline void ProcessRenderList( const RenderItem& item = renderList.GetItem( index ); DALI_PRINT_RENDER_ITEM( item ); - Renderer& renderer = item.GetRenderer(); - DepthWriteMode::Type depthWriteMode = renderer.GetDepthWriteMode(); - context.DepthMask( ( depthWriteMode == DepthWriteMode::AUTO && item.IsOpaque() ) || + DepthWriteMode::Type depthWriteMode = item.mRenderer->GetDepthWriteMode(); + context.DepthMask( ( depthWriteMode == DepthWriteMode::AUTO && item.mIsOpaque ) || ( depthWriteMode == DepthWriteMode::ON ) ); - renderer.Render( context, textureCache, bufferIndex, item.GetNode(), defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, item.GetSize(), !item.IsOpaque() ); + item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader, + item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque ); } } else @@ -158,7 +158,8 @@ inline void ProcessRenderList( { const RenderItem& item = renderList.GetItem( index ); DALI_PRINT_RENDER_ITEM( item ); - item.GetRenderer().Render( context, textureCache, bufferIndex, item.GetNode(), defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, item.GetSize(), !item.IsOpaque() ); + item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader, + item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque ); } } } @@ -170,7 +171,8 @@ inline void ProcessRenderList( const RenderItem& item = renderList.GetItem( index ); DALI_PRINT_RENDER_ITEM( item ); - item.GetRenderer().Render( context, textureCache, bufferIndex, item.GetNode(), defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, item.GetSize(), !item.IsOpaque() ); + item.mRenderer->Render( context, textureCache, bufferIndex, *item.mNode, defaultShader, + item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mSize, !item.mIsOpaque ); } } diff --git a/dali/internal/render/common/render-debug.cpp b/dali/internal/render/common/render-debug.cpp index e8c8dd35a..dc82202a1 100644 --- a/dali/internal/render/common/render-debug.cpp +++ b/dali/internal/render/common/render-debug.cpp @@ -127,7 +127,7 @@ void PrintRenderList( const RenderList& list ) void PrintRenderItem( const SceneGraph::RenderItem& item ) { std::stringstream debugStream; - debugStream << "Rendering item, ModelView: " << item.GetModelViewMatrix(); + debugStream << "Rendering item, ModelView: " << item.mModelViewMatrix; std::string debugString( debugStream.str() ); DALI_LOG_RENDER_INFO( " %s\n", debugString.c_str() ); diff --git a/dali/internal/render/common/render-debug.h b/dali/internal/render/common/render-debug.h index 3dc49fb0d..8d5176e65 100644 --- a/dali/internal/render/common/render-debug.h +++ b/dali/internal/render/common/render-debug.h @@ -66,7 +66,7 @@ namespace SceneGraph { class RenderInstruction; struct RenderList; -class RenderItem; +struct RenderItem; } namespace Render diff --git a/dali/internal/render/common/render-item.cpp b/dali/internal/render/common/render-item.cpp index d01bd4318..d81f06838 100644 --- a/dali/internal/render/common/render-item.cpp +++ b/dali/internal/render/common/render-item.cpp @@ -42,7 +42,9 @@ RenderItem* RenderItem::New() } RenderItem::RenderItem() -: mModelViewMatrix( false ), +: mModelMatrix( false ), + mModelViewMatrix( false ), + mSize(), mRenderer( NULL ), mNode( NULL ), mDepthIndex( 0 ), @@ -59,46 +61,6 @@ void RenderItem::operator delete( void* ptr ) gRenderItemPool.Free( static_cast( ptr ) ); } -void RenderItem::Reset() -{ - mRenderer = NULL; -} - -void RenderItem::SetRenderer( Render::Renderer* renderer ) -{ - mRenderer = renderer; -} - -void RenderItem::SetNode( Node* node ) -{ - mNode = node; -} - -Render::Renderer& RenderItem::GetRenderer() const -{ - return *mRenderer; -} - -Matrix& RenderItem::GetModelViewMatrix() -{ - return mModelViewMatrix; -} - -const Matrix& RenderItem::GetModelViewMatrix() const -{ - return mModelViewMatrix; -} - -void RenderItem::SetDepthIndex( int depthIndex ) -{ - mDepthIndex = depthIndex; -} - -void RenderItem::SetIsOpaque( bool isOpaque ) -{ - mIsOpaque = isOpaque; -} - } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/render/common/render-item.h b/dali/internal/render/common/render-item.h index a309f3a6b..d429452c8 100644 --- a/dali/internal/render/common/render-item.h +++ b/dali/internal/render/common/render-item.h @@ -38,17 +38,11 @@ class Renderer; namespace SceneGraph { -class RenderItem; - -typedef std::vector< RenderItem > RendererItemContainer; - /** - * A render-item is a renderer & modelView matrix pair. + * A RenderItem contains all the data needed for rendering */ -class RenderItem +struct RenderItem { -public: - /** * Construct a new RenderItem */ @@ -65,94 +59,14 @@ public: */ void operator delete( void* ptr ); - /** - * Reset the render-item. - */ - void Reset(); - - /** - * Retrieve the renderer. - * @return The renderer. - */ - Render::Renderer& GetRenderer() const; - - /** - * Set the renderer - * @param[in] renderer The renderer - */ - void SetRenderer( Render::Renderer* renderer ); - - /** - * Set the node - * @param[in] node The node - */ - void SetNode( Node* node ); - - /** - * Retrieve the node - * @return The node - */ - const Node& GetNode() const - { - return *mNode; - } - /** - * Retrieve the modelView matrix. - * @return The modelView matrix. - */ - Matrix& GetModelViewMatrix(); - - /** - * Retrieve the modelView matrix. - * @return The modelView matrix. - */ - const Matrix& GetModelViewMatrix() const; - - /** - * Retrieve the depth index - */ - int GetDepthIndex() const - { - return mDepthIndex; - } - - /** - * Set the depth index - */ - void SetDepthIndex( int depthIndex ); - /** - * Set if the RenderItem is opaque - * @param[in] isOpaque true if the RenderItem is opaque, false otherwise - */ - void SetIsOpaque( bool isOpaque ); - - /** - * Check if the RenderItem is opaque - * @return True if it is opaque, false otherwise - */ - bool IsOpaque() const - { - return mIsOpaque; - } - - /** - * Retrives the size of the render item - * @return The size of the render item - */ - const Vector3& GetSize() const - { - return mSize; - } - - /** - * Retrives the size of the render item - * @return The size of the render item - */ - Vector3& GetSize() - { - return mSize; - } + Matrix mModelMatrix; + Matrix mModelViewMatrix; + Vector3 mSize; + Render::Renderer* mRenderer; + Node* mNode; + int mDepthIndex; + bool mIsOpaque:1; private: @@ -164,13 +78,6 @@ private: // RenderItems should not be copied as they are heavy RenderItem( const RenderItem& item ); RenderItem& operator = ( const RenderItem& item ); - - Matrix mModelViewMatrix; - Vector3 mSize; - Render::Renderer* mRenderer; - Node* mNode; - int mDepthIndex; - bool mIsOpaque:1; }; } // namespace SceneGraph diff --git a/dali/internal/render/common/render-list.h b/dali/internal/render/common/render-list.h index 3e72c3193..4f509c6a3 100644 --- a/dali/internal/render/common/render-list.h +++ b/dali/internal/render/common/render-list.h @@ -41,8 +41,6 @@ namespace SceneGraph class Layer; - -class RenderItem; typedef OwnerContainer< RenderItem* > RenderItemContainer; struct RenderList; @@ -166,7 +164,6 @@ public: } // get the item mNextFree points to and increase by one RenderItem& item = *mItems[ mNextFree++ ]; - item.Reset(); return item; } @@ -185,7 +182,7 @@ public: const Render::Renderer& GetRenderer( RenderItemContainer::SizeType index ) const { DALI_ASSERT_DEBUG( index < GetCachedItemCount() ); - return mItems[ index ]->GetRenderer(); + return *mItems[ index ]->mRenderer; } /** diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 4c176af79..8791f4d76 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -443,6 +443,7 @@ void Renderer::Render( Context& context, BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, SceneGraph::Shader& defaultShader, + const Matrix& modelMatrix, const Matrix& modelViewMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, @@ -477,7 +478,7 @@ void Renderer::Render( Context& context, // Only set up and draw if we have textures and they are all valid // set projection and view matrix if program has not yet received them yet this frame - SetMatrices( *program, node.GetModelMatrix( bufferIndex ), viewMatrix, projectionMatrix, modelViewMatrix ); + SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix ); // set color uniform GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR ); diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index 11482afa3..357304755 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -200,6 +200,7 @@ public: BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, SceneGraph::Shader& defaultShader, + const Matrix& modelMatrix, const Matrix& modelViewMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, diff --git a/dali/internal/update/manager/prepare-render-instructions.cpp b/dali/internal/update/manager/prepare-render-instructions.cpp index 0f703a530..53042c953 100644 --- a/dali/internal/update/manager/prepare-render-instructions.cpp +++ b/dali/internal/update/manager/prepare-render-instructions.cpp @@ -84,21 +84,21 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex, { // Get the next free RenderItem RenderItem& item = renderList.GetNextFreeItem(); - item.SetRenderer( &renderable.mRenderer->GetRenderer() ); - item.SetNode( renderable.mNode ); - item.SetIsOpaque( opacity == Renderer::OPAQUE ); + item.mRenderer = &renderable.mRenderer->GetRenderer(); + item.mNode = renderable.mNode; + item.mIsOpaque = (opacity == Renderer::OPAQUE); if( isLayer3d ) { - item.SetDepthIndex( renderable.mRenderer->GetDepthIndex() ); + item.mDepthIndex = renderable.mRenderer->GetDepthIndex(); } else { - item.SetDepthIndex( renderable.mRenderer->GetDepthIndex() + static_cast( renderable.mNode->GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER ); + item.mDepthIndex = renderable.mRenderer->GetDepthIndex() + static_cast( renderable.mNode->GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER; } // save MV matrix onto the item - const Matrix& worldMatrix = renderable.mNode->GetWorldMatrixAndSize( item.GetSize() ); - Matrix::Multiply( item.GetModelViewMatrix(), worldMatrix, viewMatrix ); + renderable.mNode->GetWorldMatrixAndSize( item.mModelMatrix, item.mSize ); + Matrix::Multiply( item.mModelViewMatrix, item.mModelMatrix, viewMatrix ); } } } @@ -179,7 +179,7 @@ inline bool TryReuseCachedRenderers( Layer& layer, */ bool CompareItems( const RendererWithSortAttributes& lhs, const RendererWithSortAttributes& rhs ) { - if( lhs.renderItem->GetDepthIndex() == rhs.renderItem->GetDepthIndex() ) + if( lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex ) { if( lhs.shader == rhs.shader ) { @@ -191,7 +191,7 @@ bool CompareItems( const RendererWithSortAttributes& lhs, const RendererWithSort } return lhs.shader < rhs.shader; } - return lhs.renderItem->GetDepthIndex() < rhs.renderItem->GetDepthIndex(); + return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex; } /** * Function which sorts the render items by Z function, then @@ -202,8 +202,8 @@ bool CompareItems( const RendererWithSortAttributes& lhs, const RendererWithSort */ bool CompareItems3D( const RendererWithSortAttributes& lhs, const RendererWithSortAttributes& rhs ) { - bool lhsIsOpaque = lhs.renderItem->IsOpaque(); - if( lhsIsOpaque == rhs.renderItem->IsOpaque()) + bool lhsIsOpaque = lhs.renderItem->mIsOpaque; + if( lhsIsOpaque == rhs.renderItem->mIsOpaque ) { if( lhsIsOpaque ) { @@ -276,10 +276,10 @@ inline void SortRenderItems( BufferIndex bufferIndex, RenderList& renderList, La { RenderItem& item = renderList.GetItem( index ); - item.GetRenderer().SetSortAttributes( bufferIndex, sortingHelper[ index ] ); + item.mRenderer->SetSortAttributes( bufferIndex, sortingHelper[ index ] ); // the default sorting function should get inlined here - sortingHelper[ index ].zValue = Internal::Layer::ZValue( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex(); + sortingHelper[ index ].zValue = Internal::Layer::ZValue( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex; // keep the renderitem pointer in the helper so we can quickly reorder items after sort sortingHelper[ index ].renderItem = &item; @@ -292,8 +292,8 @@ inline void SortRenderItems( BufferIndex bufferIndex, RenderList& renderList, La { RenderItem& item = renderList.GetItem( index ); - item.GetRenderer().SetSortAttributes( bufferIndex, sortingHelper[ index ] ); - sortingHelper[ index ].zValue = (*sortFunction)( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex(); + item.mRenderer->SetSortAttributes( bufferIndex, sortingHelper[ index ] ); + sortingHelper[ index ].zValue = (*sortFunction)( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex; // keep the renderitem pointer in the helper so we can quickly reorder items after sort sortingHelper[ index ].renderItem = &item; @@ -317,7 +317,7 @@ inline void SortRenderItems( BufferIndex bufferIndex, RenderList& renderList, La for( unsigned int index = 0; index < renderableCount; ++index, ++renderListIter ) { *renderListIter = sortingHelper[ index ].renderItem; - DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " sortedList[%d] = %p\n", index, &sortingHelper[ index ].renderItem->GetRenderer() ); + DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " sortedList[%d] = %p\n", index, sortingHelper[ index ].renderItem->mRenderer); } } @@ -371,7 +371,7 @@ inline void AddColorRenderers( BufferIndex updateBufferIndex, // depth buffering if ( ( renderList.Count() == 1 ) && (( renderList.GetRenderer( 0 ).GetDepthWriteMode() == DepthWriteMode::OFF ) || - ( renderList.GetRenderer( 0 ).GetDepthWriteMode() == DepthWriteMode::AUTO && !renderList.GetItem(0).IsOpaque() ))) + ( renderList.GetRenderer( 0 ).GetDepthWriteMode() == DepthWriteMode::AUTO && !renderList.GetItem(0).mIsOpaque ))) { //Nothing to do here } diff --git a/dali/internal/update/manager/prepare-render-instructions.h b/dali/internal/update/manager/prepare-render-instructions.h index 33cac10d2..0abbc2b6f 100644 --- a/dali/internal/update/manager/prepare-render-instructions.h +++ b/dali/internal/update/manager/prepare-render-instructions.h @@ -37,7 +37,7 @@ class Geometry; namespace SceneGraph { class RenderTracker; -class RenderItem; +struct RenderItem; class Shader; /** diff --git a/dali/internal/update/manager/transform-manager.cpp b/dali/internal/update/manager/transform-manager.cpp index 09a70e124..e9baa2715 100644 --- a/dali/internal/update/manager/transform-manager.cpp +++ b/dali/internal/update/manager/transform-manager.cpp @@ -830,11 +830,11 @@ const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const return mBoundingSpheres[ mIds[id] ]; } -const Matrix& TransformManager::GetWorldMatrixAndSize( TransformId id, Vector3& size ) const +void TransformManager::GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const { unsigned int index = mIds[id]; + worldMatrix = mWorld[index]; size = mSize[index]; - return mWorld[index]; } } //namespace SceneGraph diff --git a/dali/internal/update/manager/transform-manager.h b/dali/internal/update/manager/transform-manager.h index 45bc00d8d..d1b6c32cf 100644 --- a/dali/internal/update/manager/transform-manager.h +++ b/dali/internal/update/manager/transform-manager.h @@ -334,10 +334,10 @@ public: /** * Get the world matrix and size of a given component * @param[in] id Id of the transform component + * @param[out] The world matrix of the component * @param[out] size size of the component - * @return The world matrix of the component */ - const Matrix& GetWorldMatrixAndSize( TransformId id, Vector3& size ) const; + void GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const; private: diff --git a/dali/internal/update/nodes/node.h b/dali/internal/update/nodes/node.h index e354b32f4..484612286 100644 --- a/dali/internal/update/nodes/node.h +++ b/dali/internal/update/nodes/node.h @@ -590,17 +590,15 @@ public: /** * Retrieve world matrix and size of the node - * + * @param[out] The local to world matrix of the node * @param[out] size The current size of the node - * @return The local to world matrix of the node */ - const Matrix& GetWorldMatrixAndSize( Vector3& size ) const + void GetWorldMatrixAndSize( Matrix& worldMatrix, Vector3& size ) const { if( mTransformId != INVALID_TRANSFORM_ID ) { - return mTransformManager->GetWorldMatrixAndSize( mTransformId, size ); + mTransformManager->GetWorldMatrixAndSize( mTransformId, worldMatrix, size ); } - return Matrix::IDENTITY; } /** -- 2.34.1