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>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
34 void texture_set_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void texture_set_test_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliTextureSetNew01(void)
46 TestApplication application;
48 TextureSet textureSet = TextureSet::New();
50 DALI_TEST_CHECK( textureSet );
54 int UtcDaliTextureSetNew02(void)
56 TestApplication application;
57 TextureSet textureSet;
58 DALI_TEST_CHECK( !textureSet );
62 int UtcDaliTextureSetCopyConstructor(void)
64 TestApplication application;
66 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
67 TextureSet textureSet = TextureSet::New();
68 textureSet.SetImage( 0u, image );
70 TextureSet textureSetCopy(textureSet);
72 DALI_TEST_CHECK( textureSetCopy );
77 int UtcDaliTextureSetAssignmentOperator(void)
79 TestApplication application;
80 TextureSet textureSet = TextureSet::New();
82 TextureSet textureSet2;
83 DALI_TEST_CHECK( !textureSet2 );
85 textureSet2 = textureSet;
86 DALI_TEST_CHECK( textureSet2 );
91 int UtcDaliTextureSetDownCast01(void)
93 TestApplication application;
94 TextureSet textureSet = TextureSet::New();
96 BaseHandle handle(textureSet);
97 TextureSet textureSet2 = TextureSet::DownCast(handle);
98 DALI_TEST_CHECK( textureSet2 );
103 int UtcDaliTextureSetDownCast02(void)
105 TestApplication application;
107 Handle handle = Handle::New(); // Create a custom object
108 TextureSet textureSet = TextureSet::DownCast(handle);
109 DALI_TEST_CHECK( !textureSet );
113 int UtcDaliTextureSetConstraint(void)
115 TestApplication application;
117 tet_infoline("Test that a custom texture set property can be constrained");
119 Shader shader = Shader::New( "VertexSource", "FragmentSource");
120 TextureSet textureSet = TextureSet::New();
122 Geometry geometry = CreateQuadGeometry();
123 Renderer renderer = Renderer::New( geometry, shader );
124 renderer.SetTextures( textureSet );
126 Actor actor = Actor::New();
127 actor.AddRenderer(renderer);
128 actor.SetSize(400, 400);
129 Stage::GetCurrent().Add(actor);
131 Vector4 initialColor = Color::WHITE;
132 Property::Index colorIndex = textureSet.RegisterProperty( "uFadeColor", initialColor );
134 application.SendNotification();
135 application.Render(0);
136 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
139 Constraint constraint = Constraint::New<Vector4>( textureSet, colorIndex, TestConstraintNoBlue );
141 application.SendNotification();
142 application.Render(0);
144 // Expect no blue component in either buffer - yellow
145 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
146 application.Render(0);
147 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
149 textureSet.RemoveConstraints();
150 textureSet.SetProperty(colorIndex, Color::WHITE );
151 application.SendNotification();
152 application.Render(0);
153 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
158 int UtcDaliTextureSetConstraint02(void)
160 TestApplication application;
162 tet_infoline("Test that a uniform map texture set property can be constrained");
164 Shader shader = Shader::New( "VertexSource", "FragmentSource");
165 TextureSet textureSet = TextureSet::New();
167 Geometry geometry = CreateQuadGeometry();
168 Renderer renderer = Renderer::New( geometry, shader );
169 renderer.SetTextures( textureSet );
171 Actor actor = Actor::New();
172 actor.AddRenderer(renderer);
173 actor.SetSize(400, 400);
174 Stage::GetCurrent().Add(actor);
175 application.SendNotification();
176 application.Render(0);
178 Vector4 initialColor = Color::WHITE;
179 Property::Index colorIndex = textureSet.RegisterProperty( "uFadeColor", initialColor );
181 TestGlAbstraction& gl = application.GetGlAbstraction();
183 application.SendNotification();
184 application.Render(0);
186 Vector4 actualValue(Vector4::ZERO);
187 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
188 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
191 Constraint constraint = Constraint::New<Vector4>( textureSet, colorIndex, TestConstraintNoBlue );
193 application.SendNotification();
194 application.Render(0);
196 // Expect no blue component in either buffer - yellow
197 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
198 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
200 application.Render(0);
201 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
202 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
204 textureSet.RemoveConstraints();
205 textureSet.SetProperty(colorIndex, Color::WHITE );
206 application.SendNotification();
207 application.Render(0);
209 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
210 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
215 int UtcDaliTextureSetAnimatedProperty01(void)
217 TestApplication application;
219 tet_infoline("Test that a non-uniform texture set property can be animated");
221 Shader shader = Shader::New( "VertexSource", "FragmentSource");
222 TextureSet textureSet = TextureSet::New();
224 Geometry geometry = CreateQuadGeometry();
225 Renderer renderer = Renderer::New( geometry, shader );
226 renderer.SetTextures( textureSet );
228 Actor actor = Actor::New();
229 actor.AddRenderer(renderer);
230 actor.SetSize(400, 400);
231 Stage::GetCurrent().Add(actor);
233 Vector4 initialColor = Color::WHITE;
234 Property::Index colorIndex = textureSet.RegisterProperty( "uFadeColor", initialColor );
236 application.SendNotification();
237 application.Render(0);
238 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
240 Animation animation = Animation::New(1.0f);
241 KeyFrames keyFrames = KeyFrames::New();
242 keyFrames.Add(0.0f, initialColor);
243 keyFrames.Add(1.0f, Color::TRANSPARENT);
244 animation.AnimateBetween( Property( textureSet, colorIndex ), keyFrames );
247 application.SendNotification();
248 application.Render(500);
250 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
252 application.Render(500);
254 DALI_TEST_EQUALS( textureSet.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
259 int UtcDaliTextureSetAnimatedProperty02(void)
261 TestApplication application;
263 tet_infoline("Test that a uniform map texture set property can be animated");
265 Shader shader = Shader::New( "VertexSource", "FragmentSource");
266 TextureSet textureSet = TextureSet::New();
268 Geometry geometry = CreateQuadGeometry();
269 Renderer renderer = Renderer::New( geometry, shader );
270 renderer.SetTextures( textureSet );
272 Actor actor = Actor::New();
273 actor.AddRenderer(renderer);
274 actor.SetSize(400, 400);
275 Stage::GetCurrent().Add(actor);
276 application.SendNotification();
277 application.Render(0);
279 Vector4 initialColor = Color::WHITE;
280 Property::Index colorIndex = textureSet.RegisterProperty( "uFadeColor", initialColor );
282 TestGlAbstraction& gl = application.GetGlAbstraction();
284 application.SendNotification();
285 application.Render(0);
287 Vector4 actualValue(Vector4::ZERO);
288 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
289 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
291 Animation animation = Animation::New(1.0f);
292 KeyFrames keyFrames = KeyFrames::New();
293 keyFrames.Add(0.0f, initialColor);
294 keyFrames.Add(1.0f, Color::TRANSPARENT);
295 animation.AnimateBetween( Property( textureSet, colorIndex ), keyFrames );
298 application.SendNotification();
299 application.Render(500);
301 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
302 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
304 application.Render(500);
305 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
306 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
311 int UtcDaliTextureSetSetImage01(void)
313 TestApplication application;
315 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
317 Shader shader = CreateShader();
318 TextureSet textureSet = CreateTextureSet();
319 textureSet.SetImage( 0u, image );
321 Geometry geometry = CreateQuadGeometry();
322 Renderer renderer = Renderer::New( geometry, shader );
323 renderer.SetTextures( textureSet );
325 Actor actor = Actor::New();
326 actor.AddRenderer(renderer);
327 actor.SetParentOrigin( ParentOrigin::CENTER );
328 actor.SetSize(400, 400);
330 Stage::GetCurrent().Add( actor );
332 TestGlAbstraction& gl = application.GetGlAbstraction();
334 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
335 texParameterTrace.Reset();
336 texParameterTrace.Enable( true );
337 application.SendNotification();
338 application.Render();
341 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
342 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
344 texParameterTrace.Enable( false );
347 // There are three calls to TexParameteri when the texture is first created
348 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
349 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
354 int UtcDaliTextureSetSetImage02(void)
356 TestApplication application;
358 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
360 Shader shader = CreateShader();
361 TextureSet textureSet = CreateTextureSet();
363 Sampler sampler = Sampler::New();
364 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
365 textureSet.SetImage( 0u, image );
366 textureSet.SetSampler( 0u, sampler );
368 Geometry geometry = CreateQuadGeometry();
369 Renderer renderer = Renderer::New( geometry, shader );
370 renderer.SetTextures( textureSet );
372 Actor actor = Actor::New();
373 actor.AddRenderer(renderer);
374 actor.SetParentOrigin( ParentOrigin::CENTER );
375 actor.SetSize(400, 400);
377 Stage::GetCurrent().Add( actor );
379 TestGlAbstraction& gl = application.GetGlAbstraction();
381 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
382 texParameterTrace.Reset();
383 texParameterTrace.Enable( true );
384 application.SendNotification();
385 application.Render();
388 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
389 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
391 texParameterTrace.Enable( false );
394 // There are three calls to TexParameteri when the texture is first created
395 // Texture minification and magnification filters are now different than default so
396 //there should have been two extra TexParameteri calls to set the new filter mode
397 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
402 int UtcDaliTextureSetSetSampler(void)
404 TestApplication application;
406 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
408 Shader shader = CreateShader();
409 TextureSet textureSet = CreateTextureSet( image );
411 Geometry geometry = CreateQuadGeometry();
412 Renderer renderer = Renderer::New( geometry, shader );
413 renderer.SetTextures( textureSet );
415 Actor actor = Actor::New();
416 actor.AddRenderer(renderer);
417 actor.SetParentOrigin( ParentOrigin::CENTER );
418 actor.SetSize(400, 400);
420 Stage::GetCurrent().Add( actor );
422 TestGlAbstraction& gl = application.GetGlAbstraction();
424 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
425 texParameterTrace.Reset();
426 texParameterTrace.Enable( true );
427 application.SendNotification();
428 application.Render();
431 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
432 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
434 texParameterTrace.Enable( false );
437 // There are three calls to TexParameteri when the texture is first created
438 // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
439 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
441 texParameterTrace.Reset();
442 texParameterTrace.Enable( true );
444 Sampler sampler = Sampler::New();
445 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
446 textureSet.SetSampler( 0u, sampler );
449 application.SendNotification();
450 application.Render();
452 texParameterTrace.Enable( false );
455 //There should have been two calls to TexParameteri to set the new filtering mode
456 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
462 int UtcDaliTextureSetGetImage(void)
464 TestApplication application;
466 TextureSet textureSet = CreateTextureSet();
467 DALI_TEST_EQUALS( textureSet.GetImage(0), Image(), TEST_LOCATION );
468 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
469 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
471 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
472 textureSet.SetImage( 0u, image );
474 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
475 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
476 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
478 textureSet.SetImage( 2u, image );
479 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
480 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
481 DALI_TEST_EQUALS( textureSet.GetImage(2), image, TEST_LOCATION );
483 textureSet.SetImage( 2u, Image() );
484 DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
485 DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
486 DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
491 int UtcDaliTextureSetGetSampler(void)
493 TestApplication application;
495 TextureSet textureSet = CreateTextureSet();
496 DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
497 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
498 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
500 Sampler sampler = Sampler::New();
501 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
502 textureSet.SetSampler( 0u, sampler );
504 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
505 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
506 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
508 textureSet.SetSampler( 2u, sampler );
509 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
510 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
511 DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
513 textureSet.SetSampler( 2u, Sampler() );
514 DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
515 DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
516 DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
521 int UtcDaliTextureSetGetTextureCount(void)
523 TestApplication application;
525 TextureSet textureSet = CreateTextureSet();
526 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
528 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
529 textureSet.SetImage( 0u, image );
530 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
532 textureSet.SetImage( 1u, image );
533 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
535 textureSet.SetSampler( 2u, Sampler::New() );
536 DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );