2 * Copyright (c) 2017 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 TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::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 UtcDaliTextureDownCast01(void)
106 TestApplication application;
107 unsigned int width(64);
108 unsigned int height(64);
109 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
111 BaseHandle handle(texture);
112 Texture texture2 = Texture::DownCast(handle);
113 DALI_TEST_CHECK( texture2 );
118 int UtcDaliTextureDownCast02(void)
120 TestApplication application;
122 Handle handle = Handle::New(); // Create a custom object
123 Texture texture = Texture::DownCast(handle);
124 DALI_TEST_CHECK( !texture );
128 int UtcDaliTextureUpload01(void)
130 TestApplication application;
133 unsigned int width(64);
134 unsigned int height(64);
135 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
137 application.GetGlAbstraction().EnableTextureCallTrace(true);
139 application.SendNotification();
140 application.Render();
142 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
144 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
146 std::stringstream out;
147 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
148 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
151 //Upload data to the texture
154 unsigned int bufferSize( width * height * 4 );
155 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
156 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
157 texture.Upload( pixelData );
158 application.SendNotification();
159 application.Render();
161 //TexImage2D should be called to upload the data
163 std::stringstream out;
164 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
165 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
168 //Upload part of the texture
170 bufferSize = width * height * 2;
171 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
172 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
173 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
174 application.SendNotification();
175 application.Render();
177 //TexSubImage2D should be called to upload the data
179 std::stringstream out;
180 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
181 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
188 int UtcDaliTextureUpload02(void)
190 TestApplication application;
193 unsigned int width(64);
194 unsigned int height(64);
195 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
197 application.GetGlAbstraction().EnableTextureCallTrace(true);
199 application.SendNotification();
200 application.Render();
202 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
204 //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
205 for( unsigned int i(0); i<6; ++i )
207 std::stringstream out;
208 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
209 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
212 unsigned int bufferSize( width * height * 4 );
213 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
214 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
216 //Upload data to the POSITIVE_X face of the texture
220 texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
221 application.SendNotification();
222 application.Render();
224 //TexImage2D should be called to upload the data to the POSITIVE_X face
226 std::stringstream out;
227 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
228 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
232 //Upload data to the NEGATIVE_X face of the texture
236 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
237 application.SendNotification();
238 application.Render();
240 //TexImage2D should be called to upload the data to the NEGATIVE_X face
242 std::stringstream out;
243 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
244 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
248 //Upload data to the POSITIVE_Y face of the texture
251 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
252 application.SendNotification();
253 application.Render();
255 //TexImage2D should be called to upload the data to the POSITIVE_Y face
257 std::stringstream out;
258 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
259 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
263 //Upload data to the NEGATIVE_Y face of the texture
266 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
267 application.SendNotification();
268 application.Render();
270 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
272 std::stringstream out;
273 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
274 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
278 //Upload data to the POSITIVE_Z face of the texture
281 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
282 application.SendNotification();
283 application.Render();
285 //TexImage2D should be called to upload the data to the POSITIVE_Z face
287 std::stringstream out;
288 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
289 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
293 //Upload data to the NEGATIVE_Z face of the texture
296 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
297 application.SendNotification();
298 application.Render();
300 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
302 std::stringstream out;
303 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
304 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
311 int UtcDaliTextureUpload03(void)
313 TestApplication application;
316 unsigned int width(64);
317 unsigned int height(64);
318 unsigned int widthMipmap1(32);
319 unsigned int heightMipmap1(32);
321 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
323 application.GetGlAbstraction().EnableTextureCallTrace(true);
325 application.SendNotification();
326 application.Render();
328 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
330 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
332 std::stringstream out;
333 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
334 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
337 //Upload data to the texture mipmap 0 and mipmap 1
340 unsigned int bufferSize( width * height * 4 );
341 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
342 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
343 texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
345 bufferSize = widthMipmap1 * heightMipmap1 * 4;
346 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
347 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
348 texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
349 application.SendNotification();
350 application.Render();
352 //TexImage2D should be called to upload the data to mipmaps 0 and 1
354 std::stringstream out;
355 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
356 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
359 std::stringstream out;
360 out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
361 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
367 int UtcDaliTextureUpload04(void)
369 TestApplication application;
372 unsigned int width(64);
373 unsigned int height(64);
374 unsigned int widthMipmap1(32);
375 unsigned int heightMipmap1(32);
377 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
379 application.GetGlAbstraction().EnableTextureCallTrace(true);
380 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
382 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
383 unsigned int bufferSize( width * height * 4 );
384 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
385 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
386 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
388 bufferSize = widthMipmap1 * heightMipmap1 * 4;
389 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
390 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
391 texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
392 application.SendNotification();
393 application.Render();
395 //TexImage2D should be called to upload the data to mipmaps 0 and 1
397 std::stringstream out;
398 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
399 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
402 std::stringstream out;
403 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
404 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
410 int UtcDaliTextureUpload05(void)
412 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
414 Pixel::COMPRESSED_R11_EAC,
415 Pixel::COMPRESSED_SIGNED_R11_EAC,
416 Pixel::COMPRESSED_RG11_EAC,
417 Pixel::COMPRESSED_SIGNED_RG11_EAC,
418 Pixel::COMPRESSED_RGB8_ETC2,
419 Pixel::COMPRESSED_SRGB8_ETC2,
420 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
421 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
422 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
423 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
424 Pixel::COMPRESSED_RGB8_ETC1,
425 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
426 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
427 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
428 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
429 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
430 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
431 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
432 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
433 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
434 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
435 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
436 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
437 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
438 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
439 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
440 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
441 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
442 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
443 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
444 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
445 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
446 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
447 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
448 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
449 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
450 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
451 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
452 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
453 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
455 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
457 for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
459 TestApplication application;
461 //Create a texture with a compressed format
462 unsigned int width(64);
463 unsigned int height(64);
464 Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
466 application.GetGlAbstraction().EnableTextureCallTrace(true);
468 application.SendNotification();
469 application.Render();
471 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
473 //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
475 std::stringstream out;
476 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
477 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
480 //Upload data to the texture
483 unsigned int bufferSize( width * height * 4 );
484 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
485 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
486 texture.Upload( pixelData );
487 application.SendNotification();
488 application.Render();
490 //CompressedTexImage2D should be called to upload the data
492 std::stringstream out;
493 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
494 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
497 //Upload part of the texture
499 bufferSize = width * height * 2;
500 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
501 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
502 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
503 application.SendNotification();
504 application.Render();
506 //CompressedTexSubImage2D should be called to upload the data
508 std::stringstream out;
509 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
510 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
513 application.GetGlAbstraction().ResetTextureCallStack();
519 int UtcDaliTextureUpload06(void)
521 TestApplication application;
524 unsigned int width(64);
525 unsigned int height(64);
526 tet_infoline( "Creating a Texure with an alpha channel" );
527 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
529 application.GetGlAbstraction().EnableTextureCallTrace(true);
531 application.SendNotification();
532 application.Render();
534 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
536 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
538 std::stringstream out;
539 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
540 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
543 tet_infoline( "Upload data to the texture" );
546 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
547 unsigned int bufferSize( width * height * 3 );
548 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
549 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
550 texture.Upload( pixelData );
551 application.SendNotification();
552 application.Render();
554 tet_infoline( "TexImage2D should be called to upload the data" );
556 std::stringstream out;
557 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
558 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
564 int UtcDaliTextureUpload07(void)
566 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
571 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
573 for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
575 TestApplication application;
578 unsigned int width(64);
579 unsigned int height(64);
580 tet_infoline( "Creating a floating point texture" );
581 Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
583 application.GetGlAbstraction().EnableTextureCallTrace(true);
585 application.SendNotification();
586 application.Render();
588 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
590 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
592 std::stringstream out;
593 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
594 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
597 tet_infoline( "Upload data to the texture" );
600 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
601 unsigned int bufferSize( width * height * 3 );
602 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
603 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
604 texture.Upload( pixelData );
605 application.SendNotification();
606 application.Render();
608 tet_infoline( "TexImage2D should be called to upload the data" );
610 std::stringstream out;
611 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
612 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
619 int UtcDaliTextureUploadSmallerThanSize(void)
621 TestApplication application;
624 unsigned int width(64);
625 unsigned int height(64);
626 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
628 application.GetGlAbstraction().EnableTextureCallTrace(true);
630 application.SendNotification();
631 application.Render();
633 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
635 //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;
640 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
641 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
644 //Upload data to the texture
647 unsigned int bufferSize( width * height * 4 );
648 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
649 PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
650 texture.Upload( pixelData );
651 application.SendNotification();
652 application.Render();
654 //TexImage2D should be called to upload the data
656 std::stringstream out;
657 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << width/2 << ", " << height/2;
659 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
660 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
666 int UtcDaliTextureGenerateMipmaps(void)
668 TestApplication application;
669 unsigned int width(64);
670 unsigned int height(64);
672 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
673 texture.GenerateMipmaps();
675 Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
676 textureCubemap.GenerateMipmaps();
678 application.GetGlAbstraction().EnableTextureCallTrace(true);
679 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
680 application.SendNotification();
681 application.Render();
684 std::stringstream out;
685 out << GL_TEXTURE_2D;
686 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
689 std::stringstream out;
690 out << GL_TEXTURE_CUBE_MAP;
691 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
697 int UtcDaliTextureGetWidth(void)
699 TestApplication application;
700 unsigned int width(64);
701 unsigned int height(64);
703 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
704 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
708 int UtcDaliTextureGetHeight(void)
710 TestApplication application;
711 unsigned int width(64);
712 unsigned int height(64);
714 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
715 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
720 int UtcDaliTextureContextLoss(void)
722 tet_infoline("UtcDaliTextureContextLoss\n");
723 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
726 unsigned int width(64);
727 unsigned int height(64);
728 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
729 DALI_TEST_CHECK( texture );
731 application.SendNotification();
732 application.Render(16);
734 // Lose & regain context (in render 'thread')
735 application.ResetContext();
736 DALI_TEST_CHECK( texture );
741 int UtcDaliNativeImageTexture(void)
743 TestApplication application;
744 tet_infoline( "UtcDaliNativeImageTexture" );
746 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
747 Texture texture = Texture::New( *(imageInterface.Get()) );
748 DALI_TEST_CHECK( texture );
750 application.SendNotification();
751 application.Render(16);
753 DALI_TEST_CHECK( texture );