2 * Copyright (c) 2023 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/rendering/texture-devel.h>
20 #include <dali/integration-api/texture-integ.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 UtcDaliTextureNew04(void)
76 TestApplication application;
78 Texture texture = Texture::New(TextureType::TEXTURE_2D);
80 DALI_TEST_CHECK(texture);
84 int UtcDaliTextureNew05(void)
86 TestApplication application;
88 uint32_t expectResourceId = 11u;
90 Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
92 DALI_TEST_CHECK(texture);
94 uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
96 DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
101 int UtcDaliTextureCopyConstructor(void)
103 TestApplication application;
105 unsigned int width(64);
106 unsigned int height(64);
107 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
109 Texture textureCopy(texture);
111 DALI_TEST_CHECK(textureCopy);
116 int UtcDaliTextureAssignmentOperator(void)
118 TestApplication application;
119 unsigned int width(64);
120 unsigned int height(64);
121 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
124 DALI_TEST_CHECK(!texture2);
127 DALI_TEST_CHECK(texture2);
132 int UtcDaliTextureMoveConstructor(void)
134 TestApplication application;
137 uint32_t height = 64;
138 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
139 DALI_TEST_CHECK(texture);
140 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
141 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
142 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
144 Texture move = std::move(texture);
145 DALI_TEST_CHECK(move);
146 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
147 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
148 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
149 DALI_TEST_CHECK(!texture);
154 int UtcDaliTextureMoveAssignment(void)
156 TestApplication application;
159 uint32_t height = 64;
160 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
161 DALI_TEST_CHECK(texture);
162 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
163 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
164 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
167 move = std::move(texture);
168 DALI_TEST_CHECK(move);
169 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
170 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
171 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
172 DALI_TEST_CHECK(!texture);
177 int UtcDaliTextureDownCast01(void)
179 TestApplication application;
180 unsigned int width(64);
181 unsigned int height(64);
182 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
184 BaseHandle handle(texture);
185 Texture texture2 = Texture::DownCast(handle);
186 DALI_TEST_CHECK(texture2);
191 int UtcDaliTextureDownCast02(void)
193 TestApplication application;
195 Handle handle = Handle::New(); // Create a custom object
196 Texture texture = Texture::DownCast(handle);
197 DALI_TEST_CHECK(!texture);
201 int UtcDaliTextureUpload01(void)
203 TestApplication application;
206 unsigned int width(64);
207 unsigned int height(64);
208 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
210 application.GetGlAbstraction().EnableTextureCallTrace(true);
212 application.SendNotification();
213 application.Render();
215 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
217 //Upload data to the texture
220 unsigned int bufferSize(width * height * 4);
221 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
222 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
223 texture.Upload(pixelData);
224 application.SendNotification();
225 application.Render();
227 //TexImage2D should be called to upload the data
229 std::stringstream out;
230 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
231 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
234 //Upload part of the texture
236 bufferSize = width * height;
237 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
238 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
239 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
240 application.SendNotification();
241 application.Render();
243 //TexSubImage2D should be called to upload the data
245 std::stringstream out;
246 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
247 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
253 int UtcDaliTextureUpload02(void)
255 TestApplication application;
258 unsigned int width(64);
259 unsigned int height(64);
260 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
262 application.GetGlAbstraction().EnableTextureCallTrace(true);
264 application.SendNotification();
265 application.Render();
267 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
269 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
270 for(unsigned int i(0); i < 6; ++i)
272 std::stringstream out;
273 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
274 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
277 unsigned int bufferSize(width * height * 4);
278 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
279 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
281 //Upload data to the POSITIVE_X face of the texture
285 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
286 application.SendNotification();
287 application.Render();
289 //TexImage2D should be called to upload the data to the POSITIVE_X face
291 std::stringstream out;
292 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
293 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
297 //Upload data to the NEGATIVE_X face of the texture
301 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
302 application.SendNotification();
303 application.Render();
305 //TexImage2D should be called to upload the data to the NEGATIVE_X face
307 std::stringstream out;
308 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
309 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
313 //Upload data to the POSITIVE_Y face of the texture
316 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
317 application.SendNotification();
318 application.Render();
320 //TexImage2D should be called to upload the data to the POSITIVE_Y face
322 std::stringstream out;
323 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
324 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
328 //Upload data to the NEGATIVE_Y face of the texture
331 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
332 application.SendNotification();
333 application.Render();
335 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
337 std::stringstream out;
338 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
339 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
343 //Upload data to the POSITIVE_Z face of the texture
346 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
347 application.SendNotification();
348 application.Render();
350 //TexImage2D should be called to upload the data to the POSITIVE_Z face
352 std::stringstream out;
353 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
354 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
358 //Upload data to the NEGATIVE_Z face of the texture
361 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
362 application.SendNotification();
363 application.Render();
365 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
367 std::stringstream out;
368 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
369 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
376 int UtcDaliTextureUpload03(void)
378 TestApplication application;
381 unsigned int width(64);
382 unsigned int height(64);
383 unsigned int widthMipmap1(32);
384 unsigned int heightMipmap1(32);
386 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
388 application.GetGlAbstraction().EnableTextureCallTrace(true);
390 application.SendNotification();
391 application.Render();
393 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
395 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
397 std::stringstream out;
398 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
399 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
402 //Upload data to the texture mipmap 0 and mipmap 1
405 unsigned int bufferSize(width * height * 4);
406 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
407 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
408 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
410 bufferSize = widthMipmap1 * heightMipmap1 * 4;
411 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
412 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
413 texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
414 application.SendNotification();
415 application.Render();
417 //TexImage2D should be called to upload the data to mipmaps 0 and 1
419 std::stringstream out;
420 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
421 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
424 std::stringstream out;
425 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
426 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
432 int UtcDaliTextureUpload04(void)
434 TestApplication application;
437 unsigned int width(64);
438 unsigned int height(64);
439 unsigned int widthMipmap1(32);
440 unsigned int heightMipmap1(32);
442 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
444 application.GetGlAbstraction().EnableTextureCallTrace(true);
445 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
447 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
448 unsigned int bufferSize(width * height * 4);
449 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
450 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
451 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
453 bufferSize = widthMipmap1 * heightMipmap1 * 4;
454 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
455 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
456 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
457 application.SendNotification();
458 application.Render();
460 //TexImage2D should be called to upload the data to mipmaps 0 and 1
462 std::stringstream out;
463 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
464 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
467 std::stringstream out;
468 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
469 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
475 int UtcDaliTextureUpload05(void)
477 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
479 Pixel::COMPRESSED_R11_EAC,
480 Pixel::COMPRESSED_SIGNED_R11_EAC,
481 Pixel::COMPRESSED_RG11_EAC,
482 Pixel::COMPRESSED_SIGNED_RG11_EAC,
483 Pixel::COMPRESSED_RGB8_ETC2,
484 Pixel::COMPRESSED_SRGB8_ETC2,
485 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
486 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
487 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
488 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
489 Pixel::COMPRESSED_RGB8_ETC1,
490 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
491 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
492 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
493 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
494 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
495 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
496 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
497 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
498 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
499 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
500 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
501 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
502 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
503 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
504 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
505 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
506 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
507 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
508 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
509 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
510 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
511 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
512 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
513 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
514 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
515 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
516 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
517 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
518 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
520 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
522 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
524 TestApplication application;
526 //Create a texture with a compressed format
527 unsigned int width(64);
528 unsigned int height(64);
529 Texture texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
531 application.GetGlAbstraction().EnableTextureCallTrace(true);
533 application.SendNotification();
534 application.Render();
536 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
538 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
540 std::stringstream out;
541 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
542 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
545 //Upload data to the texture
548 unsigned int bufferSize(width * height * 4);
549 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
550 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
551 texture.Upload(pixelData);
552 application.SendNotification();
553 application.Render();
555 //CompressedTexImage2D should be called to upload the data
557 std::stringstream out;
558 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
559 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
562 //Upload part of the texture
564 bufferSize = width * height;
565 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
566 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
567 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
568 application.SendNotification();
569 application.Render();
571 //CompressedTexSubImage2D should be called to upload the data
573 std::stringstream out;
574 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
575 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
578 application.GetGlAbstraction().ResetTextureCallStack();
584 int UtcDaliTextureUpload06(void)
586 TestApplication application;
589 unsigned int width(64);
590 unsigned int height(64);
591 tet_infoline("Creating a Texure with an alpha channel");
592 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
594 application.GetGlAbstraction().EnableTextureCallTrace(true);
596 application.SendNotification();
597 application.Render();
599 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
601 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
603 std::stringstream out;
604 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
605 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
608 tet_infoline("Upload data to the texture");
611 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
612 unsigned int bufferSize(width * height * 3);
613 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
614 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
615 texture.Upload(pixelData);
616 application.SendNotification();
617 application.Render();
619 tet_infoline("TexImage2D should be called to upload the data");
621 std::stringstream out;
622 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
623 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
629 int UtcDaliTextureUpload07(void)
631 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
636 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
638 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
640 TestApplication application;
643 unsigned int width(64);
644 unsigned int height(64);
645 tet_infoline("Creating a floating point texture");
646 Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
648 application.GetGlAbstraction().EnableTextureCallTrace(true);
650 application.SendNotification();
651 application.Render();
653 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
655 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
657 std::stringstream out;
658 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
659 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
662 tet_infoline("Upload data to the texture");
665 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
666 unsigned int bufferSize(width * height * 3);
667 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
668 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
669 texture.Upload(pixelData);
670 application.SendNotification();
671 application.Render();
673 tet_infoline("TexImage2D should be called to upload the data");
675 std::stringstream out;
676 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
677 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
684 int UtcDaliTextureUpload08(void)
686 TestApplication application;
688 //Create the texture without pixel information
689 tet_infoline("Creating a Texure without any size/format information");
690 Texture texture = Texture::New(TextureType::TEXTURE_2D);
692 application.GetGlAbstraction().EnableTextureCallTrace(true);
694 application.SendNotification();
695 application.Render();
697 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
699 tet_infoline("TexImage2D should not be called with a null pointer to reserve storage for the texture in the gpu");
700 DALI_TEST_CHECK(!callStack.FindMethod("GenTextures"));
701 DALI_TEST_CHECK(!callStack.FindMethod("TexImage2D"));
703 tet_infoline("Upload data to the texture");
704 unsigned int width(64);
705 unsigned int height(64);
708 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
709 unsigned int bufferSize(width * height * 3);
710 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
711 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
712 texture.Upload(pixelData);
713 application.SendNotification();
714 application.Render();
716 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
717 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
718 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
719 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
721 tet_infoline("TexImage2D should be called to upload the data");
722 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
724 std::stringstream out;
725 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
726 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
729 tet_infoline("Upload another data to the texture");
734 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
735 bufferSize = width * height * 4;
736 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
737 pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
738 texture.Upload(pixelData);
739 application.SendNotification();
740 application.Render();
742 tet_infoline("TexImage2D should be generate new graphics, and be called to upload the data");
743 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
745 std::stringstream out;
746 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
747 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
750 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
751 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
752 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
753 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
758 int UtcDaliTextureUploadSubPixelData01(void)
760 TestApplication application;
763 unsigned int width(64);
764 unsigned int height(64);
765 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
767 application.GetGlAbstraction().EnableTextureCallTrace(true);
769 application.SendNotification();
770 application.Render();
772 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
774 //Upload data to the texture
777 uint32_t bufferWidth = width * 2;
778 uint32_t bufferHeight = height * 2;
779 uint32_t bufferXOffset = width;
780 uint32_t bufferYOffset = height;
782 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
783 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
784 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
785 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
786 application.SendNotification();
787 application.Render();
789 //TexImage2D should be called to upload the data
791 std::stringstream out;
792 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
793 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
796 //Upload part of the texture
798 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
799 application.SendNotification();
800 application.Render();
802 //TexSubImage2D should be called to upload the data
804 std::stringstream out;
805 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
806 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
812 int UtcDaliTextureUploadSubPixelData02(void)
814 TestApplication application;
817 unsigned int width(64);
818 unsigned int height(64);
819 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
821 application.GetGlAbstraction().EnableTextureCallTrace(true);
823 application.SendNotification();
824 application.Render();
826 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
828 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
829 for(unsigned int i(0); i < 6; ++i)
831 std::stringstream out;
832 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
833 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
836 uint32_t bufferWidth = width * 2;
837 uint32_t bufferHeight = height * 2;
838 uint32_t bufferXOffset = width;
839 uint32_t bufferYOffset = height;
841 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
842 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
843 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
845 //Upload data to the POSITIVE_X face of the texture
849 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
850 application.SendNotification();
851 application.Render();
853 //TexImage2D should be called to upload the data to the POSITIVE_X face
855 std::stringstream out;
856 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
857 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
861 //Upload data to the NEGATIVE_X face of the texture
865 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
866 application.SendNotification();
867 application.Render();
869 //TexImage2D should be called to upload the data to the NEGATIVE_X face
871 std::stringstream out;
872 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
873 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
877 //Upload data to the POSITIVE_Y face of the texture
880 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
881 application.SendNotification();
882 application.Render();
884 //TexImage2D should be called to upload the data to the POSITIVE_Y face
886 std::stringstream out;
887 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
888 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
892 //Upload data to the NEGATIVE_Y face of the texture
895 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
896 application.SendNotification();
897 application.Render();
899 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
901 std::stringstream out;
902 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
903 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
907 //Upload data to the POSITIVE_Z face of the texture
910 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
911 application.SendNotification();
912 application.Render();
914 //TexImage2D should be called to upload the data to the POSITIVE_Z face
916 std::stringstream out;
917 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
918 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
922 //Upload data to the NEGATIVE_Z face of the texture
925 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
926 application.SendNotification();
927 application.Render();
929 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
931 std::stringstream out;
932 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
933 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
940 int UtcDaliTextureUploadPixelFormats(void)
942 TestApplication application;
943 application.GetGlAbstraction().EnableTextureCallTrace(true);
946 unsigned int width(64);
947 unsigned int height(64);
949 std::vector<Pixel::Format> formats =
965 Pixel::DEPTH_UNSIGNED_INT,
967 Pixel::DEPTH_STENCIL,
971 Pixel::CHROMINANCE_U,
972 Pixel::CHROMINANCE_V};
974 for(auto format : formats)
976 tet_infoline("Creating a Texure with a new or recent format");
977 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
979 application.SendNotification();
980 application.Render();
982 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
984 tet_infoline("TexImage2D should be called twice per texture");
985 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
987 std::stringstream out;
988 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
989 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
997 int UtcDaliTextureUploadSmallerThanSize(void)
999 TestApplication application;
1001 //Create the texture
1002 unsigned int width(64);
1003 unsigned int height(64);
1004 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1006 application.GetGlAbstraction().EnableTextureCallTrace(true);
1008 application.SendNotification();
1009 application.Render();
1011 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1012 callStack.EnableLogging(true);
1013 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
1014 texParamCallStack.EnableLogging(true);
1016 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
1018 std::stringstream out;
1019 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1021 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
1022 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1025 //Upload data to the texture
1028 unsigned int bufferSize(width * height * 4);
1029 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1030 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
1031 texture.Upload(pixelData);
1032 application.SendNotification();
1033 application.Render();
1035 //TexSubImage2D should be called to upload the data
1037 std::stringstream out;
1038 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
1040 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
1041 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1046 int UtcDaliTextureGenerateMipmaps(void)
1048 TestApplication application;
1049 unsigned int width(64);
1050 unsigned int height(64);
1052 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1053 texture.GenerateMipmaps();
1055 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1056 textureCubemap.GenerateMipmaps();
1058 application.GetGlAbstraction().EnableTextureCallTrace(true);
1059 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1060 application.SendNotification();
1061 application.Render();
1064 std::stringstream out;
1065 out << GL_TEXTURE_2D;
1066 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1069 std::stringstream out;
1070 out << GL_TEXTURE_CUBE_MAP;
1071 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1077 int UtcDaliTextureGenerateMipmapsCompressedFormat(void)
1079 TestApplication application;
1080 unsigned int width(64);
1081 unsigned int height(64);
1083 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA8_ETC2_EAC, width, height);
1084 texture.GenerateMipmaps();
1086 application.GetGlAbstraction().EnableTextureCallTrace(true);
1087 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1088 application.SendNotification();
1089 application.Render();
1091 // Check generate mipmap didn't called when we use compressed pixel format.
1092 DALI_TEST_CHECK(!callStack.FindMethod("GenerateMipmap"));
1097 int UtcDaliTextureGetWidth(void)
1099 TestApplication application;
1100 unsigned int width(64);
1101 unsigned int height(64);
1103 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1104 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1108 int UtcDaliTextureGetHeight(void)
1110 TestApplication application;
1111 unsigned int width(64);
1112 unsigned int height(64);
1114 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1115 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1120 int UtcDaliTextureGetTextureType(void)
1122 TestApplication application;
1123 unsigned int width(64);
1124 unsigned int height(64);
1126 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1127 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
1129 texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1130 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
1135 int UtcDaliTextureSetSize(void)
1137 TestApplication application;
1138 unsigned int width(64);
1139 unsigned int height(64);
1141 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1142 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1143 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1144 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1149 Integration::SetTextureSize(texture, ImageDimensions(width, height));
1150 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1151 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1152 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1154 application.SendNotification();
1155 application.Render();
1160 int UtcDaliTextureSetPixelFormat(void)
1162 TestApplication application;
1163 unsigned int width(64);
1164 unsigned int height(64);
1166 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1167 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1168 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1169 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1171 Integration::SetTexturePixelFormat(texture, Pixel::BGRA5551);
1172 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1173 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1174 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::BGRA5551, TEST_LOCATION);
1176 application.SendNotification();
1177 application.Render();
1182 int UtcDaliTextureContextLoss(void)
1184 tet_infoline("UtcDaliTextureContextLoss\n");
1185 TestApplication application;
1187 //Create the texture
1188 unsigned int width(64);
1189 unsigned int height(64);
1190 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1191 DALI_TEST_CHECK(texture);
1193 application.SendNotification();
1194 application.Render(16);
1196 // Lose & regain context (in render 'thread')
1197 application.ResetContext();
1198 DALI_TEST_CHECK(texture);
1203 int UtcDaliNativeImageTexture01(void)
1205 TestApplication application;
1206 tet_infoline("UtcDaliNativeImageTexture01");
1208 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1210 Texture texture = Texture::New(*(imageInterface.Get()));
1211 Actor actor = CreateRenderableActor(texture, "", "");
1212 application.GetScene().Add(actor);
1214 DALI_TEST_CHECK(texture);
1216 application.SendNotification();
1217 application.Render(16);
1219 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1220 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1221 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1223 UnparentAndReset(actor);
1225 application.SendNotification();
1226 application.Render(16);
1228 application.SendNotification();
1229 application.Render(16);
1231 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1232 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1237 int UtcDaliNativeImageTexture02(void)
1239 TestApplication application;
1240 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1242 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1243 imageInterface->mTargetTextureError = 1u;
1245 Texture texture = Texture::New(*(imageInterface.Get()));
1246 Actor actor = CreateRenderableActor(texture, "", "");
1247 application.GetScene().Add(actor);
1249 DALI_TEST_CHECK(texture);
1251 application.SendNotification();
1252 application.Render(16);
1254 // Expect 2 attempts to create the texture - once when adding the texture
1255 // to the scene-graph, and again since that failed, during the Bind.
1256 // The second one succeeds (TargetTexture only errors once)
1257 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1258 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1260 UnparentAndReset(actor);
1262 application.SendNotification();
1263 application.Render(16);
1265 application.SendNotification();
1266 application.Render(16);
1268 // Expect that there are no further calls to create/destroy resource
1269 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1270 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1275 int UtcDaliTextureGenerateMipmapsNegative(void)
1277 TestApplication application;
1278 Dali::Texture instance;
1281 instance.GenerateMipmaps();
1282 DALI_TEST_CHECK(false); // Should not get here
1286 DALI_TEST_CHECK(true); // We expect an assert
1291 int UtcDaliTextureUploadNegative01(void)
1293 TestApplication application;
1294 Dali::Texture instance;
1297 Dali::PixelData arg1;
1298 instance.Upload(arg1);
1299 DALI_TEST_CHECK(false); // Should not get here
1303 DALI_TEST_CHECK(true); // We expect an assert
1308 int UtcDaliTextureUploadNegative02(void)
1310 TestApplication application;
1311 Dali::Texture instance;
1314 Dali::PixelData arg1;
1315 unsigned int arg2(0u);
1316 unsigned int arg3(0u);
1317 unsigned int arg4(0u);
1318 unsigned int arg5(0u);
1319 unsigned int arg6(0u);
1320 unsigned int arg7(0u);
1321 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1322 DALI_TEST_CHECK(false); // Should not get here
1326 DALI_TEST_CHECK(true); // We expect an assert
1331 int UtcDaliTextureGetWidthNegative(void)
1333 TestApplication application;
1334 Dali::Texture instance;
1337 instance.GetWidth();
1338 DALI_TEST_CHECK(false); // Should not get here
1342 DALI_TEST_CHECK(true); // We expect an assert
1347 int UtcDaliTextureGetHeightNegative(void)
1349 TestApplication application;
1350 Dali::Texture instance;
1353 instance.GetHeight();
1354 DALI_TEST_CHECK(false); // Should not get here
1358 DALI_TEST_CHECK(true); // We expect an assert
1363 int UtcDaliTextureCheckNativeP(void)
1365 TestApplication application;
1366 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1367 Texture nativeTexture = Texture::New(*testNativeImage);
1369 DALI_TEST_CHECK(nativeTexture);
1370 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1374 int UtcDaliTextureCheckNativeN1(void)
1376 TestApplication application;
1377 unsigned int width(64);
1378 unsigned int height(64);
1379 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1381 DALI_TEST_CHECK(texture);
1382 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1386 int UtcDaliTextureCheckNativeN2(void)
1388 TestApplication application;
1392 bool native = DevelTexture::IsNative(texture);
1393 DALI_TEST_CHECK(native != native);
1397 DALI_TEST_CHECK(true);
1402 int UtcDaliTextureApplyFragShaderP1(void)
1404 TestApplication application;
1405 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1406 Texture nativeTexture = Texture::New(*testNativeImage);
1407 DALI_TEST_CHECK(nativeTexture);
1409 const std::string baseFragShader =
1410 "varying mediump vec4 uColor;\n"
1412 " gl_FragColor=uColor;\n"
1414 std::string fragShader = baseFragShader;
1415 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1417 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1419 DALI_TEST_CHECK(applied);
1420 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1421 DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1422 DALI_TEST_CHECK(!fragShader.empty());
1426 int UtcDaliTextureApplyFragShaderP2(void)
1428 TestApplication application;
1429 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1430 Texture nativeTexture = Texture::New(*testNativeImage);
1431 DALI_TEST_CHECK(nativeTexture);
1433 const std::string baseFragShader =
1434 "varying mediump vec4 uColor;\n"
1435 "varying vec2 vTexCoord;\n"
1436 "uniform sampler2D uNative;\n"
1438 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1440 std::string fragShader = baseFragShader;
1441 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1443 DALI_TEST_CHECK(applied);
1444 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1445 DALI_TEST_CHECK(!fragShader.empty());
1446 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1450 int UtcDaliTextureApplyFragShaderN1(void)
1452 TestApplication application;
1453 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1454 Texture nativeTexture = Texture::New(*testNativeImage);
1455 DALI_TEST_CHECK(nativeTexture);
1457 std::string fragShader;
1458 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1460 DALI_TEST_CHECK(!applied);
1461 DALI_TEST_CHECK(fragShader.empty());
1465 int UtcDaliTextureApplyFragShaderN2(void)
1467 TestApplication application;
1468 unsigned int width(64);
1469 unsigned int height(64);
1470 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1472 const std::string baseFragShader =
1473 "varying mediump vec4 uColor;\n"
1475 " gl_FragColor=uColor;\n"
1477 std::string fragShader = baseFragShader;
1478 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1480 DALI_TEST_CHECK(!applied);
1481 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1485 int UtcDaliTextureGetPixelFormat(void)
1487 TestApplication application;
1489 uint32_t height(64);
1491 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1492 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1494 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1495 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1497 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1498 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1500 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1501 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1506 int utcDaliTexturePartialUpdate01(void)
1508 TestApplication application(
1509 TestApplication::DEFAULT_SURFACE_WIDTH,
1510 TestApplication::DEFAULT_SURFACE_HEIGHT,
1511 TestApplication::DEFAULT_HORIZONTAL_DPI,
1512 TestApplication::DEFAULT_VERTICAL_DPI,
1516 tet_infoline("Check the damaged rect with partial update and texture change");
1518 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1520 std::vector<Rect<int32_t>> damagedRects;
1521 Rect<int32_t> clippingRect;
1523 Geometry geometry = CreateQuadGeometry();
1524 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1525 Renderer renderer = Renderer::New(geometry, shader);
1529 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1530 TextureSet textureSet = TextureSet::New();
1531 textureSet.SetTexture(0u, texture);
1532 renderer.SetTextures(textureSet);
1534 Actor actor = Actor::New();
1535 actor.AddRenderer(renderer);
1537 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1538 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1539 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1540 application.GetScene().Add(actor);
1542 damagedRects.clear();
1543 application.SendNotification();
1544 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1545 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1548 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1549 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1550 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1551 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1552 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1553 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1554 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1556 damagedRects.clear();
1557 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1558 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1560 // Ensure the damaged rect is empty
1561 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1564 uint32_t bufferSize(width * height * 4);
1565 uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1566 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1567 texture.Upload(pixelData);
1569 damagedRects.clear();
1570 application.SendNotification();
1571 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1572 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1575 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1576 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1577 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1578 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1579 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1580 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1581 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1583 damagedRects.clear();
1584 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1585 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1587 // Ensure the damaged rect is empty
1588 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1593 int utcDaliTexturePartialUpdate02(void)
1595 TestApplication application(
1596 TestApplication::DEFAULT_SURFACE_WIDTH,
1597 TestApplication::DEFAULT_SURFACE_HEIGHT,
1598 TestApplication::DEFAULT_HORIZONTAL_DPI,
1599 TestApplication::DEFAULT_VERTICAL_DPI,
1603 tet_infoline("Check the damaged rect with partial update and texture change");
1605 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1607 std::vector<Rect<int32_t>> damagedRects;
1608 Rect<int32_t> clippingRect;
1610 Geometry geometry = CreateQuadGeometry();
1611 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1612 Renderer renderer = Renderer::New(geometry, shader);
1616 Texture texture1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1617 Texture texture2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1618 TextureSet textureSet = TextureSet::New();
1619 textureSet.SetTexture(0u, texture1);
1620 renderer.SetTextures(textureSet);
1622 Actor actor = Actor::New();
1623 actor.AddRenderer(renderer);
1625 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1626 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1627 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1628 application.GetScene().Add(actor);
1630 damagedRects.clear();
1631 application.SendNotification();
1632 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1633 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1636 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1637 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1638 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1639 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1640 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1641 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1642 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1644 damagedRects.clear();
1645 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1646 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1648 // Ensure the damaged rect is empty
1649 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1651 // Set another texture
1652 textureSet.SetTexture(0u, texture2);
1654 damagedRects.clear();
1655 application.SendNotification();
1656 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1657 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1660 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1661 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1662 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1663 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1664 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1665 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1666 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1668 damagedRects.clear();
1669 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1670 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1672 // Ensure the damaged rect is empty
1673 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);