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>
20 #include <dali/devel-api/images/texture-set-image.h>
23 #include <dali-test-suite-utils.h>
24 #include <mesh-builder.h>
37 Actor CreateActor( SetSampler setSamplerOption )
39 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
41 Shader shader = CreateShader();
42 TextureSet textureSet = CreateTextureSet();
44 Sampler sampler = Sampler::New();
45 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
46 textureSet.SetTexture( 0u, texture );
47 if( setSamplerOption == SET_SAMPLER )
49 textureSet.SetSampler( 0u, sampler );
52 Geometry geometry = CreateQuadGeometry();
53 Renderer renderer = Renderer::New( geometry, shader );
54 renderer.SetTextures( textureSet );
56 Actor actor = Actor::New();
57 actor.AddRenderer(renderer);
58 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
59 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
67 void texture_set_test_startup(void)
69 test_return_value = TET_UNDEF;
72 void texture_set_test_cleanup(void)
74 test_return_value = TET_PASS;
77 int UtcDaliTextureSetNew01(void)
79 TestApplication application;
81 TextureSet textureSet = TextureSet::New();
83 DALI_TEST_CHECK( textureSet );
87 int UtcDaliTextureSetNew02(void)
89 TestApplication application;
90 TextureSet textureSet;
91 DALI_TEST_CHECK( !textureSet );
95 int UtcDaliTextureSetCopyConstructor(void)
97 TestApplication application;
99 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 32, 32);
100 TextureSet textureSet = TextureSet::New();
101 textureSet.SetTexture( 0u, image );
103 TextureSet textureSetCopy(textureSet);
105 DALI_TEST_CHECK( textureSetCopy );
110 int UtcDaliTextureSetAssignmentOperator(void)
112 TestApplication application;
113 TextureSet textureSet = TextureSet::New();
115 TextureSet textureSet2;
116 DALI_TEST_CHECK( !textureSet2 );
118 textureSet2 = textureSet;
119 DALI_TEST_CHECK( textureSet2 );
124 int UtcDaliTextureSetDownCast01(void)
126 TestApplication application;
127 TextureSet textureSet = TextureSet::New();
129 BaseHandle handle(textureSet);
130 TextureSet textureSet2 = TextureSet::DownCast(handle);
131 DALI_TEST_CHECK( textureSet2 );
136 int UtcDaliTextureSetDownCast02(void)
138 TestApplication application;
140 Handle handle = Handle::New(); // Create a custom object
141 TextureSet textureSet = TextureSet::DownCast(handle);
142 DALI_TEST_CHECK( !textureSet );
147 int UtcDaliTextureSetTexture01(void)
149 TestApplication application;
151 Actor actor = CreateActor( DONT_SET_SAMPLER );
153 Stage::GetCurrent().Add( actor );
155 TestGlAbstraction& gl = application.GetGlAbstraction();
157 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
158 texParameterTrace.Reset();
159 texParameterTrace.Enable( true );
160 application.SendNotification();
161 application.Render();
164 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
165 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
167 texParameterTrace.Enable( false );
170 // There are four calls to TexParameteri when the texture is first created
171 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
172 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
177 int UtcDaliTextureSetTexture02(void)
179 TestApplication application;
181 Actor actor = CreateActor(SET_SAMPLER);
183 Stage::GetCurrent().Add( actor );
185 TestGlAbstraction& gl = application.GetGlAbstraction();
187 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
188 texParameterTrace.Reset();
189 texParameterTrace.Enable( true );
190 application.SendNotification();
191 application.Render();
194 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
195 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
197 texParameterTrace.Enable( false );
200 // There are four calls to TexParameteri when the texture is first created
201 // Texture minification and magnification filters are now different than default so
202 //there should have been two extra TexParameteri calls to set the new filter mode
203 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
208 int UtcDaliTextureSetMultiple(void)
210 TestApplication application;
212 Actor actor1 = CreateActor(SET_SAMPLER);
213 Actor actor2 = CreateActor(SET_SAMPLER);
215 Stage::GetCurrent().Add( actor1 );
216 Stage::GetCurrent().Add( actor2 );
218 TestGlAbstraction& gl = application.GetGlAbstraction();
220 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
221 texParameterTrace.Reset();
222 texParameterTrace.Enable( true );
223 application.SendNotification();
224 application.Render();
227 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
228 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
230 texParameterTrace.Enable( false );
233 // For each actor there are four calls to TexParameteri when the texture is first created
234 // Texture minification and magnification filters are now different than default so
235 //there should have been two extra TexParameteri calls to set the new filter mode
236 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
241 int UtcDaliTextureSetSetSampler(void)
243 TestApplication application;
245 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
247 Shader shader = CreateShader();
248 TextureSet textureSet = CreateTextureSet( image );
250 Geometry geometry = CreateQuadGeometry();
251 Renderer renderer = Renderer::New( geometry, shader );
252 renderer.SetTextures( textureSet );
254 Actor actor = Actor::New();
255 actor.AddRenderer(renderer);
256 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
257 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
259 Stage::GetCurrent().Add( actor );
261 TestGlAbstraction& gl = application.GetGlAbstraction();
263 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
264 texParameterTrace.Reset();
265 texParameterTrace.Enable( true );
266 application.SendNotification();
267 application.Render();
270 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
271 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
273 texParameterTrace.Enable( false );
276 // There are 4 calls to TexParameteri when the texture is first created
277 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
278 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
280 texParameterTrace.Reset();
281 texParameterTrace.Enable( true );
283 Sampler sampler = Sampler::New();
284 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
285 textureSet.SetSampler( 0u, sampler );
288 application.SendNotification();
289 application.Render();
291 texParameterTrace.Enable( false );
294 //There should have been two calls to TexParameteri to set the new filtering mode
295 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
301 int UtcDaliTextureSetGetTexture(void)
303 TestApplication application;
305 TextureSet textureSet = CreateTextureSet();
306 DALI_TEST_EQUALS( textureSet.GetTexture(0), Texture(), TEST_LOCATION );
307 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
308 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
310 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
311 textureSet.SetTexture( 0u, texture );
313 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
314 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
315 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
317 textureSet.SetTexture( 2u, texture );
318 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
319 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
320 DALI_TEST_EQUALS( textureSet.GetTexture(2), texture, TEST_LOCATION );
322 textureSet.SetTexture( 2u, Texture() );
323 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
324 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
325 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
330 int UtcDaliTextureSetGetSampler(void)
332 TestApplication application;
334 TextureSet textureSet = CreateTextureSet();
335 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
336 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
337 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
339 Sampler sampler = Sampler::New();
340 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
341 textureSet.SetSampler( 0u, sampler );
343 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
344 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
345 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
347 textureSet.SetSampler( 2u, sampler );
348 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
349 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
350 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
352 textureSet.SetSampler( 2u, Sampler() );
353 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
354 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
355 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
360 int UtcDaliTextureSetGetTextureCount0(void)
362 TestApplication application;
364 TextureSet textureSet = CreateTextureSet();
365 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
367 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
368 textureSet.SetTexture( 0u, image );
369 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
371 textureSet.SetTexture( 1u, image );
372 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
374 Sampler sampler = Sampler::New();
375 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
376 textureSet.SetSampler( 2u, sampler );
377 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
379 textureSet.SetTexture( 2u, image );
380 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
381 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );
386 int UtcDaliTextureSetGetTextureCount1(void)
388 TestApplication application;
390 TextureSet textureSet = CreateTextureSet();
391 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
393 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
394 textureSet.SetTexture( 0u, texture );
395 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
397 textureSet.SetTexture( 1u, texture );
398 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
400 Sampler sampler = Sampler::New();
401 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
402 textureSet.SetSampler( 2u, sampler );
403 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
405 textureSet.SetTexture( 2u, texture );
406 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
407 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );