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/update/manager/update-manager.h>
32 GeometryPtr Geometry::New()
34 GeometryPtr geometry( new Geometry() );
35 geometry->Initialize();
39 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
41 mVertexBuffers.push_back( &vertexBuffer );
42 SceneGraph::AttachVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, *vertexBuffer.GetRenderObject() );
43 return mVertexBuffers.size() - 1u;
46 std::size_t Geometry::GetNumberOfVertexBuffers() const
48 return mVertexBuffers.size();
51 void Geometry::RemoveVertexBuffer( std::size_t index )
53 const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
54 SceneGraph::RemoveVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, renderPropertyBuffer );
56 mVertexBuffers.erase( mVertexBuffers.begin() + index );
59 void Geometry::SetIndexBuffer( const unsigned short* indices, size_t count )
61 Dali::Vector<unsigned short> indexData;
62 if( indices && count )
64 indexData.Resize( count );
65 std::copy( indices, indices + count, indexData.Begin() );
68 SceneGraph::SetIndexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, indexData );
71 void Geometry::SetType( Dali::Geometry::Type geometryType )
73 if( geometryType != mType )
75 SceneGraph::SetGeometryTypeMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, geometryType );
81 Dali::Geometry::Type Geometry::GetType() const
86 const Render::Geometry* Geometry::GetRenderObject() const
92 : mEventThreadServices( *Stage::GetCurrent() ),
93 mRenderObject( NULL ),
94 mType(Dali::Geometry::TRIANGLES)
98 void Geometry::Initialize()
100 mRenderObject = new Render::Geometry();
101 OwnerPointer< Render::Geometry > transferOwnership( mRenderObject );
102 AddGeometry( mEventThreadServices.GetUpdateManager(), transferOwnership );
105 Geometry::~Geometry()
107 if( EventThreadServices::IsCoreRunning() && mRenderObject )
109 RemoveGeometry( mEventThreadServices.GetUpdateManager(), *mRenderObject );
114 } // namespace Internal