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 <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
36 Actor CreateActor( SetSampler setSamplerOption )
38 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
40 Shader shader = CreateShader();
41 TextureSet textureSet = CreateTextureSet();
43 Sampler sampler = Sampler::New();
44 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
45 textureSet.SetTexture( 0u, texture );
46 if( setSamplerOption == SET_SAMPLER )
48 textureSet.SetSampler( 0u, sampler );
51 Geometry geometry = CreateQuadGeometry();
52 Renderer renderer = Renderer::New( geometry, shader );
53 renderer.SetTextures( textureSet );
55 Actor actor = Actor::New();
56 actor.AddRenderer(renderer);
57 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
58 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
66 void texture_set_test_startup(void)
68 test_return_value = TET_UNDEF;
71 void texture_set_test_cleanup(void)
73 test_return_value = TET_PASS;
76 int UtcDaliTextureSetNew01(void)
78 TestApplication application;
80 TextureSet textureSet = TextureSet::New();
82 DALI_TEST_CHECK( textureSet );
86 int UtcDaliTextureSetNew02(void)
88 TestApplication application;
89 TextureSet textureSet;
90 DALI_TEST_CHECK( !textureSet );
94 int UtcDaliTextureSetCopyConstructor(void)
96 TestApplication application;
98 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32);
99 TextureSet textureSet = TextureSet::New();
100 textureSet.SetTexture( 0u, image );
102 TextureSet textureSetCopy(textureSet);
104 DALI_TEST_CHECK( textureSetCopy );
109 int UtcDaliTextureSetAssignmentOperator(void)
111 TestApplication application;
112 TextureSet textureSet = TextureSet::New();
114 TextureSet textureSet2;
115 DALI_TEST_CHECK( !textureSet2 );
117 textureSet2 = textureSet;
118 DALI_TEST_CHECK( textureSet2 );
123 int UtcDaliTextureSetDownCast01(void)
125 TestApplication application;
126 TextureSet textureSet = TextureSet::New();
128 BaseHandle handle(textureSet);
129 TextureSet textureSet2 = TextureSet::DownCast(handle);
130 DALI_TEST_CHECK( textureSet2 );
135 int UtcDaliTextureSetDownCast02(void)
137 TestApplication application;
139 Handle handle = Handle::New(); // Create a custom object
140 TextureSet textureSet = TextureSet::DownCast(handle);
141 DALI_TEST_CHECK( !textureSet );
146 int UtcDaliTextureSetTexture01(void)
148 TestApplication application;
150 Actor actor = CreateActor( DONT_SET_SAMPLER );
152 application.GetScene().Add( actor );
154 TestGlAbstraction& gl = application.GetGlAbstraction();
156 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
157 texParameterTrace.Reset();
158 texParameterTrace.Enable( true );
159 application.SendNotification();
160 application.Render();
163 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
164 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
166 texParameterTrace.Enable( false );
169 // There are four calls to TexParameteri when the texture is first created
170 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
171 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
176 int UtcDaliTextureSetTexture02(void)
178 TestApplication application;
180 Actor actor = CreateActor(SET_SAMPLER);
182 application.GetScene().Add( actor );
184 TestGlAbstraction& gl = application.GetGlAbstraction();
186 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
187 texParameterTrace.Reset();
188 texParameterTrace.Enable( true );
189 application.SendNotification();
190 application.Render();
193 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
194 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
196 texParameterTrace.Enable( false );
199 // There are four calls to TexParameteri when the texture is first created
200 // Texture minification and magnification filters are now different than default so
201 //there should have been two extra TexParameteri calls to set the new filter mode
202 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
207 int UtcDaliTextureSetMultiple(void)
209 TestApplication application;
211 Actor actor1 = CreateActor(SET_SAMPLER);
212 Actor actor2 = CreateActor(SET_SAMPLER);
214 application.GetScene().Add( actor1 );
215 application.GetScene().Add( actor2 );
217 TestGlAbstraction& gl = application.GetGlAbstraction();
219 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
220 texParameterTrace.Reset();
221 texParameterTrace.Enable( true );
222 application.SendNotification();
223 application.Render();
226 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
227 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
229 texParameterTrace.Enable( false );
232 // For each actor there are four calls to TexParameteri when the texture is first created
233 // Texture minification and magnification filters are now different than default so
234 //there should have been two extra TexParameteri calls to set the new filter mode
235 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
240 int UtcDaliTextureSetSetSampler(void)
242 TestApplication application;
244 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
246 Shader shader = CreateShader();
247 TextureSet textureSet = CreateTextureSet( image );
249 Geometry geometry = CreateQuadGeometry();
250 Renderer renderer = Renderer::New( geometry, shader );
251 renderer.SetTextures( textureSet );
253 Actor actor = Actor::New();
254 actor.AddRenderer(renderer);
255 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
256 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
258 application.GetScene().Add( actor );
260 TestGlAbstraction& gl = application.GetGlAbstraction();
262 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
263 texParameterTrace.Reset();
264 texParameterTrace.Enable( true );
265 application.SendNotification();
266 application.Render();
269 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
270 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
272 texParameterTrace.Enable( false );
275 // There are 4 calls to TexParameteri when the texture is first created
276 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
277 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
279 texParameterTrace.Reset();
280 texParameterTrace.Enable( true );
282 Sampler sampler = Sampler::New();
283 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
284 textureSet.SetSampler( 0u, sampler );
287 application.SendNotification();
288 application.Render();
290 texParameterTrace.Enable( false );
293 //There should have been two calls to TexParameteri to set the new filtering mode
294 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
300 int UtcDaliTextureSetGetTexture(void)
302 TestApplication application;
304 TextureSet textureSet = CreateTextureSet();
305 DALI_TEST_EQUALS( textureSet.GetTexture(0), Texture(), TEST_LOCATION );
306 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
307 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
309 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
310 textureSet.SetTexture( 0u, texture );
312 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
313 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
314 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
316 textureSet.SetTexture( 2u, texture );
317 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
318 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
319 DALI_TEST_EQUALS( textureSet.GetTexture(2), texture, TEST_LOCATION );
321 textureSet.SetTexture( 2u, Texture() );
322 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
323 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
324 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
329 int UtcDaliTextureSetGetSampler(void)
331 TestApplication application;
333 TextureSet textureSet = CreateTextureSet();
334 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
335 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
336 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
338 Sampler sampler = Sampler::New();
339 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
340 textureSet.SetSampler( 0u, sampler );
342 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
343 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
344 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
346 textureSet.SetSampler( 2u, sampler );
347 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
348 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
349 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
351 textureSet.SetSampler( 2u, Sampler() );
352 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
353 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
354 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
359 int UtcDaliTextureSetGetTextureCount0(void)
361 TestApplication application;
363 TextureSet textureSet = CreateTextureSet();
364 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
366 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
367 textureSet.SetTexture( 0u, image );
368 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
370 textureSet.SetTexture( 1u, image );
371 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
373 Sampler sampler = Sampler::New();
374 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
375 textureSet.SetSampler( 2u, sampler );
376 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
378 textureSet.SetTexture( 2u, image );
379 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
380 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );
385 int UtcDaliTextureSetGetTextureCount1(void)
387 TestApplication application;
389 TextureSet textureSet = CreateTextureSet();
390 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
392 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
393 textureSet.SetTexture( 0u, texture );
394 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
396 textureSet.SetTexture( 1u, texture );
397 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
399 Sampler sampler = Sampler::New();
400 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
401 textureSet.SetSampler( 2u, sampler );
402 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
404 textureSet.SetTexture( 2u, texture );
405 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
406 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );