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 texture_set_startup(void)
27 test_return_value = TET_UNDEF;
30 void texture_set_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliTextureNew01(void)
37 TestApplication application;
39 unsigned int width(64);
40 unsigned int height(64);
41 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
43 DALI_TEST_CHECK( texture );
47 int UtcDaliTextureNew02(void)
49 TestApplication application;
51 DALI_TEST_CHECK( !texture );
55 int UtcDaliTextureCopyConstructor(void)
57 TestApplication application;
59 unsigned int width(64);
60 unsigned int height(64);
61 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
63 Texture textureCopy(texture);
65 DALI_TEST_CHECK( textureCopy );
70 int UtcDaliTextureAssignmentOperator(void)
72 TestApplication application;
73 unsigned int width(64);
74 unsigned int height(64);
75 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
78 DALI_TEST_CHECK( !texture2 );
81 DALI_TEST_CHECK( texture2 );
86 int UtcDaliTextureDownCast01(void)
88 TestApplication application;
89 unsigned int width(64);
90 unsigned int height(64);
91 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
93 BaseHandle handle(texture);
94 Texture texture2 = Texture::DownCast(handle);
95 DALI_TEST_CHECK( texture2 );
100 int UtcDaliTextureDownCast02(void)
102 TestApplication application;
104 Handle handle = Handle::New(); // Create a custom object
105 Texture texture = Texture::DownCast(handle);
106 DALI_TEST_CHECK( !texture );
110 int UtcDaliTextureUpload01(void)
112 TestApplication application;
115 unsigned int width(64);
116 unsigned int height(64);
117 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
119 application.GetGlAbstraction().EnableTextureCallTrace(true);
121 application.SendNotification();
122 application.Render();
124 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
126 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
128 std::stringstream out;
129 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
130 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
133 //Upload data to the texture
136 unsigned int bufferSize( width * height * 4 );
137 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
138 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
139 texture.Upload( pixelData );
140 application.SendNotification();
141 application.Render();
143 //TexImage2D should be called to upload the data
145 std::stringstream out;
146 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
147 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
150 //Upload part of the texture
152 bufferSize = width * height * 2;
153 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
154 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
155 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
156 application.SendNotification();
157 application.Render();
159 //TexSubImage2D should be called to upload the data
161 std::stringstream out;
162 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
163 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
170 int UtcDaliTextureUpload02(void)
172 TestApplication application;
175 unsigned int width(64);
176 unsigned int height(64);
177 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
179 application.GetGlAbstraction().EnableTextureCallTrace(true);
181 application.SendNotification();
182 application.Render();
184 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
186 //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
187 for( unsigned int i(0); i<6; ++i )
189 std::stringstream out;
190 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
191 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
194 unsigned int bufferSize( width * height * 4 );
195 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
196 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
198 //Upload data to the POSITIVE_X face of the texture
202 texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
203 application.SendNotification();
204 application.Render();
206 //TexImage2D should be called to upload the data to the POSITIVE_X face
208 std::stringstream out;
209 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
210 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
214 //Upload data to the NEGATIVE_X face of the texture
218 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
219 application.SendNotification();
220 application.Render();
222 //TexImage2D should be called to upload the data to the NEGATIVE_X face
224 std::stringstream out;
225 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
226 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
230 //Upload data to the POSITIVE_Y face of the texture
233 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
234 application.SendNotification();
235 application.Render();
237 //TexImage2D should be called to upload the data to the POSITIVE_Y face
239 std::stringstream out;
240 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
241 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
245 //Upload data to the NEGATIVE_Y face of the texture
248 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
249 application.SendNotification();
250 application.Render();
252 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
254 std::stringstream out;
255 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
256 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
260 //Upload data to the POSITIVE_Z face of the texture
263 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
264 application.SendNotification();
265 application.Render();
267 //TexImage2D should be called to upload the data to the POSITIVE_Z face
269 std::stringstream out;
270 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
271 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
275 //Upload data to the NEGATIVE_Z face of the texture
278 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
279 application.SendNotification();
280 application.Render();
282 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
284 std::stringstream out;
285 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
286 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
293 int UtcDaliTextureUpload03(void)
295 TestApplication application;
298 unsigned int width(64);
299 unsigned int height(64);
300 unsigned int widthMipmap1(32);
301 unsigned int heightMipmap1(32);
303 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
305 application.GetGlAbstraction().EnableTextureCallTrace(true);
307 application.SendNotification();
308 application.Render();
310 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
312 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
314 std::stringstream out;
315 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
316 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
319 //Upload data to the texture mipmap 0 and mipmap 1
322 unsigned int bufferSize( width * height * 4 );
323 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
324 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
325 texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
327 bufferSize = widthMipmap1 * heightMipmap1 * 4;
328 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
329 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
330 texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
331 application.SendNotification();
332 application.Render();
334 //TexImage2D should be called to upload the data to mipmaps 0 and 1
336 std::stringstream out;
337 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
338 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
341 std::stringstream out;
342 out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
343 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
349 int UtcDaliTextureUpload04(void)
351 TestApplication application;
354 unsigned int width(64);
355 unsigned int height(64);
356 unsigned int widthMipmap1(32);
357 unsigned int heightMipmap1(32);
359 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
361 application.GetGlAbstraction().EnableTextureCallTrace(true);
362 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
364 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
365 unsigned int bufferSize( width * height * 4 );
366 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
367 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
368 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
370 bufferSize = widthMipmap1 * heightMipmap1 * 4;
371 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
372 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
373 texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
374 application.SendNotification();
375 application.Render();
377 //TexImage2D should be called to upload the data to mipmaps 0 and 1
379 std::stringstream out;
380 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
381 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
384 std::stringstream out;
385 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
386 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
392 int UtcDaliTextureUpload05(void)
394 TestApplication application;
396 //Create a texture with a compressed format
397 unsigned int width(64);
398 unsigned int height(64);
399 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, width, height );
401 application.GetGlAbstraction().EnableTextureCallTrace(true);
403 application.SendNotification();
404 application.Render();
406 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
408 //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
410 std::stringstream out;
411 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
412 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
415 //Upload data to the texture
418 unsigned int bufferSize( width * height * 4 );
419 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
420 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
421 texture.Upload( pixelData );
422 application.SendNotification();
423 application.Render();
425 //CompressedTexImage2D should be called to upload the data
427 std::stringstream out;
428 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
429 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
432 //Upload part of the texture
434 bufferSize = width * height * 2;
435 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
436 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
437 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
438 application.SendNotification();
439 application.Render();
441 //CompressedTexSubImage2D should be called to upload the data
443 std::stringstream out;
444 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
445 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
452 int UtcDaliTextureGenerateMipmaps(void)
454 TestApplication application;
455 unsigned int width(64);
456 unsigned int height(64);
458 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
459 texture.GenerateMipmaps();
461 Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
462 textureCubemap.GenerateMipmaps();
464 application.GetGlAbstraction().EnableTextureCallTrace(true);
465 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
466 application.SendNotification();
467 application.Render();
470 std::stringstream out;
471 out << GL_TEXTURE_2D;
472 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
475 std::stringstream out;
476 out << GL_TEXTURE_CUBE_MAP;
477 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
483 int UtcDaliTextureGetWidth(void)
485 TestApplication application;
486 unsigned int width(64);
487 unsigned int height(64);
489 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
490 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
494 int UtcDaliTextureGetHeight(void)
496 TestApplication application;
497 unsigned int width(64);
498 unsigned int height(64);
500 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
501 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );