8945a75878002e438d5e3d102353774b1e70b507
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-Image-Culling.cpp
1 /*
2  * Copyright (c) 2014 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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 void utc_dali_internal_image_culling_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_internal_image_culling_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37
38 namespace
39 {
40 #define NUM_ROWS 9
41 #define NUM_COLS 9
42 #define NUM_ROWS_PER_PANE 3
43 #define NUM_COLS_PER_PANE 3
44 const unsigned int TEXTURE_ID_OFFSET = 23;
45
46 Image LoadImage( TestApplication& application, GLuint textureId, int width, int height )
47 {
48   Image image;
49   char* filename = NULL;
50   int numChars = asprintf(&filename, "image%u.png", textureId );
51
52   if( numChars > 0 )
53   {
54     const Vector2 closestImageSize( width, height );
55     application.GetPlatform().SetClosestImageSize(closestImageSize);
56
57     image = Image::New( filename, Image::Immediate, Image::Never );
58     free (filename);
59   }
60   DALI_TEST_CHECK(image);
61   application.SendNotification();
62   application.Render(16);
63
64   std::vector<GLuint> ids;
65   ids.push_back( textureId );
66   application.GetGlAbstraction().SetNextTextureIds( ids );
67
68   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
69   Integration::ResourcePointer resource(bitmap);
70   bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
71   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
72   Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
73   DALI_TEST_CHECK( request != NULL );
74   if(request)
75   {
76     application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
77   }
78   application.SendNotification();
79   application.Render(16);
80   application.GetPlatform().ClearReadyResources();
81   application.GetPlatform().DiscardRequest();
82   application.SendNotification();
83   application.Render(16);
84
85   return image;
86 }
87
88 ImageActor CreateOnStageActor(TestApplication& application, Image image, int width, int height, bool testDraw)
89 {
90   ImageActor imageActor = ImageActor::New(image);
91   Stage::GetCurrent().Add(imageActor);
92
93   imageActor.SetParentOrigin(ParentOrigin::CENTER);
94   application.SendNotification();
95   application.Render(16);
96   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
97   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
98   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
99
100   if(testDraw)
101   {
102     DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
103     DALI_TEST_CHECK( textureTrace.FindMethod( "BindTexture" ) );
104     const std::vector<GLuint>& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
105     DALI_TEST_CHECK( textures.size() > 0 );
106     if( textures.size() > 0 )
107     {
108       DALI_TEST_CHECK( textures[0] == 23 );
109     }
110   }
111   return imageActor;
112 }
113
114
115 void TestImageInside( TestApplication& application, int width, int height )
116 {
117   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
118   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
119   textureTrace.Enable(true);
120   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
121   drawTrace.Enable(true);
122
123   Image image = LoadImage( application, 23, width, height );
124
125   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
126   imageActor.SetPosition(0.0f, 0.0f, 0.0f);
127
128   Vector3 imageSize = imageActor.GetCurrentSize();
129   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
130
131   drawTrace.Reset();
132   imageActor.SetParentOrigin(ParentOrigin::TOP_LEFT);
133   application.SendNotification();
134   application.Render(16);
135   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
136
137   drawTrace.Reset();
138   imageActor.SetParentOrigin(ParentOrigin::TOP_RIGHT);
139   application.SendNotification();
140   application.Render(16);
141   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
142
143   drawTrace.Reset();
144   imageActor.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
145   application.SendNotification();
146   application.Render(16);
147   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
148
149   drawTrace.Reset();
150   imageActor.SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
151   application.SendNotification();
152   application.Render(16);
153   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
154 }
155
156
157 bool RepositionActor(TestApplication& application, Actor actor, float x, float y, bool inside)
158 {
159   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
160
161   drawTrace.Reset();
162   actor.SetPosition( x, y, 0.0f);
163   application.SendNotification();
164   application.Render(16);
165
166   bool found = drawTrace.FindMethod( "DrawArrays" );
167   return (inside && found) || (!inside && !found);
168 }
169
170
171 void RepositionActorWithAngle(TestApplication& application, Actor actor, float x, float y, float angle, bool inside)
172 {
173   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
174
175   drawTrace.Reset();
176   actor.SetPosition( x, y, 0.0f);
177   actor.SetRotation( Degree(angle), Vector3::ZAXIS );
178   application.SendNotification();
179   application.Render(16);
180   if( inside )
181   {
182     bool found = drawTrace.FindMethod( "DrawArrays" );
183     if( ! found ) tet_printf( "Not drawn: Position:(%3.0f, %3.0f)\n", x, y );
184     DALI_TEST_CHECK( found );
185   }
186   else
187   {
188     bool found = drawTrace.FindMethod( "DrawArrays" );
189     if( found ) tet_printf( "Drawn when not needed: Position:(%3.0f, %3.0f)\n", x, y );
190     DALI_TEST_CHECK( ! found );
191   }
192 }
193
194 void RepositionActorOutside(TestApplication& application, Actor actor, float x, float y, bool drawn )
195 {
196   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
197
198   drawTrace.Reset();
199   actor.SetPosition( x, y, 0.0f);
200   application.SendNotification();
201   application.Render(16);
202   if( drawn )
203   {
204     bool found = drawTrace.FindMethod( "DrawArrays" );
205     if( ! found ) tet_printf( "Not drawn: Position:(%3.0f, %3.0f)\n", x, y );
206     DALI_TEST_CHECK( found );
207   }
208   else
209   {
210     bool found = drawTrace.FindMethod( "DrawArrays" );
211     if( found ) tet_printf( "Drawn unnecessarily: Position:(%3.0f, %3.0f)\n", x, y );
212     DALI_TEST_CHECK( ! found );
213   }
214
215 }
216
217 void SphereTestImageAtBoundary( TestApplication& application, int width, int height )
218 {
219   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
220   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
221   textureTrace.Enable(true);
222   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
223   drawTrace.Enable(true);
224
225   Vector2 stageSize = Stage::GetCurrent().GetSize();
226
227   Image image = LoadImage(application, 23, width, height);
228   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
229
230   Vector3 imageSize = imageActor.GetCurrentSize();
231   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
232
233   imageSize.z = 0.0f;
234   float radius = imageSize.Length() * 0.5f; // Radius of bounding box
235   tet_printf("Testing Stage Size: (%3.0f, %3.0f) image size:(%3.0f, %3.0f) := radius=%3.0f\n",
236              stageSize.x, stageSize.y, imageSize.x, imageSize.y, radius);
237
238   for( int i=0; i<=radius; i++ )
239   {
240     float x1 = -stageSize.x/2.0f - i;
241     float x2 =  stageSize.x/2.0f + i;
242     float y1 = -stageSize.y/2.0f - i;
243     float y2 =  stageSize.y/2.0f + i;
244
245     //tet_printf("Testing i=%d\n",i);
246
247     // Test paths marked with dots
248     //  + . . . . . .
249     //  .\_     ^
250     //  .  \_   | within radius
251     //  .    \  v
252     //  .     +-----
253     //  .     | Stage
254
255     for( int j=-10; j<=10; j++ )
256     {
257       float x = ((stageSize.x+2*radius)/21.0f) * j;
258       float y = ((stageSize.y+2*radius)/21.0f) * j;
259
260       RepositionActor( application, imageActor, x1, y, true );
261       RepositionActor( application, imageActor, x2, y, true );
262       RepositionActor( application, imageActor, x, y1, true );
263       RepositionActor( application, imageActor, x, y2, true );
264     }
265   }
266 }
267
268 void OBBTestImageAtBoundary( TestApplication& application, int width, int height )
269 {
270   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
271   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
272   textureTrace.Enable(true);
273   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
274   drawTrace.Enable(true);
275
276   Vector2 stageSize = Stage::GetCurrent().GetSize();
277
278   Image image = LoadImage(application, 23, width, height);
279   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
280
281   Vector3 imageSize = imageActor.GetCurrentSize();
282   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
283
284   imageSize.z = 0.0f;
285   tet_printf("Testing Stage Size: (%3.0f, %3.0f) image size:(%3.0f, %3.0f) \n",
286              stageSize.x, stageSize.y, imageSize.x, imageSize.y);
287
288   int successCount = 0;
289   int totalCount = 0;
290   for( int i=0; i<100; i++ )
291   {
292     float x1 = -stageSize.x/2.0f - imageSize.x*i/200.0f;
293     float x2 =  stageSize.x/2.0f + imageSize.x*i/200.0f;
294     float y1 = -stageSize.y/2.0f - imageSize.y*i/200.0f;
295     float y2 =  stageSize.y/2.0f + imageSize.y*i/200.0f;
296
297     //tet_printf("Testing i=%d\n",i);
298
299     // Test paths marked with dots
300     //  + . . . . . .
301     //  .\_     ^
302     //  .  \_   | within radius
303     //  .    \  v
304     //  .     +-----
305     //  .     | Stage
306
307     for( int j=-10; j<=10; j++ )
308     {
309       float x = ((stageSize.x+imageSize.x/2.0f)/21.0f) * j;
310       float y = ((stageSize.y+imageSize.y/2.0f)/21.0f) * j;
311
312       if(RepositionActor( application, imageActor, x1, y, true )) successCount++;
313       if(RepositionActor( application, imageActor, x2, y, true )) successCount++;
314       if(RepositionActor( application, imageActor, x, y1, true )) successCount++;
315       if(RepositionActor( application, imageActor, x, y2, true )) successCount++;
316
317       totalCount += 4;
318     }
319   }
320   DALI_TEST_EQUALS(successCount, totalCount, TEST_LOCATION);
321   tet_printf( "Test succeeded with %d passes out of %d tests\n", successCount, totalCount);
322 }
323
324
325 void SphereTestImageOutsideBoundary( TestApplication& application, int width, int height )
326 {
327   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
328   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
329   textureTrace.Enable(true);
330   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
331   drawTrace.Enable(true);
332
333   Vector2 stageSize = Stage::GetCurrent().GetSize();
334
335   Image image = LoadImage( application, 23, width, height );
336
337   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
338   Vector3 imageSize = imageActor.GetCurrentSize();
339   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
340
341   imageSize.z = 0.0f;
342   float radius = imageSize.Length() * 0.5f; // Radius of bounding box
343   tet_printf("Testing Stage Size: (%3.0f, %3.0f) image size:(%3.0f, %3.0f) := radius=%3.0f\n",
344              stageSize.x, stageSize.y, imageSize.x, imageSize.y, radius);
345
346   for( int i=0; i<100; i++ )
347   {
348     // Try from 3 times
349     float x1 = -stageSize.x/2.0f - imageSize.x*i/200.0f;
350     float x2 =  stageSize.x/2.0f + imageSize.x*i/200.0f;
351     float y1 = -stageSize.y/2.0f - imageSize.y*i/200.0f;
352     float y2 =  stageSize.y/2.0f + imageSize.y*i/200.0f;
353
354
355     //tet_printf("Testing i=%d\n",i);
356     for( int j=-10; j<=10; j++ )
357     {
358       float x = (stageSize.x/17.0f) * j; // use larger intervals to test more area
359       float y = (stageSize.y/17.0f) * j;
360
361       RepositionActor( application, imageActor, x1, y, false );
362       RepositionActor( application, imageActor, x2, y, false );
363       RepositionActor( application, imageActor, x, y1, false );
364       RepositionActor( application, imageActor, x, y2, false );
365     }
366   }
367 }
368
369 void OBBTestImageOutsideBoundary( TestApplication& application, int width, int height )
370 {
371   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
372   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
373   textureTrace.Enable(true);
374   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
375   drawTrace.Enable(true);
376
377   Vector2 stageSize = Stage::GetCurrent().GetSize();
378
379   Image image = LoadImage( application, 23, width, height );
380
381   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
382   Vector3 imageSize = imageActor.GetCurrentSize();
383   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
384
385   imageSize.z = 0.0f;
386   tet_printf("Testing Stage Size: (%3.0f, %3.0f) image size:(%3.0f, %3.0f)\n",
387              stageSize.x, stageSize.y, imageSize.x, imageSize.y);
388
389   int successCount=0;
390   int totalCount=0;
391
392   for( int i=0; i<=100; i++ )
393   {
394     float x1 = -stageSize.x/2.0f - imageSize.x * (1.5f + i/100.0f);
395     float x2 =  stageSize.x/2.0f + imageSize.x * (1.5f + i/100.0f);
396     float y1 = -stageSize.y/2.0f - imageSize.y * (1.5f + i/100.0f);
397     float y2 =  stageSize.y/2.0f + imageSize.y * (1.5f + i/100.0f);
398
399     for( int j=-10; j<=10; j++ )
400     {
401       float x = (stageSize.x/17.0f) * j; // use larger intervals to test more area
402       float y = (stageSize.y/17.0f) * j;
403
404       if(RepositionActor( application, imageActor, x1, y, false )) successCount++;
405       if(RepositionActor( application, imageActor, x2, y, false )) successCount++;
406       if(RepositionActor( application, imageActor, x, y1, false )) successCount++;
407       if(RepositionActor( application, imageActor, x, y2, false )) successCount++;
408       totalCount+=4;
409     }
410   }
411   DALI_TEST_EQUALS(successCount, totalCount, TEST_LOCATION);
412   tet_printf( "Test succeeded with %d passes out of %d tests\n", successCount, totalCount);
413 }
414
415 void TestPlaneOfImages(TestApplication& application, float z)
416 {
417   Vector2 stageSize = Stage::GetCurrent().GetSize();
418   Vector2 imageSize = stageSize/3.0f;
419
420   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
421   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
422   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
423
424   // Create a grid of 9 x 9 actors; only the central 3x3 are in viewport
425
426   ActorContainer actors;
427   for( int i = 0; i < NUM_ROWS*NUM_COLS; i++ )
428   {
429     GLuint textureId = TEXTURE_ID_OFFSET+i;
430     Image image = LoadImage( application, textureId, imageSize.x, imageSize.y );
431     ImageActor imageActor = CreateOnStageActor(application, image, imageSize.x, imageSize.y, false );
432     actors.push_back(imageActor);
433   }
434   application.SendNotification();
435   application.Render(16);
436
437   drawTrace.Reset();
438   textureTrace.Reset();
439   drawTrace.Enable(true);
440   textureTrace.Enable(true);
441   application.GetGlAbstraction().ClearBoundTextures();
442
443   for( int row=0; row<NUM_ROWS; row++)
444   {
445     for( int col=0; col<NUM_COLS; col++)
446     {
447       // col:    0   1   2  | 3   4   5 | 6   7   8
448       //
449       //        -4/3 -1 -2/3 -1/3  0 1/3 |2/3 1  4/3
450       // col*2 -5
451       //         0   2   4
452       // NUM_COLS = 9 NUM_COLS_PER_PANE = 3   (A pane is stage sized)
453       //
454       // NUM_COLS / NUM_COLS_PER_PANE => number of panes
455       // 3 per pane, splits into -1/3, 0, +1/3
456       // number of lh planes * number of cols per plane
457       // Center column maps to zero, index of center column = num_cols / 2 rounded down
458       // index - that  and divide by number of cols per pane.
459       // 0 1 2 3 4  5 6 7 8  9 10 11 12
460       float xOffset = (int)(col - (NUM_COLS/2));
461       float yOffset = (int)(row - (NUM_ROWS/2));
462       float x = stageSize.x*xOffset / (float)(NUM_COLS_PER_PANE);
463       float y = stageSize.y*yOffset / (float)(NUM_ROWS_PER_PANE);
464       actors[row*NUM_COLS+col].SetPosition( x, y, z );
465     }
466   }
467
468   application.SendNotification();
469   application.Render(16);
470
471   DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
472
473   typedef std::vector<GLuint> TexVec;
474   const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
475   DALI_TEST_CHECK( textures.size() >= NUM_ROWS_PER_PANE * NUM_COLS_PER_PANE );
476   if( textures.size() > 0 )
477   {
478     int foundCount=0;
479     int expectedCount = 0;
480     for(unsigned int row=0; row<NUM_ROWS; row++)
481     {
482       for(unsigned int col=0; col<NUM_ROWS; col++)
483       {
484         Vector3 pos = actors[row*NUM_COLS+col].GetCurrentPosition();
485         if( -stageSize.x/2.0f <= pos.x && pos.x <= stageSize.x/2.0f &&
486             -stageSize.y/2.0f <= pos.y && pos.y <= stageSize.y/2.0f )
487         {
488           expectedCount++;
489           GLuint texId = (row*NUM_COLS+col)+TEXTURE_ID_OFFSET;
490
491           for(TexVec::const_iterator iter = textures.begin(); iter != textures.end(); iter++)
492           {
493             if(*iter == texId)
494             {
495               foundCount++;
496             }
497           }
498         }
499       }
500     }
501     tet_printf("Number of expected draws: %u\n", expectedCount);
502     DALI_TEST_EQUALS(foundCount, expectedCount, TEST_LOCATION);
503   }
504   int numDrawCalls = drawTrace.CountMethod("DrawArrays");
505   DALI_TEST_CHECK( numDrawCalls >= NUM_ROWS_PER_PANE * NUM_COLS_PER_PANE );
506
507   tet_printf("Number of bound textures: %u\n", textures.size());
508   tet_printf("Number of draw calls: %d\n", numDrawCalls);
509 }
510
511 } // namespace
512
513 int UtcDaliImageCulling_Inside01(void)
514 {
515   tet_infoline( "Testing that 80x80 image positioned inside the stage is drawn\n");
516
517   TestApplication application;
518
519   TestImageInside(application, 80, 80);
520
521   END_TEST;
522 }
523
524 int UtcDaliImageCulling_Inside02(void)
525 {
526   tet_infoline( "Testing that 120x40 image positioned inside the stage is drawn\n");
527
528   TestApplication application;
529
530   TestImageInside(application, 120, 40);
531
532   END_TEST;
533 }
534
535 int UtcDaliImageCulling_Inside03(void)
536 {
537   tet_infoline( "Testing that 40x120 image positioned inside the stage is drawn\n");
538
539   TestApplication application;
540
541   TestImageInside(application, 40, 120);
542
543   END_TEST;
544 }
545
546 int UtcDaliImageCulling_Inside04(void)
547 {
548   tet_infoline( "Testing that 500x2 image positioned inside the stage is drawn\n");
549   TestApplication application;
550   TestImageInside(application, 500, 2);
551   END_TEST;
552 }
553
554 int UtcDaliImageCulling_Inside05(void)
555 {
556   tet_infoline( "Testing that 2x500 image positioned inside the stage is drawn\n");
557   TestApplication application;
558   TestImageInside(application, 2, 500);
559   END_TEST;
560 }
561
562
563 int UtcDaliImageCulling_WithinBoundary01(void)
564 {
565   tet_infoline("Test that 80x80 image positioned outside the stage but with bounding box intersecting the stage is drawn\n");
566
567   TestApplication application;
568   OBBTestImageAtBoundary( application, 80, 80);
569   END_TEST;
570 }
571 int UtcDaliImageCulling_WithinBoundary02(void)
572 {
573   tet_infoline("Test that 120x40 image positioned outside the stage but with bounding box intersecting the stage is drawn\n");
574
575   TestApplication application;
576   OBBTestImageAtBoundary( application, 120, 40 );
577   END_TEST;
578 }
579 int UtcDaliImageCulling_WithinBoundary03(void)
580 {
581   tet_infoline("Test that 40x120 image positioned outside the stage but with bounding box intersecting the stage is drawn\n");
582
583   TestApplication application;
584   OBBTestImageAtBoundary( application, 40, 120);
585   END_TEST;
586 }
587
588 int UtcDaliImageCulling_WithinBoundary04(void)
589 {
590   tet_infoline("Test that 500x2 images positioned outside the stage but with bounding box intersecting the stage is drawn\n");
591
592   TestApplication application;
593   OBBTestImageAtBoundary( application, 500, 2 );
594   END_TEST;
595 }
596
597 int UtcDaliImageCulling_WithinBoundary05(void)
598 {
599   tet_infoline("Test that 2x500 images positioned outside the stage but with bounding box intersecting the stage is drawn\n");
600
601   TestApplication application;
602   OBBTestImageAtBoundary( application, 2, 500 );
603   END_TEST;
604 }
605
606 int UtcDaliImageCulling_OutsideBoundary01(void)
607 {
608   tet_infoline("Test that 80x80 image positioned outside the stage by more than 2 times\n"
609                "the radius of the bounding circle  is not drawn\n");
610
611   TestApplication application;
612   OBBTestImageOutsideBoundary( application, 80, 80 );
613   END_TEST;
614 }
615
616 int UtcDaliImageCulling_OutsideBoundary02(void)
617 {
618   tet_infoline("Test that 120x40 image positioned outside the stage by more than 2 times\n"
619                "the radius of the bounding circle  is not drawn\n");
620
621   TestApplication application;
622   OBBTestImageOutsideBoundary( application, 120, 40 );
623   END_TEST;
624 }
625 int UtcDaliImageCulling_OutsideBoundary03(void)
626 {
627   tet_infoline("Test that 40x120 image positioned outside the stage by more than 2 times\n"
628                "the radius of the bounding circle  is not drawn\n");
629
630   TestApplication application;
631   OBBTestImageOutsideBoundary( application, 40, 120 );
632   END_TEST;
633 }
634
635 int UtcDaliImageCulling_OutsideBoundary04(void)
636 {
637   tet_infoline("Test that 500x2 image positioned outside the stage by more than 2 times\n"
638                "the radius of the bounding circle  is not drawn\n");
639
640   TestApplication application;
641   OBBTestImageOutsideBoundary( application, 500, 2 );
642   END_TEST;
643 }
644
645 int UtcDaliImageCulling_OutsideBoundary05(void)
646 {
647   tet_infoline("Test that 2x500 image positioned outside the stage by more than 2 times\n"
648                "the radius of the bounding circle  is not drawn\n");
649
650   TestApplication application;
651   OBBTestImageOutsideBoundary( application, 2, 500 );
652   END_TEST;
653 }
654
655 int UtcDaliImageCulling_OutsideIntersect01(void)
656 {
657   TestApplication application;
658
659   tet_infoline("Test that actors positioned outside the stage with bounding boxes also\n"
660                "outside the stage but intersecting it are still drawn");
661
662   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
663   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
664   textureTrace.Enable(true);
665   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
666   drawTrace.Enable(true);
667   Vector2 stageSize = Stage::GetCurrent().GetSize();
668
669   float width = stageSize.x*5.0f;
670   float height = stageSize.y*0.2f;
671   Image image = LoadImage( application, 23,  width, height);
672   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
673
674   RepositionActor( application, imageActor, stageSize.x*1.2f, 0.0f, true);
675   RepositionActor( application, imageActor, stageSize.x*1.2f, -stageSize.y*0.55f, true);
676   RepositionActor( application, imageActor, stageSize.x*1.2f, stageSize.y*0.55f, true);
677   END_TEST;
678 }
679
680 int UtcDaliImageCulling_OutsideIntersect02(void)
681 {
682   TestApplication application;
683
684   tet_infoline("Test that actors positioned outside the stage with bounding boxes also\n"
685                "outside the stage that cross planes are not drawn");
686
687   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
688   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
689   textureTrace.Enable(true);
690   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
691   drawTrace.Enable(true);
692   Vector2 stageSize = Stage::GetCurrent().GetSize();
693
694   float width = stageSize.x*5.0f;
695   float height = stageSize.y*0.2f;
696   Image image = LoadImage( application, 23,  width, height);
697   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
698
699   RepositionActor( application, imageActor,  stageSize.x*10.0f,  stageSize.y*0.5f, false);
700   RepositionActor( application, imageActor, -stageSize.x*10.0f,  stageSize.y*0.5f, false);
701   RepositionActor( application, imageActor,  stageSize.x*10.0f, -stageSize.y*0.5f, false);
702   RepositionActor( application, imageActor, -stageSize.x*10.0f, -stageSize.y*0.5f, false);
703   END_TEST;
704 }
705
706 int UtcDaliImageCulling_OutsideIntersect03(void)
707 {
708   TestApplication application;
709
710   tet_infoline("Test that image actor larger than the stage, positioned outside the stage \n"
711                "with bounding boxes also outside the stage but intersecting it is still drawn\n");
712
713   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
714   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
715   textureTrace.Enable(true);
716   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
717   drawTrace.Enable(true);
718   Vector2 stageSize = Stage::GetCurrent().GetSize();
719
720   // Try an actor bigger than the stage, with center outside stage
721   float width = stageSize.x*5.0f;
722   float height = stageSize.y*5.0f;
723   Image image = LoadImage( application, 23,  width, height);
724   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
725
726   RepositionActor( application, imageActor, stageSize.x*1.2f, 0.0f, true);
727   RepositionActor( application, imageActor, stageSize.x*1.2f, -stageSize.y*1.1f, true);
728   RepositionActor( application, imageActor, stageSize.x*1.2f, stageSize.y*1.1f, true);
729
730   END_TEST;
731 }
732
733 int UtcDaliImageCulling_OutsideIntersect04(void)
734 {
735   TestApplication application;
736
737   tet_infoline("Test that image actors positioned outside the stage, with bounding boxes\n"
738                "also outside the stage but intersecting it, and angled at 45 degrees to\n"
739                "the corners are still drawn\n");
740
741   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
742   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
743   textureTrace.Enable(true);
744   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
745   drawTrace.Enable(true);
746   Vector2 stageSize = Stage::GetCurrent().GetSize();
747
748   // Test image at 45 degrees outside corners of stage
749   float width = 400.0f;
750   float height = 200.0f;
751   Image image = LoadImage( application, 23,  width, height);
752   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
753
754   RepositionActorWithAngle( application, imageActor, -stageSize.x*0.55f, -stageSize.y*0.55, 135.0f, true);
755   RepositionActorWithAngle( application, imageActor, -stageSize.x*0.55f,  stageSize.y*0.55, 225.0f, true);
756   RepositionActorWithAngle( application, imageActor,  stageSize.x*0.55f, -stageSize.y*0.55,  45.0f, true);
757   RepositionActorWithAngle( application, imageActor,  stageSize.x*0.55f,  stageSize.y*0.55, 315.0f, true);
758
759   END_TEST;
760 }
761
762 int UtcDaliImageCulling_Plane01(void)
763 {
764   tet_infoline("Test that a set of image actors with different images are drawn appropriately");
765
766   TestApplication application;
767
768   TestPlaneOfImages(application, 0.0f);
769   END_TEST;
770 }
771
772 int UtcDaliImageCulling_Plane02(void)
773 {
774   tet_infoline("Test that a set of image actors with different images are drawn appropriately");
775
776   TestApplication application;
777
778   TestPlaneOfImages(application, 100.0f);
779   END_TEST;
780 }
781
782 int UtcDaliImageCulling_Plane03(void)
783 {
784   tet_infoline("Test that a set of image actors with different images are drawn appropriately");
785
786   TestApplication application;
787
788   TestPlaneOfImages(application, -100.0f);
789   END_TEST;
790 }
791
792 int UtcDaliImageCulling_Plane04(void)
793 {
794   tet_infoline("Test that a set of image actors with different images are drawn appropriately");
795
796   TestApplication application;
797
798   TestPlaneOfImages(application, -200.0f);
799   END_TEST;
800 }
801
802 int UtcDaliImageCulling_Disable(void)
803 {
804   tet_infoline("Test that culling can be disabled");
805
806   TestApplication application;
807   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
808   TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
809   textureTrace.Enable(true);
810   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
811   drawTrace.Enable(true);
812
813   Vector2 stageSize = Stage::GetCurrent().GetSize();
814   float width=80;
815   float height=80;
816   Image image = LoadImage( application, 23, width, height );
817
818   ImageActor imageActor = CreateOnStageActor(application, image, width, height, true);
819   Vector3 imageSize = imageActor.GetCurrentSize();
820   DALI_TEST_EQUALS( imageSize, Vector3(width, height, std::min(width, height)), TEST_LOCATION);
821
822   imageSize.z = 0.0f;
823
824   tet_infoline("Setting cull mode to false\n");
825   Stage::GetCurrent().GetRenderTaskList().GetTask(0).SetCullMode(false);
826
827   float x1 = -stageSize.x - imageSize.x;
828   float x2 =  stageSize.x + imageSize.x;
829   float y1 = -stageSize.y - imageSize.y;
830   float y2 =  stageSize.y + imageSize.y;
831
832   // Positioning actors outside stage, with no culling, they should still be drawn.
833   RepositionActorOutside( application, imageActor, x1, y1, true );
834   RepositionActorOutside( application, imageActor, x2, y1, true );
835   RepositionActorOutside( application, imageActor, x1, y2, true );
836   RepositionActorOutside( application, imageActor, x2, y2, true );
837
838   tet_infoline("Setting cull mode to true\n");
839   Stage::GetCurrent().GetRenderTaskList().GetTask(0).SetCullMode(true);
840
841   RepositionActorOutside( application, imageActor, x1, y1, false );
842   RepositionActorOutside( application, imageActor, x2, y1, false );
843   RepositionActorOutside( application, imageActor, x1, y2, false );
844   RepositionActorOutside( application, imageActor, x2, y2, false );
845
846   END_TEST;
847 }