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( "geometry-half-extents", VECTOR3, true, true, true, Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS )
44 DALI_PROPERTY( "requires-depth-test", BOOLEAN, true, false, true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
45 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
47 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> GEOMETRY_IMPL = { DEFAULT_PROPERTY_DETAILS };
51 return Dali::Geometry::New();
54 TypeRegistration mType( typeid( Dali::Geometry ), typeid( Dali::Handle ), Create );
56 } // unnamed namespace
58 GeometryPtr Geometry::New()
60 GeometryPtr geometry( new Geometry() );
61 geometry->Initialize();
65 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
67 PropertyBufferConnector connector;
68 connector.Set( vertexBuffer, OnStage() );
69 mVertexBufferConnectors.push_back( connector );
71 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = dynamic_cast<const SceneGraph::PropertyBuffer&>( *vertexBuffer.GetSceneObject() );
73 SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
75 return mVertexBufferConnectors.size() - 1u;
78 std::size_t Geometry::GetNumberOfVertexBuffers() const
80 return mVertexBufferConnectors.size();
83 void Geometry::RemoveVertexBuffer( std::size_t index )
85 mVertexBufferConnectors.erase( mVertexBufferConnectors.begin() + index );
88 void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
90 mIndexBufferConnector.Set( indexBuffer, OnStage() );
92 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = dynamic_cast<const SceneGraph::PropertyBuffer&>( *indexBuffer.GetSceneObject() );
94 SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
97 void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
99 if( NULL != mSceneObject )
101 SceneGraph::DoubleBufferedPropertyMessage<int>::Send(
102 GetEventThreadServices(),
104 &mSceneObject->mGeometryType,
105 &SceneGraph::DoubleBufferedProperty<int>::Set,
106 static_cast<int>(geometryType) );
110 Dali::Geometry::GeometryType Geometry::GetGeometryType() const
112 return mSceneObject->GetGeometryType(GetEventThreadServices().GetEventBufferIndex());
115 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
117 if( NULL != mSceneObject )
119 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, static_cast<int>(requiresDepthTest) );
123 bool Geometry::GetRequiresDepthTesting() const
127 // mSceneObject is being used in a separate thread; copy the value from the previous update
128 return mSceneObject->GetRequiresDepthTesting(GetEventThreadServices().GetEventBufferIndex());
133 const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
138 unsigned int Geometry::GetDefaultPropertyCount() const
140 return GEOMETRY_IMPL.GetDefaultPropertyCount();
143 void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
145 GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
148 const char* Geometry::GetDefaultPropertyName(Property::Index index) const
150 return GEOMETRY_IMPL.GetDefaultPropertyName( index );
153 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
155 return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
158 bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
160 return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
163 bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
165 return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
168 bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
170 return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
173 Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
175 return GEOMETRY_IMPL.GetDefaultPropertyType( index );
178 void Geometry::SetDefaultProperty( Property::Index index,
179 const Property::Value& propertyValue )
183 case Dali::Geometry::Property::GEOMETRY_TYPE :
185 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mGeometryType, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
188 case Dali::Geometry::Property::GEOMETRY_CENTER :
190 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
194 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
196 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mHalfExtents, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
200 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
202 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
208 void Geometry::SetSceneGraphProperty( Property::Index index,
209 const PropertyMetadata& entry,
210 const Property::Value& value )
212 GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
215 Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
217 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
218 Property::Value value;
222 case Dali::Geometry::Property::GEOMETRY_TYPE :
226 value = mSceneObject->mGeometryType[bufferIndex];
230 case Dali::Geometry::Property::GEOMETRY_CENTER :
234 value = mSceneObject->mCenter[bufferIndex];
239 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
243 value = mSceneObject->mHalfExtents[bufferIndex];
248 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
252 value = mSceneObject->mRequiresDepthTest[bufferIndex];
261 const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
266 const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
271 const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
273 const SceneGraph::PropertyBase* property = NULL;
277 property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
278 &Geometry::FindAnimatableProperty,
279 &Geometry::FindCustomProperty,
282 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
286 case Dali::Geometry::Property::GEOMETRY_CENTER :
288 property = &mSceneObject->mCenter;
291 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
293 property = &mSceneObject->mHalfExtents;
298 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
307 const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
309 const PropertyInputImpl* property = NULL;
313 const SceneGraph::PropertyBase* baseProperty =
314 GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
315 &Geometry::FindAnimatableProperty,
316 &Geometry::FindCustomProperty,
319 property = static_cast<const PropertyInputImpl*>( baseProperty );
321 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
325 case Dali::Geometry::Property::GEOMETRY_TYPE :
327 property = &mSceneObject->mGeometryType;
330 case Dali::Geometry::Property::GEOMETRY_CENTER :
332 property = &mSceneObject->mCenter;
335 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
337 property = &mSceneObject->mHalfExtents;
340 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
342 property = &mSceneObject->mRequiresDepthTest;
347 DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
357 int Geometry::GetPropertyComponentIndex( Property::Index index ) const
359 // @todo MESH_REWORK - Change this if component properties are added for center/half-extent
360 return Property::INVALID_COMPONENT_INDEX;
363 bool Geometry::OnStage() const
368 void Geometry::Connect()
372 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
373 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
377 it->OnStageConnect();
379 mIndexBufferConnector.OnStageConnect();
382 void Geometry::Disconnect()
386 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
387 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
391 it->OnStageDisconnect();
393 mIndexBufferConnector.OnStageDisconnect();
397 : mSceneObject( NULL ),
402 void Geometry::Initialize()
404 EventThreadServices& eventThreadServices = GetEventThreadServices();
405 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
407 mSceneObject = new SceneGraph::Geometry();
408 AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
410 eventThreadServices.RegisterObject( this );
413 Geometry::~Geometry()
415 if( EventThreadServices::IsCoreRunning() )
417 EventThreadServices& eventThreadServices = GetEventThreadServices();
418 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
419 RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
421 eventThreadServices.UnregisterObject( this );
426 } // namespace Internal