2 * Copyright (c) 2021 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 Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
40 Texture texture = Texture::New(type, format, width, height);
42 int bufferSize = width * height * Pixel::GetBytesPerPixel(format);
43 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
44 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
45 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
49 int UtcDaliTextureNew01(void)
51 TestApplication application;
53 unsigned int width(64);
54 unsigned int height(64);
55 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
57 DALI_TEST_CHECK(texture);
61 int UtcDaliTextureNew02(void)
63 TestApplication application;
65 DALI_TEST_CHECK(!texture);
69 int UtcDaliTextureNew03(void)
71 TestApplication application;
73 // Create a native image source.
74 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
76 // Create a texture from the native image source.
77 Texture nativeTexture = Texture::New(*testNativeImage);
79 // Check the texture was created OK.
80 DALI_TEST_CHECK(nativeTexture);
85 int UtcDaliTextureCopyConstructor(void)
87 TestApplication application;
89 unsigned int width(64);
90 unsigned int height(64);
91 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
93 Texture textureCopy(texture);
95 DALI_TEST_CHECK(textureCopy);
100 int UtcDaliTextureAssignmentOperator(void)
102 TestApplication application;
103 unsigned int width(64);
104 unsigned int height(64);
105 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
108 DALI_TEST_CHECK(!texture2);
111 DALI_TEST_CHECK(texture2);
116 int UtcDaliTextureMoveConstructor(void)
118 TestApplication application;
121 uint32_t height = 64;
122 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
123 DALI_TEST_CHECK(texture);
124 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
125 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
126 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
128 Texture move = std::move(texture);
129 DALI_TEST_CHECK(move);
130 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
132 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
133 DALI_TEST_CHECK(!texture);
138 int UtcDaliTextureMoveAssignment(void)
140 TestApplication application;
143 uint32_t height = 64;
144 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
145 DALI_TEST_CHECK(texture);
146 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
147 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
148 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
151 move = std::move(texture);
152 DALI_TEST_CHECK(move);
153 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
154 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
155 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
156 DALI_TEST_CHECK(!texture);
161 int UtcDaliTextureDownCast01(void)
163 TestApplication application;
164 unsigned int width(64);
165 unsigned int height(64);
166 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
168 BaseHandle handle(texture);
169 Texture texture2 = Texture::DownCast(handle);
170 DALI_TEST_CHECK(texture2);
175 int UtcDaliTextureDownCast02(void)
177 TestApplication application;
179 Handle handle = Handle::New(); // Create a custom object
180 Texture texture = Texture::DownCast(handle);
181 DALI_TEST_CHECK(!texture);
185 int UtcDaliTextureUpload01(void)
187 TestApplication application;
190 unsigned int width(64);
191 unsigned int height(64);
192 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
194 application.GetGlAbstraction().EnableTextureCallTrace(true);
196 application.SendNotification();
197 application.Render();
199 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
201 //Upload data to the texture
204 unsigned int bufferSize(width * height * 4);
205 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
206 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
207 texture.Upload(pixelData);
208 application.SendNotification();
209 application.Render();
211 //TexImage2D should be called to upload the data
213 std::stringstream out;
214 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
215 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
218 //Upload part of the texture
220 bufferSize = width * height * 2;
221 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
222 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
223 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
224 application.SendNotification();
225 application.Render();
227 //TexSubImage2D should be called to upload the data
229 std::stringstream out;
230 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
231 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
237 int UtcDaliTextureUpload02(void)
239 TestApplication application;
242 unsigned int width(64);
243 unsigned int height(64);
244 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
246 application.GetGlAbstraction().EnableTextureCallTrace(true);
248 application.SendNotification();
249 application.Render();
251 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
253 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
254 for(unsigned int i(0); i < 6; ++i)
256 std::stringstream out;
257 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
258 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
261 unsigned int bufferSize(width * height * 4);
262 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
263 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
265 //Upload data to the POSITIVE_X face of the texture
269 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
270 application.SendNotification();
271 application.Render();
273 //TexImage2D should be called to upload the data to the POSITIVE_X face
275 std::stringstream out;
276 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
277 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
281 //Upload data to the NEGATIVE_X face of the texture
285 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
286 application.SendNotification();
287 application.Render();
289 //TexImage2D should be called to upload the data to the NEGATIVE_X face
291 std::stringstream out;
292 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
293 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
297 //Upload data to the POSITIVE_Y face of the texture
300 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
301 application.SendNotification();
302 application.Render();
304 //TexImage2D should be called to upload the data to the POSITIVE_Y face
306 std::stringstream out;
307 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
308 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
312 //Upload data to the NEGATIVE_Y face of the texture
315 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
316 application.SendNotification();
317 application.Render();
319 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
321 std::stringstream out;
322 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
323 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
327 //Upload data to the POSITIVE_Z face of the texture
330 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
331 application.SendNotification();
332 application.Render();
334 //TexImage2D should be called to upload the data to the POSITIVE_Z face
336 std::stringstream out;
337 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
338 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
342 //Upload data to the NEGATIVE_Z face of the texture
345 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
346 application.SendNotification();
347 application.Render();
349 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
351 std::stringstream out;
352 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
353 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
360 int UtcDaliTextureUpload03(void)
362 TestApplication application;
365 unsigned int width(64);
366 unsigned int height(64);
367 unsigned int widthMipmap1(32);
368 unsigned int heightMipmap1(32);
370 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
372 application.GetGlAbstraction().EnableTextureCallTrace(true);
374 application.SendNotification();
375 application.Render();
377 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
379 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
381 std::stringstream out;
382 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
383 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
386 //Upload data to the texture mipmap 0 and mipmap 1
389 unsigned int bufferSize(width * height * 4);
390 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
391 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
392 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
394 bufferSize = widthMipmap1 * heightMipmap1 * 4;
395 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
396 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
397 texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
398 application.SendNotification();
399 application.Render();
401 //TexImage2D should be called to upload the data to mipmaps 0 and 1
403 std::stringstream out;
404 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
405 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
408 std::stringstream out;
409 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
410 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
416 int UtcDaliTextureUpload04(void)
418 TestApplication application;
421 unsigned int width(64);
422 unsigned int height(64);
423 unsigned int widthMipmap1(32);
424 unsigned int heightMipmap1(32);
426 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
428 application.GetGlAbstraction().EnableTextureCallTrace(true);
429 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
431 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
432 unsigned int bufferSize(width * height * 4);
433 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
434 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
435 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
437 bufferSize = widthMipmap1 * heightMipmap1 * 4;
438 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
439 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
440 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
441 application.SendNotification();
442 application.Render();
444 //TexImage2D should be called to upload the data to mipmaps 0 and 1
446 std::stringstream out;
447 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
448 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
451 std::stringstream out;
452 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
453 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
459 int UtcDaliTextureUpload05(void)
461 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
463 Pixel::COMPRESSED_R11_EAC,
464 Pixel::COMPRESSED_SIGNED_R11_EAC,
465 Pixel::COMPRESSED_RG11_EAC,
466 Pixel::COMPRESSED_SIGNED_RG11_EAC,
467 Pixel::COMPRESSED_RGB8_ETC2,
468 Pixel::COMPRESSED_SRGB8_ETC2,
469 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
470 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
471 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
472 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
473 Pixel::COMPRESSED_RGB8_ETC1,
474 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
475 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
476 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
477 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
478 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
479 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
480 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
481 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
482 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
483 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
484 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
485 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
486 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
487 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
488 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
489 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
491 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
492 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
493 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
494 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
495 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
496 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
497 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
498 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
499 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
500 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
501 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
502 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
504 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
506 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
508 TestApplication application;
510 //Create a texture with a compressed format
511 unsigned int width(64);
512 unsigned int height(64);
513 Texture texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
515 application.GetGlAbstraction().EnableTextureCallTrace(true);
517 application.SendNotification();
518 application.Render();
520 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
522 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
524 std::stringstream out;
525 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
526 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
529 //Upload data to the texture
532 unsigned int bufferSize(width * height * 4);
533 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
534 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
535 texture.Upload(pixelData);
536 application.SendNotification();
537 application.Render();
539 //CompressedTexImage2D should be called to upload the data
541 std::stringstream out;
542 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
543 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
546 //Upload part of the texture
548 bufferSize = width * height * 2;
549 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
550 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
551 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
552 application.SendNotification();
553 application.Render();
555 //CompressedTexSubImage2D should be called to upload the data
557 std::stringstream out;
558 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
559 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
562 application.GetGlAbstraction().ResetTextureCallStack();
568 int UtcDaliTextureUpload06(void)
570 TestApplication application;
573 unsigned int width(64);
574 unsigned int height(64);
575 tet_infoline("Creating a Texure with an alpha channel");
576 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
578 application.GetGlAbstraction().EnableTextureCallTrace(true);
580 application.SendNotification();
581 application.Render();
583 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
585 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
587 std::stringstream out;
588 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
589 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
592 tet_infoline("Upload data to the texture");
595 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
596 unsigned int bufferSize(width * height * 3);
597 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
598 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
599 texture.Upload(pixelData);
600 application.SendNotification();
601 application.Render();
603 tet_infoline("TexImage2D should be called to upload the data");
605 std::stringstream out;
606 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
607 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
613 int UtcDaliTextureUpload07(void)
615 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
620 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
622 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
624 TestApplication application;
627 unsigned int width(64);
628 unsigned int height(64);
629 tet_infoline("Creating a floating point texture");
630 Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
632 application.GetGlAbstraction().EnableTextureCallTrace(true);
634 application.SendNotification();
635 application.Render();
637 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
639 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
641 std::stringstream out;
642 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
643 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
646 tet_infoline("Upload data to the texture");
649 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
650 unsigned int bufferSize(width * height * 3);
651 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
652 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
653 texture.Upload(pixelData);
654 application.SendNotification();
655 application.Render();
657 tet_infoline("TexImage2D should be called to upload the data");
659 std::stringstream out;
660 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
661 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
668 int UtcDaliTextureUploadPixelFormats(void)
670 TestApplication application;
671 application.GetGlAbstraction().EnableTextureCallTrace(true);
674 unsigned int width(64);
675 unsigned int height(64);
677 std::vector<Pixel::Format> formats =
693 Pixel::DEPTH_UNSIGNED_INT,
695 Pixel::DEPTH_STENCIL};
697 for(auto format : formats)
699 tet_infoline("Creating a Texure with an alpha channel");
700 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
702 application.SendNotification();
703 application.Render();
705 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
707 tet_infoline("TexImage2D should be called twice per texture");
708 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
710 std::stringstream out;
711 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
712 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
720 int UtcDaliTextureUploadSmallerThanSize(void)
722 TestApplication application;
725 unsigned int width(64);
726 unsigned int height(64);
727 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
729 application.GetGlAbstraction().EnableTextureCallTrace(true);
731 application.SendNotification();
732 application.Render();
734 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
735 callStack.EnableLogging(true);
736 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
737 texParamCallStack.EnableLogging(true);
739 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
741 std::stringstream out;
742 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
744 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
745 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
748 //Upload data to the texture
751 unsigned int bufferSize(width * height * 4);
752 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
753 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
754 texture.Upload(pixelData);
755 application.SendNotification();
756 application.Render();
758 //TexSubImage2D should be called to upload the data
760 std::stringstream out;
761 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
763 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
764 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
769 int UtcDaliTextureGenerateMipmaps(void)
771 #ifdef OLD_GRAPHICS_TEST
772 TestApplication application;
773 unsigned int width(64);
774 unsigned int height(64);
776 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
777 texture.GenerateMipmaps();
779 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
780 textureCubemap.GenerateMipmaps();
782 application.GetGlAbstraction().EnableTextureCallTrace(true);
783 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
784 application.SendNotification();
785 application.Render();
788 std::stringstream out;
789 out << GL_TEXTURE_2D;
790 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
793 std::stringstream out;
794 out << GL_TEXTURE_CUBE_MAP;
795 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
804 int UtcDaliTextureGetWidth(void)
806 TestApplication application;
807 unsigned int width(64);
808 unsigned int height(64);
810 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
811 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
815 int UtcDaliTextureGetHeight(void)
817 TestApplication application;
818 unsigned int width(64);
819 unsigned int height(64);
821 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
822 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
827 int UtcDaliTextureContextLoss(void)
829 tet_infoline("UtcDaliTextureContextLoss\n");
830 TestApplication application;
833 unsigned int width(64);
834 unsigned int height(64);
835 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
836 DALI_TEST_CHECK(texture);
838 application.SendNotification();
839 application.Render(16);
841 // Lose & regain context (in render 'thread')
842 application.ResetContext();
843 DALI_TEST_CHECK(texture);
848 int UtcDaliNativeImageTexture01(void)
850 TestApplication application;
851 tet_infoline("UtcDaliNativeImageTexture01");
853 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
855 Texture texture = Texture::New(*(imageInterface.Get()));
856 Actor actor = CreateRenderableActor(texture, "", "");
857 application.GetScene().Add(actor);
859 DALI_TEST_CHECK(texture);
861 application.SendNotification();
862 application.Render(16);
864 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
865 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
866 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
868 UnparentAndReset(actor);
870 application.SendNotification();
871 application.Render(16);
873 application.SendNotification();
874 application.Render(16);
876 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
877 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
882 int UtcDaliNativeImageTexture02(void)
884 TestApplication application;
885 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
887 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
888 imageInterface->mTargetTextureError = 1u;
890 Texture texture = Texture::New(*(imageInterface.Get()));
891 Actor actor = CreateRenderableActor(texture, "", "");
892 application.GetScene().Add(actor);
894 DALI_TEST_CHECK(texture);
896 application.SendNotification();
897 application.Render(16);
899 // Expect 2 attempts to create the texture - once when adding the texture
900 // to the scene-graph, and again since that failed, during the Bind.
901 // The second one succeeds (TargetTexture only errors once)
902 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
903 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
905 UnparentAndReset(actor);
907 application.SendNotification();
908 application.Render(16);
910 application.SendNotification();
911 application.Render(16);
913 // Expect that there are no further calls to create/destroy resource
914 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
915 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
920 int UtcDaliTextureGenerateMipmapsNegative(void)
922 TestApplication application;
923 Dali::Texture instance;
926 instance.GenerateMipmaps();
927 DALI_TEST_CHECK(false); // Should not get here
931 DALI_TEST_CHECK(true); // We expect an assert
936 int UtcDaliTextureUploadNegative01(void)
938 TestApplication application;
939 Dali::Texture instance;
942 Dali::PixelData arg1;
943 instance.Upload(arg1);
944 DALI_TEST_CHECK(false); // Should not get here
948 DALI_TEST_CHECK(true); // We expect an assert
953 int UtcDaliTextureUploadNegative02(void)
955 TestApplication application;
956 Dali::Texture instance;
959 Dali::PixelData arg1;
960 unsigned int arg2(0u);
961 unsigned int arg3(0u);
962 unsigned int arg4(0u);
963 unsigned int arg5(0u);
964 unsigned int arg6(0u);
965 unsigned int arg7(0u);
966 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
967 DALI_TEST_CHECK(false); // Should not get here
971 DALI_TEST_CHECK(true); // We expect an assert
976 int UtcDaliTextureGetWidthNegative(void)
978 TestApplication application;
979 Dali::Texture instance;
983 DALI_TEST_CHECK(false); // Should not get here
987 DALI_TEST_CHECK(true); // We expect an assert
992 int UtcDaliTextureGetHeightNegative(void)
994 TestApplication application;
995 Dali::Texture instance;
998 instance.GetHeight();
999 DALI_TEST_CHECK(false); // Should not get here
1003 DALI_TEST_CHECK(true); // We expect an assert
1008 int UtcDaliTextureCheckNativeP(void)
1010 TestApplication application;
1011 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1012 Texture nativeTexture = Texture::New(*testNativeImage);
1014 DALI_TEST_CHECK(nativeTexture);
1015 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1019 int UtcDaliTextureCheckNativeN1(void)
1021 TestApplication application;
1022 unsigned int width(64);
1023 unsigned int height(64);
1024 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1026 DALI_TEST_CHECK(texture);
1027 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1031 int UtcDaliTextureCheckNativeN2(void)
1033 TestApplication application;
1037 bool native = DevelTexture::IsNative(texture);
1038 DALI_TEST_CHECK(native != native);
1042 DALI_TEST_CHECK(true);
1047 int UtcDaliTextureApplyFragShaderP1(void)
1049 TestApplication application;
1050 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1051 Texture nativeTexture = Texture::New(*testNativeImage);
1052 DALI_TEST_CHECK(nativeTexture);
1054 const std::string baseFragShader =
1055 "varying mediump vec4 uColor;\n"
1057 " gl_FragColor=uColor;\n"
1059 std::string fragShader = baseFragShader;
1060 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1062 DALI_TEST_CHECK(applied);
1063 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1064 DALI_TEST_CHECK(!fragShader.empty());
1068 int UtcDaliTextureApplyFragShaderP2(void)
1070 TestApplication application;
1071 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1072 Texture nativeTexture = Texture::New(*testNativeImage);
1073 DALI_TEST_CHECK(nativeTexture);
1075 const std::string baseFragShader =
1076 "varying mediump vec4 uColor;\n"
1077 "varying vec2 vTexCoord;\n"
1078 "uniform sampler2D uNative;\n"
1080 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1082 std::string fragShader = baseFragShader;
1083 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1085 DALI_TEST_CHECK(applied);
1086 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1087 DALI_TEST_CHECK(!fragShader.empty());
1088 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1092 int UtcDaliTextureApplyFragShaderN1(void)
1094 TestApplication application;
1095 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1096 Texture nativeTexture = Texture::New(*testNativeImage);
1097 DALI_TEST_CHECK(nativeTexture);
1099 std::string fragShader;
1100 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1102 DALI_TEST_CHECK(!applied);
1103 DALI_TEST_CHECK(fragShader.empty());
1107 int UtcDaliTextureApplyFragShaderN2(void)
1109 TestApplication application;
1110 unsigned int width(64);
1111 unsigned int height(64);
1112 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1114 const std::string baseFragShader =
1115 "varying mediump vec4 uColor;\n"
1117 " gl_FragColor=uColor;\n"
1119 std::string fragShader = baseFragShader;
1120 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1122 DALI_TEST_CHECK(!applied);
1123 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));