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.
17 #include "mesh-builder.h"
22 Material CreateMaterial()
24 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
25 Material material = Material::New(shader);
30 Material CreateMaterial( Image image )
32 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
33 Material material = Material::New(shader);
35 material.AddTexture( image, "sTexture" );
40 PropertyBuffer CreatePropertyBuffer()
42 Property::Map texturedQuadVertexFormat;
43 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
44 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
46 PropertyBuffer vertexData = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
50 Geometry CreateQuadGeometry(void)
52 PropertyBuffer vertexData = CreatePropertyBuffer();
53 return CreateQuadGeometryFromBuffer( vertexData );
56 Geometry CreateQuadGeometryFromBuffer( PropertyBuffer vertexData )
58 const float halfQuadSize = .5f;
59 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
60 TexturedQuadVertex texturedQuadVertexData[4] = {
61 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
62 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
63 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
64 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
65 vertexData.SetData(texturedQuadVertexData);
67 unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
68 Property::Map indexFormat;
69 indexFormat["indices"] = Property::INTEGER;
70 PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) );
71 indices.SetData(indexData);
73 Geometry geometry = Geometry::New();
74 geometry.AddVertexBuffer( vertexData );
75 geometry.SetIndexBuffer( indices );