From 132198d566f8fe76dc068861866f4e20fa8d69a5 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 5 Mar 2015 19:05:22 +0000 Subject: [PATCH] Messages and ownership of update objects Change-Id: Iaf66aedb9e6133cf9a0542165462e20ab444b494 --- dali/internal/file.list | 2 +- dali/internal/update/common/discard-queue.cpp | 39 +++++++ dali/internal/update/common/discard-queue.h | 20 ++++ ...-buffer.cpp => scene-graph-property-buffer.cpp} | 2 +- ...erty-buffer.h => scene-graph-property-buffer.h} | 6 + dali/internal/update/common/uniform-map.h | 7 +- .../update/effects/scene-graph-material.cpp | 28 +---- .../internal/update/effects/scene-graph-material.h | 69 ++++++------ .../update/effects/scene-graph-sampler.cpp | 3 + dali/internal/update/effects/scene-graph-sampler.h | 51 +++++++++ .../update/geometry/scene-graph-geometry.cpp | 38 ++++++- .../update/geometry/scene-graph-geometry.h | 80 +++++++++++++- dali/internal/update/manager/update-manager.cpp | 121 +++++++++++++++++++-- dali/internal/update/manager/update-manager.h | 88 ++++++++++++++- .../scene-graph-renderer-attachment.cpp | 8 +- .../scene-graph-renderer-attachment.h | 39 ++++++- 16 files changed, 512 insertions(+), 89 deletions(-) rename dali/internal/update/common/{property-buffer.cpp => scene-graph-property-buffer.cpp} (95%) rename dali/internal/update/common/{property-buffer.h => scene-graph-property-buffer.h} (82%) diff --git a/dali/internal/file.list b/dali/internal/file.list index 05283a1..6483c94 100644 --- a/dali/internal/file.list +++ b/dali/internal/file.list @@ -147,7 +147,7 @@ internal_src_files = \ $(internal_src_dir)/update/animation/scene-graph-constraint-base.cpp \ $(internal_src_dir)/update/common/discard-queue.cpp \ $(internal_src_dir)/update/common/property-base.cpp \ - $(internal_src_dir)/update/common/property-buffer.cpp \ + $(internal_src_dir)/update/common/scene-graph-property-buffer.cpp \ $(internal_src_dir)/update/common/property-condition-functions.cpp \ $(internal_src_dir)/update/common/property-condition-step-functions.cpp \ $(internal_src_dir)/update/common/property-condition-variable-step-functions.cpp \ diff --git a/dali/internal/update/common/discard-queue.cpp b/dali/internal/update/common/discard-queue.cpp index 164035b..0e68aca 100644 --- a/dali/internal/update/common/discard-queue.cpp +++ b/dali/internal/update/common/discard-queue.cpp @@ -79,6 +79,41 @@ void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachmen } } +void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry ) +{ + DALI_ASSERT_DEBUG( NULL != geometry ); + + // The GL resources will now be freed in frame N + // The Update for frame N+1 may occur in parallel with the rendering of frame N + // Queue the node for destruction in frame N+2 + if ( 0u == updateBufferIndex ) + { + mGeometryQueue0.PushBack( geometry ); + } + else + { + mGeometryQueue1.PushBack( geometry ); + } +} + +void DiscardQueue::Add( BufferIndex updateBufferIndex, Material* material ) +{ + DALI_ASSERT_DEBUG( NULL != material ); + + // The GL resources will now be freed in frame N + // The Update for frame N+1 may occur in parallel with the rendering of frame N + // Queue the node for destruction in frame N+2 + if ( 0u == updateBufferIndex ) + { + mMaterialQueue0.PushBack( material ); + } + else + { + mMaterialQueue1.PushBack( material ); + } +} + + void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader ) { DALI_ASSERT_DEBUG( NULL != shader ); @@ -107,12 +142,16 @@ void DiscardQueue::Clear( BufferIndex updateBufferIndex ) mNodeQueue0.Clear(); mAttachmentQueue0.Clear(); mShaderQueue0.Clear(); + mGeometryQueue0.Clear(); + mMaterialQueue0.Clear(); } else { mNodeQueue1.Clear(); mAttachmentQueue1.Clear(); mShaderQueue1.Clear(); + mGeometryQueue1.Clear(); + mMaterialQueue1.Clear(); } } diff --git a/dali/internal/update/common/discard-queue.h b/dali/internal/update/common/discard-queue.h index 879cc5b..56bd2db 100644 --- a/dali/internal/update/common/discard-queue.h +++ b/dali/internal/update/common/discard-queue.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include namespace Dali { @@ -52,6 +54,8 @@ class DiscardQueue public: typedef OwnerContainer< Shader* > ShaderQueue; + typedef OwnerContainer< Geometry* > GeometryQueue; + typedef OwnerContainer< Material* > MaterialQueue; /** * Create a new DiscardQueue. @@ -83,6 +87,18 @@ public: void Add( BufferIndex updateBufferIndex, NodeAttachment* attachment ); /** + * Adds an unwanted geometry to the discard queue. + * A message will be sent to clean up GL resources in the next Render + */ + void Add( BufferIndex updateBufferIndex, Geometry* geometry ); + + /** + * Adds an unwanted material to the discard queue. + * A message will be sent to clean up GL resources in the next Render. + */ + void Add( BufferIndex updateBufferIndex, Material* material ); + + /** * Adds an unwanted shader to the discard queue. * A message will be sent to clean-up GL resources in the next Render. * @pre This method is not thread-safe, and should only be called from the update-thread. @@ -114,11 +130,15 @@ private: NodeOwnerContainer mNodeQueue0; NodeAttachmentOwnerContainer mAttachmentQueue0; ShaderQueue mShaderQueue0; + GeometryQueue mGeometryQueue0; + MaterialQueue mMaterialQueue0; // Messages are queued here when the update buffer index == 1 NodeOwnerContainer mNodeQueue1; NodeAttachmentOwnerContainer mAttachmentQueue1; ShaderQueue mShaderQueue1; + GeometryQueue mGeometryQueue1; + MaterialQueue mMaterialQueue1; }; } // namespace SceneGraph diff --git a/dali/internal/update/common/property-buffer.cpp b/dali/internal/update/common/scene-graph-property-buffer.cpp similarity index 95% rename from dali/internal/update/common/property-buffer.cpp rename to dali/internal/update/common/scene-graph-property-buffer.cpp index af43f0e..b1a1396 100644 --- a/dali/internal/update/common/property-buffer.cpp +++ b/dali/internal/update/common/scene-graph-property-buffer.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "property-buffer.h" +#include "scene-graph-property-buffer.h" namespace Dali { diff --git a/dali/internal/update/common/property-buffer.h b/dali/internal/update/common/scene-graph-property-buffer.h similarity index 82% rename from dali/internal/update/common/property-buffer.h rename to dali/internal/update/common/scene-graph-property-buffer.h index 492ceb9..bbc1425 100644 --- a/dali/internal/update/common/property-buffer.h +++ b/dali/internal/update/common/scene-graph-property-buffer.h @@ -27,6 +27,12 @@ namespace SceneGraph class PropertyBuffer { public: + //@todo MESH_REWORK Remove when we have working property buffers + static PropertyBuffer* NewQuadVertices(); + + //@todo MESH_REWORK Remove when we have working property buffers + static PropertyBuffer* NewQuadIndices(); + /** * Constructor */ diff --git a/dali/internal/update/common/uniform-map.h b/dali/internal/update/common/uniform-map.h index 16f54a9..1fb6e43 100644 --- a/dali/internal/update/common/uniform-map.h +++ b/dali/internal/update/common/uniform-map.h @@ -38,7 +38,12 @@ public: /** * Constructor */ - UniformMap; + UniformMap(); + + /** + * Destructor + */ + ~UniformMap(); private: // data diff --git a/dali/internal/update/effects/scene-graph-material.cpp b/dali/internal/update/effects/scene-graph-material.cpp index 575c4cb..146e20e 100644 --- a/dali/internal/update/effects/scene-graph-material.cpp +++ b/dali/internal/update/effects/scene-graph-material.cpp @@ -28,9 +28,7 @@ namespace SceneGraph { Material::Material() -: mShader(NULL), - mCullFaceMode( CullNone ), - mBlendingOptions() +: mShader(NULL) { } @@ -47,12 +45,12 @@ Shader* Material::GetShader() return mShader; } -void Material::AddSampler( Sampler* sampler ) +void Material::AddSampler( const Sampler* sampler ) { // @todo MESH_REWORK } -void Material::RemoveSampler( Sampler* sampler ) +void Material::RemoveSampler( const Sampler* sampler ) { // @todo MESH_REWORK } @@ -63,26 +61,6 @@ const Material::Samplers& Material::GetSamplers() const return mSamplers; } -void Material::SetFaceCulling( BufferIndex updateBufferIndex, Dali::CullFaceMode mode ) -{ - // @todo MESH_REWORK -} - -CullFaceMode Material::GetFaceCulling() const -{ - // @todo MESH_REWORK - return mCullFaceMode; -} - -void Material::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options ) -{ - // @todo MESH_REWORK -} - -void Material::SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color ) -{ - // @todo MESH_REWORK -} } // namespace SceneGraph diff --git a/dali/internal/update/effects/scene-graph-material.h b/dali/internal/update/effects/scene-graph-material.h index c1675c1..fa5cce7 100644 --- a/dali/internal/update/effects/scene-graph-material.h +++ b/dali/internal/update/effects/scene-graph-material.h @@ -20,6 +20,7 @@ #include // For CullFaceMode #include #include +#include #include #include #include @@ -64,13 +65,13 @@ public: * Add a sampler (image + sampler modes) to the material * @param[in] sampler A sampler to add */ - void AddSampler( Sampler* sampler ); + void AddSampler( const Sampler* sampler ); /** * Remove a sampler (image + sampler modes) from the material * @param[in] sampler A sampler to remove */ - void RemoveSampler( Sampler* sampler ); + void RemoveSampler( const Sampler* sampler ); /** * Get the samplers this material uses. @@ -78,40 +79,46 @@ public: */ const Samplers& GetSamplers() const; - /** - * Set the face culling mode for geometry used by this material - * @param[in] mode The face culling mode to use - */ - void SetFaceCulling( BufferIndex updateBufferIndex, Dali::CullFaceMode mode ); +private: + Shader* mShader; + Samplers mSamplers; // Not owned (though who does?) - /** - * Get the face culling mode - * @return the face culling mdoe - */ - CullFaceMode GetFaceCulling() const ; + // @todo MESH_REWORK add property values for cull face mode, blending options, blend color + // Add getters/setters? +}; - // @note Blending mode is per actor, not per material (requires actor color) +inline void SetShaderMessage( EventToUpdate& eventToUpdate, const Material& material, Shader& shader ) +{ + typedef MessageValue1< Material, Shader* > LocalType; - /** - * Set the blending options. This should only be called from the update-thread. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] options A bitmask of blending options. - */ - void SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options ); + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); - /** - * Set the blend-color. This should only be called from the update-thread. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] color The new blend-color. - */ - void SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color ); + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &material, &Material::SetShader, &shader ); +} -private: - Shader* mShader; - Samplers mSamplers; // Not owned (though who does?) - Dali::CullFaceMode mCullFaceMode:3; - BlendingOptions mBlendingOptions; -}; +inline void AddSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler ) +{ + typedef MessageValue1< Material, const Sampler* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &material, &Material::AddSampler, &sampler ); +} + +inline void RemoveSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler ) +{ + typedef MessageValue1< Material, const Sampler* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &material, &Material::RemoveSampler, &sampler ); +} } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/update/effects/scene-graph-sampler.cpp b/dali/internal/update/effects/scene-graph-sampler.cpp index 92472db..4014226 100644 --- a/dali/internal/update/effects/scene-graph-sampler.cpp +++ b/dali/internal/update/effects/scene-graph-sampler.cpp @@ -47,10 +47,13 @@ void Sampler::SetUniformName( const std::string& samplerName ) void Sampler::SetTextureId( ResourceId textureId ) { + mTextureId = textureId; } void Sampler::SetFilterMode( BufferIndex bufferIndex, FilterMode minFilter, FilterMode magFilter ) { + mMinFilter[bufferIndex] = minFilter; + mMagFilter[bufferIndex] = magFilter; } void Sampler::SetWrapMode( BufferIndex bufferIndex, WrapMode uWrap, WrapMode vWrap ) diff --git a/dali/internal/update/effects/scene-graph-sampler.h b/dali/internal/update/effects/scene-graph-sampler.h index 632170a..950b5f9 100644 --- a/dali/internal/update/effects/scene-graph-sampler.h +++ b/dali/internal/update/effects/scene-graph-sampler.h @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -128,6 +129,56 @@ private: DoubleBuffered mVWrapMode; ///< The vertical wrap mode }; +inline void SetUniformNameMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, const std::string& name ) +{ + typedef MessageValue1< Sampler, std::string > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &sampler, &Sampler::SetUniformName, name ); +} + +} // namespace SceneGraph + +// Declare enum as a message parameter type outside the SceneGraph namespace +template <> struct ParameterType< SceneGraph::Sampler::FilterMode > : public BasicType< SceneGraph::Sampler::FilterMode > {}; + +namespace SceneGraph +{ + +inline void SetFilterModeMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, Sampler::FilterMode minFilter, Sampler::FilterMode magFilter ) +{ + typedef MessageDoubleBuffered2< Sampler, Sampler::FilterMode, Sampler::FilterMode > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &sampler, &Sampler::SetFilterMode, minFilter, magFilter ); +} + +} // namespace SceneGraph + +// Declare enum as a message parameter type +template <> struct ParameterType< SceneGraph::Sampler::WrapMode > : public BasicType< SceneGraph::Sampler::WrapMode > {}; + +namespace SceneGraph +{ + +inline void SetWrapModeMessage( EventToUpdate& eventToUpdate, const SceneGraph::Sampler& sampler, SceneGraph::Sampler::WrapMode horizontalWrap, SceneGraph::Sampler::WrapMode verticalWrap ) +{ + typedef MessageDoubleBuffered2< Sampler, Sampler::WrapMode, Sampler::WrapMode > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &sampler, &Sampler::SetWrapMode, horizontalWrap, verticalWrap ); +} + + } // namespace SceneGraph } // namespace Internal } // namespace Dali diff --git a/dali/internal/update/geometry/scene-graph-geometry.cpp b/dali/internal/update/geometry/scene-graph-geometry.cpp index 136a771..6a07a39 100644 --- a/dali/internal/update/geometry/scene-graph-geometry.cpp +++ b/dali/internal/update/geometry/scene-graph-geometry.cpp @@ -26,26 +26,56 @@ namespace SceneGraph Geometry::Geometry() : mGeometryType(Dali::Geometry::TRIANGLES) { + // @todo MESH_REWORK Remove this code when we have working property buffers + // @todo It's also the wrong place to do this temporary work + PropertyBuffer* vertexPropertyBuffer = PropertyBuffer::NewQuadVertices(); + mVertexBuffers.PushBack( vertexPropertyBuffer ); + + mIndexBuffer = PropertyBuffer::NewQuadIndices(); } Geometry::~Geometry() { + // @todo Inform renderers of deletion of buffers? +} + +void Geometry::AddVertexBuffer( PropertyBuffer* vertexBuffer ) +{ + mVertexBuffers.PushBack( vertexBuffer ); } -void Geometry::AddVertexBuffer( PropertyBuffer vertexBuffer ) +void Geometry::RemoveVertexBuffer( PropertyBuffer* vertexBuffer ) { + DALI_ASSERT_DEBUG( NULL != vertexBuffer ); + + // Find the object and destroy it + for ( OwnerContainer< PropertyBuffer* >::Iterator iter = mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter ) + { + PropertyBuffer* current = *iter; + if ( current == vertexBuffer ) + { + mVertexBuffers.Erase( iter ); + return; + } + } + + DALI_ASSERT_DEBUG(false); } -void Geometry::RemoveVertexBuffer( PropertyBuffer vertexBuffer ) +void Geometry::SetIndexBuffer( PropertyBuffer* indexBuffer ) { + mIndexBuffer = indexBuffer; } -void Geometry::SetIndexBuffer( PropertyBuffer indexBuffer ) +void Geometry::ClearIndexBuffer() { + // @todo Actually delete, or put on Discard Queue and tell Renderer in render thread? + mIndexBuffer.Reset(); } void Geometry::SetGeometryType( Geometry::GeometryType geometryType ) { + mGeometryType = geometryType; } const Geometry::VertexBuffers& Geometry::GetVertexBuffers() @@ -55,7 +85,7 @@ const Geometry::VertexBuffers& Geometry::GetVertexBuffers() const PropertyBuffer& Geometry::GetIndexBuffer() { - return mIndexBuffer; + return *mIndexBuffer.Get(); } Geometry::GeometryType Geometry::GetGeometryType( ) diff --git a/dali/internal/update/geometry/scene-graph-geometry.h b/dali/internal/update/geometry/scene-graph-geometry.h index 93ce584..86da67d 100644 --- a/dali/internal/update/geometry/scene-graph-geometry.h +++ b/dali/internal/update/geometry/scene-graph-geometry.h @@ -18,9 +18,10 @@ */ #include +#include #include #include -#include +#include namespace Dali { @@ -53,19 +54,25 @@ public: /** * Add a property buffer to be used as a vertex buffer */ - void AddVertexBuffer( PropertyBuffer vertexBuffer ); + void AddVertexBuffer( PropertyBuffer* vertexBuffer ); /** * Remove a property buffer to be used as a vertex buffer * @param[in] vertexBuffer the associated vertex buffer to remove */ - void RemoveVertexBuffer( PropertyBuffer vertexBuffer ); + void RemoveVertexBuffer( PropertyBuffer* vertexBuffer ); /** * Set the buffer to be used as a source of indices for the geometry * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes. */ - void SetIndexBuffer( PropertyBuffer indexBuffer ); + void SetIndexBuffer( PropertyBuffer* indexBuffer ); + + /** + * Clear the index buffer if it is no longer required, e.g. if changing geometry type + * to POINTS. + */ + void ClearIndexBuffer(); /** * Set the type of geometry to draw (Points, Lines, Triangles, etc) @@ -93,10 +100,73 @@ public: // GeometryDataProvider private: VertexBuffers mVertexBuffers; ///< The vertex buffers - PropertyBuffer mIndexBuffer; ///< The index buffer if required + OwnerPointer mIndexBuffer; ///< The index buffer if required GeometryType mGeometryType; ///< The type of geometry (tris/lines etc) }; +inline void AddVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer ) +{ + typedef MessageValue1< Geometry, OwnerPointer > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, &vertexBuffer ); +} + +inline void RemoveVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer ) +{ + typedef MessageValue1< Geometry, PropertyBuffer* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, &vertexBuffer ); +} + +inline void SetIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& indexBuffer ) +{ + typedef MessageValue1< Geometry, OwnerPointer< PropertyBuffer > > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, &indexBuffer ); +} + +inline void ClearIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry ) +{ + typedef Message< Geometry > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer ); +} + +} // namespace SceneGraph + +// Declare enum as a message parameter type +template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {}; + +namespace SceneGraph +{ + +inline void SetGeometryTypeMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType ) +{ + typedef MessageValue1< Geometry, SceneGraph::Geometry::GeometryType > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType ); +} + } // namespace SceneGraph } // namespace Internal } // namespace Dali diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index 33ebb76..3b0f651 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -38,23 +38,25 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #include #include -#include #include -#include -#include -#include #include #include #include +#include +#include +#include +#include +#include #include #include @@ -124,6 +126,14 @@ void DestroyNodeSet( std::set& nodeSet ) } //namespace +typedef OwnerContainer< Geometry* > GeometryContainer; +typedef GeometryContainer::Iterator GeometryIter; +typedef GeometryContainer::ConstIterator GeometryConstIter; + +typedef OwnerContainer< Material* > MaterialContainer; +typedef MaterialContainer::Iterator MaterialIter; +typedef MaterialContainer::ConstIterator MaterialConstIter; + typedef OwnerContainer< Shader* > ShaderContainer; typedef ShaderContainer::Iterator ShaderIter; typedef ShaderContainer::ConstIterator ShaderConstIter; @@ -258,6 +268,9 @@ struct UpdateManager::Impl AnimationContainer animations; ///< A container of owned animations PropertyNotificationContainer propertyNotifications; ///< A container of owner property notifications. + GeometryContainer geometries; ///< A container of geometries + MaterialContainer materials; ///< A container of materials + ShaderContainer shaders; ///< A container of owned shaders MessageQueue messageQueue; ///< The messages queued from the event-thread @@ -519,6 +532,67 @@ void UpdateManager::PropertyNotificationSetNotify( PropertyNotification* propert propertyNotification->SetNotifyMode( notifyMode ); } + +void UpdateManager::AddGeometry( Geometry* geometry ) +{ + DALI_ASSERT_DEBUG( NULL != geometry ); + mImpl->geometries.PushBack( geometry ); +} + +void UpdateManager::RemoveGeometry( Geometry* geometry ) +{ + DALI_ASSERT_DEBUG(geometry != NULL); + + GeometryContainer& geometries = mImpl->geometries; + + // Find the geometry and destroy it + for ( GeometryIter iter = geometries.Begin(); iter != geometries.End(); ++iter ) + { + Geometry& current = **iter; + if ( ¤t == geometry ) + { + // Transfer ownership to the discard queue + // This keeps the geometry alive, until the render-thread has finished with it + mImpl->discardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), geometries.Release( iter ) ); + + return; + } + } + + // Should not reach here + DALI_ASSERT_DEBUG(false); +} + +void UpdateManager::AddMaterial( Material* material ) +{ + DALI_ASSERT_DEBUG( NULL != material ); + + mImpl->materials.PushBack( material ); +} + +void UpdateManager::RemoveMaterial( Material* material ) +{ + DALI_ASSERT_DEBUG(material != NULL); + + MaterialContainer& materials = mImpl->materials; + + // Find the material and destroy it + for ( MaterialIter iter = materials.Begin(); iter != materials.End(); ++iter ) + { + Material& current = **iter; + if ( ¤t == material ) + { + // Transfer ownership to the discard queue + // This keeps the material alive, until the render-thread has finished with it + mImpl->discardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), materials.Release( iter ) ); + + return; + } + } + // Should not reach here + DALI_ASSERT_DEBUG(false); +} + void UpdateManager::AddShader( Shader* shader ) { DALI_ASSERT_DEBUG( NULL != shader ); @@ -542,7 +616,7 @@ void UpdateManager::AddShader( Shader* shader ) shader->Initialize( mImpl->renderQueue, mImpl->sceneController->GetTextureCache() ); } -void UpdateManager::RemoveShader(Shader* shader) +void UpdateManager::RemoveShader( Shader* shader ) { DALI_ASSERT_DEBUG(shader != NULL); @@ -694,6 +768,18 @@ void UpdateManager::ResetProperties() (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() ); } + // Reset animatable material properties to base values + for (MaterialIter iter = mImpl->materials.Begin(); iter != mImpl->materials.End(); ++iter) + { + (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() ); + } + + // Reset animatable geometry properties to base values + for (GeometryIter iter = mImpl->geometries.Begin(); iter != mImpl->geometries.End(); ++iter) + { + (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() ); + } + // Reset animatable shader properties to base values for (ShaderIter iter = mImpl->shaders.Begin(); iter != mImpl->shaders.End(); ++iter) { @@ -807,6 +893,21 @@ void UpdateManager::ApplyConstraints() mImpl->activeConstraints += ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() ); } + // Constrain Materials and geometries + MaterialContainer& materials = mImpl->materials; + for ( MaterialIter iter = materials.Begin(); iter != materials.End(); ++iter ) + { + Material& material = **iter; + mImpl->activeConstraints += ConstrainPropertyOwner( material, mSceneGraphBuffers.GetUpdateBufferIndex() ); + } + + GeometryContainer& geometries = mImpl->geometries; + for ( GeometryIter iter = geometries.Begin(); iter != geometries.End(); ++iter ) + { + Geometry& geometry = **iter; + mImpl->activeConstraints += ConstrainPropertyOwner( geometry, mSceneGraphBuffers.GetUpdateBufferIndex() ); + } + // constrain shaders... (in construction order) ShaderContainer& shaders = mImpl->shaders; diff --git a/dali/internal/update/manager/update-manager.h b/dali/internal/update/manager/update-manager.h index 47c047a..d174bdf 100644 --- a/dali/internal/update/manager/update-manager.h +++ b/dali/internal/update/manager/update-manager.h @@ -21,17 +21,23 @@ // INTERNAL INCLUDES #include #include + #include + #include #include -#include -#include -#include -#include +#include + #include +#include #include +#include +#include +#include +#include #include -#include + +#include namespace Dali { @@ -257,6 +263,31 @@ public: */ void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode ); + + /** + * Add a geometry to the scene graph + * @param[in] geometry The geometry to add + */ + void AddGeometry( Geometry* geometry ); + + /** + * Remove a geometry from the scene graph + * @param[in] geometry The geometry to remove + */ + void RemoveGeometry( Geometry* geometry ); + + /** + * Add a material to the scene graph + * @param[in] material The material to add + */ + void AddMaterial( Material* material ); + + /** + * Remove a material from the scene graph + * @param[in] material The material to remove + */ + void RemoveMaterial( Material* material ); + // Shaders /** @@ -620,6 +651,53 @@ inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager, new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode ); } +inline void AddGeometryMessage( UpdateManager& manager, Geometry& geometry ) +{ + typedef MessageValue1< UpdateManager, OwnerPointer< Geometry > > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry ); +} + +// The render thread can safely change the Geometry +inline void RemoveGeometryMessage( UpdateManager& manager, Geometry& geometry ) +{ + typedef MessageValue1< UpdateManager, Geometry* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry ); +} + +inline void AddMaterialMessage( UpdateManager& manager, Material& material ) +{ + typedef MessageValue1< UpdateManager, OwnerPointer< Material > > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::AddMaterial, &material ); +} + +// The render thread can safely change the Material +inline void RemoveMaterialMessage( UpdateManager& manager, Material& material ) +{ + typedef MessageValue1< UpdateManager, Material* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &manager, &UpdateManager::RemoveMaterial, &material ); +} + + // The render thread can safely change the Shader inline void AddShaderMessage( UpdateManager& manager, Shader& shader ) { diff --git a/dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp b/dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp index 63ba684..377a812 100644 --- a/dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp +++ b/dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp @@ -37,10 +37,10 @@ RendererAttachment::~RendererAttachment() mGeometry=NULL; } -void RendererAttachment::SetMaterial(const Material& material) +void RendererAttachment::SetMaterial(const Material* material) { // @todo MESH_REWORK - mMaterial = &material; + mMaterial = material; } const Material& RendererAttachment::GetMaterial() const @@ -48,10 +48,10 @@ const Material& RendererAttachment::GetMaterial() const return *mMaterial; } -void RendererAttachment::SetGeometry(const Geometry& geometry) +void RendererAttachment::SetGeometry(const Geometry* geometry) { // @todo MESH_REWORK - mGeometry = &geometry; + mGeometry = geometry; } const Geometry& RendererAttachment::GetGeometry() const diff --git a/dali/internal/update/node-attachments/scene-graph-renderer-attachment.h b/dali/internal/update/node-attachments/scene-graph-renderer-attachment.h index 27194ce..b4eda54 100644 --- a/dali/internal/update/node-attachments/scene-graph-renderer-attachment.h +++ b/dali/internal/update/node-attachments/scene-graph-renderer-attachment.h @@ -48,7 +48,7 @@ public: * Set the material for the renderer * @param[in] material The material this renderer will use */ - void SetMaterial(const Material& material); + void SetMaterial(const Material* material); /** * Get the material of this renderer @@ -60,7 +60,7 @@ public: * Set the geometry for the renderer * @param[in] geometry The geometry this renderer will use */ - void SetGeometry(const Geometry& geometry); + void SetGeometry(const Geometry* geometry); /** * Get the geometry of this renderer @@ -86,6 +86,41 @@ private: int mDepthIndex; ///< Used only in PrepareRenderInstructions }; +// Messages for RendererAttachment + +inline void SetMaterialMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Material& material ) +{ + typedef MessageValue1< RendererAttachment, const Material* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &attachment, &RendererAttachment::SetMaterial, &material ); +} + +inline void SetGeometryMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Geometry& geometry ) +{ + typedef MessageValue1< RendererAttachment, const Geometry* > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &attachment, &RendererAttachment::SetGeometry, &geometry ); +} + +inline void SetDepthIndexMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, int depthIndex ) +{ + typedef MessageValue1< RendererAttachment, int > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &attachment, &RendererAttachment::SetDepthIndex, depthIndex ); +} + } // namespace SceneGraph } // namespace Internal } // namespace Dali -- 2.7.4