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 mVertexBuffers.push_back( &vertexBuffer );
67 SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, *vertexBuffer.GetRenderObject() );
68 return mVertexBuffers.size() - 1u;
71 std::size_t Geometry::GetNumberOfVertexBuffers() const
73 return mVertexBuffers.size();
76 void Geometry::RemoveVertexBuffer( std::size_t index )
78 const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
79 SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, renderPropertyBuffer );
81 mVertexBuffers.erase( mVertexBuffers.begin() + index );
84 void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
86 mIndexBuffer = &indexBuffer;
87 SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, *indexBuffer.GetRenderObject() );
90 void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
92 if( NULL != mSceneObject )
94 SceneGraph::DoubleBufferedPropertyMessage<int>::Send(
95 GetEventThreadServices(),
97 &mSceneObject->mGeometryType,
98 &SceneGraph::DoubleBufferedProperty<int>::Set,
99 static_cast<int>(geometryType) );
103 Dali::Geometry::GeometryType Geometry::GetGeometryType() const
105 return mSceneObject->GetGeometryType(GetEventThreadServices().GetEventBufferIndex());
108 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
110 if( NULL != mSceneObject )
112 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, static_cast<int>(requiresDepthTest) );
116 bool Geometry::GetRequiresDepthTesting() const
120 // mSceneObject is being used in a separate thread; copy the value from the previous update
121 return mSceneObject->GetRequiresDepthTesting(GetEventThreadServices().GetEventBufferIndex());
126 const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
131 unsigned int Geometry::GetDefaultPropertyCount() const
133 return GEOMETRY_IMPL.GetDefaultPropertyCount();
136 void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
138 GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
141 const char* Geometry::GetDefaultPropertyName(Property::Index index) const
143 return GEOMETRY_IMPL.GetDefaultPropertyName( index );
146 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
148 return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
151 bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
153 return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
156 bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
158 return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
161 bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
163 return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
166 Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
168 return GEOMETRY_IMPL.GetDefaultPropertyType( index );
171 void Geometry::SetDefaultProperty( Property::Index index,
172 const Property::Value& propertyValue )
176 case Dali::Geometry::Property::GEOMETRY_TYPE :
178 SceneGraph::DoubleBufferedPropertyMessage<int>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mGeometryType, &SceneGraph::DoubleBufferedProperty<int>::Set, propertyValue.Get<int>() );
181 case Dali::Geometry::Property::GEOMETRY_CENTER :
183 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
186 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
188 SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
194 void Geometry::SetSceneGraphProperty( Property::Index index,
195 const PropertyMetadata& entry,
196 const Property::Value& value )
198 GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
201 Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
203 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
204 Property::Value value;
208 case Dali::Geometry::Property::GEOMETRY_TYPE :
212 value = mSceneObject->mGeometryType[bufferIndex];
216 case Dali::Geometry::Property::GEOMETRY_CENTER :
220 value = mSceneObject->mCenter[bufferIndex];
225 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
229 value = mSceneObject->mRequiresDepthTest[bufferIndex];
238 const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
243 const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
248 const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
250 const SceneGraph::PropertyBase* property = NULL;
254 property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
255 &Geometry::FindAnimatableProperty,
256 &Geometry::FindCustomProperty,
259 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
263 case Dali::Geometry::Property::GEOMETRY_CENTER :
265 property = &mSceneObject->mCenter;
270 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
279 const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
281 const PropertyInputImpl* property = NULL;
285 const SceneGraph::PropertyBase* baseProperty =
286 GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
287 &Geometry::FindAnimatableProperty,
288 &Geometry::FindCustomProperty,
291 property = static_cast<const PropertyInputImpl*>( baseProperty );
293 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
297 case Dali::Geometry::Property::GEOMETRY_TYPE :
299 property = &mSceneObject->mGeometryType;
302 case Dali::Geometry::Property::GEOMETRY_CENTER :
304 property = &mSceneObject->mCenter;
307 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
309 property = &mSceneObject->mRequiresDepthTest;
314 DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
324 int Geometry::GetPropertyComponentIndex( Property::Index index ) const
326 // @todo MESH_REWORK - Change this if component properties are added for center/half-extent
327 return Property::INVALID_COMPONENT_INDEX;
330 bool Geometry::OnStage() const
335 void Geometry::Connect()
340 void Geometry::Disconnect()
346 : mIndexBuffer( NULL ),
347 mSceneObject( NULL ),
352 void Geometry::Initialize()
354 EventThreadServices& eventThreadServices = GetEventThreadServices();
355 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
357 mSceneObject = new SceneGraph::Geometry();
358 AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
360 eventThreadServices.RegisterObject( this );
363 Geometry::~Geometry()
365 if( EventThreadServices::IsCoreRunning() )
367 EventThreadServices& eventThreadServices = GetEventThreadServices();
368 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
369 RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
371 eventThreadServices.UnregisterObject( this );
376 } // namespace Internal