Move GLES 3.0 floating point pixel formats to Public API
[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
514   END_TEST;
515 }
516
517 int UtcDaliTextureUpload06(void)
518 {
519   TestApplication application;
520
521   //Create the texture
522   unsigned int width(64);
523   unsigned int height(64);
524   tet_infoline( "Creating a Texure with an alpha channel" );
525   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
526
527   application.GetGlAbstraction().EnableTextureCallTrace(true);
528
529   application.SendNotification();
530   application.Render();
531
532   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
533
534   tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
535   {
536     std::stringstream out;
537     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
538     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
539   }
540
541   tet_infoline( "Upload data to the texture" );
542   callStack.Reset();
543
544   tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
545   unsigned int bufferSize( width * height * 3 );
546   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
547   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
548   texture.Upload( pixelData );
549   application.SendNotification();
550   application.Render();
551
552   tet_infoline( "TexImage2D should be called to upload the data" );
553   {
554     std::stringstream out;
555     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
556     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
557   }
558
559   END_TEST;
560 }
561
562 int UtcDaliTextureUpload07(void)
563 {
564   Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
565   {
566     Pixel::RGB16F,
567     Pixel::RGB32F,
568   };
569   const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
570
571   for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
572   {
573     TestApplication application;
574
575     //Create the texture
576     unsigned int width(64);
577     unsigned int height(64);
578     tet_infoline( "Creating a floating point texture" );
579     Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
580
581     application.GetGlAbstraction().EnableTextureCallTrace(true);
582
583     application.SendNotification();
584     application.Render();
585
586     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
587
588     tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
589     {
590       std::stringstream out;
591       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
592       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
593     }
594
595     tet_infoline( "Upload data to the texture" );
596     callStack.Reset();
597
598     tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
599     unsigned int bufferSize( width * height * 3 );
600     unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
601     PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
602     texture.Upload( pixelData );
603     application.SendNotification();
604     application.Render();
605
606     tet_infoline( "TexImage2D should be called to upload the data" );
607     {
608       std::stringstream out;
609       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
610       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
611     }
612   }
613
614   END_TEST;
615 }
616
617 int UtcDaliTextureUploadSmallerThanSize(void)
618 {
619   TestApplication application;
620
621   //Create the texture
622   unsigned int width(64);
623   unsigned int height(64);
624   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
625
626   application.GetGlAbstraction().EnableTextureCallTrace(true);
627
628   application.SendNotification();
629   application.Render();
630
631   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
632
633   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
634   {
635     std::stringstream out;
636     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
637     std::string params;
638     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
639     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
640   }
641
642   //Upload data to the texture
643   callStack.Reset();
644
645   unsigned int bufferSize( width * height * 4 );
646   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
647   PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
648   texture.Upload( pixelData );
649   application.SendNotification();
650   application.Render();
651
652   //TexImage2D should be called to upload the data
653   {
654     std::stringstream out;
655     out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " <<  0u << ", " << width/2 << ", " <<  height/2;
656     std::string params;
657     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
658     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
659   }
660
661   END_TEST;
662 }
663
664 int UtcDaliTextureGenerateMipmaps(void)
665 {
666   TestApplication application;
667   unsigned int width(64);
668   unsigned int height(64);
669
670   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
671   texture.GenerateMipmaps();
672
673   Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
674   textureCubemap.GenerateMipmaps();
675
676   application.GetGlAbstraction().EnableTextureCallTrace(true);
677   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
678   application.SendNotification();
679   application.Render();
680
681   {
682     std::stringstream out;
683     out << GL_TEXTURE_2D;
684     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
685   }
686   {
687     std::stringstream out;
688     out << GL_TEXTURE_CUBE_MAP;
689     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
690   }
691
692   END_TEST;
693 }
694
695 int UtcDaliTextureGetWidth(void)
696 {
697   TestApplication application;
698   unsigned int width(64);
699   unsigned int height(64);
700
701   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
702   DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
703   END_TEST;
704 }
705
706 int UtcDaliTextureGetHeight(void)
707 {
708   TestApplication application;
709   unsigned int width(64);
710   unsigned int height(64);
711
712   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
713   DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
714
715   END_TEST;
716 }
717
718 int UtcDaliTextureContextLoss(void)
719 {
720   tet_infoline("UtcDaliTextureContextLoss\n");
721   TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
722
723   //Create the texture
724   unsigned int width(64);
725   unsigned int height(64);
726   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
727   DALI_TEST_CHECK( texture );
728
729   application.SendNotification();
730   application.Render(16);
731
732   // Lose & regain context (in render 'thread')
733   application.ResetContext();
734   DALI_TEST_CHECK( texture );
735
736   END_TEST;
737 }
738
739 int UtcDaliNativeImageTexture(void)
740 {
741   TestApplication application;
742   tet_infoline( "UtcDaliNativeImageTexture" );
743
744   TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
745   Texture texture = Texture::New( *(imageInterface.Get()) );
746   DALI_TEST_CHECK( texture );
747
748   application.SendNotification();
749   application.Render(16);
750
751   DALI_TEST_CHECK( texture );
752
753   END_TEST;
754 }
755