2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
22 #include <dali/public-api/object/type-registry.h>
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
26 #include <dali/internal/update/common/double-buffered-property.h>
27 #include <dali/internal/update/manager/update-manager.h>
38 * |name |type |writable|animatable|constraint-input|enum for index-checking|
40 DALI_PROPERTY_TABLE_BEGIN
41 DALI_PROPERTY( "geometry-type", STRING, true, false, true, Dali::Geometry::Property::GEOMETRY_TYPE )
42 DALI_PROPERTY( "geometry-center", VECTOR3, true, true, true, Dali::Geometry::Property::GEOMETRY_CENTER )
43 DALI_PROPERTY( "requires-depth-test", BOOLEAN, true, false, true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
44 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
46 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> GEOMETRY_IMPL = { DEFAULT_PROPERTY_DETAILS };
50 return Dali::Geometry::New();
53 TypeRegistration mType( typeid( Dali::Geometry ), typeid( Dali::Handle ), Create );
55 } // unnamed namespace
57 GeometryPtr Geometry::New()
59 GeometryPtr geometry( new Geometry() );
60 geometry->Initialize();
64 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
66 PropertyBufferConnector connector;
67 connector.Set( vertexBuffer, OnStage() );
68 mVertexBufferConnectors.push_back( connector );
70 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = static_cast<const SceneGraph::PropertyBuffer&>( *vertexBuffer.GetSceneObject() );
72 SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
74 return mVertexBufferConnectors.size() - 1u;
77 std::size_t Geometry::GetNumberOfVertexBuffers() const
79 return mVertexBufferConnectors.size();
82 void Geometry::RemoveVertexBuffer( std::size_t index )
84 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = static_cast<const SceneGraph::PropertyBuffer&>( *(mVertexBufferConnectors[index].Get()->GetSceneObject()) );
85 SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
87 mVertexBufferConnectors.erase( mVertexBufferConnectors.begin() + index );
90 void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
92 mIndexBufferConnector.Set( indexBuffer, OnStage() );
94 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = dynamic_cast<const SceneGraph::PropertyBuffer&>( *indexBuffer.GetSceneObject() );
96 SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
99 void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
101 if( NULL != mSceneObject )
103 SceneGraph::DoubleBufferedPropertyMessage<int>::Send(
104 GetEventThreadServices(),
106 &mSceneObject->mGeometryType,
107 &SceneGraph::DoubleBufferedProperty<int>::Set,
108 static_cast<int>(geometryType) );
112 Dali::Geometry::GeometryType Geometry::GetGeometryType() const
114 return mSceneObject->GetGeometryType(GetEventThreadServices().GetEventBufferIndex());
117 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
119 if( NULL != mSceneObject )
121 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, static_cast<int>(requiresDepthTest) );
125 bool Geometry::GetRequiresDepthTesting() const
129 // mSceneObject is being used in a separate thread; copy the value from the previous update
130 return mSceneObject->GetRequiresDepthTesting(GetEventThreadServices().GetEventBufferIndex());
135 const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
140 unsigned int Geometry::GetDefaultPropertyCount() const
142 return GEOMETRY_IMPL.GetDefaultPropertyCount();
145 void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
147 GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
150 const char* Geometry::GetDefaultPropertyName(Property::Index index) const
152 return GEOMETRY_IMPL.GetDefaultPropertyName( index );
155 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
157 return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
160 bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
162 return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
165 bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
167 return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
170 bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
172 return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
175 Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
177 return GEOMETRY_IMPL.GetDefaultPropertyType( index );
180 void Geometry::SetDefaultProperty( Property::Index index,
181 const Property::Value& propertyValue )
185 case Dali::Geometry::Property::GEOMETRY_TYPE :
187 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mGeometryType, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
190 case Dali::Geometry::Property::GEOMETRY_CENTER :
192 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
195 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
197 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
203 void Geometry::SetSceneGraphProperty( Property::Index index,
204 const PropertyMetadata& entry,
205 const Property::Value& value )
207 GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
210 Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
212 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
213 Property::Value value;
217 case Dali::Geometry::Property::GEOMETRY_TYPE :
221 value = mSceneObject->mGeometryType[bufferIndex];
225 case Dali::Geometry::Property::GEOMETRY_CENTER :
229 value = mSceneObject->mCenter[bufferIndex];
234 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
238 value = mSceneObject->mRequiresDepthTest[bufferIndex];
247 const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
252 const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
257 const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
259 const SceneGraph::PropertyBase* property = NULL;
263 property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
264 &Geometry::FindAnimatableProperty,
265 &Geometry::FindCustomProperty,
268 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
272 case Dali::Geometry::Property::GEOMETRY_CENTER :
274 property = &mSceneObject->mCenter;
279 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
288 const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
290 const PropertyInputImpl* property = NULL;
294 const SceneGraph::PropertyBase* baseProperty =
295 GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
296 &Geometry::FindAnimatableProperty,
297 &Geometry::FindCustomProperty,
300 property = static_cast<const PropertyInputImpl*>( baseProperty );
302 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
306 case Dali::Geometry::Property::GEOMETRY_TYPE :
308 property = &mSceneObject->mGeometryType;
311 case Dali::Geometry::Property::GEOMETRY_CENTER :
313 property = &mSceneObject->mCenter;
316 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
318 property = &mSceneObject->mRequiresDepthTest;
323 DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
333 int Geometry::GetPropertyComponentIndex( Property::Index index ) const
335 // @todo MESH_REWORK - Change this if component properties are added for center/half-extent
336 return Property::INVALID_COMPONENT_INDEX;
339 bool Geometry::OnStage() const
344 void Geometry::Connect()
348 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
349 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
353 it->OnStageConnect();
355 mIndexBufferConnector.OnStageConnect();
358 void Geometry::Disconnect()
362 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
363 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
367 it->OnStageDisconnect();
369 mIndexBufferConnector.OnStageDisconnect();
373 : mSceneObject( NULL ),
378 void Geometry::Initialize()
380 EventThreadServices& eventThreadServices = GetEventThreadServices();
381 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
383 mSceneObject = new SceneGraph::Geometry();
384 AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
386 eventThreadServices.RegisterObject( this );
389 Geometry::~Geometry()
391 if( EventThreadServices::IsCoreRunning() )
393 EventThreadServices& eventThreadServices = GetEventThreadServices();
394 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
395 RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
397 eventThreadServices.UnregisterObject( this );
402 } // namespace Internal