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 UtcDaliTextureGetWidth(void)
1079 TestApplication application;
1080 unsigned int width(64);
1081 unsigned int height(64);
1083 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1084 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1088 int UtcDaliTextureGetHeight(void)
1090 TestApplication application;
1091 unsigned int width(64);
1092 unsigned int height(64);
1094 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1095 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1100 int UtcDaliTextureGetTextureType(void)
1102 TestApplication application;
1103 unsigned int width(64);
1104 unsigned int height(64);
1106 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1107 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
1109 texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1110 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
1115 int UtcDaliTextureSetSize(void)
1117 TestApplication application;
1118 unsigned int width(64);
1119 unsigned int height(64);
1121 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1122 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1123 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1124 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1129 Integration::SetTextureSize(texture, ImageDimensions(width, height));
1130 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1131 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1132 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1134 application.SendNotification();
1135 application.Render();
1140 int UtcDaliTextureSetPixelFormat(void)
1142 TestApplication application;
1143 unsigned int width(64);
1144 unsigned int height(64);
1146 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1147 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1148 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1149 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1151 Integration::SetTexturePixelFormat(texture, Pixel::BGRA5551);
1152 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1153 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1154 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::BGRA5551, TEST_LOCATION);
1156 application.SendNotification();
1157 application.Render();
1162 int UtcDaliTextureContextLoss(void)
1164 tet_infoline("UtcDaliTextureContextLoss\n");
1165 TestApplication application;
1167 //Create the texture
1168 unsigned int width(64);
1169 unsigned int height(64);
1170 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1171 DALI_TEST_CHECK(texture);
1173 application.SendNotification();
1174 application.Render(16);
1176 // Lose & regain context (in render 'thread')
1177 application.ResetContext();
1178 DALI_TEST_CHECK(texture);
1183 int UtcDaliNativeImageTexture01(void)
1185 TestApplication application;
1186 tet_infoline("UtcDaliNativeImageTexture01");
1188 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1190 Texture texture = Texture::New(*(imageInterface.Get()));
1191 Actor actor = CreateRenderableActor(texture, "", "");
1192 application.GetScene().Add(actor);
1194 DALI_TEST_CHECK(texture);
1196 application.SendNotification();
1197 application.Render(16);
1199 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1200 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1201 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1203 UnparentAndReset(actor);
1205 application.SendNotification();
1206 application.Render(16);
1208 application.SendNotification();
1209 application.Render(16);
1211 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1212 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1217 int UtcDaliNativeImageTexture02(void)
1219 TestApplication application;
1220 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1222 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1223 imageInterface->mTargetTextureError = 1u;
1225 Texture texture = Texture::New(*(imageInterface.Get()));
1226 Actor actor = CreateRenderableActor(texture, "", "");
1227 application.GetScene().Add(actor);
1229 DALI_TEST_CHECK(texture);
1231 application.SendNotification();
1232 application.Render(16);
1234 // Expect 2 attempts to create the texture - once when adding the texture
1235 // to the scene-graph, and again since that failed, during the Bind.
1236 // The second one succeeds (TargetTexture only errors once)
1237 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1238 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1240 UnparentAndReset(actor);
1242 application.SendNotification();
1243 application.Render(16);
1245 application.SendNotification();
1246 application.Render(16);
1248 // Expect that there are no further calls to create/destroy resource
1249 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1250 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1255 int UtcDaliTextureGenerateMipmapsNegative(void)
1257 TestApplication application;
1258 Dali::Texture instance;
1261 instance.GenerateMipmaps();
1262 DALI_TEST_CHECK(false); // Should not get here
1266 DALI_TEST_CHECK(true); // We expect an assert
1271 int UtcDaliTextureUploadNegative01(void)
1273 TestApplication application;
1274 Dali::Texture instance;
1277 Dali::PixelData arg1;
1278 instance.Upload(arg1);
1279 DALI_TEST_CHECK(false); // Should not get here
1283 DALI_TEST_CHECK(true); // We expect an assert
1288 int UtcDaliTextureUploadNegative02(void)
1290 TestApplication application;
1291 Dali::Texture instance;
1294 Dali::PixelData arg1;
1295 unsigned int arg2(0u);
1296 unsigned int arg3(0u);
1297 unsigned int arg4(0u);
1298 unsigned int arg5(0u);
1299 unsigned int arg6(0u);
1300 unsigned int arg7(0u);
1301 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1302 DALI_TEST_CHECK(false); // Should not get here
1306 DALI_TEST_CHECK(true); // We expect an assert
1311 int UtcDaliTextureGetWidthNegative(void)
1313 TestApplication application;
1314 Dali::Texture instance;
1317 instance.GetWidth();
1318 DALI_TEST_CHECK(false); // Should not get here
1322 DALI_TEST_CHECK(true); // We expect an assert
1327 int UtcDaliTextureGetHeightNegative(void)
1329 TestApplication application;
1330 Dali::Texture instance;
1333 instance.GetHeight();
1334 DALI_TEST_CHECK(false); // Should not get here
1338 DALI_TEST_CHECK(true); // We expect an assert
1343 int UtcDaliTextureCheckNativeP(void)
1345 TestApplication application;
1346 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1347 Texture nativeTexture = Texture::New(*testNativeImage);
1349 DALI_TEST_CHECK(nativeTexture);
1350 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1354 int UtcDaliTextureCheckNativeN1(void)
1356 TestApplication application;
1357 unsigned int width(64);
1358 unsigned int height(64);
1359 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1361 DALI_TEST_CHECK(texture);
1362 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1366 int UtcDaliTextureCheckNativeN2(void)
1368 TestApplication application;
1372 bool native = DevelTexture::IsNative(texture);
1373 DALI_TEST_CHECK(native != native);
1377 DALI_TEST_CHECK(true);
1382 int UtcDaliTextureApplyFragShaderP1(void)
1384 TestApplication application;
1385 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1386 Texture nativeTexture = Texture::New(*testNativeImage);
1387 DALI_TEST_CHECK(nativeTexture);
1389 const std::string baseFragShader =
1390 "varying mediump vec4 uColor;\n"
1392 " gl_FragColor=uColor;\n"
1394 std::string fragShader = baseFragShader;
1395 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1397 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1399 DALI_TEST_CHECK(applied);
1400 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1401 DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1402 DALI_TEST_CHECK(!fragShader.empty());
1406 int UtcDaliTextureApplyFragShaderP2(void)
1408 TestApplication application;
1409 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1410 Texture nativeTexture = Texture::New(*testNativeImage);
1411 DALI_TEST_CHECK(nativeTexture);
1413 const std::string baseFragShader =
1414 "varying mediump vec4 uColor;\n"
1415 "varying vec2 vTexCoord;\n"
1416 "uniform sampler2D uNative;\n"
1418 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1420 std::string fragShader = baseFragShader;
1421 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1423 DALI_TEST_CHECK(applied);
1424 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1425 DALI_TEST_CHECK(!fragShader.empty());
1426 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1430 int UtcDaliTextureApplyFragShaderN1(void)
1432 TestApplication application;
1433 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1434 Texture nativeTexture = Texture::New(*testNativeImage);
1435 DALI_TEST_CHECK(nativeTexture);
1437 std::string fragShader;
1438 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1440 DALI_TEST_CHECK(!applied);
1441 DALI_TEST_CHECK(fragShader.empty());
1445 int UtcDaliTextureApplyFragShaderN2(void)
1447 TestApplication application;
1448 unsigned int width(64);
1449 unsigned int height(64);
1450 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1452 const std::string baseFragShader =
1453 "varying mediump vec4 uColor;\n"
1455 " gl_FragColor=uColor;\n"
1457 std::string fragShader = baseFragShader;
1458 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1460 DALI_TEST_CHECK(!applied);
1461 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1465 int UtcDaliTextureGetPixelFormat(void)
1467 TestApplication application;
1469 uint32_t height(64);
1471 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1472 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1474 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1475 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1477 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1478 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1480 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1481 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1486 int utcDaliTexturePartialUpdate01(void)
1488 TestApplication application(
1489 TestApplication::DEFAULT_SURFACE_WIDTH,
1490 TestApplication::DEFAULT_SURFACE_HEIGHT,
1491 TestApplication::DEFAULT_HORIZONTAL_DPI,
1492 TestApplication::DEFAULT_VERTICAL_DPI,
1496 tet_infoline("Check the damaged rect with partial update and texture change");
1498 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1500 std::vector<Rect<int32_t>> damagedRects;
1501 Rect<int32_t> clippingRect;
1503 Geometry geometry = CreateQuadGeometry();
1504 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1505 Renderer renderer = Renderer::New(geometry, shader);
1509 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1510 TextureSet textureSet = TextureSet::New();
1511 textureSet.SetTexture(0u, texture);
1512 renderer.SetTextures(textureSet);
1514 Actor actor = Actor::New();
1515 actor.AddRenderer(renderer);
1517 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1518 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1519 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1520 application.GetScene().Add(actor);
1522 damagedRects.clear();
1523 application.SendNotification();
1524 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1525 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1528 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1529 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1530 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1531 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1532 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1533 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1534 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1536 damagedRects.clear();
1537 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1538 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1540 // Ensure the damaged rect is empty
1541 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1544 uint32_t bufferSize(width * height * 4);
1545 uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1546 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1547 texture.Upload(pixelData);
1549 damagedRects.clear();
1550 application.SendNotification();
1551 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1552 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1555 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1556 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1557 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1558 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1559 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1560 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1561 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1563 damagedRects.clear();
1564 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1565 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1567 // Ensure the damaged rect is empty
1568 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1573 int utcDaliTexturePartialUpdate02(void)
1575 TestApplication application(
1576 TestApplication::DEFAULT_SURFACE_WIDTH,
1577 TestApplication::DEFAULT_SURFACE_HEIGHT,
1578 TestApplication::DEFAULT_HORIZONTAL_DPI,
1579 TestApplication::DEFAULT_VERTICAL_DPI,
1583 tet_infoline("Check the damaged rect with partial update and texture change");
1585 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1587 std::vector<Rect<int32_t>> damagedRects;
1588 Rect<int32_t> clippingRect;
1590 Geometry geometry = CreateQuadGeometry();
1591 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1592 Renderer renderer = Renderer::New(geometry, shader);
1596 Texture texture1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1597 Texture texture2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1598 TextureSet textureSet = TextureSet::New();
1599 textureSet.SetTexture(0u, texture1);
1600 renderer.SetTextures(textureSet);
1602 Actor actor = Actor::New();
1603 actor.AddRenderer(renderer);
1605 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1606 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1607 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1608 application.GetScene().Add(actor);
1610 damagedRects.clear();
1611 application.SendNotification();
1612 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1613 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1616 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1617 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1618 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1619 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1620 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1621 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1622 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1624 damagedRects.clear();
1625 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1626 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1628 // Ensure the damaged rect is empty
1629 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1631 // Set another texture
1632 textureSet.SetTexture(0u, texture2);
1634 damagedRects.clear();
1635 application.SendNotification();
1636 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1637 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1640 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1641 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1642 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1643 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1644 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1645 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1646 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1648 damagedRects.clear();
1649 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1650 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1652 // Ensure the damaged rect is empty
1653 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);