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( "requires-depth-test", BOOLEAN, true, false, true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
43 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
45 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> GEOMETRY_IMPL = { DEFAULT_PROPERTY_DETAILS };
49 return Dali::Geometry::New();
52 TypeRegistration mType( typeid( Dali::Geometry ), typeid( Dali::Handle ), Create );
54 } // unnamed namespace
56 GeometryPtr Geometry::New()
58 GeometryPtr geometry( new Geometry() );
59 geometry->Initialize();
63 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
65 mVertexBuffers.push_back( &vertexBuffer );
66 SceneGraph::AddVertexBufferMessage( GetEventThreadServices(), *mSceneObject, *vertexBuffer.GetRenderObject() );
67 return mVertexBuffers.size() - 1u;
70 std::size_t Geometry::GetNumberOfVertexBuffers() const
72 return mVertexBuffers.size();
75 void Geometry::RemoveVertexBuffer( std::size_t index )
77 const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
78 SceneGraph::RemoveVertexBufferMessage( GetEventThreadServices(), *mSceneObject, renderPropertyBuffer );
80 mVertexBuffers.erase( mVertexBuffers.begin() + index );
83 void Geometry::SetIndexBuffer( PropertyBuffer& indexBuffer )
85 mIndexBuffer = &indexBuffer;
86 SceneGraph::SetIndexBufferMessage( GetEventThreadServices(), *mSceneObject, *indexBuffer.GetRenderObject() );
89 void Geometry::SetGeometryType( Dali::Geometry::GeometryType geometryType )
91 if( geometryType != mGeometryType )
93 SceneGraph::SetGeometryTypeMessage(GetEventThreadServices(),
97 mGeometryType = geometryType;
101 Dali::Geometry::GeometryType Geometry::GetGeometryType() const
103 return mGeometryType;
106 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
108 if( requiresDepthTest != mRequiresDepthTest )
110 SceneGraph::SetGeometryRequiresDepthTestMessage(GetEventThreadServices(),
114 mRequiresDepthTest = requiresDepthTest;
118 bool Geometry::GetRequiresDepthTesting() const
120 return mRequiresDepthTest;
123 const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
128 unsigned int Geometry::GetDefaultPropertyCount() const
130 return GEOMETRY_IMPL.GetDefaultPropertyCount();
133 void Geometry::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
135 GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
138 const char* Geometry::GetDefaultPropertyName(Property::Index index) const
140 return GEOMETRY_IMPL.GetDefaultPropertyName( index );
143 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
145 return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
148 bool Geometry::IsDefaultPropertyWritable( Property::Index index ) const
150 return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
153 bool Geometry::IsDefaultPropertyAnimatable( Property::Index index ) const
155 return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
158 bool Geometry::IsDefaultPropertyAConstraintInput( Property::Index index ) const
160 return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
163 Property::Type Geometry::GetDefaultPropertyType( Property::Index index ) const
165 return GEOMETRY_IMPL.GetDefaultPropertyType( index );
168 void Geometry::SetDefaultProperty( Property::Index index,
169 const Property::Value& propertyValue )
173 case Dali::Geometry::Property::GEOMETRY_TYPE :
175 Dali::Geometry::GeometryType geometryType = static_cast<Dali::Geometry::GeometryType>(propertyValue.Get<int>());
176 if( geometryType != mGeometryType )
178 SceneGraph::SetGeometryTypeMessage(GetEventThreadServices(), *mSceneObject, geometryType );
179 mGeometryType = geometryType;
183 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
185 bool requiresDepthTest = propertyValue.Get<bool>();
186 if( requiresDepthTest != mRequiresDepthTest )
188 SceneGraph::SetGeometryRequiresDepthTestMessage(GetEventThreadServices(), *mSceneObject, requiresDepthTest);
189 mRequiresDepthTest = requiresDepthTest;
196 void Geometry::SetSceneGraphProperty( Property::Index index,
197 const PropertyMetadata& entry,
198 const Property::Value& value )
200 GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
203 Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
205 Property::Value value;
209 case Dali::Geometry::Property::GEOMETRY_TYPE :
213 value = mGeometryType;
217 case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
221 value = mRequiresDepthTest;
230 const SceneGraph::PropertyOwner* Geometry::GetPropertyOwner() const
235 const SceneGraph::PropertyOwner* Geometry::GetSceneObject() const
240 const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Property::Index index ) const
242 const SceneGraph::PropertyBase* property = NULL;
245 property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
246 &Geometry::FindAnimatableProperty,
247 &Geometry::FindCustomProperty,
254 const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index index ) const
256 const PropertyInputImpl* property = NULL;
260 const SceneGraph::PropertyBase* baseProperty =
261 GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
262 &Geometry::FindAnimatableProperty,
263 &Geometry::FindCustomProperty,
266 property = static_cast<const PropertyInputImpl*>( baseProperty );
272 bool Geometry::OnStage() const
277 void Geometry::Connect()
282 void Geometry::Disconnect()
288 : mSceneObject( NULL ),
289 mIndexBuffer( NULL ),
290 mGeometryType(Dali::Geometry::TRIANGLES),
291 mRequiresDepthTest(false),
296 void Geometry::Initialize()
298 EventThreadServices& eventThreadServices = GetEventThreadServices();
299 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
301 mSceneObject = new SceneGraph::Geometry();
302 AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
304 eventThreadServices.RegisterObject( this );
307 Geometry::~Geometry()
309 if( EventThreadServices::IsCoreRunning() )
311 EventThreadServices& eventThreadServices = GetEventThreadServices();
312 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
313 RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
315 eventThreadServices.UnregisterObject( this );
320 } // namespace Internal