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.
17 #include <dali-test-suite-utils.h>
18 #include <dali/dali.h>
20 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
21 #include <test-actor-utils.h>
22 #include <test-graphics-application.h>
23 #include <test-graphics-sampler.h>
27 void utc_dali_program_startup(void)
29 test_return_value = TET_UNDEF;
31 void utc_dali_program_cleanup(void)
33 test_return_value = TET_PASS;
38 const std::string VERT_SHADER_SOURCE = "myVertShaderSource";
39 const std::string FRAG_SHADER_SOURCE =
41 "uniform sampler2D sAlbedo;\n"
42 "uniform sampler2D sMetalRoughness;\n"
43 "uniform sampler2D sNormals;\n"
44 "uniform sampler2D sAmbientOcclusion;\n"
45 "uniform mediump vec3 lightDirection;\n"
46 "in mediump vec2 vTexCoord;\n"
49 " gl_fragColor = texture2d(sAlbedo, vTexCoord) + lightDirection*texture2d(sNormals, vTexCoord);\n"
51 } //anonymous namespace
53 int UtcDaliGraphicsProgram(void)
55 TestGraphicsApplication app;
56 tet_infoline("UtcDaliProgram - check that right sampler uniforms are bound for textures");
58 Texture normals = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 16u, 16u);
59 Texture metalroughness = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 16u, 16u);
60 Texture ao = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 16u, 16u);
61 Texture albedo = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 16u, 16u);
63 TextureSet textureSet = TextureSet::New();
64 textureSet.SetTexture(0, albedo);
65 textureSet.SetTexture(1, metalroughness);
66 textureSet.SetTexture(2, normals);
67 textureSet.SetTexture(3, ao);
69 Actor actor = CreateRenderableActor2(textureSet, VERT_SHADER_SOURCE, FRAG_SHADER_SOURCE);
70 app.GetScene().Add(actor);
72 auto& gl = app.GetGlAbstraction();
73 auto& glUniformTrace = gl.GetSetUniformTrace();
74 glUniformTrace.Enable(true);
75 glUniformTrace.EnableLogging(true);
77 std::vector<ActiveUniform> activeUniforms{
78 {"sAlbedo", GL_SAMPLER_2D, 1},
79 {"sAmbientOcclusion", GL_SAMPLER_2D, 1},
80 {"sNormals", GL_SAMPLER_2D, 1},
81 {"sMetalRoughness", GL_SAMPLER_2D, 1}};
82 gl.SetActiveUniforms(activeUniforms);
84 app.SendNotification();
85 app.Render(16); // The above actor will get rendered and drawn once.
87 // Check what uniform values were set:
89 DALI_TEST_CHECK(gl.GetUniformValue("sAlbedo", value)); // First in frag shader
90 DALI_TEST_EQUALS(value, 0, TEST_LOCATION);
91 DALI_TEST_CHECK(gl.GetUniformValue("sAmbientOcclusion", value)); // 4th
92 DALI_TEST_EQUALS(value, 3, TEST_LOCATION);
93 DALI_TEST_CHECK(gl.GetUniformValue("sNormals", value)); // 3rd
94 DALI_TEST_EQUALS(value, 2, TEST_LOCATION);
95 DALI_TEST_CHECK(gl.GetUniformValue("sMetalRoughness", value)); // 2nd
96 DALI_TEST_EQUALS(value, 1, TEST_LOCATION);