Dali 3D User Interface Engine
geometry-impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 // CLASS HEADER
19 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
20 
21 // INTERNAL INCLUDES
23 
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
27 
28 namespace Dali
29 {
30 namespace Internal
31 {
32 
33 namespace
34 {
35 
40 DALI_PROPERTY( "geometryType", STRING, true, false, true, Dali::Geometry::Property::GEOMETRY_TYPE )
41 DALI_PROPERTY( "requiresDepthTest", BOOLEAN, true, false, true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
43 
44 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> GEOMETRY_IMPL = { DEFAULT_PROPERTY_DETAILS };
45 
47 {
48  return Dali::Geometry::New();
49 }
50 
52 
53 } // unnamed namespace
54 
56 {
57  GeometryPtr geometry( new Geometry() );
58  geometry->Initialize();
59  return geometry;
60 }
61 
62 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
63 {
64  mVertexBuffers.push_back( &vertexBuffer );
66  return mVertexBuffers.size() - 1u;
67 }
68 
70 {
71  return mVertexBuffers.size();
72 }
73 
74 void Geometry::RemoveVertexBuffer( std::size_t index )
75 {
76  const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
78 
79  mVertexBuffers.erase( mVertexBuffers.begin() + index );
80 }
81 
83 {
84  mIndexBuffer = &indexBuffer;
86 }
87 
89 {
90  if( geometryType != mGeometryType )
91  {
93  *mSceneObject,
94  geometryType );
95 
96  mGeometryType = geometryType;
97  }
98 }
99 
101 {
102  return mGeometryType;
103 }
104 
105 void Geometry::SetRequiresDepthTesting( bool requiresDepthTest )
106 {
107  if( requiresDepthTest != mRequiresDepthTest )
108  {
110  *mSceneObject,
111  requiresDepthTest );
112 
113  mRequiresDepthTest = requiresDepthTest;
114  }
115 }
116 
118 {
119  return mRequiresDepthTest;
120 }
121 
123 {
124  return mSceneObject;
125 }
126 
128 {
129  return GEOMETRY_IMPL.GetDefaultPropertyCount();
130 }
131 
133 {
134  GEOMETRY_IMPL.GetDefaultPropertyIndices( indices );
135 }
136 
138 {
139  return GEOMETRY_IMPL.GetDefaultPropertyName( index );
140 }
141 
142 Property::Index Geometry::GetDefaultPropertyIndex( const std::string& name ) const
143 {
144  return GEOMETRY_IMPL.GetDefaultPropertyIndex( name );
145 }
146 
148 {
149  return GEOMETRY_IMPL.IsDefaultPropertyWritable( index );
150 }
151 
153 {
154  return GEOMETRY_IMPL.IsDefaultPropertyAnimatable( index );
155 }
156 
158 {
159  return GEOMETRY_IMPL.IsDefaultPropertyAConstraintInput( index );
160 }
161 
163 {
164  return GEOMETRY_IMPL.GetDefaultPropertyType( index );
165 }
166 
168  const Property::Value& propertyValue )
169 {
170  switch( index )
171  {
173  {
174  Dali::Geometry::GeometryType geometryType = static_cast<Dali::Geometry::GeometryType>(propertyValue.Get<int>());
175  if( geometryType != mGeometryType )
176  {
178  mGeometryType = geometryType;
179  }
180  break;
181  }
183  {
184  bool requiresDepthTest = propertyValue.Get<bool>();
185  if( requiresDepthTest != mRequiresDepthTest )
186  {
188  mRequiresDepthTest = requiresDepthTest;
189  }
190  break;
191  }
192  }
193 }
194 
196  const PropertyMetadata& entry,
197  const Property::Value& value )
198 {
199  GEOMETRY_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
200 }
201 
203 {
204  Property::Value value;
205 
206  switch( index )
207  {
209  {
210  if( mSceneObject )
211  {
212  value = mGeometryType;
213  }
214  break;
215  }
217  {
218  if( mSceneObject )
219  {
220  value = mRequiresDepthTest;
221  }
222  break;
223  }
224  }
225 
226  return value;
227 }
228 
230 {
231  return mSceneObject;
232 }
233 
235 {
236  return mSceneObject;
237 }
238 
240 {
241  const SceneGraph::PropertyBase* property = NULL;
242  if( OnStage() )
243  {
244  property = GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
247  index );
248  }
249 
250  return property;
251 }
252 
254 {
255  const PropertyInputImpl* property = NULL;
256 
257  if( OnStage() )
258  {
259  const SceneGraph::PropertyBase* baseProperty =
260  GEOMETRY_IMPL.GetRegisteredSceneGraphProperty ( this,
263  index );
264 
265  property = static_cast<const PropertyInputImpl*>( baseProperty );
266  }
267 
268  return property;
269 }
270 
271 bool Geometry::OnStage() const
272 {
273  return mOnStage;
274 }
275 
277 {
278  mOnStage = true;
279 }
280 
282 {
283  mOnStage = false;
284 }
285 
287 : mSceneObject( NULL ),
288  mIndexBuffer( NULL ),
289  mGeometryType(Dali::Geometry::TRIANGLES),
290  mRequiresDepthTest(false),
291  mOnStage( false )
292 {
293 }
294 
296 {
297  EventThreadServices& eventThreadServices = GetEventThreadServices();
298  SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
299 
301  AddMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
302 
303  eventThreadServices.RegisterObject( this );
304 }
305 
307 {
309  {
310  EventThreadServices& eventThreadServices = GetEventThreadServices();
311  SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
312  RemoveMessage( updateManager, updateManager.GetGeometryOwner(), *mSceneObject );
313 
314  eventThreadServices.UnregisterObject( this );
315  }
316 }
317 
318 
319 } // namespace Internal
320 } // namespace Dali
Dali Docs Home
Read more about Dali