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 UtcDaliTextureSetMoveConstructor(void)
125 TestApplication application;
127 TextureSet textureSet = TextureSet::New();
128 DALI_TEST_CHECK( textureSet );
129 DALI_TEST_EQUALS( 1, textureSet.GetBaseObject().ReferenceCount(), TEST_LOCATION );
131 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32 );
132 textureSet.SetTexture( 0u, texture );
133 DALI_TEST_EQUALS( textureSet.GetTexture( 0u ), texture, TEST_LOCATION );
135 TextureSet move = std::move( textureSet );
136 DALI_TEST_CHECK( move );
137 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
138 DALI_TEST_EQUALS( move.GetTexture( 0u ), texture, TEST_LOCATION );
139 DALI_TEST_CHECK( !textureSet );
144 int UtcDaliTextureSetMoveAssignment(void)
146 TestApplication application;
148 TextureSet textureSet = TextureSet::New();
149 DALI_TEST_CHECK( textureSet );
150 DALI_TEST_EQUALS( 1, textureSet.GetBaseObject().ReferenceCount(), TEST_LOCATION );
152 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32 );
153 textureSet.SetTexture( 0u, texture );
154 DALI_TEST_EQUALS( textureSet.GetTexture( 0u ), texture, TEST_LOCATION );
157 move = std::move( textureSet );
158 DALI_TEST_CHECK( move );
159 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
160 DALI_TEST_EQUALS( move.GetTexture( 0u ), texture, TEST_LOCATION );
161 DALI_TEST_CHECK( !textureSet );
166 int UtcDaliTextureSetDownCast01(void)
168 TestApplication application;
169 TextureSet textureSet = TextureSet::New();
171 BaseHandle handle(textureSet);
172 TextureSet textureSet2 = TextureSet::DownCast(handle);
173 DALI_TEST_CHECK( textureSet2 );
178 int UtcDaliTextureSetDownCast02(void)
180 TestApplication application;
182 Handle handle = Handle::New(); // Create a custom object
183 TextureSet textureSet = TextureSet::DownCast(handle);
184 DALI_TEST_CHECK( !textureSet );
189 int UtcDaliTextureSetTexture01(void)
191 TestApplication application;
193 Actor actor = CreateActor( DONT_SET_SAMPLER );
195 application.GetScene().Add( actor );
197 TestGlAbstraction& gl = application.GetGlAbstraction();
199 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
200 texParameterTrace.Reset();
201 texParameterTrace.Enable( true );
202 application.SendNotification();
203 application.Render();
206 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
207 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
209 texParameterTrace.Enable( false );
212 // There are four calls to TexParameteri when the texture is first created
213 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
214 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
219 int UtcDaliTextureSetTexture02(void)
221 TestApplication application;
223 Actor actor = CreateActor(SET_SAMPLER);
225 application.GetScene().Add( actor );
227 TestGlAbstraction& gl = application.GetGlAbstraction();
229 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
230 texParameterTrace.Reset();
231 texParameterTrace.Enable( true );
232 application.SendNotification();
233 application.Render();
236 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
237 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
239 texParameterTrace.Enable( false );
242 // There are four calls to TexParameteri when the texture is first created
243 // Texture minification and magnification filters are now different than default so
244 //there should have been two extra TexParameteri calls to set the new filter mode
245 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
250 int UtcDaliTextureSetMultiple(void)
252 TestApplication application;
254 Actor actor1 = CreateActor(SET_SAMPLER);
255 Actor actor2 = CreateActor(SET_SAMPLER);
257 application.GetScene().Add( actor1 );
258 application.GetScene().Add( actor2 );
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 // For each actor there are four calls to TexParameteri when the texture is first created
276 // Texture minification and magnification filters are now different than default so
277 //there should have been two extra TexParameteri calls to set the new filter mode
278 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
283 int UtcDaliTextureSetSetSampler(void)
285 TestApplication application;
287 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
289 Shader shader = CreateShader();
290 TextureSet textureSet = CreateTextureSet( image );
292 Geometry geometry = CreateQuadGeometry();
293 Renderer renderer = Renderer::New( geometry, shader );
294 renderer.SetTextures( textureSet );
296 Actor actor = Actor::New();
297 actor.AddRenderer(renderer);
298 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
299 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
301 application.GetScene().Add( actor );
303 TestGlAbstraction& gl = application.GetGlAbstraction();
305 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
306 texParameterTrace.Reset();
307 texParameterTrace.Enable( true );
308 application.SendNotification();
309 application.Render();
312 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
313 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
315 texParameterTrace.Enable( false );
318 // There are 4 calls to TexParameteri when the texture is first created
319 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
320 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
322 texParameterTrace.Reset();
323 texParameterTrace.Enable( true );
325 Sampler sampler = Sampler::New();
326 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
327 textureSet.SetSampler( 0u, sampler );
330 application.SendNotification();
331 application.Render();
333 texParameterTrace.Enable( false );
336 //There should have been two calls to TexParameteri to set the new filtering mode
337 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
343 int UtcDaliTextureSetGetTexture(void)
345 TestApplication application;
347 TextureSet textureSet = CreateTextureSet();
348 DALI_TEST_EQUALS( textureSet.GetTexture(0), Texture(), TEST_LOCATION );
349 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
350 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
352 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
353 textureSet.SetTexture( 0u, texture );
355 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
356 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
357 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
359 textureSet.SetTexture( 2u, texture );
360 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
361 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
362 DALI_TEST_EQUALS( textureSet.GetTexture(2), texture, TEST_LOCATION );
364 textureSet.SetTexture( 2u, Texture() );
365 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
366 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
367 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
372 int UtcDaliTextureSetGetSampler(void)
374 TestApplication application;
376 TextureSet textureSet = CreateTextureSet();
377 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
378 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
379 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
381 Sampler sampler = Sampler::New();
382 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
383 textureSet.SetSampler( 0u, sampler );
385 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
386 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
387 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
389 textureSet.SetSampler( 2u, sampler );
390 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
391 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
392 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
394 textureSet.SetSampler( 2u, Sampler() );
395 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
396 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
397 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
402 int UtcDaliTextureSetGetTextureCount0(void)
404 TestApplication application;
406 TextureSet textureSet = CreateTextureSet();
407 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
409 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
410 textureSet.SetTexture( 0u, image );
411 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
413 textureSet.SetTexture( 1u, image );
414 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
416 Sampler sampler = Sampler::New();
417 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
418 textureSet.SetSampler( 2u, sampler );
419 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
421 textureSet.SetTexture( 2u, image );
422 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
423 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );
428 int UtcDaliTextureSetGetTextureCount1(void)
430 TestApplication application;
432 TextureSet textureSet = CreateTextureSet();
433 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
435 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
436 textureSet.SetTexture( 0u, texture );
437 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
439 textureSet.SetTexture( 1u, texture );
440 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
442 Sampler sampler = Sampler::New();
443 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
444 textureSet.SetSampler( 2u, sampler );
445 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
447 textureSet.SetTexture( 2u, texture );
448 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
449 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );