ef8131f2fb3e2379deffb7ea1cd6d769f6862e09
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / geometry-impl.cpp
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
22 #include <dali/public-api/object/type-registry.h>
23
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/update/manager/update-manager.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31
32 GeometryPtr Geometry::New()
33 {
34   GeometryPtr geometry( new Geometry() );
35   geometry->Initialize();
36   return geometry;
37 }
38
39 std::size_t Geometry::AddVertexBuffer( PropertyBuffer& vertexBuffer )
40 {
41   mVertexBuffers.push_back( &vertexBuffer );
42   SceneGraph::AttachVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, *vertexBuffer.GetRenderObject() );
43   return mVertexBuffers.size() - 1u;
44 }
45
46 std::size_t Geometry::GetNumberOfVertexBuffers() const
47 {
48   return mVertexBuffers.size();
49 }
50
51 void Geometry::RemoveVertexBuffer( std::size_t index )
52 {
53   const Render::PropertyBuffer& renderPropertyBuffer = static_cast<const Render::PropertyBuffer&>( *(mVertexBuffers[index]->GetRenderObject()) );
54   SceneGraph::RemoveVertexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, renderPropertyBuffer );
55
56   mVertexBuffers.erase( mVertexBuffers.begin() + index );
57 }
58
59 void Geometry::SetIndexBuffer( const uint16_t* indices, size_t count )
60 {
61   Dali::Vector<uint16_t> indexData;
62   if( indices && count )
63   {
64     indexData.Resize( count );
65     std::copy( indices, indices + count, indexData.Begin() );
66   }
67
68   SceneGraph::SetIndexBufferMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, indexData );
69 }
70
71 void Geometry::SetType( Dali::Geometry::Type geometryType )
72 {
73   if( geometryType != mType )
74   {
75     SceneGraph::SetGeometryTypeMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, geometryType );
76
77     mType = geometryType;
78   }
79 }
80
81 Dali::Geometry::Type Geometry::GetType() const
82 {
83   return mType;
84 }
85
86 const Render::Geometry* Geometry::GetRenderObject() const
87 {
88   return mRenderObject;
89 }
90
91 Geometry::Geometry()
92 : mEventThreadServices( *Stage::GetCurrent() ),
93   mRenderObject( NULL ),
94   mType(Dali::Geometry::TRIANGLES)
95 {
96 }
97
98 void Geometry::Initialize()
99 {
100   mRenderObject = new Render::Geometry();
101   OwnerPointer< Render::Geometry > transferOwnership( mRenderObject );
102   AddGeometry( mEventThreadServices.GetUpdateManager(), transferOwnership );
103 }
104
105 Geometry::~Geometry()
106 {
107   if( EventThreadServices::IsCoreRunning() && mRenderObject )
108   {
109     RemoveGeometry( mEventThreadServices.GetUpdateManager(), *mRenderObject );
110   }
111 }
112
113
114 } // namespace Internal
115 } // namespace Dali