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/public-api/dali-core.h>
21 #include <test-native-image.h>
25 #include <mesh-builder.h>
27 void texture_set_startup(void)
29 test_return_value = TET_UNDEF;
32 void texture_set_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliTextureNew01(void)
39 TestApplication application;
41 unsigned int width(64);
42 unsigned int height(64);
43 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
45 DALI_TEST_CHECK(texture);
49 int UtcDaliTextureNew02(void)
51 TestApplication application;
53 DALI_TEST_CHECK(!texture);
57 int UtcDaliTextureNew03(void)
59 TestApplication application;
61 // Create a native image source.
62 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
64 // Create a texture from the native image source.
65 Texture nativeTexture = Texture::New(*testNativeImage);
67 // Check the texture was created OK.
68 DALI_TEST_CHECK(nativeTexture);
73 int UtcDaliTextureCopyConstructor(void)
75 TestApplication application;
77 unsigned int width(64);
78 unsigned int height(64);
79 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
81 Texture textureCopy(texture);
83 DALI_TEST_CHECK(textureCopy);
88 int UtcDaliTextureAssignmentOperator(void)
90 TestApplication application;
91 unsigned int width(64);
92 unsigned int height(64);
93 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
96 DALI_TEST_CHECK(!texture2);
99 DALI_TEST_CHECK(texture2);
104 int UtcDaliTextureMoveConstructor(void)
106 TestApplication application;
109 uint32_t height = 64;
110 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
111 DALI_TEST_CHECK(texture);
112 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
114 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
116 Texture move = std::move(texture);
117 DALI_TEST_CHECK(move);
118 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
119 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
120 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
121 DALI_TEST_CHECK(!texture);
126 int UtcDaliTextureMoveAssignment(void)
128 TestApplication application;
131 uint32_t height = 64;
132 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
133 DALI_TEST_CHECK(texture);
134 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
135 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
136 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
139 move = std::move(texture);
140 DALI_TEST_CHECK(move);
141 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
143 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
144 DALI_TEST_CHECK(!texture);
149 int UtcDaliTextureDownCast01(void)
151 TestApplication application;
152 unsigned int width(64);
153 unsigned int height(64);
154 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
156 BaseHandle handle(texture);
157 Texture texture2 = Texture::DownCast(handle);
158 DALI_TEST_CHECK(texture2);
163 int UtcDaliTextureDownCast02(void)
165 TestApplication application;
167 Handle handle = Handle::New(); // Create a custom object
168 Texture texture = Texture::DownCast(handle);
169 DALI_TEST_CHECK(!texture);
173 int UtcDaliTextureUpload01(void)
175 TestApplication application;
178 unsigned int width(64);
179 unsigned int height(64);
180 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
182 application.GetGlAbstraction().EnableTextureCallTrace(true);
184 application.SendNotification();
185 application.Render();
187 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
189 //Upload data to the texture
192 unsigned int bufferSize(width * height * 4);
193 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
194 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
195 texture.Upload(pixelData);
196 application.SendNotification();
197 application.Render();
199 //TexImage2D should be called to upload the data
201 std::stringstream out;
202 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
203 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
206 //Upload part of the texture
208 bufferSize = width * height;
209 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
210 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
211 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
212 application.SendNotification();
213 application.Render();
215 //TexSubImage2D should be called to upload the data
217 std::stringstream out;
218 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
219 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
225 int UtcDaliTextureUpload02(void)
227 TestApplication application;
230 unsigned int width(64);
231 unsigned int height(64);
232 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
234 application.GetGlAbstraction().EnableTextureCallTrace(true);
236 application.SendNotification();
237 application.Render();
239 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
241 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
242 for(unsigned int i(0); i < 6; ++i)
244 std::stringstream out;
245 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
246 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
249 unsigned int bufferSize(width * height * 4);
250 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
251 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
253 //Upload data to the POSITIVE_X face of the texture
257 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
258 application.SendNotification();
259 application.Render();
261 //TexImage2D should be called to upload the data to the POSITIVE_X face
263 std::stringstream out;
264 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
265 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
269 //Upload data to the NEGATIVE_X face of the texture
273 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
274 application.SendNotification();
275 application.Render();
277 //TexImage2D should be called to upload the data to the NEGATIVE_X face
279 std::stringstream out;
280 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
281 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
285 //Upload data to the POSITIVE_Y face of the texture
288 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
289 application.SendNotification();
290 application.Render();
292 //TexImage2D should be called to upload the data to the POSITIVE_Y face
294 std::stringstream out;
295 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
296 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
300 //Upload data to the NEGATIVE_Y face of the texture
303 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
304 application.SendNotification();
305 application.Render();
307 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
309 std::stringstream out;
310 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
311 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
315 //Upload data to the POSITIVE_Z face of the texture
318 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
319 application.SendNotification();
320 application.Render();
322 //TexImage2D should be called to upload the data to the POSITIVE_Z face
324 std::stringstream out;
325 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
326 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
330 //Upload data to the NEGATIVE_Z face of the texture
333 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
334 application.SendNotification();
335 application.Render();
337 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
339 std::stringstream out;
340 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
341 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
348 int UtcDaliTextureUpload03(void)
350 TestApplication application;
353 unsigned int width(64);
354 unsigned int height(64);
355 unsigned int widthMipmap1(32);
356 unsigned int heightMipmap1(32);
358 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
360 application.GetGlAbstraction().EnableTextureCallTrace(true);
362 application.SendNotification();
363 application.Render();
365 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
367 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
369 std::stringstream out;
370 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
371 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
374 //Upload data to the texture mipmap 0 and mipmap 1
377 unsigned int bufferSize(width * height * 4);
378 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
379 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
380 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
382 bufferSize = widthMipmap1 * heightMipmap1 * 4;
383 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
384 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
385 texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
386 application.SendNotification();
387 application.Render();
389 //TexImage2D should be called to upload the data to mipmaps 0 and 1
391 std::stringstream out;
392 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
393 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
396 std::stringstream out;
397 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
398 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
404 int UtcDaliTextureUpload04(void)
406 TestApplication application;
409 unsigned int width(64);
410 unsigned int height(64);
411 unsigned int widthMipmap1(32);
412 unsigned int heightMipmap1(32);
414 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
416 application.GetGlAbstraction().EnableTextureCallTrace(true);
417 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
419 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
420 unsigned int bufferSize(width * height * 4);
421 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
422 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
423 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
425 bufferSize = widthMipmap1 * heightMipmap1 * 4;
426 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
427 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
428 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
429 application.SendNotification();
430 application.Render();
432 //TexImage2D should be called to upload the data to mipmaps 0 and 1
434 std::stringstream out;
435 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
436 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
439 std::stringstream out;
440 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
441 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
447 int UtcDaliTextureUpload05(void)
449 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
451 Pixel::COMPRESSED_R11_EAC,
452 Pixel::COMPRESSED_SIGNED_R11_EAC,
453 Pixel::COMPRESSED_RG11_EAC,
454 Pixel::COMPRESSED_SIGNED_RG11_EAC,
455 Pixel::COMPRESSED_RGB8_ETC2,
456 Pixel::COMPRESSED_SRGB8_ETC2,
457 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
458 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
459 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
460 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
461 Pixel::COMPRESSED_RGB8_ETC1,
462 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
463 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
464 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
465 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
466 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
467 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
468 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
469 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
470 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
471 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
472 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
473 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
474 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
475 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
476 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
477 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
478 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
479 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
480 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
481 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
482 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
483 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
484 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
485 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
486 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
487 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
488 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
489 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
492 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
494 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
496 TestApplication application;
498 //Create a texture with a compressed format
499 unsigned int width(64);
500 unsigned int height(64);
501 Texture texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
503 application.GetGlAbstraction().EnableTextureCallTrace(true);
505 application.SendNotification();
506 application.Render();
508 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
510 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
512 std::stringstream out;
513 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
514 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
517 //Upload data to the texture
520 unsigned int bufferSize(width * height * 4);
521 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
522 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
523 texture.Upload(pixelData);
524 application.SendNotification();
525 application.Render();
527 //CompressedTexImage2D should be called to upload the data
529 std::stringstream out;
530 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
531 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
534 //Upload part of the texture
536 bufferSize = width * height;
537 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
538 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
539 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
540 application.SendNotification();
541 application.Render();
543 //CompressedTexSubImage2D should be called to upload the data
545 std::stringstream out;
546 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
547 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
550 application.GetGlAbstraction().ResetTextureCallStack();
556 int UtcDaliTextureUpload06(void)
558 TestApplication application;
561 unsigned int width(64);
562 unsigned int height(64);
563 tet_infoline("Creating a Texure with an alpha channel");
564 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
566 application.GetGlAbstraction().EnableTextureCallTrace(true);
568 application.SendNotification();
569 application.Render();
571 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
573 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
575 std::stringstream out;
576 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
577 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
580 tet_infoline("Upload data to the texture");
583 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
584 unsigned int bufferSize(width * height * 3);
585 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
586 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
587 texture.Upload(pixelData);
588 application.SendNotification();
589 application.Render();
591 tet_infoline("TexImage2D should be called to upload the data");
593 std::stringstream out;
594 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
595 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
601 int UtcDaliTextureUpload07(void)
603 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
608 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
610 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
612 TestApplication application;
615 unsigned int width(64);
616 unsigned int height(64);
617 tet_infoline("Creating a floating point texture");
618 Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
620 application.GetGlAbstraction().EnableTextureCallTrace(true);
622 application.SendNotification();
623 application.Render();
625 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
627 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
629 std::stringstream out;
630 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
631 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
634 tet_infoline("Upload data to the texture");
637 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
638 unsigned int bufferSize(width * height * 3);
639 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
640 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
641 texture.Upload(pixelData);
642 application.SendNotification();
643 application.Render();
645 tet_infoline("TexImage2D should be called to upload the data");
647 std::stringstream out;
648 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
649 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
656 int UtcDaliTextureUploadSubPixelData01(void)
658 TestApplication application;
661 unsigned int width(64);
662 unsigned int height(64);
663 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
665 application.GetGlAbstraction().EnableTextureCallTrace(true);
667 application.SendNotification();
668 application.Render();
670 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
672 //Upload data to the texture
675 uint32_t bufferWidth = width * 2;
676 uint32_t bufferHeight = height * 2;
677 uint32_t bufferXOffset = width;
678 uint32_t bufferYOffset = height;
680 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
681 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
682 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
683 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
684 application.SendNotification();
685 application.Render();
687 //TexImage2D should be called to upload the data
689 std::stringstream out;
690 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
691 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
694 //Upload part of the texture
696 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
697 application.SendNotification();
698 application.Render();
700 //TexSubImage2D should be called to upload the data
702 std::stringstream out;
703 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
704 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
710 int UtcDaliTextureUploadSubPixelData02(void)
712 TestApplication application;
715 unsigned int width(64);
716 unsigned int height(64);
717 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
719 application.GetGlAbstraction().EnableTextureCallTrace(true);
721 application.SendNotification();
722 application.Render();
724 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
726 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
727 for(unsigned int i(0); i < 6; ++i)
729 std::stringstream out;
730 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
731 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
734 uint32_t bufferWidth = width * 2;
735 uint32_t bufferHeight = height * 2;
736 uint32_t bufferXOffset = width;
737 uint32_t bufferYOffset = height;
739 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
740 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
741 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
743 //Upload data to the POSITIVE_X face of the texture
747 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
748 application.SendNotification();
749 application.Render();
751 //TexImage2D should be called to upload the data to the POSITIVE_X face
753 std::stringstream out;
754 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
755 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
759 //Upload data to the NEGATIVE_X face of the texture
763 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
764 application.SendNotification();
765 application.Render();
767 //TexImage2D should be called to upload the data to the NEGATIVE_X face
769 std::stringstream out;
770 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
771 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
775 //Upload data to the POSITIVE_Y face of the texture
778 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
779 application.SendNotification();
780 application.Render();
782 //TexImage2D should be called to upload the data to the POSITIVE_Y face
784 std::stringstream out;
785 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
786 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
790 //Upload data to the NEGATIVE_Y face of the texture
793 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
794 application.SendNotification();
795 application.Render();
797 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
799 std::stringstream out;
800 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
801 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
805 //Upload data to the POSITIVE_Z face of the texture
808 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
809 application.SendNotification();
810 application.Render();
812 //TexImage2D should be called to upload the data to the POSITIVE_Z face
814 std::stringstream out;
815 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
816 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
820 //Upload data to the NEGATIVE_Z face of the texture
823 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
824 application.SendNotification();
825 application.Render();
827 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
829 std::stringstream out;
830 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
831 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
838 int UtcDaliTextureUploadPixelFormats(void)
840 TestApplication application;
841 application.GetGlAbstraction().EnableTextureCallTrace(true);
844 unsigned int width(64);
845 unsigned int height(64);
847 std::vector<Pixel::Format> formats =
863 Pixel::DEPTH_UNSIGNED_INT,
865 Pixel::DEPTH_STENCIL,
869 Pixel::CHROMINANCE_U,
870 Pixel::CHROMINANCE_V};
872 for(auto format : formats)
874 tet_infoline("Creating a Texure with a new or recent format");
875 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
877 application.SendNotification();
878 application.Render();
880 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
882 tet_infoline("TexImage2D should be called twice per texture");
883 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
885 std::stringstream out;
886 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
887 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
895 int UtcDaliTextureUploadSmallerThanSize(void)
897 TestApplication application;
900 unsigned int width(64);
901 unsigned int height(64);
902 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
904 application.GetGlAbstraction().EnableTextureCallTrace(true);
906 application.SendNotification();
907 application.Render();
909 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
910 callStack.EnableLogging(true);
911 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
912 texParamCallStack.EnableLogging(true);
914 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
916 std::stringstream out;
917 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
919 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
920 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
923 //Upload data to the texture
926 unsigned int bufferSize(width * height * 4);
927 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
928 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
929 texture.Upload(pixelData);
930 application.SendNotification();
931 application.Render();
933 //TexSubImage2D should be called to upload the data
935 std::stringstream out;
936 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
938 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
939 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
944 int UtcDaliTextureGenerateMipmaps(void)
946 TestApplication application;
947 unsigned int width(64);
948 unsigned int height(64);
950 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
951 texture.GenerateMipmaps();
953 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
954 textureCubemap.GenerateMipmaps();
956 application.GetGlAbstraction().EnableTextureCallTrace(true);
957 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
958 application.SendNotification();
959 application.Render();
962 std::stringstream out;
963 out << GL_TEXTURE_2D;
964 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
967 std::stringstream out;
968 out << GL_TEXTURE_CUBE_MAP;
969 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
975 int UtcDaliTextureGetWidth(void)
977 TestApplication application;
978 unsigned int width(64);
979 unsigned int height(64);
981 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
982 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
986 int UtcDaliTextureGetHeight(void)
988 TestApplication application;
989 unsigned int width(64);
990 unsigned int height(64);
992 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
993 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
998 int UtcDaliTextureContextLoss(void)
1000 tet_infoline("UtcDaliTextureContextLoss\n");
1001 TestApplication application;
1003 //Create the texture
1004 unsigned int width(64);
1005 unsigned int height(64);
1006 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1007 DALI_TEST_CHECK(texture);
1009 application.SendNotification();
1010 application.Render(16);
1012 // Lose & regain context (in render 'thread')
1013 application.ResetContext();
1014 DALI_TEST_CHECK(texture);
1019 int UtcDaliNativeImageTexture01(void)
1021 TestApplication application;
1022 tet_infoline("UtcDaliNativeImageTexture01");
1024 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1026 Texture texture = Texture::New(*(imageInterface.Get()));
1027 Actor actor = CreateRenderableActor(texture, "", "");
1028 application.GetScene().Add(actor);
1030 DALI_TEST_CHECK(texture);
1032 application.SendNotification();
1033 application.Render(16);
1035 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1036 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1037 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1039 UnparentAndReset(actor);
1041 application.SendNotification();
1042 application.Render(16);
1044 application.SendNotification();
1045 application.Render(16);
1047 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1048 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1053 int UtcDaliNativeImageTexture02(void)
1055 TestApplication application;
1056 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1058 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1059 imageInterface->mTargetTextureError = 1u;
1061 Texture texture = Texture::New(*(imageInterface.Get()));
1062 Actor actor = CreateRenderableActor(texture, "", "");
1063 application.GetScene().Add(actor);
1065 DALI_TEST_CHECK(texture);
1067 application.SendNotification();
1068 application.Render(16);
1070 // Expect 2 attempts to create the texture - once when adding the texture
1071 // to the scene-graph, and again since that failed, during the Bind.
1072 // The second one succeeds (TargetTexture only errors once)
1073 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1074 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1076 UnparentAndReset(actor);
1078 application.SendNotification();
1079 application.Render(16);
1081 application.SendNotification();
1082 application.Render(16);
1084 // Expect that there are no further calls to create/destroy resource
1085 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1086 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1091 int UtcDaliTextureGenerateMipmapsNegative(void)
1093 TestApplication application;
1094 Dali::Texture instance;
1097 instance.GenerateMipmaps();
1098 DALI_TEST_CHECK(false); // Should not get here
1102 DALI_TEST_CHECK(true); // We expect an assert
1107 int UtcDaliTextureUploadNegative01(void)
1109 TestApplication application;
1110 Dali::Texture instance;
1113 Dali::PixelData arg1;
1114 instance.Upload(arg1);
1115 DALI_TEST_CHECK(false); // Should not get here
1119 DALI_TEST_CHECK(true); // We expect an assert
1124 int UtcDaliTextureUploadNegative02(void)
1126 TestApplication application;
1127 Dali::Texture instance;
1130 Dali::PixelData arg1;
1131 unsigned int arg2(0u);
1132 unsigned int arg3(0u);
1133 unsigned int arg4(0u);
1134 unsigned int arg5(0u);
1135 unsigned int arg6(0u);
1136 unsigned int arg7(0u);
1137 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1138 DALI_TEST_CHECK(false); // Should not get here
1142 DALI_TEST_CHECK(true); // We expect an assert
1147 int UtcDaliTextureGetWidthNegative(void)
1149 TestApplication application;
1150 Dali::Texture instance;
1153 instance.GetWidth();
1154 DALI_TEST_CHECK(false); // Should not get here
1158 DALI_TEST_CHECK(true); // We expect an assert
1163 int UtcDaliTextureGetHeightNegative(void)
1165 TestApplication application;
1166 Dali::Texture instance;
1169 instance.GetHeight();
1170 DALI_TEST_CHECK(false); // Should not get here
1174 DALI_TEST_CHECK(true); // We expect an assert
1179 int UtcDaliTextureCheckNativeP(void)
1181 TestApplication application;
1182 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1183 Texture nativeTexture = Texture::New(*testNativeImage);
1185 DALI_TEST_CHECK(nativeTexture);
1186 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1190 int UtcDaliTextureCheckNativeN1(void)
1192 TestApplication application;
1193 unsigned int width(64);
1194 unsigned int height(64);
1195 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1197 DALI_TEST_CHECK(texture);
1198 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1202 int UtcDaliTextureCheckNativeN2(void)
1204 TestApplication application;
1208 bool native = DevelTexture::IsNative(texture);
1209 DALI_TEST_CHECK(native != native);
1213 DALI_TEST_CHECK(true);
1218 int UtcDaliTextureApplyFragShaderP1(void)
1220 TestApplication application;
1221 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1222 Texture nativeTexture = Texture::New(*testNativeImage);
1223 DALI_TEST_CHECK(nativeTexture);
1225 const std::string baseFragShader =
1226 "varying mediump vec4 uColor;\n"
1228 " gl_FragColor=uColor;\n"
1230 std::string fragShader = baseFragShader;
1231 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1233 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1235 DALI_TEST_CHECK(applied);
1236 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1237 DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1238 DALI_TEST_CHECK(!fragShader.empty());
1242 int UtcDaliTextureApplyFragShaderP2(void)
1244 TestApplication application;
1245 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1246 Texture nativeTexture = Texture::New(*testNativeImage);
1247 DALI_TEST_CHECK(nativeTexture);
1249 const std::string baseFragShader =
1250 "varying mediump vec4 uColor;\n"
1251 "varying vec2 vTexCoord;\n"
1252 "uniform sampler2D uNative;\n"
1254 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1256 std::string fragShader = baseFragShader;
1257 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1259 DALI_TEST_CHECK(applied);
1260 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1261 DALI_TEST_CHECK(!fragShader.empty());
1262 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1266 int UtcDaliTextureApplyFragShaderN1(void)
1268 TestApplication application;
1269 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1270 Texture nativeTexture = Texture::New(*testNativeImage);
1271 DALI_TEST_CHECK(nativeTexture);
1273 std::string fragShader;
1274 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1276 DALI_TEST_CHECK(!applied);
1277 DALI_TEST_CHECK(fragShader.empty());
1281 int UtcDaliTextureApplyFragShaderN2(void)
1283 TestApplication application;
1284 unsigned int width(64);
1285 unsigned int height(64);
1286 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1288 const std::string baseFragShader =
1289 "varying mediump vec4 uColor;\n"
1291 " gl_FragColor=uColor;\n"
1293 std::string fragShader = baseFragShader;
1294 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1296 DALI_TEST_CHECK(!applied);
1297 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1301 int UtcDaliTextureGetPixelFormat(void)
1303 TestApplication application;
1305 uint32_t height(64);
1307 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1308 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1310 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1311 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1313 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1314 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1316 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1317 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1322 int utcDaliTexturePartialUpdate01(void)
1324 TestApplication application(
1325 TestApplication::DEFAULT_SURFACE_WIDTH,
1326 TestApplication::DEFAULT_SURFACE_HEIGHT,
1327 TestApplication::DEFAULT_HORIZONTAL_DPI,
1328 TestApplication::DEFAULT_VERTICAL_DPI,
1332 tet_infoline("Check the damaged rect with partial update and texture change");
1334 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1336 std::vector<Rect<int32_t>> damagedRects;
1337 Rect<int32_t> clippingRect;
1339 Geometry geometry = CreateQuadGeometry();
1340 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1341 Renderer renderer = Renderer::New(geometry, shader);
1345 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1346 TextureSet textureSet = TextureSet::New();
1347 textureSet.SetTexture(0u, texture);
1348 renderer.SetTextures(textureSet);
1350 Actor actor = Actor::New();
1351 actor.AddRenderer(renderer);
1353 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1354 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1355 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1356 application.GetScene().Add(actor);
1358 damagedRects.clear();
1359 application.SendNotification();
1360 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1361 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1364 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1365 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1366 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1367 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1368 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1369 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1370 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1372 damagedRects.clear();
1373 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1374 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1376 // Ensure the damaged rect is empty
1377 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1380 uint32_t bufferSize(width * height * 4);
1381 uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1382 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1383 texture.Upload(pixelData);
1385 damagedRects.clear();
1386 application.SendNotification();
1387 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1388 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1391 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1392 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1393 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1394 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1395 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1396 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1397 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1399 damagedRects.clear();
1400 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1401 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1403 // Ensure the damaged rect is empty
1404 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1409 int utcDaliTexturePartialUpdate02(void)
1411 TestApplication application(
1412 TestApplication::DEFAULT_SURFACE_WIDTH,
1413 TestApplication::DEFAULT_SURFACE_HEIGHT,
1414 TestApplication::DEFAULT_HORIZONTAL_DPI,
1415 TestApplication::DEFAULT_VERTICAL_DPI,
1419 tet_infoline("Check the damaged rect with partial update and texture change");
1421 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1423 std::vector<Rect<int32_t>> damagedRects;
1424 Rect<int32_t> clippingRect;
1426 Geometry geometry = CreateQuadGeometry();
1427 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1428 Renderer renderer = Renderer::New(geometry, shader);
1432 Texture texture1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1433 Texture texture2 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1434 TextureSet textureSet = TextureSet::New();
1435 textureSet.SetTexture(0u, texture1);
1436 renderer.SetTextures(textureSet);
1438 Actor actor = Actor::New();
1439 actor.AddRenderer(renderer);
1441 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1442 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1443 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1444 application.GetScene().Add(actor);
1446 damagedRects.clear();
1447 application.SendNotification();
1448 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1449 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1452 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1453 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1454 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1455 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1456 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1457 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1458 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1460 damagedRects.clear();
1461 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1462 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1464 // Ensure the damaged rect is empty
1465 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1467 // Set another texture
1468 textureSet.SetTexture(0u, texture2);
1470 damagedRects.clear();
1471 application.SendNotification();
1472 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1473 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1476 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1477 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1478 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1479 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1480 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1481 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1482 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1484 damagedRects.clear();
1485 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1486 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1488 // Ensure the damaged rect is empty
1489 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);