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 = static_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 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = static_cast<const SceneGraph::PropertyBuffer&>( *(mVertexBufferConnectors[index].Get()->GetSceneObject()) );
86 SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
88 mVertexBufferConnectors.erase( mVertexBufferConnectors.begin() + index );
91 void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
93 mIndexBufferConnector.Set( indexBuffer, OnStage() );
95 const SceneGraph::PropertyBuffer& sceneGraphPropertyBuffer = dynamic_cast<const SceneGraph::PropertyBuffer&>( *indexBuffer.GetSceneObject() );
97 SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, sceneGraphPropertyBuffer );
100 void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
102 if( NULL != mSceneObject )
104 SceneGraph::DoubleBufferedPropertyMessage<int>::Send(
105 GetEventThreadServices(),
107 &mSceneObject->mGeometryType,
108 &SceneGraph::DoubleBufferedProperty<int>::Set,
109 static_cast<int>(geometryType) );
113 Dali::Geometry::GeometryType Geometry::GetGeometryType() const
115 return mSceneObject->GetGeometryType(GetEventThreadServices().GetEventBufferIndex());
118 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
120 if( NULL != mSceneObject )
122 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, static_cast<int>(requiresDepthTest) );
126 bool Geometry::GetRequiresDepthTesting() const
130 // mSceneObject is being used in a separate thread; copy the value from the previous update
131 return mSceneObject->GetRequiresDepthTesting(GetEventThreadServices().GetEventBufferIndex());
136 const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
141 unsigned int Geometry::GetDefaultPropertyCount() const
143 return GEOMETRY_IMPL.GetDefaultPropertyCount();
146 void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
148 GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
151 const char* Geometry::GetDefaultPropertyName(Property::Index index) const
153 return GEOMETRY_IMPL.GetDefaultPropertyName( index );
156 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
158 return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
161 bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
163 return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
166 bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
168 return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
171 bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
173 return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
176 Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
178 return GEOMETRY_IMPL.GetDefaultPropertyType( index );
181 void Geometry::SetDefaultProperty( Property::Index index,
182 const Property::Value& propertyValue )
186 case Dali::Geometry::Property::GEOMETRY_TYPE :
188 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mGeometryType, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
191 case Dali::Geometry::Property::GEOMETRY_CENTER :
193 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
197 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
199 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mHalfExtents, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
203 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
205 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
211 void Geometry::SetSceneGraphProperty( Property::Index index,
212 const PropertyMetadata& entry,
213 const Property::Value& value )
215 GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
218 Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
220 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
221 Property::Value value;
225 case Dali::Geometry::Property::GEOMETRY_TYPE :
229 value = mSceneObject->mGeometryType[bufferIndex];
233 case Dali::Geometry::Property::GEOMETRY_CENTER :
237 value = mSceneObject->mCenter[bufferIndex];
242 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
246 value = mSceneObject->mHalfExtents[bufferIndex];
251 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
255 value = mSceneObject->mRequiresDepthTest[bufferIndex];
264 const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
269 const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
274 const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
276 const SceneGraph::PropertyBase* property = NULL;
280 property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
281 &Geometry::FindAnimatableProperty,
282 &Geometry::FindCustomProperty,
285 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
289 case Dali::Geometry::Property::GEOMETRY_CENTER :
291 property = &mSceneObject->mCenter;
294 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
296 property = &mSceneObject->mHalfExtents;
301 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
310 const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
312 const PropertyInputImpl* property = NULL;
316 const SceneGraph::PropertyBase* baseProperty =
317 GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
318 &Geometry::FindAnimatableProperty,
319 &Geometry::FindCustomProperty,
322 property = static_cast<const PropertyInputImpl*>( baseProperty );
324 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
328 case Dali::Geometry::Property::GEOMETRY_TYPE :
330 property = &mSceneObject->mGeometryType;
333 case Dali::Geometry::Property::GEOMETRY_CENTER :
335 property = &mSceneObject->mCenter;
338 case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
340 property = &mSceneObject->mHalfExtents;
343 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
345 property = &mSceneObject->mRequiresDepthTest;
350 DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
360 int Geometry::GetPropertyComponentIndex( Property::Index index ) const
362 // @todo MESH_REWORK - Change this if component properties are added for center/half-extent
363 return Property::INVALID_COMPONENT_INDEX;
366 bool Geometry::OnStage() const
371 void Geometry::Connect()
375 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
376 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
380 it->OnStageConnect();
382 mIndexBufferConnector.OnStageConnect();
385 void Geometry::Disconnect()
389 PropertyBufferConnectorContainer::const_iterator end = mVertexBufferConnectors.end();
390 for( PropertyBufferConnectorContainer::iterator it = mVertexBufferConnectors.begin();
394 it->OnStageDisconnect();
396 mIndexBufferConnector.OnStageDisconnect();
400 : mSceneObject( NULL ),
405 void Geometry::Initialize()
407 EventThreadServices& eventThreadServices = GetEventThreadServices();
408 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
410 mSceneObject = new SceneGraph::Geometry();
411 AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
413 eventThreadServices.RegisterObject( this );
416 Geometry::~Geometry()
418 if( EventThreadServices::IsCoreRunning() )
420 EventThreadServices& eventThreadServices = GetEventThreadServices();
421 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
422 RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
424 eventThreadServices.UnregisterObject( this );
429 } // namespace Internal