2 * Copyright (c) 2016 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>
27 void texture_set_test_startup(void)
29 test_return_value = TET_UNDEF;
32 void texture_set_test_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliTextureSetNew01(void)
39 TestApplication application;
41 TextureSet textureSet = TextureSet::New();
43 DALI_TEST_CHECK( textureSet );
47 int UtcDaliTextureSetNew02(void)
49 TestApplication application;
50 TextureSet textureSet;
51 DALI_TEST_CHECK( !textureSet );
55 int UtcDaliTextureSetCopyConstructor(void)
57 TestApplication application;
59 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
60 TextureSet textureSet = TextureSet::New();
61 TextureSetImage( textureSet, 0u, image );
63 TextureSet textureSetCopy(textureSet);
65 DALI_TEST_CHECK( textureSetCopy );
70 int UtcDaliTextureSetAssignmentOperator(void)
72 TestApplication application;
73 TextureSet textureSet = TextureSet::New();
75 TextureSet textureSet2;
76 DALI_TEST_CHECK( !textureSet2 );
78 textureSet2 = textureSet;
79 DALI_TEST_CHECK( textureSet2 );
84 int UtcDaliTextureSetDownCast01(void)
86 TestApplication application;
87 TextureSet textureSet = TextureSet::New();
89 BaseHandle handle(textureSet);
90 TextureSet textureSet2 = TextureSet::DownCast(handle);
91 DALI_TEST_CHECK( textureSet2 );
96 int UtcDaliTextureSetDownCast02(void)
98 TestApplication application;
100 Handle handle = Handle::New(); // Create a custom object
101 TextureSet textureSet = TextureSet::DownCast(handle);
102 DALI_TEST_CHECK( !textureSet );
107 int UtcDaliTextureSetTexture01(void)
109 TestApplication application;
111 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
113 Shader shader = CreateShader();
114 TextureSet textureSet = CreateTextureSet();
115 textureSet.SetTexture( 0u, texture );
117 Geometry geometry = CreateQuadGeometry();
118 Renderer renderer = Renderer::New( geometry, shader );
119 renderer.SetTextures( textureSet );
121 Actor actor = Actor::New();
122 actor.AddRenderer(renderer);
123 actor.SetParentOrigin( ParentOrigin::CENTER );
124 actor.SetSize(400, 400);
126 Stage::GetCurrent().Add( actor );
128 TestGlAbstraction& gl = application.GetGlAbstraction();
130 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
131 texParameterTrace.Reset();
132 texParameterTrace.Enable( true );
133 application.SendNotification();
134 application.Render();
137 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
138 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
140 texParameterTrace.Enable( false );
143 // There are four calls to TexParameteri when the texture is first created
144 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
145 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
150 int UtcDaliTextureSetTexture02(void)
152 TestApplication application;
154 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
156 Shader shader = CreateShader();
157 TextureSet textureSet = CreateTextureSet();
159 Sampler sampler = Sampler::New();
160 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
161 textureSet.SetTexture( 0u, texture );
162 textureSet.SetSampler( 0u, sampler );
164 Geometry geometry = CreateQuadGeometry();
165 Renderer renderer = Renderer::New( geometry, shader );
166 renderer.SetTextures( textureSet );
168 Actor actor = Actor::New();
169 actor.AddRenderer(renderer);
170 actor.SetParentOrigin( ParentOrigin::CENTER );
171 actor.SetSize(400, 400);
173 Stage::GetCurrent().Add( actor );
175 TestGlAbstraction& gl = application.GetGlAbstraction();
177 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
178 texParameterTrace.Reset();
179 texParameterTrace.Enable( true );
180 application.SendNotification();
181 application.Render();
184 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
185 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
187 texParameterTrace.Enable( false );
190 // There are four calls to TexParameteri when the texture is first created
191 // Texture minification and magnification filters are now different than default so
192 //there should have been two extra TexParameteri calls to set the new filter mode
193 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
197 int UtcDaliTextureSetSetSampler(void)
199 TestApplication application;
201 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
203 Shader shader = CreateShader();
204 TextureSet textureSet = CreateTextureSet( image );
206 Geometry geometry = CreateQuadGeometry();
207 Renderer renderer = Renderer::New( geometry, shader );
208 renderer.SetTextures( textureSet );
210 Actor actor = Actor::New();
211 actor.AddRenderer(renderer);
212 actor.SetParentOrigin( ParentOrigin::CENTER );
213 actor.SetSize(400, 400);
215 Stage::GetCurrent().Add( actor );
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 // There are 4 calls to TexParameteri when the texture is first created
233 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
234 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
236 texParameterTrace.Reset();
237 texParameterTrace.Enable( true );
239 Sampler sampler = Sampler::New();
240 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
241 textureSet.SetSampler( 0u, sampler );
244 application.SendNotification();
245 application.Render();
247 texParameterTrace.Enable( false );
250 //There should have been two calls to TexParameteri to set the new filtering mode
251 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
257 int UtcDaliTextureSetGetTexture(void)
259 TestApplication application;
261 TextureSet textureSet = CreateTextureSet();
262 DALI_TEST_EQUALS( textureSet.GetTexture(0), Texture(), TEST_LOCATION );
263 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
264 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
266 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
267 textureSet.SetTexture( 0u, texture );
269 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
270 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
271 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
273 textureSet.SetTexture( 2u, texture );
274 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
275 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
276 DALI_TEST_EQUALS( textureSet.GetTexture(2), texture, TEST_LOCATION );
278 textureSet.SetTexture( 2u, Texture() );
279 DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
280 DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
281 DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
286 int UtcDaliTextureSetGetSampler(void)
288 TestApplication application;
290 TextureSet textureSet = CreateTextureSet();
291 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
292 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
293 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
295 Sampler sampler = Sampler::New();
296 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
297 textureSet.SetSampler( 0u, sampler );
299 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
300 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
301 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
303 textureSet.SetSampler( 2u, sampler );
304 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
305 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
306 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
308 textureSet.SetSampler( 2u, Sampler() );
309 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
310 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
311 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
316 int UtcDaliTextureSetGetTextureCount0(void)
318 TestApplication application;
320 TextureSet textureSet = CreateTextureSet();
321 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
323 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
324 TextureSetImage( textureSet, 0u, image );
325 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
327 TextureSetImage( textureSet, 1u, image );
328 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
330 Sampler sampler = Sampler::New();
331 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
332 textureSet.SetSampler( 2u, sampler );
333 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
335 TextureSetImage( textureSet, 2u, image );
336 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
337 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );
342 int UtcDaliTextureSetGetTextureCount1(void)
344 TestApplication application;
346 TextureSet textureSet = CreateTextureSet();
347 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
349 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
350 textureSet.SetTexture( 0u, texture );
351 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
353 textureSet.SetTexture( 1u, texture );
354 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
356 Sampler sampler = Sampler::New();
357 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
358 textureSet.SetSampler( 2u, sampler );
359 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
361 textureSet.SetTexture( 2u, texture );
362 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
363 DALI_TEST_EQUALS( textureSet.GetSampler(2u), sampler, TEST_LOCATION );