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/public-api/dali-core.h>
21 #include <test-native-image.h>
25 #include <mesh-builder.h>
27 void texture_set_startup(void)
29 test_return_value = TET_UNDEF;
32 void texture_set_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliTextureNew01(void)
39 TestApplication application;
41 unsigned int width(64);
42 unsigned int height(64);
43 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
45 DALI_TEST_CHECK(texture);
49 int UtcDaliTextureNew02(void)
51 TestApplication application;
53 DALI_TEST_CHECK(!texture);
57 int UtcDaliTextureNew03(void)
59 TestApplication application;
61 // Create a native image source.
62 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
64 // Create a texture from the native image source.
65 Texture nativeTexture = Texture::New(*testNativeImage);
67 // Check the texture was created OK.
68 DALI_TEST_CHECK(nativeTexture);
73 int UtcDaliTextureCopyConstructor(void)
75 TestApplication application;
77 unsigned int width(64);
78 unsigned int height(64);
79 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
81 Texture textureCopy(texture);
83 DALI_TEST_CHECK(textureCopy);
88 int UtcDaliTextureAssignmentOperator(void)
90 TestApplication application;
91 unsigned int width(64);
92 unsigned int height(64);
93 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
96 DALI_TEST_CHECK(!texture2);
99 DALI_TEST_CHECK(texture2);
104 int UtcDaliTextureMoveConstructor(void)
106 TestApplication application;
109 uint32_t height = 64;
110 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
111 DALI_TEST_CHECK(texture);
112 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
114 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
116 Texture move = std::move(texture);
117 DALI_TEST_CHECK(move);
118 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
119 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
120 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
121 DALI_TEST_CHECK(!texture);
126 int UtcDaliTextureMoveAssignment(void)
128 TestApplication application;
131 uint32_t height = 64;
132 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
133 DALI_TEST_CHECK(texture);
134 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
135 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
136 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
139 move = std::move(texture);
140 DALI_TEST_CHECK(move);
141 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
143 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
144 DALI_TEST_CHECK(!texture);
149 int UtcDaliTextureDownCast01(void)
151 TestApplication application;
152 unsigned int width(64);
153 unsigned int height(64);
154 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
156 BaseHandle handle(texture);
157 Texture texture2 = Texture::DownCast(handle);
158 DALI_TEST_CHECK(texture2);
163 int UtcDaliTextureDownCast02(void)
165 TestApplication application;
167 Handle handle = Handle::New(); // Create a custom object
168 Texture texture = Texture::DownCast(handle);
169 DALI_TEST_CHECK(!texture);
173 int UtcDaliTextureUpload01(void)
175 TestApplication application;
178 unsigned int width(64);
179 unsigned int height(64);
180 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
182 application.GetGlAbstraction().EnableTextureCallTrace(true);
184 application.SendNotification();
185 application.Render();
187 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
189 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
191 std::stringstream out;
192 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
193 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
196 //Upload data to the texture
199 unsigned int bufferSize(width * height * 4);
200 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
201 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
202 texture.Upload(pixelData);
203 application.SendNotification();
204 application.Render();
206 //TexImage2D should be called to upload the data
208 std::stringstream out;
209 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
210 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
213 //Upload part of the texture
215 bufferSize = width * height * 2;
216 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
217 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
218 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
219 application.SendNotification();
220 application.Render();
222 //TexSubImage2D should be called to upload the data
224 std::stringstream out;
225 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
226 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
232 int UtcDaliTextureUpload02(void)
234 TestApplication application;
237 unsigned int width(64);
238 unsigned int height(64);
239 Texture texture = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
241 application.GetGlAbstraction().EnableTextureCallTrace(true);
243 application.SendNotification();
244 application.Render();
246 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
248 //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
249 for(unsigned int i(0); i < 6; ++i)
251 std::stringstream out;
252 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
253 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
256 unsigned int bufferSize(width * height * 4);
257 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
258 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
260 //Upload data to the POSITIVE_X face of the texture
264 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
265 application.SendNotification();
266 application.Render();
268 //TexImage2D should be called to upload the data to the POSITIVE_X face
270 std::stringstream out;
271 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
272 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
276 //Upload data to the NEGATIVE_X face of the texture
280 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
281 application.SendNotification();
282 application.Render();
284 //TexImage2D should be called to upload the data to the NEGATIVE_X face
286 std::stringstream out;
287 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
288 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
292 //Upload data to the POSITIVE_Y face of the texture
295 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
296 application.SendNotification();
297 application.Render();
299 //TexImage2D should be called to upload the data to the POSITIVE_Y face
301 std::stringstream out;
302 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
303 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
307 //Upload data to the NEGATIVE_Y face of the texture
310 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
311 application.SendNotification();
312 application.Render();
314 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
316 std::stringstream out;
317 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
318 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
322 //Upload data to the POSITIVE_Z face of the texture
325 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
326 application.SendNotification();
327 application.Render();
329 //TexImage2D should be called to upload the data to the POSITIVE_Z face
331 std::stringstream out;
332 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
333 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
337 //Upload data to the NEGATIVE_Z face of the texture
340 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
341 application.SendNotification();
342 application.Render();
344 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
346 std::stringstream out;
347 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
348 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
355 int UtcDaliTextureUpload03(void)
357 TestApplication application;
360 unsigned int width(64);
361 unsigned int height(64);
362 unsigned int widthMipmap1(32);
363 unsigned int heightMipmap1(32);
365 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
367 application.GetGlAbstraction().EnableTextureCallTrace(true);
369 application.SendNotification();
370 application.Render();
372 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
374 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
376 std::stringstream out;
377 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
378 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
381 //Upload data to the texture 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, 0u, 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, 0u, 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_2D << ", " << 0u << ", " << width << ", " << height;
400 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
403 std::stringstream out;
404 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
405 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
411 int UtcDaliTextureUpload04(void)
413 TestApplication application;
416 unsigned int width(64);
417 unsigned int height(64);
418 unsigned int widthMipmap1(32);
419 unsigned int heightMipmap1(32);
421 Texture texture = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
423 application.GetGlAbstraction().EnableTextureCallTrace(true);
424 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
426 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
427 unsigned int bufferSize(width * height * 4);
428 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
429 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
430 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
432 bufferSize = widthMipmap1 * heightMipmap1 * 4;
433 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
434 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
435 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
436 application.SendNotification();
437 application.Render();
439 //TexImage2D should be called to upload the data to mipmaps 0 and 1
441 std::stringstream out;
442 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
443 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
446 std::stringstream out;
447 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
448 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
454 int UtcDaliTextureUpload05(void)
456 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
458 Pixel::COMPRESSED_R11_EAC,
459 Pixel::COMPRESSED_SIGNED_R11_EAC,
460 Pixel::COMPRESSED_RG11_EAC,
461 Pixel::COMPRESSED_SIGNED_RG11_EAC,
462 Pixel::COMPRESSED_RGB8_ETC2,
463 Pixel::COMPRESSED_SRGB8_ETC2,
464 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
465 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
466 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
467 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
468 Pixel::COMPRESSED_RGB8_ETC1,
469 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
470 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
471 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
472 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
473 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
474 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
475 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
476 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
477 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
478 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
479 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
480 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
481 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
482 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
483 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
484 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
485 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
486 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
487 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
488 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
489 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
491 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
492 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
493 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
494 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
495 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
496 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
497 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
499 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
501 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
503 TestApplication application;
505 //Create a texture with a compressed format
506 unsigned int width(64);
507 unsigned int height(64);
508 Texture texture = Texture::New(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
510 application.GetGlAbstraction().EnableTextureCallTrace(true);
512 application.SendNotification();
513 application.Render();
515 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
517 //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
519 std::stringstream out;
520 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
521 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
524 //Upload data to the texture
527 unsigned int bufferSize(width * height * 4);
528 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
529 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
530 texture.Upload(pixelData);
531 application.SendNotification();
532 application.Render();
534 //CompressedTexImage2D should be called to upload the data
536 std::stringstream out;
537 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
538 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
541 //Upload part of the texture
543 bufferSize = width * height * 2;
544 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
545 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
546 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
547 application.SendNotification();
548 application.Render();
550 //CompressedTexSubImage2D should be called to upload the data
552 std::stringstream out;
553 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
554 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
557 application.GetGlAbstraction().ResetTextureCallStack();
563 int UtcDaliTextureUpload06(void)
565 TestApplication application;
568 unsigned int width(64);
569 unsigned int height(64);
570 tet_infoline("Creating a Texure with an alpha channel");
571 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
573 application.GetGlAbstraction().EnableTextureCallTrace(true);
575 application.SendNotification();
576 application.Render();
578 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
580 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
582 std::stringstream out;
583 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
584 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
587 tet_infoline("Upload data to the texture");
590 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
591 unsigned int bufferSize(width * height * 3);
592 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
593 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
594 texture.Upload(pixelData);
595 application.SendNotification();
596 application.Render();
598 tet_infoline("TexImage2D should be called to upload the data");
600 std::stringstream out;
601 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
602 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
608 int UtcDaliTextureUpload07(void)
610 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
615 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
617 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
619 TestApplication application;
622 unsigned int width(64);
623 unsigned int height(64);
624 tet_infoline("Creating a floating point texture");
625 Texture texture = Texture::New(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
627 application.GetGlAbstraction().EnableTextureCallTrace(true);
629 application.SendNotification();
630 application.Render();
632 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
634 tet_infoline("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;
638 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
641 tet_infoline("Upload data to the texture");
644 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
645 unsigned int bufferSize(width * height * 3);
646 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
647 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
648 texture.Upload(pixelData);
649 application.SendNotification();
650 application.Render();
652 tet_infoline("TexImage2D should be called to upload the data");
654 std::stringstream out;
655 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
656 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
663 int UtcDaliTextureUploadSmallerThanSize(void)
665 TestApplication application;
668 unsigned int width(64);
669 unsigned int height(64);
670 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
672 application.GetGlAbstraction().EnableTextureCallTrace(true);
674 application.SendNotification();
675 application.Render();
677 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
679 //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
681 std::stringstream out;
682 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
684 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
685 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
688 //Upload data to the texture
691 unsigned int bufferSize(width * height * 4);
692 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
693 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
694 texture.Upload(pixelData);
695 application.SendNotification();
696 application.Render();
698 //TexImage2D should be called to upload the data
700 std::stringstream out;
701 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
703 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
704 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
710 int UtcDaliTextureGenerateMipmaps(void)
712 TestApplication application;
713 unsigned int width(64);
714 unsigned int height(64);
716 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
717 texture.GenerateMipmaps();
719 Texture textureCubemap = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
720 textureCubemap.GenerateMipmaps();
722 application.GetGlAbstraction().EnableTextureCallTrace(true);
723 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
724 application.SendNotification();
725 application.Render();
728 std::stringstream out;
729 out << GL_TEXTURE_2D;
730 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
733 std::stringstream out;
734 out << GL_TEXTURE_CUBE_MAP;
735 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
741 int UtcDaliTextureGetWidth(void)
743 TestApplication application;
744 unsigned int width(64);
745 unsigned int height(64);
747 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
748 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
752 int UtcDaliTextureGetHeight(void)
754 TestApplication application;
755 unsigned int width(64);
756 unsigned int height(64);
758 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
759 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
764 int UtcDaliTextureContextLoss(void)
766 tet_infoline("UtcDaliTextureContextLoss\n");
767 TestApplication application;
770 unsigned int width(64);
771 unsigned int height(64);
772 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
773 DALI_TEST_CHECK(texture);
775 application.SendNotification();
776 application.Render(16);
778 // Lose & regain context (in render 'thread')
779 application.ResetContext();
780 DALI_TEST_CHECK(texture);
785 int UtcDaliNativeImageTexture01(void)
787 TestApplication application;
788 tet_infoline("UtcDaliNativeImageTexture01");
790 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
792 Texture texture = Texture::New(*(imageInterface.Get()));
793 Actor actor = CreateRenderableActor(texture, "", "");
794 application.GetScene().Add(actor);
796 DALI_TEST_CHECK(texture);
798 application.SendNotification();
799 application.Render(16);
801 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
802 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
803 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
805 UnparentAndReset(actor);
807 application.SendNotification();
808 application.Render(16);
810 application.SendNotification();
811 application.Render(16);
813 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
814 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
819 int UtcDaliNativeImageTexture02(void)
821 TestApplication application;
822 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
824 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
825 imageInterface->mTargetTextureError = 1u;
827 Texture texture = Texture::New(*(imageInterface.Get()));
828 Actor actor = CreateRenderableActor(texture, "", "");
829 application.GetScene().Add(actor);
831 DALI_TEST_CHECK(texture);
833 application.SendNotification();
834 application.Render(16);
836 // Expect 2 attempts to create the texture - once when adding the texture
837 // to the scene-graph, and again since that failed, during the Bind.
838 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
839 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
841 UnparentAndReset(actor);
843 application.SendNotification();
844 application.Render(16);
846 application.SendNotification();
847 application.Render(16);
849 // Expect that there are no further calls to create/destroy resource
850 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
851 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
856 int UtcDaliTextureGenerateMipmapsNegative(void)
858 TestApplication application;
859 Dali::Texture instance;
862 instance.GenerateMipmaps();
863 DALI_TEST_CHECK(false); // Should not get here
867 DALI_TEST_CHECK(true); // We expect an assert
872 int UtcDaliTextureUploadNegative01(void)
874 TestApplication application;
875 Dali::Texture instance;
878 Dali::PixelData arg1;
879 instance.Upload(arg1);
880 DALI_TEST_CHECK(false); // Should not get here
884 DALI_TEST_CHECK(true); // We expect an assert
889 int UtcDaliTextureUploadNegative02(void)
891 TestApplication application;
892 Dali::Texture instance;
895 Dali::PixelData arg1;
896 unsigned int arg2(0u);
897 unsigned int arg3(0u);
898 unsigned int arg4(0u);
899 unsigned int arg5(0u);
900 unsigned int arg6(0u);
901 unsigned int arg7(0u);
902 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
903 DALI_TEST_CHECK(false); // Should not get here
907 DALI_TEST_CHECK(true); // We expect an assert
912 int UtcDaliTextureGetWidthNegative(void)
914 TestApplication application;
915 Dali::Texture instance;
919 DALI_TEST_CHECK(false); // Should not get here
923 DALI_TEST_CHECK(true); // We expect an assert
928 int UtcDaliTextureGetHeightNegative(void)
930 TestApplication application;
931 Dali::Texture instance;
934 instance.GetHeight();
935 DALI_TEST_CHECK(false); // Should not get here
939 DALI_TEST_CHECK(true); // We expect an assert