Messages and ownership of update objects
[platform/core/uifw/dali-core.git] / dali / internal / update / geometry / scene-graph-geometry.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 #include "scene-graph-geometry.h"
18
19 namespace Dali
20 {
21 namespace Internal
22 {
23 namespace SceneGraph
24 {
25
26 Geometry::Geometry()
27 : mGeometryType(Dali::Geometry::TRIANGLES)
28 {
29   // @todo MESH_REWORK Remove this code when we have working property buffers
30   // @todo It's also the wrong place to do this temporary work
31   PropertyBuffer* vertexPropertyBuffer = PropertyBuffer::NewQuadVertices();
32   mVertexBuffers.PushBack( vertexPropertyBuffer );
33
34   mIndexBuffer = PropertyBuffer::NewQuadIndices();
35 }
36
37 Geometry::~Geometry()
38 {
39   // @todo Inform renderers of deletion of buffers?
40 }
41
42 void Geometry::AddVertexBuffer( PropertyBuffer* vertexBuffer )
43 {
44   mVertexBuffers.PushBack( vertexBuffer );
45 }
46
47 void Geometry::RemoveVertexBuffer( PropertyBuffer* vertexBuffer )
48 {
49   DALI_ASSERT_DEBUG( NULL != vertexBuffer );
50
51   // Find the object and destroy it
52   for ( OwnerContainer< PropertyBuffer* >::Iterator iter = mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter )
53   {
54     PropertyBuffer* current = *iter;
55     if ( current == vertexBuffer )
56     {
57       mVertexBuffers.Erase( iter );
58       return;
59     }
60   }
61
62   DALI_ASSERT_DEBUG(false);
63 }
64
65 void Geometry::SetIndexBuffer( PropertyBuffer* indexBuffer )
66 {
67   mIndexBuffer = indexBuffer;
68 }
69
70 void Geometry::ClearIndexBuffer()
71 {
72   // @todo Actually delete, or put on Discard Queue and tell Renderer in render thread?
73   mIndexBuffer.Reset();
74 }
75
76 void Geometry::SetGeometryType( Geometry::GeometryType geometryType )
77 {
78   mGeometryType = geometryType;
79 }
80
81 const Geometry::VertexBuffers& Geometry::GetVertexBuffers()
82 {
83   return mVertexBuffers;
84 }
85
86 const PropertyBuffer& Geometry::GetIndexBuffer()
87 {
88   return *mIndexBuffer.Get();
89 }
90
91 Geometry::GeometryType Geometry::GetGeometryType( )
92 {
93   return mGeometryType;
94 }
95
96 } // namespace SceneGraph
97 } // namespace Internal
98 } // namespace Dali