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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali/devel-api/images/pixel-data-devel.h>
20 #include <dali-test-suite-utils.h>
21 #include <test-native-image.h>
25 #include <mesh-builder.h>
27 void texture_set_startup(void)
29 test_return_value = TET_UNDEF;
32 void texture_set_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliTextureNew01(void)
39 TestApplication application;
41 unsigned int width(64);
42 unsigned int height(64);
43 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
45 DALI_TEST_CHECK( texture );
49 int UtcDaliTextureNew02(void)
51 TestApplication application;
53 DALI_TEST_CHECK( !texture );
57 int UtcDaliTextureNew03(void)
59 TestApplication application;
61 // Create a native image source.
62 TestNativeImagePointer testNativeImage = TestNativeImage::New( 64u, 64u );
64 // Create a texture from the native image source.
65 Texture nativeTexture = Texture::New( *testNativeImage );
67 // Check the texture was created OK.
68 DALI_TEST_CHECK( nativeTexture );
73 int UtcDaliTextureCopyConstructor(void)
75 TestApplication application;
77 unsigned int width(64);
78 unsigned int height(64);
79 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
81 Texture textureCopy(texture);
83 DALI_TEST_CHECK( textureCopy );
88 int UtcDaliTextureAssignmentOperator(void)
90 TestApplication application;
91 unsigned int width(64);
92 unsigned int height(64);
93 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
96 DALI_TEST_CHECK( !texture2 );
99 DALI_TEST_CHECK( texture2 );
104 int UtcDaliTextureMoveConstructor(void)
106 TestApplication application;
109 uint32_t height = 64;
110 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
111 DALI_TEST_CHECK( texture );
112 DALI_TEST_EQUALS( 1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION );
113 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
114 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
116 Texture move = std::move( texture );
117 DALI_TEST_CHECK( move );
118 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
119 DALI_TEST_EQUALS( move.GetWidth(), width, TEST_LOCATION );
120 DALI_TEST_EQUALS( move.GetHeight(), height, TEST_LOCATION );
121 DALI_TEST_CHECK( !texture );
126 int UtcDaliTextureMoveAssignment(void)
128 TestApplication application;
131 uint32_t height = 64;
132 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
133 DALI_TEST_CHECK( texture );
134 DALI_TEST_EQUALS( 1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION );
135 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
136 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
139 move = std::move( texture );
140 DALI_TEST_CHECK( move );
141 DALI_TEST_EQUALS( 1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
142 DALI_TEST_EQUALS( move.GetWidth(), width, TEST_LOCATION );
143 DALI_TEST_EQUALS( move.GetHeight(), height, TEST_LOCATION );
144 DALI_TEST_CHECK( !texture );
149 int UtcDaliTextureDownCast01(void)
151 TestApplication application;
152 unsigned int width(64);
153 unsigned int height(64);
154 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
156 BaseHandle handle(texture);
157 Texture texture2 = Texture::DownCast(handle);
158 DALI_TEST_CHECK( texture2 );
163 int UtcDaliTextureDownCast02(void)
165 TestApplication application;
167 Handle handle = Handle::New(); // Create a custom object
168 Texture texture = Texture::DownCast(handle);
169 DALI_TEST_CHECK( !texture );
173 int UtcDaliTextureUpload01(void)
175 TestApplication application;
178 unsigned int width(64);
179 unsigned int height(64);
180 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
182 application.GetGlAbstraction().EnableTextureCallTrace(true);
184 application.SendNotification();
185 application.Render();
187 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
189 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
191 std::stringstream out;
192 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
193 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
196 //Upload data to the texture
199 unsigned int bufferSize( width * height * 4 );
200 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
201 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
202 texture.Upload( pixelData );
203 application.SendNotification();
204 application.Render();
206 //TexImage2D should be called to upload the data
208 std::stringstream out;
209 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
210 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
213 //Upload part of the texture
215 bufferSize = width * height * 2;
216 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
217 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
218 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
219 application.SendNotification();
220 application.Render();
222 //TexSubImage2D should be called to upload the data
224 std::stringstream out;
225 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
226 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
233 int UtcDaliTextureUpload02(void)
235 TestApplication application;
238 unsigned int width(64);
239 unsigned int height(64);
240 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
242 application.GetGlAbstraction().EnableTextureCallTrace(true);
244 application.SendNotification();
245 application.Render();
247 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
249 //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
250 for( unsigned int i(0); i<6; ++i )
252 std::stringstream out;
253 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
254 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
257 unsigned int bufferSize( width * height * 4 );
258 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
259 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
261 //Upload data to the POSITIVE_X face of the texture
265 texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
266 application.SendNotification();
267 application.Render();
269 //TexImage2D should be called to upload the data to the POSITIVE_X face
271 std::stringstream out;
272 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
273 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
277 //Upload data to the NEGATIVE_X face of the texture
281 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
282 application.SendNotification();
283 application.Render();
285 //TexImage2D should be called to upload the data to the NEGATIVE_X face
287 std::stringstream out;
288 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
289 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
293 //Upload data to the POSITIVE_Y face of the texture
296 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
297 application.SendNotification();
298 application.Render();
300 //TexImage2D should be called to upload the data to the POSITIVE_Y face
302 std::stringstream out;
303 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
304 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
308 //Upload data to the NEGATIVE_Y face of the texture
311 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
312 application.SendNotification();
313 application.Render();
315 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
317 std::stringstream out;
318 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
319 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
323 //Upload data to the POSITIVE_Z face of the texture
326 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
327 application.SendNotification();
328 application.Render();
330 //TexImage2D should be called to upload the data to the POSITIVE_Z face
332 std::stringstream out;
333 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
334 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
338 //Upload data to the NEGATIVE_Z face of the texture
341 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
342 application.SendNotification();
343 application.Render();
345 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
347 std::stringstream out;
348 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
349 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
356 int UtcDaliTextureUpload03(void)
358 TestApplication application;
361 unsigned int width(64);
362 unsigned int height(64);
363 unsigned int widthMipmap1(32);
364 unsigned int heightMipmap1(32);
366 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
368 application.GetGlAbstraction().EnableTextureCallTrace(true);
370 application.SendNotification();
371 application.Render();
373 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
375 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
377 std::stringstream out;
378 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
379 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
382 //Upload data to the texture mipmap 0 and mipmap 1
385 unsigned int bufferSize( width * height * 4 );
386 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
387 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
388 texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
390 bufferSize = widthMipmap1 * heightMipmap1 * 4;
391 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
392 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
393 texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
394 application.SendNotification();
395 application.Render();
397 //TexImage2D should be called to upload the data to mipmaps 0 and 1
399 std::stringstream out;
400 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
401 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
404 std::stringstream out;
405 out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
406 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
412 int UtcDaliTextureUpload04(void)
414 TestApplication application;
417 unsigned int width(64);
418 unsigned int height(64);
419 unsigned int widthMipmap1(32);
420 unsigned int heightMipmap1(32);
422 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
424 application.GetGlAbstraction().EnableTextureCallTrace(true);
425 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
427 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
428 unsigned int bufferSize( width * height * 4 );
429 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
430 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
431 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
433 bufferSize = widthMipmap1 * heightMipmap1 * 4;
434 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
435 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
436 texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
437 application.SendNotification();
438 application.Render();
440 //TexImage2D should be called to upload the data to mipmaps 0 and 1
442 std::stringstream out;
443 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
444 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
447 std::stringstream out;
448 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
449 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
455 int UtcDaliTextureUpload05(void)
457 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
459 Pixel::COMPRESSED_R11_EAC,
460 Pixel::COMPRESSED_SIGNED_R11_EAC,
461 Pixel::COMPRESSED_RG11_EAC,
462 Pixel::COMPRESSED_SIGNED_RG11_EAC,
463 Pixel::COMPRESSED_RGB8_ETC2,
464 Pixel::COMPRESSED_SRGB8_ETC2,
465 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
466 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
467 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
468 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
469 Pixel::COMPRESSED_RGB8_ETC1,
470 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
471 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
472 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
473 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
474 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
475 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
476 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
477 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
478 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
479 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
480 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
481 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
482 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
483 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
484 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
485 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
486 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
487 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
488 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
489 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
491 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
492 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
493 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
494 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
495 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
496 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
497 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
498 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
500 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
502 for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
504 TestApplication application;
506 //Create a texture with a compressed format
507 unsigned int width(64);
508 unsigned int height(64);
509 Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
511 application.GetGlAbstraction().EnableTextureCallTrace(true);
513 application.SendNotification();
514 application.Render();
516 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
518 //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
520 std::stringstream out;
521 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
522 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
525 //Upload data to the texture
528 unsigned int bufferSize( width * height * 4 );
529 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
530 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
531 texture.Upload( pixelData );
532 application.SendNotification();
533 application.Render();
535 //CompressedTexImage2D should be called to upload the data
537 std::stringstream out;
538 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
539 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
542 //Upload part of the texture
544 bufferSize = width * height * 2;
545 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
546 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
547 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
548 application.SendNotification();
549 application.Render();
551 //CompressedTexSubImage2D should be called to upload the data
553 std::stringstream out;
554 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
555 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
558 application.GetGlAbstraction().ResetTextureCallStack();
564 int UtcDaliTextureUpload06(void)
566 TestApplication application;
569 unsigned int width(64);
570 unsigned int height(64);
571 tet_infoline( "Creating a Texure with an alpha channel" );
572 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
574 application.GetGlAbstraction().EnableTextureCallTrace(true);
576 application.SendNotification();
577 application.Render();
579 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
581 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
583 std::stringstream out;
584 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
585 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
588 tet_infoline( "Upload data to the texture" );
591 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
592 unsigned int bufferSize( width * height * 3 );
593 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
594 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
595 texture.Upload( pixelData );
596 application.SendNotification();
597 application.Render();
599 tet_infoline( "TexImage2D should be called to upload the data" );
601 std::stringstream out;
602 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
603 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
609 int UtcDaliTextureUpload07(void)
611 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
616 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
618 for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
620 TestApplication application;
623 unsigned int width(64);
624 unsigned int height(64);
625 tet_infoline( "Creating a floating point texture" );
626 Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
628 application.GetGlAbstraction().EnableTextureCallTrace(true);
630 application.SendNotification();
631 application.Render();
633 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
635 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
637 std::stringstream out;
638 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
639 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
642 tet_infoline( "Upload data to the texture" );
645 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
646 unsigned int bufferSize( width * height * 3 );
647 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
648 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
649 texture.Upload( pixelData );
650 application.SendNotification();
651 application.Render();
653 tet_infoline( "TexImage2D should be called to upload the data" );
655 std::stringstream out;
656 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
657 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
664 int UtcDaliTextureUploadSmallerThanSize(void)
666 TestApplication application;
669 unsigned int width(64);
670 unsigned int height(64);
671 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
673 application.GetGlAbstraction().EnableTextureCallTrace(true);
675 application.SendNotification();
676 application.Render();
678 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
680 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
682 std::stringstream out;
683 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
685 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
686 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
689 //Upload data to the texture
692 unsigned int bufferSize( width * height * 4 );
693 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
694 PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
695 texture.Upload( pixelData );
696 application.SendNotification();
697 application.Render();
699 //TexImage2D should be called to upload the data
701 std::stringstream out;
702 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << width/2 << ", " << height/2;
704 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
705 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
711 int UtcDaliTextureGenerateMipmaps(void)
713 TestApplication application;
714 unsigned int width(64);
715 unsigned int height(64);
717 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
718 texture.GenerateMipmaps();
720 Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
721 textureCubemap.GenerateMipmaps();
723 application.GetGlAbstraction().EnableTextureCallTrace(true);
724 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
725 application.SendNotification();
726 application.Render();
729 std::stringstream out;
730 out << GL_TEXTURE_2D;
731 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
734 std::stringstream out;
735 out << GL_TEXTURE_CUBE_MAP;
736 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
742 int UtcDaliTextureGetWidth(void)
744 TestApplication application;
745 unsigned int width(64);
746 unsigned int height(64);
748 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
749 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
753 int UtcDaliTextureGetHeight(void)
755 TestApplication application;
756 unsigned int width(64);
757 unsigned int height(64);
759 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
760 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
765 int UtcDaliTextureContextLoss(void)
767 tet_infoline("UtcDaliTextureContextLoss\n");
768 TestApplication application;
771 unsigned int width(64);
772 unsigned int height(64);
773 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
774 DALI_TEST_CHECK( texture );
776 application.SendNotification();
777 application.Render(16);
779 // Lose & regain context (in render 'thread')
780 application.ResetContext();
781 DALI_TEST_CHECK( texture );
786 int UtcDaliNativeImageTexture01(void)
788 TestApplication application;
789 tet_infoline( "UtcDaliNativeImageTexture01" );
791 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
793 Texture texture = Texture::New( *(imageInterface.Get()) );
794 Actor actor = CreateRenderableActor(texture, "", "");
795 application.GetScene().Add(actor);
797 DALI_TEST_CHECK( texture );
799 application.SendNotification();
800 application.Render(16);
802 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
803 DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION );
804 DALI_TEST_EQUALS( actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16,16,0)), TEST_LOCATION);
806 UnparentAndReset(actor);
808 application.SendNotification();
809 application.Render(16);
811 application.SendNotification();
812 application.Render(16);
814 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
815 DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION );
821 int UtcDaliNativeImageTexture02(void)
823 TestApplication application;
824 tet_infoline( "UtcDaliNativeImageTexture02 - test error on TargetTexture" );
826 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
827 imageInterface->mTargetTextureError = 1u;
829 Texture texture = Texture::New( *(imageInterface.Get()) );
830 Actor actor = CreateRenderableActor(texture, "", "");
831 application.GetScene().Add(actor);
833 DALI_TEST_CHECK( texture );
835 application.SendNotification();
836 application.Render(16);
838 // Expect 2 attempts to create the texture - once when adding the texture
839 // to the scene-graph, and again since that failed, during the Bind.
840 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
841 DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
843 UnparentAndReset(actor);
845 application.SendNotification();
846 application.Render(16);
848 application.SendNotification();
849 application.Render(16);
851 // Expect that there are no further calls to create/destroy resource
852 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
853 DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
858 int UtcDaliTextureGenerateMipmapsNegative(void)
860 TestApplication application;
861 Dali::Texture instance;
864 instance.GenerateMipmaps();
865 DALI_TEST_CHECK(false); // Should not get here
869 DALI_TEST_CHECK(true); // We expect an assert
874 int UtcDaliTextureUploadNegative01(void)
876 TestApplication application;
877 Dali::Texture instance;
880 Dali::PixelData arg1;
881 instance.Upload(arg1);
882 DALI_TEST_CHECK(false); // Should not get here
886 DALI_TEST_CHECK(true); // We expect an assert
891 int UtcDaliTextureUploadNegative02(void)
893 TestApplication application;
894 Dali::Texture instance;
897 Dali::PixelData arg1;
898 unsigned int arg2(0u);
899 unsigned int arg3(0u);
900 unsigned int arg4(0u);
901 unsigned int arg5(0u);
902 unsigned int arg6(0u);
903 unsigned int arg7(0u);
904 instance.Upload(arg1,arg2,arg3,arg4,arg5,arg6,arg7);
905 DALI_TEST_CHECK(false); // Should not get here
909 DALI_TEST_CHECK(true); // We expect an assert
914 int UtcDaliTextureGetWidthNegative(void)
916 TestApplication application;
917 Dali::Texture instance;
921 DALI_TEST_CHECK(false); // Should not get here
925 DALI_TEST_CHECK(true); // We expect an assert
930 int UtcDaliTextureGetHeightNegative(void)
932 TestApplication application;
933 Dali::Texture instance;
936 instance.GetHeight();
937 DALI_TEST_CHECK(false); // Should not get here
941 DALI_TEST_CHECK(true); // We expect an assert