2 * Copyright (c) 2021 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"
31 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
32 attribute mediump vec2 aPosition;\n
33 uniform mediump mat4 uMvpMatrix;\n
34 uniform mediump vec3 uSize;\n
37 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
39 vertexPosition.xyz *= uSize;
41 gl_Position = uMvpMatrix * vertexPosition;
45 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
46 uniform lowp vec4 uColor;\n
49 gl_FragColor = uColor;
53 } // unnamed namespace
55 Actor CreateRenderableActor()
57 return CreateRenderableActor(Texture(), VERTEX_SHADER, FRAGMENT_SHADER);
60 Actor CreateRenderableActor(Texture texture)
62 return CreateRenderableActor(texture, VERTEX_SHADER, FRAGMENT_SHADER);
65 Actor CreateRenderableActor(Texture texture, const std::string& vertexShader, const std::string& fragmentShader)
67 // Create the geometry
68 Geometry geometry = CreateQuadGeometry();
71 Shader shader = Shader::New(vertexShader, fragmentShader);
73 // Create renderer from geometry and material
74 Renderer renderer = Renderer::New(geometry, shader);
76 // Create actor and set renderer
77 Actor actor = Actor::New();
78 actor.AddRenderer(renderer);
80 // If we a texture, then create a texture-set and add to renderer
83 TextureSet textureSet = TextureSet::New();
84 textureSet.SetTexture(0u, texture);
85 renderer.SetTextures(textureSet);
87 // Set actor to the size of the texture if set
88 actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
94 Actor CreateRenderableActor2(TextureSet textures, const std::string& vertexShader, const std::string& fragmentShader)
96 // Create the geometry
97 Geometry geometry = CreateQuadGeometry();
100 Shader shader = Shader::New(vertexShader, fragmentShader);
102 // Create renderer from geometry and material
103 Renderer renderer = Renderer::New(geometry, shader);
105 // Create actor and set renderer
106 Actor actor = Actor::New();
107 actor.AddRenderer(renderer);
109 // If we a texture, then create a texture-set and add to renderer
112 renderer.SetTextures(textures);
114 auto texture = textures.GetTexture(0);
116 // Set actor to the size of the texture if set
117 actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
123 Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
125 Texture texture = Texture::New(type, format, width, height);
127 int bufferSize = width * height * 2;
128 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
129 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
130 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);