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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
25 void sampler_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void sampler_test_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliSamplerNew01(void)
37 TestApplication application;
39 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
40 Sampler sampler = Sampler::New(image, "sTexture");
42 DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION );
46 int UtcDaliSamplerNew02(void)
48 TestApplication application;
50 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
54 int UtcDaliSamplerDownCast01(void)
56 TestApplication application;
57 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
58 Sampler sampler = Sampler::New(image, "sTexture");
60 BaseHandle handle(sampler);
61 Sampler sampler2 = Sampler::DownCast(handle);
62 DALI_TEST_EQUALS( (bool)sampler2, true, TEST_LOCATION );
66 int UtcDaliSamplerDownCast02(void)
68 TestApplication application;
71 Sampler sampler = Sampler::DownCast(handle);
72 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
77 int UtcDaliSamplerSetUniformName01(void)
79 TestApplication application;
81 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
82 Sampler sampler = Sampler::New(image, "sTexture");
83 sampler.SetUniformName( "sEffectTexture" );
85 Material material = CreateMaterial(1.0f);
86 material.AddSampler( sampler );
88 Geometry geometry = CreateQuadGeometry();
89 Renderer renderer = Renderer::New( geometry, material );
90 Actor actor = Actor::New();
91 actor.AddRenderer(renderer);
92 actor.SetParentOrigin( ParentOrigin::CENTER );
93 actor.SetSize(400, 400);
95 Stage::GetCurrent().Add( actor );
97 TestGlAbstraction& gl = application.GetGlAbstraction();
99 application.SendNotification();
100 application.Render();
103 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
104 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
110 int UtcDaliSamplerSetUniformName02(void)
112 TestApplication application;
114 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
115 Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
116 Sampler sampler1 = Sampler::New(image, "sTexture");
117 sampler1.SetUniformName( "sEffectTexture" );
119 Sampler sampler2 = Sampler::New(image2, "sTexture2");
121 Material material = CreateMaterial(1.0f);
122 material.AddSampler( sampler1 );
123 material.AddSampler( sampler2 );
125 Geometry geometry = CreateQuadGeometry();
126 Renderer renderer = Renderer::New( geometry, material );
127 Actor actor = Actor::New();
128 actor.AddRenderer(renderer);
129 actor.SetParentOrigin( ParentOrigin::CENTER );
130 actor.SetSize(400, 400);
132 Stage::GetCurrent().Add( actor );
134 TestGlAbstraction& gl = application.GetGlAbstraction();
136 application.SendNotification();
137 application.Render();
140 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
141 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
143 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
144 DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
150 int UtcDaliSamplerUniformMap01(void)
152 TestApplication application;
154 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
155 Sampler sampler = Sampler::New(image, "sTexture");
156 sampler.SetUniformName( "sEffectTexture" );
158 Material material = CreateMaterial(1.0f);
159 material.AddSampler( sampler );
161 Geometry geometry = CreateQuadGeometry();
162 Renderer renderer = Renderer::New( geometry, material );
163 Actor actor = Actor::New();
164 actor.AddRenderer(renderer);
165 actor.SetParentOrigin( ParentOrigin::CENTER );
166 actor.SetSize(400, 400);
167 Stage::GetCurrent().Add( actor );
169 float initialValue = 1.0f;
170 Property::Index widthClampIndex = sampler.RegisterProperty("width-clamp", initialValue );
171 sampler.AddUniformMapping( widthClampIndex, std::string("uWidthClamp") );
173 TestGlAbstraction& gl = application.GetGlAbstraction();
175 application.SendNotification();
176 application.Render();
178 float actualValue=0.0f;
179 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
180 DALI_TEST_EQUALS( actualValue, initialValue, TEST_LOCATION );
182 Animation animation = Animation::New(1.0f);
183 KeyFrames keyFrames = KeyFrames::New();
184 keyFrames.Add(0.0f, 0.0f);
185 keyFrames.Add(1.0f, 640.0f);
186 animation.AnimateBetween( Property( sampler, widthClampIndex ), keyFrames );
189 application.SendNotification();
190 application.Render( 500 );
192 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
193 DALI_TEST_EQUALS( actualValue, 320.0f, TEST_LOCATION );
195 application.Render( 500 );
196 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uWidthClamp", actualValue ) );
197 DALI_TEST_EQUALS( actualValue, 640.0f, TEST_LOCATION );