[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali/devel-api/images/pixel-data-devel.h>
20 #include <dali-test-suite-utils.h>
21 #include <test-native-image.h>
22
23 using namespace Dali;
24
25 #include <mesh-builder.h>
26
27 void texture_set_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void texture_set_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 int UtcDaliTextureNew01(void)
38 {
39   TestApplication application;
40
41   unsigned int width(64);
42   unsigned int height(64);
43   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
44
45   DALI_TEST_CHECK( texture );
46   END_TEST;
47 }
48
49 int UtcDaliTextureNew02(void)
50 {
51   TestApplication application;
52   Texture texture;
53   DALI_TEST_CHECK( !texture );
54   END_TEST;
55 }
56
57 int UtcDaliTextureNew03(void)
58 {
59   TestApplication application;
60
61   // Create a native image source.
62   TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::New( 64u, 64u );
63
64   // Create a texture from the native image source.
65   Texture nativeTexture = Texture::New( *testNativeImage );
66
67   // Check the texture was created OK.
68   DALI_TEST_CHECK( nativeTexture );
69
70   END_TEST;
71 }
72
73 int UtcDaliTextureCopyConstructor(void)
74 {
75   TestApplication application;
76
77   unsigned int width(64);
78   unsigned int height(64);
79   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
80
81   Texture textureCopy(texture);
82
83   DALI_TEST_CHECK( textureCopy );
84
85   END_TEST;
86 }
87
88 int UtcDaliTextureAssignmentOperator(void)
89 {
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 );
94
95   Texture texture2;
96   DALI_TEST_CHECK( !texture2 );
97
98   texture2 = texture;
99   DALI_TEST_CHECK( texture2 );
100
101   END_TEST;
102 }
103
104 int UtcDaliTextureDownCast01(void)
105 {
106   TestApplication application;
107   unsigned int width(64);
108   unsigned int height(64);
109   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
110
111   BaseHandle handle(texture);
112   Texture texture2 = Texture::DownCast(handle);
113   DALI_TEST_CHECK( texture2 );
114
115   END_TEST;
116 }
117
118 int UtcDaliTextureDownCast02(void)
119 {
120   TestApplication application;
121
122   Handle handle = Handle::New(); // Create a custom object
123   Texture texture = Texture::DownCast(handle);
124   DALI_TEST_CHECK( !texture );
125   END_TEST;
126 }
127
128 int UtcDaliTextureUpload01(void)
129 {
130   TestApplication application;
131
132   //Create the texture
133   unsigned int width(64);
134   unsigned int height(64);
135   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
136
137   application.GetGlAbstraction().EnableTextureCallTrace(true);
138
139   application.SendNotification();
140   application.Render();
141
142   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
143
144   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
145   {
146     std::stringstream out;
147     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
148     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
149   }
150
151   //Upload data to the texture
152   callStack.Reset();
153
154   unsigned int bufferSize( width * height * 4 );
155   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
156   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
157   texture.Upload( pixelData );
158   application.SendNotification();
159   application.Render();
160
161   //TexImage2D should be called to upload the data
162   {
163     std::stringstream out;
164     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
165     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
166   }
167
168   //Upload part of the texture
169   callStack.Reset();
170   bufferSize =  width * height * 2;
171   buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
172   PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
173   texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
174   application.SendNotification();
175   application.Render();
176
177   //TexSubImage2D should be called to upload the data
178   {
179     std::stringstream out;
180     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
181     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
182   }
183
184
185   END_TEST;
186 }
187
188 int UtcDaliTextureUpload02(void)
189 {
190   TestApplication application;
191
192   //Create the texture
193   unsigned int width(64);
194   unsigned int height(64);
195   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
196
197   application.GetGlAbstraction().EnableTextureCallTrace(true);
198
199   application.SendNotification();
200   application.Render();
201
202   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
203
204   //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
205   for( unsigned int i(0); i<6; ++i )
206   {
207     std::stringstream out;
208     out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
209     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
210   }
211
212   unsigned int bufferSize( width * height * 4 );
213   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
214   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
215
216   //Upload data to the POSITIVE_X face of the texture
217   {
218     callStack.Reset();
219
220     texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
221     application.SendNotification();
222     application.Render();
223
224     //TexImage2D should be called to upload the data to the POSITIVE_X face
225     {
226       std::stringstream out;
227       out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
228       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
229     }
230   }
231
232   //Upload data to the NEGATIVE_X face of the texture
233   {
234     callStack.Reset();
235
236     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
237     application.SendNotification();
238     application.Render();
239
240     //TexImage2D should be called to upload the data to the NEGATIVE_X face
241     {
242       std::stringstream out;
243       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
244       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
245     }
246   }
247
248   //Upload data to the POSITIVE_Y face of the texture
249   {
250     callStack.Reset();
251     texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
252     application.SendNotification();
253     application.Render();
254
255     //TexImage2D should be called to upload the data to the POSITIVE_Y face
256     {
257       std::stringstream out;
258       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
259       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
260     }
261   }
262
263   //Upload data to the NEGATIVE_Y face of the texture
264   {
265     callStack.Reset();
266     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
267     application.SendNotification();
268     application.Render();
269
270     //TexImage2D should be called to upload the data to the NEGATIVE_Y face
271     {
272       std::stringstream out;
273       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
274       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
275     }
276   }
277
278   //Upload data to the POSITIVE_Z face of the texture
279   {
280     callStack.Reset();
281     texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
282     application.SendNotification();
283     application.Render();
284
285     //TexImage2D should be called to upload the data to the POSITIVE_Z face
286     {
287       std::stringstream out;
288       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
289       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
290     }
291   }
292
293   //Upload data to the NEGATIVE_Z face of the texture
294   {
295     callStack.Reset();
296     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
297     application.SendNotification();
298     application.Render();
299
300     //TexImage2D should be called to upload the data to the NEGATIVE_Z face
301     {
302       std::stringstream out;
303       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
304       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
305     }
306   }
307
308   END_TEST;
309 }
310
311 int UtcDaliTextureUpload03(void)
312 {
313   TestApplication application;
314
315   //Create the texture
316   unsigned int width(64);
317   unsigned int height(64);
318   unsigned int widthMipmap1(32);
319   unsigned int heightMipmap1(32);
320
321   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
322
323   application.GetGlAbstraction().EnableTextureCallTrace(true);
324
325   application.SendNotification();
326   application.Render();
327
328   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
329
330   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
331   {
332     std::stringstream out;
333     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
334     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
335   }
336
337   //Upload data to the texture mipmap 0 and mipmap 1
338   callStack.Reset();
339
340   unsigned int bufferSize( width * height * 4 );
341   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc(  bufferSize ) );
342   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
343   texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
344
345   bufferSize = widthMipmap1 * heightMipmap1 * 4;
346   buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
347   PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
348   texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
349   application.SendNotification();
350   application.Render();
351
352   //TexImage2D should be called to upload the data to mipmaps 0 and 1
353   {
354     std::stringstream out;
355     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
356     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
357   }
358   {
359     std::stringstream out;
360     out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
361     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
362   }
363
364   END_TEST;
365 }
366
367 int UtcDaliTextureUpload04(void)
368 {
369   TestApplication application;
370
371   //Create the texture
372   unsigned int width(64);
373   unsigned int height(64);
374   unsigned int widthMipmap1(32);
375   unsigned int heightMipmap1(32);
376
377   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
378
379   application.GetGlAbstraction().EnableTextureCallTrace(true);
380   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
381
382   //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
383   unsigned int bufferSize( width * height * 4 );
384   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
385   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
386   texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
387
388   bufferSize = widthMipmap1 * heightMipmap1 * 4;
389   buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
390   PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
391   texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
392   application.SendNotification();
393   application.Render();
394
395   //TexImage2D should be called to upload the data to mipmaps 0 and 1
396   {
397     std::stringstream out;
398     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
399     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
400   }
401   {
402     std::stringstream out;
403     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
404     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
405   }
406
407   END_TEST;
408 }
409
410 int UtcDaliTextureUpload05(void)
411 {
412   Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
413   {
414     Pixel::COMPRESSED_R11_EAC,
415     Pixel::COMPRESSED_SIGNED_R11_EAC,
416     Pixel::COMPRESSED_RG11_EAC,
417     Pixel::COMPRESSED_SIGNED_RG11_EAC,
418     Pixel::COMPRESSED_RGB8_ETC2,
419     Pixel::COMPRESSED_SRGB8_ETC2,
420     Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
421     Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
422     Pixel::COMPRESSED_RGBA8_ETC2_EAC,
423     Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
424     Pixel::COMPRESSED_RGB8_ETC1,
425     Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
426     Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
427     Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
428     Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
429     Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
430     Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
431     Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
432     Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
433     Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
434     Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
435     Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
436     Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
437     Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
438     Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
439     Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
440     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
441     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
442     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
443     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
444     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
445     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
446     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
447     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
448     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
449     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
450     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
451     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
452     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
453     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
454   };
455   const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
456
457   for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
458   {
459     TestApplication application;
460
461     //Create a texture with a compressed format
462     unsigned int width(64);
463     unsigned int height(64);
464     Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
465
466     application.GetGlAbstraction().EnableTextureCallTrace(true);
467
468     application.SendNotification();
469     application.Render();
470
471     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
472
473     //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
474     {
475       std::stringstream out;
476       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
477       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
478     }
479
480     //Upload data to the texture
481     callStack.Reset();
482
483     unsigned int bufferSize( width * height * 4 );
484     unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
485     PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
486     texture.Upload( pixelData );
487     application.SendNotification();
488     application.Render();
489
490     //CompressedTexImage2D should be called to upload the data
491     {
492       std::stringstream out;
493       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
494       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
495     }
496
497     //Upload part of the texture
498     callStack.Reset();
499     bufferSize =  width * height * 2;
500     buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
501     PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
502     texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
503     application.SendNotification();
504     application.Render();
505
506     //CompressedTexSubImage2D should be called to upload the data
507     {
508       std::stringstream out;
509       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
510       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
511     }
512
513     application.GetGlAbstraction().ResetTextureCallStack();
514   }
515
516   END_TEST;
517 }
518
519 int UtcDaliTextureUpload06(void)
520 {
521   TestApplication application;
522
523   //Create the texture
524   unsigned int width(64);
525   unsigned int height(64);
526   tet_infoline( "Creating a Texure with an alpha channel" );
527   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
528
529   application.GetGlAbstraction().EnableTextureCallTrace(true);
530
531   application.SendNotification();
532   application.Render();
533
534   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
535
536   tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
537   {
538     std::stringstream out;
539     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
540     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
541   }
542
543   tet_infoline( "Upload data to the texture" );
544   callStack.Reset();
545
546   tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
547   unsigned int bufferSize( width * height * 3 );
548   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
549   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
550   texture.Upload( pixelData );
551   application.SendNotification();
552   application.Render();
553
554   tet_infoline( "TexImage2D should be called to upload the data" );
555   {
556     std::stringstream out;
557     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
558     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
559   }
560
561   END_TEST;
562 }
563
564 int UtcDaliTextureUpload07(void)
565 {
566   Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
567   {
568     Pixel::RGB16F,
569     Pixel::RGB32F,
570   };
571   const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
572
573   for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
574   {
575     TestApplication application;
576
577     //Create the texture
578     unsigned int width(64);
579     unsigned int height(64);
580     tet_infoline( "Creating a floating point texture" );
581     Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
582
583     application.GetGlAbstraction().EnableTextureCallTrace(true);
584
585     application.SendNotification();
586     application.Render();
587
588     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
589
590     tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
591     {
592       std::stringstream out;
593       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
594       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
595     }
596
597     tet_infoline( "Upload data to the texture" );
598     callStack.Reset();
599
600     tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
601     unsigned int bufferSize( width * height * 3 );
602     unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
603     PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
604     texture.Upload( pixelData );
605     application.SendNotification();
606     application.Render();
607
608     tet_infoline( "TexImage2D should be called to upload the data" );
609     {
610       std::stringstream out;
611       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
612       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
613     }
614   }
615
616   END_TEST;
617 }
618
619 int UtcDaliTextureUploadSmallerThanSize(void)
620 {
621   TestApplication application;
622
623   //Create the texture
624   unsigned int width(64);
625   unsigned int height(64);
626   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
627
628   application.GetGlAbstraction().EnableTextureCallTrace(true);
629
630   application.SendNotification();
631   application.Render();
632
633   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
634
635   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
636   {
637     std::stringstream out;
638     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
639     std::string params;
640     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
641     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
642   }
643
644   //Upload data to the texture
645   callStack.Reset();
646
647   unsigned int bufferSize( width * height * 4 );
648   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
649   PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
650   texture.Upload( pixelData );
651   application.SendNotification();
652   application.Render();
653
654   //TexImage2D should be called to upload the data
655   {
656     std::stringstream out;
657     out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " <<  0u << ", " << width/2 << ", " <<  height/2;
658     std::string params;
659     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
660     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
661   }
662
663   END_TEST;
664 }
665
666 int UtcDaliTextureGenerateMipmaps(void)
667 {
668   TestApplication application;
669   unsigned int width(64);
670   unsigned int height(64);
671
672   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
673   texture.GenerateMipmaps();
674
675   Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
676   textureCubemap.GenerateMipmaps();
677
678   application.GetGlAbstraction().EnableTextureCallTrace(true);
679   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
680   application.SendNotification();
681   application.Render();
682
683   {
684     std::stringstream out;
685     out << GL_TEXTURE_2D;
686     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
687   }
688   {
689     std::stringstream out;
690     out << GL_TEXTURE_CUBE_MAP;
691     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
692   }
693
694   END_TEST;
695 }
696
697 int UtcDaliTextureGetWidth(void)
698 {
699   TestApplication application;
700   unsigned int width(64);
701   unsigned int height(64);
702
703   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
704   DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
705   END_TEST;
706 }
707
708 int UtcDaliTextureGetHeight(void)
709 {
710   TestApplication application;
711   unsigned int width(64);
712   unsigned int height(64);
713
714   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
715   DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
716
717   END_TEST;
718 }
719
720 int UtcDaliTextureContextLoss(void)
721 {
722   tet_infoline("UtcDaliTextureContextLoss\n");
723   TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
724
725   //Create the texture
726   unsigned int width(64);
727   unsigned int height(64);
728   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
729   DALI_TEST_CHECK( texture );
730
731   application.SendNotification();
732   application.Render(16);
733
734   // Lose & regain context (in render 'thread')
735   application.ResetContext();
736   DALI_TEST_CHECK( texture );
737
738   END_TEST;
739 }
740
741 int UtcDaliNativeImageTexture(void)
742 {
743   TestApplication application;
744   tet_infoline( "UtcDaliNativeImageTexture" );
745
746   TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
747   Texture texture = Texture::New( *(imageInterface.Get()) );
748   DALI_TEST_CHECK( texture );
749
750   application.SendNotification();
751   application.Render(16);
752
753   DALI_TEST_CHECK( texture );
754
755   END_TEST;
756 }
757