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-test-suite-utils.h>
19 #include <dali/devel-api/images/pixel-data-devel.h>
20 #include <dali/devel-api/rendering/texture-devel.h>
21 #include <dali/public-api/dali-core.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 TestNativeImagePointer testNativeImage = TestNativeImage::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 UtcDaliTextureMoveConstructor(void)
107 TestApplication application;
110 uint32_t height = 64;
111 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
112 DALI_TEST_CHECK(texture);
113 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
114 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
115 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
117 Texture move = std::move(texture);
118 DALI_TEST_CHECK(move);
119 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
120 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
121 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
122 DALI_TEST_CHECK(!texture);
127 int UtcDaliTextureMoveAssignment(void)
129 TestApplication application;
132 uint32_t height = 64;
133 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
134 DALI_TEST_CHECK(texture);
135 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
136 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
137 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
140 move = std::move(texture);
141 DALI_TEST_CHECK(move);
142 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
143 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
144 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
145 DALI_TEST_CHECK(!texture);
150 int UtcDaliTextureDownCast01(void)
152 TestApplication application;
153 unsigned int width(64);
154 unsigned int height(64);
155 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
157 BaseHandle handle(texture);
158 Texture texture2 = Texture::DownCast(handle);
159 DALI_TEST_CHECK(texture2);
164 int UtcDaliTextureDownCast02(void)
166 TestApplication application;
168 Handle handle = Handle::New(); // Create a custom object
169 Texture texture = Texture::DownCast(handle);
170 DALI_TEST_CHECK(!texture);
174 int UtcDaliTextureUpload01(void)
176 TestApplication application;
179 unsigned int width(64);
180 unsigned int height(64);
181 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
183 application.GetGlAbstraction().EnableTextureCallTrace(true);
185 application.SendNotification();
186 application.Render();
188 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
190 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
192 std::stringstream out;
193 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
194 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
197 //Upload data to the texture
200 unsigned int bufferSize(width * height * 4);
201 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
202 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
203 texture.Upload(pixelData);
204 application.SendNotification();
205 application.Render();
207 //TexImage2D should be called to upload the data
209 std::stringstream out;
210 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
211 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
214 //Upload part of the texture
216 bufferSize = width * height * 2;
217 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
218 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
219 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
220 application.SendNotification();
221 application.Render();
223 //TexSubImage2D should be called to upload the data
225 std::stringstream out;
226 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
227 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);
820 int UtcDaliNativeImageTexture02(void)
822 TestApplication application;
823 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
825 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
826 imageInterface->mTargetTextureError = 1u;
828 Texture texture = Texture::New(*(imageInterface.Get()));
829 Actor actor = CreateRenderableActor(texture, "", "");
830 application.GetScene().Add(actor);
832 DALI_TEST_CHECK(texture);
834 application.SendNotification();
835 application.Render(16);
837 // Expect 2 attempts to create the texture - once when adding the texture
838 // to the scene-graph, and again since that failed, during the Bind.
839 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
840 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
842 UnparentAndReset(actor);
844 application.SendNotification();
845 application.Render(16);
847 application.SendNotification();
848 application.Render(16);
850 // Expect that there are no further calls to create/destroy resource
851 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
852 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
857 int UtcDaliTextureGenerateMipmapsNegative(void)
859 TestApplication application;
860 Dali::Texture instance;
863 instance.GenerateMipmaps();
864 DALI_TEST_CHECK(false); // Should not get here
868 DALI_TEST_CHECK(true); // We expect an assert
873 int UtcDaliTextureUploadNegative01(void)
875 TestApplication application;
876 Dali::Texture instance;
879 Dali::PixelData arg1;
880 instance.Upload(arg1);
881 DALI_TEST_CHECK(false); // Should not get here
885 DALI_TEST_CHECK(true); // We expect an assert
890 int UtcDaliTextureUploadNegative02(void)
892 TestApplication application;
893 Dali::Texture instance;
896 Dali::PixelData arg1;
897 unsigned int arg2(0u);
898 unsigned int arg3(0u);
899 unsigned int arg4(0u);
900 unsigned int arg5(0u);
901 unsigned int arg6(0u);
902 unsigned int arg7(0u);
903 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
904 DALI_TEST_CHECK(false); // Should not get here
908 DALI_TEST_CHECK(true); // We expect an assert
913 int UtcDaliTextureGetWidthNegative(void)
915 TestApplication application;
916 Dali::Texture instance;
920 DALI_TEST_CHECK(false); // Should not get here
924 DALI_TEST_CHECK(true); // We expect an assert
929 int UtcDaliTextureGetHeightNegative(void)
931 TestApplication application;
932 Dali::Texture instance;
935 instance.GetHeight();
936 DALI_TEST_CHECK(false); // Should not get here
940 DALI_TEST_CHECK(true); // We expect an assert
945 int UtcDaliTextureCheckNativeP(void)
947 TestApplication application;
948 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
949 Texture nativeTexture = Texture::New(*testNativeImage);
951 DALI_TEST_CHECK(nativeTexture);
952 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
956 int UtcDaliTextureCheckNativeN1(void)
958 TestApplication application;
959 unsigned int width(64);
960 unsigned int height(64);
961 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
963 DALI_TEST_CHECK(texture);
964 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
968 int UtcDaliTextureCheckNativeN2(void)
970 TestApplication application;
974 bool native = DevelTexture::IsNative(texture);
975 DALI_TEST_CHECK(native != native);
979 DALI_TEST_CHECK(true);
984 int UtcDaliTextureApplyFragShaderP1(void)
986 TestApplication application;
987 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
988 Texture nativeTexture = Texture::New(*testNativeImage);
989 DALI_TEST_CHECK(nativeTexture);
991 const std::string baseFragShader =
992 "varying mediump vec4 uColor;\n"
994 " gl_FragColor=uColor;\n"
996 std::string fragShader = baseFragShader;
997 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
999 DALI_TEST_CHECK(applied);
1000 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1001 DALI_TEST_CHECK(!fragShader.empty());
1005 int UtcDaliTextureApplyFragShaderP2(void)
1007 TestApplication application;
1008 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1009 Texture nativeTexture = Texture::New(*testNativeImage);
1010 DALI_TEST_CHECK(nativeTexture);
1012 const std::string baseFragShader =
1013 "varying mediump vec4 uColor;\n"
1014 "varying vec2 vTexCoord;\n"
1015 "uniform sampler2D uNative;\n"
1017 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1019 std::string fragShader = baseFragShader;
1020 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1022 DALI_TEST_CHECK(applied);
1023 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1024 DALI_TEST_CHECK(!fragShader.empty());
1025 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1029 int UtcDaliTextureApplyFragShaderN1(void)
1031 TestApplication application;
1032 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1033 Texture nativeTexture = Texture::New(*testNativeImage);
1034 DALI_TEST_CHECK(nativeTexture);
1036 std::string fragShader;
1037 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1039 DALI_TEST_CHECK(!applied);
1040 DALI_TEST_CHECK(fragShader.empty());
1044 int UtcDaliTextureApplyFragShaderN2(void)
1046 TestApplication application;
1047 unsigned int width(64);
1048 unsigned int height(64);
1049 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1051 const std::string baseFragShader =
1052 "varying mediump vec4 uColor;\n"
1054 " gl_FragColor=uColor;\n"
1056 std::string fragShader = baseFragShader;
1057 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1059 DALI_TEST_CHECK(!applied);
1060 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));