2 * Copyright (c) 2016 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/devel-api/images/pixel-devel.h>
21 #include <dali-test-suite-utils.h>
22 #include <test-native-image.h>
26 #include <mesh-builder.h>
28 void texture_set_startup(void)
30 test_return_value = TET_UNDEF;
33 void texture_set_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliTextureNew01(void)
40 TestApplication application;
42 unsigned int width(64);
43 unsigned int height(64);
44 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
46 DALI_TEST_CHECK( texture );
50 int UtcDaliTextureNew02(void)
52 TestApplication application;
54 DALI_TEST_CHECK( !texture );
58 int UtcDaliTextureNew03(void)
60 TestApplication application;
62 // Create a native image source.
63 TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::New( 64u, 64u );
65 // Create a texture from the native image source.
66 Texture nativeTexture = Texture::New( *testNativeImage );
68 // Check the texture was created OK.
69 DALI_TEST_CHECK( nativeTexture );
74 int UtcDaliTextureCopyConstructor(void)
76 TestApplication application;
78 unsigned int width(64);
79 unsigned int height(64);
80 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
82 Texture textureCopy(texture);
84 DALI_TEST_CHECK( textureCopy );
89 int UtcDaliTextureAssignmentOperator(void)
91 TestApplication application;
92 unsigned int width(64);
93 unsigned int height(64);
94 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
97 DALI_TEST_CHECK( !texture2 );
100 DALI_TEST_CHECK( texture2 );
105 int UtcDaliTextureDownCast01(void)
107 TestApplication application;
108 unsigned int width(64);
109 unsigned int height(64);
110 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
112 BaseHandle handle(texture);
113 Texture texture2 = Texture::DownCast(handle);
114 DALI_TEST_CHECK( texture2 );
119 int UtcDaliTextureDownCast02(void)
121 TestApplication application;
123 Handle handle = Handle::New(); // Create a custom object
124 Texture texture = Texture::DownCast(handle);
125 DALI_TEST_CHECK( !texture );
129 int UtcDaliTextureUpload01(void)
131 TestApplication application;
134 unsigned int width(64);
135 unsigned int height(64);
136 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
138 application.GetGlAbstraction().EnableTextureCallTrace(true);
140 application.SendNotification();
141 application.Render();
143 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
145 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
147 std::stringstream out;
148 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
149 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
152 //Upload data to the texture
155 unsigned int bufferSize( width * height * 4 );
156 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
157 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
158 texture.Upload( pixelData );
159 application.SendNotification();
160 application.Render();
162 //TexImage2D should be called to upload the data
164 std::stringstream out;
165 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
166 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
169 //Upload part of the texture
171 bufferSize = width * height * 2;
172 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
173 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
174 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
175 application.SendNotification();
176 application.Render();
178 //TexSubImage2D should be called to upload the data
180 std::stringstream out;
181 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
182 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
189 int UtcDaliTextureUpload02(void)
191 TestApplication application;
194 unsigned int width(64);
195 unsigned int height(64);
196 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
198 application.GetGlAbstraction().EnableTextureCallTrace(true);
200 application.SendNotification();
201 application.Render();
203 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
205 //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
206 for( unsigned int i(0); i<6; ++i )
208 std::stringstream out;
209 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
210 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
213 unsigned int bufferSize( width * height * 4 );
214 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
215 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
217 //Upload data to the POSITIVE_X face of the texture
221 texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
222 application.SendNotification();
223 application.Render();
225 //TexImage2D should be called to upload the data to the POSITIVE_X face
227 std::stringstream out;
228 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
229 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
233 //Upload data to the NEGATIVE_X face of the texture
237 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
238 application.SendNotification();
239 application.Render();
241 //TexImage2D should be called to upload the data to the NEGATIVE_X face
243 std::stringstream out;
244 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
245 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
249 //Upload data to the POSITIVE_Y face of the texture
252 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
253 application.SendNotification();
254 application.Render();
256 //TexImage2D should be called to upload the data to the POSITIVE_Y face
258 std::stringstream out;
259 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
260 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
264 //Upload data to the NEGATIVE_Y face of the texture
267 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
268 application.SendNotification();
269 application.Render();
271 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
273 std::stringstream out;
274 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
275 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
279 //Upload data to the POSITIVE_Z face of the texture
282 texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
283 application.SendNotification();
284 application.Render();
286 //TexImage2D should be called to upload the data to the POSITIVE_Z face
288 std::stringstream out;
289 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
290 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
294 //Upload data to the NEGATIVE_Z face of the texture
297 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
298 application.SendNotification();
299 application.Render();
301 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
303 std::stringstream out;
304 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
305 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
312 int UtcDaliTextureUpload03(void)
314 TestApplication application;
317 unsigned int width(64);
318 unsigned int height(64);
319 unsigned int widthMipmap1(32);
320 unsigned int heightMipmap1(32);
322 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
324 application.GetGlAbstraction().EnableTextureCallTrace(true);
326 application.SendNotification();
327 application.Render();
329 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
331 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
333 std::stringstream out;
334 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
335 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
338 //Upload data to the texture mipmap 0 and mipmap 1
341 unsigned int bufferSize( width * height * 4 );
342 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
343 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
344 texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
346 bufferSize = widthMipmap1 * heightMipmap1 * 4;
347 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
348 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
349 texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
350 application.SendNotification();
351 application.Render();
353 //TexImage2D should be called to upload the data to mipmaps 0 and 1
355 std::stringstream out;
356 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
357 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
360 std::stringstream out;
361 out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
362 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
368 int UtcDaliTextureUpload04(void)
370 TestApplication application;
373 unsigned int width(64);
374 unsigned int height(64);
375 unsigned int widthMipmap1(32);
376 unsigned int heightMipmap1(32);
378 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
380 application.GetGlAbstraction().EnableTextureCallTrace(true);
381 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
383 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
384 unsigned int bufferSize( width * height * 4 );
385 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
386 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
387 texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
389 bufferSize = widthMipmap1 * heightMipmap1 * 4;
390 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
391 PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
392 texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
393 application.SendNotification();
394 application.Render();
396 //TexImage2D should be called to upload the data to mipmaps 0 and 1
398 std::stringstream out;
399 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
400 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
403 std::stringstream out;
404 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
405 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
411 int UtcDaliTextureUpload05(void)
413 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
415 Pixel::COMPRESSED_R11_EAC,
416 Pixel::COMPRESSED_SIGNED_R11_EAC,
417 Pixel::COMPRESSED_RG11_EAC,
418 Pixel::COMPRESSED_SIGNED_RG11_EAC,
419 Pixel::COMPRESSED_RGB8_ETC2,
420 Pixel::COMPRESSED_SRGB8_ETC2,
421 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
422 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
423 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
424 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
425 Pixel::COMPRESSED_RGB8_ETC1,
426 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
427 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
428 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
429 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
430 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
431 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
432 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
433 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
434 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
435 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
436 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
437 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
438 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
439 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
440 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
441 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
442 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
443 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
444 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
445 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
446 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
447 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
448 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
449 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
450 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
451 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
452 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
453 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
454 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
456 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
458 for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
460 TestApplication application;
462 //Create a texture with a compressed format
463 unsigned int width(64);
464 unsigned int height(64);
465 Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
467 application.GetGlAbstraction().EnableTextureCallTrace(true);
469 application.SendNotification();
470 application.Render();
472 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
474 //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
476 std::stringstream out;
477 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
478 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
481 //Upload data to the texture
484 unsigned int bufferSize( width * height * 4 );
485 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
486 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
487 texture.Upload( pixelData );
488 application.SendNotification();
489 application.Render();
491 //CompressedTexImage2D should be called to upload the data
493 std::stringstream out;
494 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
495 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
498 //Upload part of the texture
500 bufferSize = width * height * 2;
501 buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
502 PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
503 texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
504 application.SendNotification();
505 application.Render();
507 //CompressedTexSubImage2D should be called to upload the data
509 std::stringstream out;
510 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " << height/2 << ", " << width/2 << ", " << height/2;
511 DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
518 int UtcDaliTextureUpload06(void)
520 TestApplication application;
523 unsigned int width(64);
524 unsigned int height(64);
525 tet_infoline( "Creating a Texure with an alpha channel" );
526 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
528 application.GetGlAbstraction().EnableTextureCallTrace(true);
530 application.SendNotification();
531 application.Render();
533 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
535 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
537 std::stringstream out;
538 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
539 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
542 tet_infoline( "Upload data to the texture" );
545 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
546 unsigned int bufferSize( width * height * 3 );
547 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
548 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
549 texture.Upload( pixelData );
550 application.SendNotification();
551 application.Render();
553 tet_infoline( "TexImage2D should be called to upload the data" );
555 std::stringstream out;
556 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
557 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
563 int UtcDaliTextureUpload07(void)
565 DevelPixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
570 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( DevelPixel::Format );
572 for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
574 TestApplication application;
577 unsigned int width(64);
578 unsigned int height(64);
579 tet_infoline( "Creating a floating point texture" );
580 Texture texture = Texture::New( TextureType::TEXTURE_2D, static_cast<Pixel::Format>( FLOATING_POINT_PIXEL_FORMATS[index] ), width, height );
582 application.GetGlAbstraction().EnableTextureCallTrace(true);
584 application.SendNotification();
585 application.Render();
587 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
589 tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
591 std::stringstream out;
592 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
593 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
596 tet_infoline( "Upload data to the texture" );
599 tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
600 unsigned int bufferSize( width * height * 3 );
601 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
602 PixelData pixelData = DevelPixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
603 texture.Upload( pixelData );
604 application.SendNotification();
605 application.Render();
607 tet_infoline( "TexImage2D should be called to upload the data" );
609 std::stringstream out;
610 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
611 DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
618 int UtcDaliTextureUploadSmallerThanSize(void)
620 TestApplication application;
623 unsigned int width(64);
624 unsigned int height(64);
625 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
627 application.GetGlAbstraction().EnableTextureCallTrace(true);
629 application.SendNotification();
630 application.Render();
632 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
634 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
636 std::stringstream out;
637 out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
639 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
640 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
643 //Upload data to the texture
646 unsigned int bufferSize( width * height * 4 );
647 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
648 PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
649 texture.Upload( pixelData );
650 application.SendNotification();
651 application.Render();
653 //TexImage2D should be called to upload the data
655 std::stringstream out;
656 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << width/2 << ", " << height/2;
658 DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
659 DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
665 int UtcDaliTextureGenerateMipmaps(void)
667 TestApplication application;
668 unsigned int width(64);
669 unsigned int height(64);
671 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
672 texture.GenerateMipmaps();
674 Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
675 textureCubemap.GenerateMipmaps();
677 application.GetGlAbstraction().EnableTextureCallTrace(true);
678 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
679 application.SendNotification();
680 application.Render();
683 std::stringstream out;
684 out << GL_TEXTURE_2D;
685 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
688 std::stringstream out;
689 out << GL_TEXTURE_CUBE_MAP;
690 DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
696 int UtcDaliTextureGetWidth(void)
698 TestApplication application;
699 unsigned int width(64);
700 unsigned int height(64);
702 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
703 DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
707 int UtcDaliTextureGetHeight(void)
709 TestApplication application;
710 unsigned int width(64);
711 unsigned int height(64);
713 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
714 DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
719 int UtcDaliTextureContextLoss(void)
721 tet_infoline("UtcDaliTextureContextLoss\n");
722 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
725 unsigned int width(64);
726 unsigned int height(64);
727 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
728 DALI_TEST_CHECK( texture );
730 application.SendNotification();
731 application.Render(16);
733 // Lose & regain context (in render 'thread')
734 application.ResetContext();
735 DALI_TEST_CHECK( texture );
740 int UtcDaliNativeImageTexture(void)
742 TestApplication application;
743 tet_infoline( "UtcDaliNativeImageTexture" );
745 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
746 Texture texture = Texture::New( *(imageInterface.Get()) );
747 DALI_TEST_CHECK( texture );
749 application.SendNotification();
750 application.Render(16);
752 DALI_TEST_CHECK( texture );