2 * Copyright (c) 2020 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.
19 #include "test-actor-utils.h"
22 #include <dali/public-api/dali-core.h>
25 #include "mesh-builder.h"
33 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
34 attribute mediump vec2 aPosition;\n
35 uniform mediump mat4 uMvpMatrix;\n
36 uniform mediump vec3 uSize;\n
40 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
41 vertexPosition.xyz *= uSize;\n
42 gl_Position = uMvpMatrix * vertexPosition;\n
46 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
47 uniform lowp vec4 uColor;\n
51 gl_FragColor = uColor;\n
55 } // unnamed namespace
57 Actor CreateRenderableActor()
59 return CreateRenderableActor( Texture(), VERTEX_SHADER, FRAGMENT_SHADER );
62 Actor CreateRenderableActor( Texture texture )
64 return CreateRenderableActor( texture, VERTEX_SHADER, FRAGMENT_SHADER );
67 Actor CreateRenderableActor( Texture texture, const std::string& vertexShader, const std::string& fragmentShader )
69 // Create the geometry
70 Geometry geometry = CreateQuadGeometry();
73 Shader shader = Shader::New( vertexShader, fragmentShader );
75 // Create renderer from geometry and material
76 Renderer renderer = Renderer::New( geometry, shader );
78 // Create actor and set renderer
79 Actor actor = Actor::New();
80 actor.AddRenderer( renderer );
82 // If we a texture, then create a texture-set and add to renderer
85 TextureSet textureSet = TextureSet::New();
86 textureSet.SetTexture( 0u, texture );
87 renderer.SetTextures( textureSet );
89 // Set actor to the size of the texture if set
90 actor.SetProperty( Actor::Property::SIZE, Vector2( texture.GetWidth(), texture.GetHeight() ) );