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>
24 #include <dali-test-suite-utils.h>
25 #include <mesh-builder.h>
29 void sampler_test_startup(void)
31 test_return_value = TET_UNDEF;
34 void sampler_test_cleanup(void)
36 test_return_value = TET_PASS;
39 int UtcDaliSamplerNew01(void)
41 TestApplication application;
42 Sampler sampler = Sampler::New();
44 DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION );
48 int UtcDaliSamplerNew02(void)
50 TestApplication application;
52 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
56 int UtcDaliSamplerCopyConstructor(void)
58 TestApplication application;
59 tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
61 // Initialize an object, ref count == 1
62 Sampler sampler = Sampler::New();
64 DALI_TEST_EQUALS(1, sampler.GetBaseObject().ReferenceCount(), TEST_LOCATION);
66 // Copy the object, ref count == 2
67 Sampler copy(sampler);
68 DALI_TEST_CHECK(copy);
71 DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION);
77 int UtcDaliSamplerDownCast01(void)
79 TestApplication application;
80 Sampler sampler = Sampler::New();
82 BaseHandle handle(sampler);
83 Sampler sampler2 = Sampler::DownCast(handle);
84 DALI_TEST_EQUALS( (bool)sampler2, true, TEST_LOCATION );
88 int UtcDaliSamplerDownCast02(void)
90 TestApplication application;
93 Sampler sampler = Sampler::DownCast(handle);
94 DALI_TEST_EQUALS( (bool)sampler, false, TEST_LOCATION );
98 int UtcDaliSamplerAssignmentOperator(void)
100 TestApplication application;
101 Sampler sampler1 = Sampler::New();
105 DALI_TEST_CHECK(!(sampler1 == sampler2));
109 DALI_TEST_CHECK(sampler1 == sampler2);
111 sampler2 = Sampler::New();
113 DALI_TEST_CHECK(!(sampler1 == sampler2));
118 int UtcSamplerSetFilterMode(void)
120 TestApplication application;
122 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
123 Sampler sampler = Sampler::New();
125 TextureSet textureSet = CreateTextureSet();
126 textureSet.SetTexture(0u, image);
127 textureSet.SetSampler( 0u, sampler );
129 Shader shader = CreateShader();
130 Geometry geometry = CreateQuadGeometry();
131 Renderer renderer = Renderer::New( geometry, shader );
132 renderer.SetTextures( textureSet );
133 Actor actor = Actor::New();
134 actor.AddRenderer(renderer);
135 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
136 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
137 application.GetScene().Add( actor );
140 TestGlAbstraction& gl = application.GetGlAbstraction();
142 /**************************************************************/
144 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
145 texParameterTrace.Reset();
146 texParameterTrace.Enable( true );
148 sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
149 application.SendNotification();
150 application.Render();
152 texParameterTrace.Enable( false );
156 // There are 4 calls to TexParameteri when the texture is first created
157 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
159 std::stringstream out;
160 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
161 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
163 /**************************************************************/
165 texParameterTrace.Reset();
166 texParameterTrace.Enable( true );
168 sampler.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
170 // Flush the queue and render once
171 application.SendNotification();
172 application.Render();
174 texParameterTrace.Enable( false );
178 // Should not make any calls when settings are the same (DEFAULT = LINEAR )
179 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
181 /**************************************************************/
183 texParameterTrace.Reset();
184 texParameterTrace.Enable( true );
186 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
188 // Flush the queue and render once
189 application.SendNotification();
190 application.Render();
192 texParameterTrace.Enable( false );
194 // Verify actor gl state
195 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
198 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
199 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
202 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
203 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
206 /**************************************************************/
208 texParameterTrace.Reset();
209 texParameterTrace.Enable( true );
211 sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
213 // Flush the queue and render once
214 application.SendNotification();
215 application.Render();
217 texParameterTrace.Enable( false );
219 // Verify actor gl state
220 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
223 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
224 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
226 /**************************************************************/
228 texParameterTrace.Reset();
229 texParameterTrace.Enable( true );
231 sampler.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
233 // Flush the queue and render once
234 application.SendNotification();
235 application.Render();
237 texParameterTrace.Enable( false );
239 // Verify actor gl state
240 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
243 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
244 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
249 int UtcSamplerSetWrapMode1(void)
251 TestApplication application;
253 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
254 TextureSet textureSet = CreateTextureSet();
255 Sampler sampler = Sampler::New();
256 textureSet.SetTexture(0u, image);
257 textureSet.SetSampler( 0u, sampler );
259 Shader shader = CreateShader();
260 Geometry geometry = CreateQuadGeometry();
261 Renderer renderer = Renderer::New( geometry, shader );
262 renderer.SetTextures( textureSet );
264 Actor actor = Actor::New();
265 actor.AddRenderer(renderer);
266 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
267 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
268 application.GetScene().Add( actor );
270 TestGlAbstraction& gl = application.GetGlAbstraction();
272 //****************************************
273 // CLAMP_TO_EDGE / CLAMP_TO_EDGE
274 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
275 texParameterTrace.Reset();
276 texParameterTrace.Enable( true );
278 application.SendNotification();
279 application.Render();
281 texParameterTrace.Enable( false );
285 // There are 4 calls to TexParameteri when the texture is first created
286 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
288 std::stringstream out;
289 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_CLAMP_TO_EDGE;
290 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
293 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE;
294 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(3, "TexParameteri", out.str()), true, TEST_LOCATION);
296 texParameterTrace.Reset();
297 texParameterTrace.Enable( true );
299 sampler.SetWrapMode( WrapMode::DEFAULT, WrapMode::DEFAULT );
301 // Flush the queue and render once
302 application.SendNotification();
303 application.Render();
305 texParameterTrace.Enable( false );
309 // Should not make any calls when settings are the same
310 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
312 //Todo: Test the other wrap mode ( REPEAT, MIRRORED_REPEAT ) , currently not support!!
317 int UtcSamplerSetWrapMode2(void)
319 TestApplication application;
321 // Create a cube-map texture.
322 unsigned int width = 8u;
323 unsigned int height = 8u;
324 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
326 // Create source image data.
327 unsigned int bufferSize( width * height * 4 );
328 unsigned char* buffer= new unsigned char[ bufferSize ];
329 memset( buffer, 0u, bufferSize );
331 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::DELETE_ARRAY );
333 // Upload the source image data to all 6 sides of our cube-map.
334 texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
335 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
336 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
337 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
338 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
339 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
341 // Finalize the cube-map setup.
342 TextureSet textureSet = TextureSet::New();
343 textureSet.SetTexture( 0u, texture );
345 Sampler sampler = Sampler::New();
346 textureSet.SetSampler( 0u, sampler );
348 Shader shader = CreateShader();
349 Geometry geometry = CreateQuadGeometry();
350 Renderer renderer = Renderer::New( geometry, shader );
351 renderer.SetTextures( textureSet );
353 Actor actor = Actor::New();
354 actor.AddRenderer(renderer);
355 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
356 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
357 application.GetScene().Add( actor );
359 TestGlAbstraction& gl = application.GetGlAbstraction();
361 application.SendNotification();
362 application.Render();
364 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
365 texParameterTrace.Reset();
366 texParameterTrace.Enable( true );
368 // Call the 3 dimensional wrap mode API.
369 sampler.SetWrapMode( WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE );
371 application.SendNotification();
372 application.Render();
374 // Verify that no TexParameteri calls occurred since wrap mode hasn't changed.
375 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0u, TEST_LOCATION );
378 sampler.SetWrapMode( WrapMode::REPEAT, WrapMode::REPEAT, WrapMode::REPEAT );
379 texParameterTrace.Reset();
380 application.SendNotification();
381 application.Render();
383 texParameterTrace.Enable( false );
385 // Verify that 3 TexParameteri calls occurred.
386 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3u, TEST_LOCATION );