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>
25 void sampler_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void sampler_test_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliSamplerNew01(void)
37 TestApplication application;
39 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
40 Sampler sampler = Sampler::New(image, "sTexture");
42 DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION );
46 int UtcDaliSamplerNew02(void)
48 TestApplication application;
50 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
54 int UtcDaliSamplerCopyConstructor(void)
56 TestApplication application;
57 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
59 // Initialize an object, ref count == 1
60 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
61 Sampler sampler = Sampler::New(image, "sTexture");
63 DALI_TEST_EQUALS(1, sampler.GetBaseObject().ReferenceCount(), TEST_LOCATION);
65 // Copy the object, ref count == 2
66 Sampler copy(sampler);
67 DALI_TEST_CHECK(copy);
70 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
77 int UtcDaliSamplerDownCast01(void)
79 TestApplication application;
80 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
81 Sampler sampler = Sampler::New(image, "sTexture");
83 BaseHandle handle(sampler);
84 Sampler sampler2 = Sampler::DownCast(handle);
85 DALI_TEST_EQUALS( (bool)sampler2, true, TEST_LOCATION );
89 int UtcDaliSamplerDownCast02(void)
91 TestApplication application;
94 Sampler sampler = Sampler::DownCast(handle);
95 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
99 int UtcDaliSamplerAssignmentOperator(void)
101 TestApplication application;
103 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
104 Sampler sampler1 = Sampler::New(image, "sTexture");
108 DALI_TEST_CHECK(!(sampler1 == sampler2));
112 DALI_TEST_CHECK(sampler1 == sampler2);
114 sampler2 = Sampler::New(image, "sTexture");
116 DALI_TEST_CHECK(!(sampler1 == sampler2));
121 int UtcDaliSamplerSetUniformName01(void)
123 TestApplication application;
125 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
126 Sampler sampler = Sampler::New(image, "sTexture");
127 sampler.SetUniformName( "sEffectTexture" );
129 Material material = CreateMaterial(1.0f);
130 material.AddSampler( sampler );
132 Geometry geometry = CreateQuadGeometry();
133 Renderer renderer = Renderer::New( geometry, material );
134 Actor actor = Actor::New();
135 actor.AddRenderer(renderer);
136 actor.SetParentOrigin( ParentOrigin::CENTER );
137 actor.SetSize(400, 400);
139 Stage::GetCurrent().Add( actor );
141 TestGlAbstraction& gl = application.GetGlAbstraction();
143 application.SendNotification();
144 application.Render();
147 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
148 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
153 int UtcDaliSamplerSetUniformName02(void)
155 TestApplication application;
157 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
158 Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
159 Sampler sampler1 = Sampler::New(image, "sTexture");
160 sampler1.SetUniformName( "sEffectTexture" );
162 Sampler sampler2 = Sampler::New(image2, "sTexture2");
164 Material material = CreateMaterial(1.0f);
165 material.AddSampler( sampler1 );
166 material.AddSampler( sampler2 );
168 Geometry geometry = CreateQuadGeometry();
169 Renderer renderer = Renderer::New( geometry, material );
170 Actor actor = Actor::New();
171 actor.AddRenderer(renderer);
172 actor.SetParentOrigin( ParentOrigin::CENTER );
173 actor.SetSize(400, 400);
175 Stage::GetCurrent().Add( actor );
177 TestGlAbstraction& gl = application.GetGlAbstraction();
179 application.SendNotification();
180 application.Render();
183 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
184 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
186 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
187 DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
192 int UtcDaliSamplerSetGetImage(void)
194 TestApplication application;
196 Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
197 Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
198 Sampler sampler = Sampler::New(image1, "sTexture");
200 DALI_TEST_CHECK(image1 == sampler.GetImage());
202 sampler.SetImage( image2 );
203 DALI_TEST_CHECK(!(image1 == sampler.GetImage()));
204 DALI_TEST_CHECK(image2 == sampler.GetImage());
209 int UtcSamplerSetFilterMode(void)
211 TestApplication application;
213 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
214 Sampler sampler = Sampler::New(image, "sTexture");
216 Material material = CreateMaterial(1.0f);
217 material.AddSampler( sampler );
219 Geometry geometry = CreateQuadGeometry();
220 Renderer renderer = Renderer::New( geometry, material );
221 Actor actor = Actor::New();
222 actor.AddRenderer(renderer);
223 actor.SetParentOrigin( ParentOrigin::CENTER );
224 actor.SetSize(400, 400);
225 Stage::GetCurrent().Add( actor );
227 float initialValue = 1.0f;
228 sampler.RegisterProperty("uWidthClamp", initialValue );
230 TestGlAbstraction& gl = application.GetGlAbstraction();
232 /**************************************************************/
234 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
235 texParameterTrace.Reset();
236 texParameterTrace.Enable( true );
238 sampler.SetFilterMode( Sampler::DEFAULT, Sampler::DEFAULT );
239 application.SendNotification();
240 application.Render();
242 texParameterTrace.Enable( false );
246 // There are two calls to TexParameteri when the texture is first created
247 // Texture mag filter is not called as the first time set it uses the system default
248 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
250 std::stringstream out;
251 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
252 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
254 /**************************************************************/
256 texParameterTrace.Reset();
257 texParameterTrace.Enable( true );
259 sampler.SetFilterMode( Sampler::DEFAULT, Sampler::DEFAULT );
261 // Flush the queue and render once
262 application.SendNotification();
263 application.Render();
265 texParameterTrace.Enable( false );
269 // Should not make any calls when settings are the same
270 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
272 /**************************************************************/
274 texParameterTrace.Reset();
275 texParameterTrace.Enable( true );
277 sampler.SetFilterMode( Sampler::NEAREST, Sampler::NEAREST );
279 // Flush the queue and render once
280 application.SendNotification();
281 application.Render();
283 texParameterTrace.Enable( false );
285 // Verify actor gl state
286 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
289 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
290 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
293 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
294 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
296 /**************************************************************/
298 texParameterTrace.Reset();
299 texParameterTrace.Enable( true );
301 sampler.SetFilterMode( Sampler::NEAREST, Sampler::LINEAR );
303 // Flush the queue and render once
304 application.SendNotification();
305 application.Render();
307 texParameterTrace.Enable( false );
309 // Verify actor gl state
310 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
313 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
314 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
316 /**************************************************************/
318 texParameterTrace.Reset();
319 texParameterTrace.Enable( true );
321 sampler.SetFilterMode( Sampler::NONE, Sampler::NONE );
323 // Flush the queue and render once
324 application.SendNotification();
325 application.Render();
327 texParameterTrace.Enable( false );
329 // Verify actor gl state
330 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
333 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
334 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
339 int UtcSamplerSetWrapMode(void)
341 TestApplication application;
343 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
344 Sampler sampler = Sampler::New(image, "sTexture");
346 Material material = CreateMaterial(1.0f);
347 material.AddSampler( sampler );
349 Geometry geometry = CreateQuadGeometry();
350 Renderer renderer = Renderer::New( geometry, material );
351 Actor actor = Actor::New();
352 actor.AddRenderer(renderer);
353 actor.SetParentOrigin( ParentOrigin::CENTER );
354 actor.SetSize(400, 400);
355 Stage::GetCurrent().Add( actor );
357 TestGlAbstraction& gl = application.GetGlAbstraction();
359 //****************************************
360 // CLAMP_TO_EDGE / CLAMP_TO_EDGE
361 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
362 texParameterTrace.Reset();
363 texParameterTrace.Enable( true );
365 application.SendNotification();
366 application.Render();
368 texParameterTrace.Enable( false );
372 // There are two calls to TexParameteri when the texture is first created
373 // Texture mag filter is not called as the first time set it uses the system default
374 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
376 std::stringstream out;
377 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_CLAMP_TO_EDGE;
378 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
381 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE;
382 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
384 texParameterTrace.Reset();
385 texParameterTrace.Enable( true );
387 sampler.SetWrapMode( Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE );
389 // Flush the queue and render once
390 application.SendNotification();
391 application.Render();
393 texParameterTrace.Enable( false );
397 // Should not make any calls when settings are the same
398 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
400 //Todo: Test the other wrap mode ( REPEAT, MIRRORED_REPEAT ) , currently not support!!
405 int UtcSamplerSetAffectsTransparency(void)
407 TestApplication application;
409 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
410 Sampler sampler = Sampler::New(image, "sTexture");
412 Material material = CreateMaterial(1.0f);
413 material.AddSampler( sampler );
415 Geometry geometry = CreateQuadGeometry();
416 Renderer renderer = Renderer::New( geometry, material );
417 Actor actor = Actor::New();
418 actor.AddRenderer(renderer);
419 actor.SetParentOrigin( ParentOrigin::CENTER );
420 actor.SetSize(400, 400);
421 Stage::GetCurrent().Add( actor );
423 TestGlAbstraction& gl = application.GetGlAbstraction();
425 // Test SetAffectsTransparency( false )
426 sampler.SetAffectsTransparency( false );
428 gl.EnableCullFaceCallTrace(true);
429 application.SendNotification();
430 application.Render();
432 TraceCallStack& glEnableStack = gl.GetCullFaceTrace();
433 std::ostringstream blendStr;
434 blendStr << GL_BLEND;
435 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
437 // Test SetAffectsTransparency( true )
438 sampler.SetAffectsTransparency( true );
440 glEnableStack.Reset();
441 gl.EnableCullFaceCallTrace(true);
442 application.SendNotification();
443 application.Render();
445 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );