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 UtcDaliTextureNew04(void)
75 TestApplication application;
77 Texture texture = Texture::New(TextureType::TEXTURE_2D);
79 DALI_TEST_CHECK(texture);
83 int UtcDaliTextureCopyConstructor(void)
85 TestApplication application;
87 unsigned int width(64);
88 unsigned int height(64);
89 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
91 Texture textureCopy(texture);
93 DALI_TEST_CHECK(textureCopy);
98 int UtcDaliTextureAssignmentOperator(void)
100 TestApplication application;
101 unsigned int width(64);
102 unsigned int height(64);
103 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
106 DALI_TEST_CHECK(!texture2);
109 DALI_TEST_CHECK(texture2);
114 int UtcDaliTextureMoveConstructor(void)
116 TestApplication application;
119 uint32_t height = 64;
120 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
121 DALI_TEST_CHECK(texture);
122 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
123 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
124 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
126 Texture move = std::move(texture);
127 DALI_TEST_CHECK(move);
128 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
129 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
130 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
131 DALI_TEST_CHECK(!texture);
136 int UtcDaliTextureMoveAssignment(void)
138 TestApplication application;
141 uint32_t height = 64;
142 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
143 DALI_TEST_CHECK(texture);
144 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
145 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
146 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
149 move = std::move(texture);
150 DALI_TEST_CHECK(move);
151 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
152 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
153 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
154 DALI_TEST_CHECK(!texture);
159 int UtcDaliTextureDownCast01(void)
161 TestApplication application;
162 unsigned int width(64);
163 unsigned int height(64);
164 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
166 BaseHandle handle(texture);
167 Texture texture2 = Texture::DownCast(handle);
168 DALI_TEST_CHECK(texture2);
173 int UtcDaliTextureDownCast02(void)
175 TestApplication application;
177 Handle handle = Handle::New(); // Create a custom object
178 Texture texture = Texture::DownCast(handle);
179 DALI_TEST_CHECK(!texture);
183 int UtcDaliTextureUpload01(void)
185 TestApplication application;
188 unsigned int width(64);
189 unsigned int height(64);
190 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
192 application.GetGlAbstraction().EnableTextureCallTrace(true);
194 application.SendNotification();
195 application.Render();
197 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
199 //Upload data to the texture
202 unsigned int bufferSize(width * height * 4);
203 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
204 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
205 texture.Upload(pixelData);
206 application.SendNotification();
207 application.Render();
209 //TexImage2D should be called to upload the data
211 std::stringstream out;
212 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
213 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
216 //Upload part of the texture
218 bufferSize = width * height;
219 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
220 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
221 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
222 application.SendNotification();
223 application.Render();
225 //TexSubImage2D should be called to upload the data
227 std::stringstream out;
228 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
229 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
235 int UtcDaliTextureUpload02(void)
237 TestApplication application;
240 unsigned int width(64);
241 unsigned int height(64);
242 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
244 application.GetGlAbstraction().EnableTextureCallTrace(true);
246 application.SendNotification();
247 application.Render();
249 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
251 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
252 for(unsigned int i(0); i < 6; ++i)
254 std::stringstream out;
255 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
256 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
259 unsigned int bufferSize(width * height * 4);
260 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
261 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
263 //Upload data to the POSITIVE_X face of the texture
267 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
268 application.SendNotification();
269 application.Render();
271 //TexImage2D should be called to upload the data to the POSITIVE_X face
273 std::stringstream out;
274 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
275 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
279 //Upload data to the NEGATIVE_X face of the texture
283 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
284 application.SendNotification();
285 application.Render();
287 //TexImage2D should be called to upload the data to the NEGATIVE_X face
289 std::stringstream out;
290 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
291 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
295 //Upload data to the POSITIVE_Y face of the texture
298 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
299 application.SendNotification();
300 application.Render();
302 //TexImage2D should be called to upload the data to the POSITIVE_Y face
304 std::stringstream out;
305 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
306 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
310 //Upload data to the NEGATIVE_Y face of the texture
313 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
314 application.SendNotification();
315 application.Render();
317 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
319 std::stringstream out;
320 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
321 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
325 //Upload data to the POSITIVE_Z face of the texture
328 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
329 application.SendNotification();
330 application.Render();
332 //TexImage2D should be called to upload the data to the POSITIVE_Z face
334 std::stringstream out;
335 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
336 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
340 //Upload data to the NEGATIVE_Z face of the texture
343 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
344 application.SendNotification();
345 application.Render();
347 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
349 std::stringstream out;
350 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
351 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
358 int UtcDaliTextureUpload03(void)
360 TestApplication application;
363 unsigned int width(64);
364 unsigned int height(64);
365 unsigned int widthMipmap1(32);
366 unsigned int heightMipmap1(32);
368 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
370 application.GetGlAbstraction().EnableTextureCallTrace(true);
372 application.SendNotification();
373 application.Render();
375 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
377 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
379 std::stringstream out;
380 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
381 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
384 //Upload data to the texture mipmap 0 and mipmap 1
387 unsigned int bufferSize(width * height * 4);
388 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
389 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
390 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
392 bufferSize = widthMipmap1 * heightMipmap1 * 4;
393 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
394 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
395 texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
396 application.SendNotification();
397 application.Render();
399 //TexImage2D should be called to upload the data to mipmaps 0 and 1
401 std::stringstream out;
402 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
403 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
406 std::stringstream out;
407 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
408 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
414 int UtcDaliTextureUpload04(void)
416 TestApplication application;
419 unsigned int width(64);
420 unsigned int height(64);
421 unsigned int widthMipmap1(32);
422 unsigned int heightMipmap1(32);
424 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
426 application.GetGlAbstraction().EnableTextureCallTrace(true);
427 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
429 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
430 unsigned int bufferSize(width * height * 4);
431 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
432 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
433 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
435 bufferSize = widthMipmap1 * heightMipmap1 * 4;
436 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
437 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
438 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
439 application.SendNotification();
440 application.Render();
442 //TexImage2D should be called to upload the data to mipmaps 0 and 1
444 std::stringstream out;
445 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
446 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
449 std::stringstream out;
450 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
451 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
457 int UtcDaliTextureUpload05(void)
459 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
461 Pixel::COMPRESSED_R11_EAC,
462 Pixel::COMPRESSED_SIGNED_R11_EAC,
463 Pixel::COMPRESSED_RG11_EAC,
464 Pixel::COMPRESSED_SIGNED_RG11_EAC,
465 Pixel::COMPRESSED_RGB8_ETC2,
466 Pixel::COMPRESSED_SRGB8_ETC2,
467 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
468 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
469 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
470 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
471 Pixel::COMPRESSED_RGB8_ETC1,
472 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
473 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
474 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
475 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
476 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
477 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
478 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
479 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
480 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
481 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
482 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
483 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
484 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
485 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
486 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
487 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
488 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
489 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
491 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
492 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
493 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
494 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
495 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
496 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
497 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
498 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
499 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
500 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
502 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
504 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
506 TestApplication application;
508 //Create a texture with a compressed format
509 unsigned int width(64);
510 unsigned int height(64);
511 Texture texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
513 application.GetGlAbstraction().EnableTextureCallTrace(true);
515 application.SendNotification();
516 application.Render();
518 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
520 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
522 std::stringstream out;
523 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
524 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
527 //Upload data to the texture
530 unsigned int bufferSize(width * height * 4);
531 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
532 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
533 texture.Upload(pixelData);
534 application.SendNotification();
535 application.Render();
537 //CompressedTexImage2D should be called to upload the data
539 std::stringstream out;
540 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
541 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
544 //Upload part of the texture
546 bufferSize = width * height;
547 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
548 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
549 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
550 application.SendNotification();
551 application.Render();
553 //CompressedTexSubImage2D should be called to upload the data
555 std::stringstream out;
556 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
557 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
560 application.GetGlAbstraction().ResetTextureCallStack();
566 int UtcDaliTextureUpload06(void)
568 TestApplication application;
571 unsigned int width(64);
572 unsigned int height(64);
573 tet_infoline("Creating a Texure with an alpha channel");
574 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
576 application.GetGlAbstraction().EnableTextureCallTrace(true);
578 application.SendNotification();
579 application.Render();
581 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
583 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
585 std::stringstream out;
586 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
587 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
590 tet_infoline("Upload data to the texture");
593 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
594 unsigned int bufferSize(width * height * 3);
595 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
596 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
597 texture.Upload(pixelData);
598 application.SendNotification();
599 application.Render();
601 tet_infoline("TexImage2D should be called to upload the data");
603 std::stringstream out;
604 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
605 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
611 int UtcDaliTextureUpload07(void)
613 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
618 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
620 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
622 TestApplication application;
625 unsigned int width(64);
626 unsigned int height(64);
627 tet_infoline("Creating a floating point texture");
628 Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
630 application.GetGlAbstraction().EnableTextureCallTrace(true);
632 application.SendNotification();
633 application.Render();
635 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
637 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
639 std::stringstream out;
640 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
641 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
644 tet_infoline("Upload data to the texture");
647 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
648 unsigned int bufferSize(width * height * 3);
649 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
650 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
651 texture.Upload(pixelData);
652 application.SendNotification();
653 application.Render();
655 tet_infoline("TexImage2D should be called to upload the data");
657 std::stringstream out;
658 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
659 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
666 int UtcDaliTextureUpload08(void)
668 TestApplication application;
670 //Create the texture without pixel information
671 tet_infoline("Creating a Texure without any size/format information");
672 Texture texture = Texture::New(TextureType::TEXTURE_2D);
674 application.GetGlAbstraction().EnableTextureCallTrace(true);
676 application.SendNotification();
677 application.Render();
679 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
681 tet_infoline("TexImage2D should not be called with a null pointer to reserve storage for the texture in the gpu");
682 DALI_TEST_CHECK(!callStack.FindMethod("GenTextures"));
683 DALI_TEST_CHECK(!callStack.FindMethod("TexImage2D"));
685 tet_infoline("Upload data to the texture");
686 unsigned int width(64);
687 unsigned int height(64);
690 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
691 unsigned int bufferSize(width * height * 3);
692 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
693 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
694 texture.Upload(pixelData);
695 application.SendNotification();
696 application.Render();
698 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
699 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
700 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
701 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
703 tet_infoline("TexImage2D should be called to upload the data");
704 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
706 std::stringstream out;
707 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
708 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
711 tet_infoline("Upload another data to the texture");
716 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
717 bufferSize = width * height * 4;
718 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
719 pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
720 texture.Upload(pixelData);
721 application.SendNotification();
722 application.Render();
724 tet_infoline("TexImage2D should be generate new graphics, and be called to upload the data");
725 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
727 std::stringstream out;
728 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
729 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
732 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
733 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
734 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
735 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
740 int UtcDaliTextureUploadSubPixelData01(void)
742 TestApplication application;
745 unsigned int width(64);
746 unsigned int height(64);
747 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
749 application.GetGlAbstraction().EnableTextureCallTrace(true);
751 application.SendNotification();
752 application.Render();
754 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
756 //Upload data to the texture
759 uint32_t bufferWidth = width * 2;
760 uint32_t bufferHeight = height * 2;
761 uint32_t bufferXOffset = width;
762 uint32_t bufferYOffset = height;
764 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
765 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
766 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
767 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
768 application.SendNotification();
769 application.Render();
771 //TexImage2D should be called to upload the data
773 std::stringstream out;
774 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
775 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
778 //Upload part of the texture
780 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
781 application.SendNotification();
782 application.Render();
784 //TexSubImage2D should be called to upload the data
786 std::stringstream out;
787 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
788 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
794 int UtcDaliTextureUploadSubPixelData02(void)
796 TestApplication application;
799 unsigned int width(64);
800 unsigned int height(64);
801 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
803 application.GetGlAbstraction().EnableTextureCallTrace(true);
805 application.SendNotification();
806 application.Render();
808 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
810 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
811 for(unsigned int i(0); i < 6; ++i)
813 std::stringstream out;
814 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
815 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
818 uint32_t bufferWidth = width * 2;
819 uint32_t bufferHeight = height * 2;
820 uint32_t bufferXOffset = width;
821 uint32_t bufferYOffset = height;
823 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
824 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
825 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
827 //Upload data to the POSITIVE_X face of the texture
831 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
832 application.SendNotification();
833 application.Render();
835 //TexImage2D should be called to upload the data to the POSITIVE_X face
837 std::stringstream out;
838 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
839 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
843 //Upload data to the NEGATIVE_X face of the texture
847 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
848 application.SendNotification();
849 application.Render();
851 //TexImage2D should be called to upload the data to the NEGATIVE_X face
853 std::stringstream out;
854 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
855 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
859 //Upload data to the POSITIVE_Y face of the texture
862 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
863 application.SendNotification();
864 application.Render();
866 //TexImage2D should be called to upload the data to the POSITIVE_Y face
868 std::stringstream out;
869 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
870 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
874 //Upload data to the NEGATIVE_Y face of the texture
877 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
878 application.SendNotification();
879 application.Render();
881 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
883 std::stringstream out;
884 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
885 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
889 //Upload data to the POSITIVE_Z face of the texture
892 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
893 application.SendNotification();
894 application.Render();
896 //TexImage2D should be called to upload the data to the POSITIVE_Z face
898 std::stringstream out;
899 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
900 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
904 //Upload data to the NEGATIVE_Z face of the texture
907 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
908 application.SendNotification();
909 application.Render();
911 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
913 std::stringstream out;
914 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
915 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
922 int UtcDaliTextureUploadPixelFormats(void)
924 TestApplication application;
925 application.GetGlAbstraction().EnableTextureCallTrace(true);
928 unsigned int width(64);
929 unsigned int height(64);
931 std::vector<Pixel::Format> formats =
947 Pixel::DEPTH_UNSIGNED_INT,
949 Pixel::DEPTH_STENCIL,
953 Pixel::CHROMINANCE_U,
954 Pixel::CHROMINANCE_V};
956 for(auto format : formats)
958 tet_infoline("Creating a Texure with a new or recent format");
959 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
961 application.SendNotification();
962 application.Render();
964 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
966 tet_infoline("TexImage2D should be called twice per texture");
967 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
969 std::stringstream out;
970 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
971 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
979 int UtcDaliTextureUploadSmallerThanSize(void)
981 TestApplication application;
984 unsigned int width(64);
985 unsigned int height(64);
986 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
988 application.GetGlAbstraction().EnableTextureCallTrace(true);
990 application.SendNotification();
991 application.Render();
993 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
994 callStack.EnableLogging(true);
995 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
996 texParamCallStack.EnableLogging(true);
998 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
1000 std::stringstream out;
1001 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1003 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
1004 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1007 //Upload data to the texture
1010 unsigned int bufferSize(width * height * 4);
1011 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1012 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
1013 texture.Upload(pixelData);
1014 application.SendNotification();
1015 application.Render();
1017 //TexSubImage2D should be called to upload the data
1019 std::stringstream out;
1020 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
1022 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
1023 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1028 int UtcDaliTextureGenerateMipmaps(void)
1030 TestApplication application;
1031 unsigned int width(64);
1032 unsigned int height(64);
1034 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1035 texture.GenerateMipmaps();
1037 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1038 textureCubemap.GenerateMipmaps();
1040 application.GetGlAbstraction().EnableTextureCallTrace(true);
1041 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1042 application.SendNotification();
1043 application.Render();
1046 std::stringstream out;
1047 out << GL_TEXTURE_2D;
1048 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1051 std::stringstream out;
1052 out << GL_TEXTURE_CUBE_MAP;
1053 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1059 int UtcDaliTextureGetWidth(void)
1061 TestApplication application;
1062 unsigned int width(64);
1063 unsigned int height(64);
1065 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1066 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1070 int UtcDaliTextureGetHeight(void)
1072 TestApplication application;
1073 unsigned int width(64);
1074 unsigned int height(64);
1076 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1077 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1082 int UtcDaliTextureContextLoss(void)
1084 tet_infoline("UtcDaliTextureContextLoss\n");
1085 TestApplication application;
1087 //Create the texture
1088 unsigned int width(64);
1089 unsigned int height(64);
1090 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1091 DALI_TEST_CHECK(texture);
1093 application.SendNotification();
1094 application.Render(16);
1096 // Lose & regain context (in render 'thread')
1097 application.ResetContext();
1098 DALI_TEST_CHECK(texture);
1103 int UtcDaliNativeImageTexture01(void)
1105 TestApplication application;
1106 tet_infoline("UtcDaliNativeImageTexture01");
1108 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1110 Texture texture = Texture::New(*(imageInterface.Get()));
1111 Actor actor = CreateRenderableActor(texture, "", "");
1112 application.GetScene().Add(actor);
1114 DALI_TEST_CHECK(texture);
1116 application.SendNotification();
1117 application.Render(16);
1119 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1120 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1121 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1123 UnparentAndReset(actor);
1125 application.SendNotification();
1126 application.Render(16);
1128 application.SendNotification();
1129 application.Render(16);
1131 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1132 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1137 int UtcDaliNativeImageTexture02(void)
1139 TestApplication application;
1140 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1142 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1143 imageInterface->mTargetTextureError = 1u;
1145 Texture texture = Texture::New(*(imageInterface.Get()));
1146 Actor actor = CreateRenderableActor(texture, "", "");
1147 application.GetScene().Add(actor);
1149 DALI_TEST_CHECK(texture);
1151 application.SendNotification();
1152 application.Render(16);
1154 // Expect 2 attempts to create the texture - once when adding the texture
1155 // to the scene-graph, and again since that failed, during the Bind.
1156 // The second one succeeds (TargetTexture only errors once)
1157 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1158 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1160 UnparentAndReset(actor);
1162 application.SendNotification();
1163 application.Render(16);
1165 application.SendNotification();
1166 application.Render(16);
1168 // Expect that there are no further calls to create/destroy resource
1169 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1170 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1175 int UtcDaliTextureGenerateMipmapsNegative(void)
1177 TestApplication application;
1178 Dali::Texture instance;
1181 instance.GenerateMipmaps();
1182 DALI_TEST_CHECK(false); // Should not get here
1186 DALI_TEST_CHECK(true); // We expect an assert
1191 int UtcDaliTextureUploadNegative01(void)
1193 TestApplication application;
1194 Dali::Texture instance;
1197 Dali::PixelData arg1;
1198 instance.Upload(arg1);
1199 DALI_TEST_CHECK(false); // Should not get here
1203 DALI_TEST_CHECK(true); // We expect an assert
1208 int UtcDaliTextureUploadNegative02(void)
1210 TestApplication application;
1211 Dali::Texture instance;
1214 Dali::PixelData arg1;
1215 unsigned int arg2(0u);
1216 unsigned int arg3(0u);
1217 unsigned int arg4(0u);
1218 unsigned int arg5(0u);
1219 unsigned int arg6(0u);
1220 unsigned int arg7(0u);
1221 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1222 DALI_TEST_CHECK(false); // Should not get here
1226 DALI_TEST_CHECK(true); // We expect an assert
1231 int UtcDaliTextureGetWidthNegative(void)
1233 TestApplication application;
1234 Dali::Texture instance;
1237 instance.GetWidth();
1238 DALI_TEST_CHECK(false); // Should not get here
1242 DALI_TEST_CHECK(true); // We expect an assert
1247 int UtcDaliTextureGetHeightNegative(void)
1249 TestApplication application;
1250 Dali::Texture instance;
1253 instance.GetHeight();
1254 DALI_TEST_CHECK(false); // Should not get here
1258 DALI_TEST_CHECK(true); // We expect an assert
1263 int UtcDaliTextureCheckNativeP(void)
1265 TestApplication application;
1266 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1267 Texture nativeTexture = Texture::New(*testNativeImage);
1269 DALI_TEST_CHECK(nativeTexture);
1270 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1274 int UtcDaliTextureCheckNativeN1(void)
1276 TestApplication application;
1277 unsigned int width(64);
1278 unsigned int height(64);
1279 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1281 DALI_TEST_CHECK(texture);
1282 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1286 int UtcDaliTextureCheckNativeN2(void)
1288 TestApplication application;
1292 bool native = DevelTexture::IsNative(texture);
1293 DALI_TEST_CHECK(native != native);
1297 DALI_TEST_CHECK(true);
1302 int UtcDaliTextureApplyFragShaderP1(void)
1304 TestApplication application;
1305 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1306 Texture nativeTexture = Texture::New(*testNativeImage);
1307 DALI_TEST_CHECK(nativeTexture);
1309 const std::string baseFragShader =
1310 "varying mediump vec4 uColor;\n"
1312 " gl_FragColor=uColor;\n"
1314 std::string fragShader = baseFragShader;
1315 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1317 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1319 DALI_TEST_CHECK(applied);
1320 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1321 DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1322 DALI_TEST_CHECK(!fragShader.empty());
1326 int UtcDaliTextureApplyFragShaderP2(void)
1328 TestApplication application;
1329 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1330 Texture nativeTexture = Texture::New(*testNativeImage);
1331 DALI_TEST_CHECK(nativeTexture);
1333 const std::string baseFragShader =
1334 "varying mediump vec4 uColor;\n"
1335 "varying vec2 vTexCoord;\n"
1336 "uniform sampler2D uNative;\n"
1338 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1340 std::string fragShader = baseFragShader;
1341 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1343 DALI_TEST_CHECK(applied);
1344 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1345 DALI_TEST_CHECK(!fragShader.empty());
1346 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1350 int UtcDaliTextureApplyFragShaderN1(void)
1352 TestApplication application;
1353 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1354 Texture nativeTexture = Texture::New(*testNativeImage);
1355 DALI_TEST_CHECK(nativeTexture);
1357 std::string fragShader;
1358 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1360 DALI_TEST_CHECK(!applied);
1361 DALI_TEST_CHECK(fragShader.empty());
1365 int UtcDaliTextureApplyFragShaderN2(void)
1367 TestApplication application;
1368 unsigned int width(64);
1369 unsigned int height(64);
1370 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1372 const std::string baseFragShader =
1373 "varying mediump vec4 uColor;\n"
1375 " gl_FragColor=uColor;\n"
1377 std::string fragShader = baseFragShader;
1378 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1380 DALI_TEST_CHECK(!applied);
1381 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1385 int UtcDaliTextureGetPixelFormat(void)
1387 TestApplication application;
1389 uint32_t height(64);
1391 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1392 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1394 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1395 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1397 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1398 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1400 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1401 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1406 int utcDaliTexturePartialUpdate01(void)
1408 TestApplication application(
1409 TestApplication::DEFAULT_SURFACE_WIDTH,
1410 TestApplication::DEFAULT_SURFACE_HEIGHT,
1411 TestApplication::DEFAULT_HORIZONTAL_DPI,
1412 TestApplication::DEFAULT_VERTICAL_DPI,
1416 tet_infoline("Check the damaged rect with partial update and texture change");
1418 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1420 std::vector<Rect<int32_t>> damagedRects;
1421 Rect<int32_t> clippingRect;
1423 Geometry geometry = CreateQuadGeometry();
1424 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1425 Renderer renderer = Renderer::New(geometry, shader);
1429 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1430 TextureSet textureSet = TextureSet::New();
1431 textureSet.SetTexture(0u, texture);
1432 renderer.SetTextures(textureSet);
1434 Actor actor = Actor::New();
1435 actor.AddRenderer(renderer);
1437 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1438 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1439 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1440 application.GetScene().Add(actor);
1442 damagedRects.clear();
1443 application.SendNotification();
1444 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1445 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1448 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1449 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1450 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1451 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1452 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1453 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1454 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1456 damagedRects.clear();
1457 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1458 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1460 // Ensure the damaged rect is empty
1461 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1464 uint32_t bufferSize(width * height * 4);
1465 uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1466 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1467 texture.Upload(pixelData);
1469 damagedRects.clear();
1470 application.SendNotification();
1471 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1472 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1475 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1476 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1477 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1478 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1479 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1480 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1481 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1483 damagedRects.clear();
1484 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1485 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1487 // Ensure the damaged rect is empty
1488 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1493 int utcDaliTexturePartialUpdate02(void)
1495 TestApplication application(
1496 TestApplication::DEFAULT_SURFACE_WIDTH,
1497 TestApplication::DEFAULT_SURFACE_HEIGHT,
1498 TestApplication::DEFAULT_HORIZONTAL_DPI,
1499 TestApplication::DEFAULT_VERTICAL_DPI,
1503 tet_infoline("Check the damaged rect with partial update and texture change");
1505 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1507 std::vector<Rect<int32_t>> damagedRects;
1508 Rect<int32_t> clippingRect;
1510 Geometry geometry = CreateQuadGeometry();
1511 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1512 Renderer renderer = Renderer::New(geometry, shader);
1516 Texture texture1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1517 Texture texture2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1518 TextureSet textureSet = TextureSet::New();
1519 textureSet.SetTexture(0u, texture1);
1520 renderer.SetTextures(textureSet);
1522 Actor actor = Actor::New();
1523 actor.AddRenderer(renderer);
1525 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1526 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1527 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1528 application.GetScene().Add(actor);
1530 damagedRects.clear();
1531 application.SendNotification();
1532 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1533 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1536 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1537 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1538 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1539 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1540 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1541 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1542 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1544 damagedRects.clear();
1545 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1546 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1548 // Ensure the damaged rect is empty
1549 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1551 // Set another texture
1552 textureSet.SetTexture(0u, texture2);
1554 damagedRects.clear();
1555 application.SendNotification();
1556 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1557 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1560 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1561 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1562 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1563 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1564 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1565 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1566 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1568 damagedRects.clear();
1569 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1570 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1572 // Ensure the damaged rect is empty
1573 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);