Merge branch 'devel/new_mesh' into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / dali-test-suite-utils / mesh-builder.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 "mesh-builder.h"
18
19 namespace Dali
20 {
21
22 Material CreateMaterial(float opacity)
23 {
24   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
25   Material material = Material::New(shader);
26
27   Vector4 color = Color::WHITE;
28   color.a = opacity;
29   material.SetProperty(Material::Property::COLOR, color);
30   return material;
31 }
32
33 Material CreateMaterial(float opacity, Image image)
34 {
35   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
36   Material material = Material::New(shader);
37
38   Vector4 color = Color::WHITE;
39   color.a = opacity;
40   material.SetProperty(Material::Property::COLOR, color);
41
42   Sampler sampler = Sampler::New( image, "sTexture" );
43   material.AddSampler( sampler );
44
45   return material;
46 }
47
48 PropertyBuffer CreatePropertyBuffer()
49 {
50   Property::Map texturedQuadVertexFormat;
51   texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
52   texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
53
54   PropertyBuffer vertexData = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
55   return vertexData;
56 }
57
58 Geometry CreateQuadGeometry(void)
59 {
60   PropertyBuffer vertexData = CreatePropertyBuffer();
61   return CreateQuadGeometryFromBuffer( vertexData );
62 }
63
64 Geometry CreateQuadGeometryFromBuffer( PropertyBuffer vertexData )
65 {
66   const float halfQuadSize = .5f;
67   struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
68   TexturedQuadVertex texturedQuadVertexData[4] = {
69     { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
70     { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
71     { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
72     { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
73   vertexData.SetData(texturedQuadVertexData);
74
75   unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
76   Property::Map indexFormat;
77   indexFormat["indices"] = Property::UNSIGNED_INTEGER;
78   PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) );
79   indices.SetData(indexData);
80
81   Geometry geometry = Geometry::New();
82   geometry.AddVertexBuffer( vertexData );
83   geometry.SetIndexBuffer( indices );
84
85   return geometry;
86 }
87
88
89
90 } // namespace Dali