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