41bc77cb0369fccabe5cfd1cb5c044d730ceceaa
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / renderer-factory-cache.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 // CLASS HEADER
18 #include "renderer-factory-cache.h"
19
20 // Internal HEADER
21 #include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 namespace Internal
30 {
31
32 RendererFactoryCache::RendererFactoryCache()
33 {
34 }
35
36 RendererFactoryCache::~RendererFactoryCache()
37 {
38   for( int i=0; i<= SHADER_TYPE_MAX; i++)
39   {
40     if(mShader[i])
41     {
42       mShader[i].Reset();
43     }
44   }
45
46   for( int i=0; i<= GEOMETRY_TYPE_MAX; i++)
47   {
48     if(mGeometry[i])
49     {
50       mGeometry[i].Reset();
51     }
52   }
53 }
54
55
56 Geometry RendererFactoryCache::GetGeometry( GeometryType type )
57 {
58   return mGeometry[type];
59 }
60
61 void RendererFactoryCache::SaveGeometry( GeometryType type, Geometry geometry )
62 {
63   mGeometry[type] = geometry;
64 }
65
66 Shader RendererFactoryCache::GetShader( ShaderType type )
67 {
68   return mShader[type];
69 }
70
71 void RendererFactoryCache::SaveShader( ShaderType type, Shader shader )
72 {
73   mShader[type] = shader;
74 }
75
76 Geometry RendererFactoryCache::CreateQuadGeometry()
77 {
78   const float halfWidth = 0.5f;
79   const float halfHeight = 0.5f;
80   struct QuadVertex { Vector2 position;};
81   QuadVertex quadVertexData[4] =
82   {
83       { Vector2(-halfWidth, -halfHeight) },
84       { Vector2( halfWidth, -halfHeight) },
85       { Vector2(-halfWidth, halfHeight)  },
86       { Vector2( halfWidth, halfHeight)  }
87   };
88
89   Property::Map quadVertexFormat;
90   quadVertexFormat["aPosition"] = Property::VECTOR2;
91   PropertyBuffer quadVertices = PropertyBuffer::New( quadVertexFormat, 4 );
92   quadVertices.SetData(quadVertexData);
93
94   // Create the geometry object
95   Geometry geometry = Geometry::New();
96   geometry.AddVertexBuffer( quadVertices );
97   geometry.SetGeometryType( Geometry::TRIANGLE_STRIP );
98
99   return geometry;
100 }
101
102 } // namespace Internal
103
104 } // namespace Toolkit
105
106 } // namespace Dali
107