2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/dali-core.h>
20 #include <dali/devel-api/images/texture-set-image.h>
26 #include <dali-test-suite-utils.h>
27 #include <mesh-builder.h>
31 #define MAKE_SHADER(A)#A
33 const char* VERTEX_SHADER = MAKE_SHADER(
34 attribute mediump vec2 aPosition;
35 attribute mediump vec2 aTexCoord;
36 uniform mediump mat4 uMvpMatrix;
37 uniform mediump vec3 uSize;
38 varying mediump vec2 vTexCoord;
42 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
43 vertexPosition.xyz *= uSize;
44 vertexPosition = uMvpMatrix * vertexPosition;
45 vTexCoord = aTexCoord;
46 gl_Position = vertexPosition;
50 const char* FRAGMENT_SHADER = MAKE_SHADER(
51 uniform Sampler2D sTexture;
52 varying mediump vec2 vTexCoord;
55 gl_FragColor = texture2D( sTexture, vTexCoord );
59 Actor CreateMeshActorToStage( TestApplication& application, Vector3 parentOrigin = ParentOrigin::CENTER, Vector3 anchorPoint = AnchorPoint::CENTER, Shader::Hint::Value shaderHints = Shader::Hint::NONE )
61 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
62 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
64 Geometry geometry = CreateQuadGeometry();
65 Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, shaderHints );
66 TextureSet textureSet = TextureSet::New();
67 TextureSetImage( textureSet, 0u, image );
68 Renderer renderer = Renderer::New( geometry, shader );
69 renderer.SetTextures( textureSet );
71 Actor meshActor = Actor::New();
72 meshActor.AddRenderer( renderer );
73 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f ) );
74 meshActor.SetParentOrigin( parentOrigin );
75 meshActor.SetAnchorPoint( anchorPoint );
76 Stage::GetCurrent().Add( meshActor );
78 application.SendNotification();
79 application.Render( 16 );
84 bool GetCameraDepths( TestApplication& application, float& nearPlane, float& farPlane, float& cameraDepth )
86 RenderTaskList renderTasks = Stage::GetCurrent().GetRenderTaskList();
87 CameraActor cameraActor;
88 for( unsigned int i = 0; i < renderTasks.GetTaskCount(); ++i )
90 RenderTask task = renderTasks.GetTask( i );
91 cameraActor = task.GetCameraActor();
99 application.SendNotification();
100 application.Render( 16 );
102 nearPlane = cameraActor.GetNearClippingPlane();
103 farPlane = cameraActor.GetFarClippingPlane();
104 cameraDepth = cameraActor.GetCurrentPosition().z;
107 return !!cameraActor;
110 int UtcFrustumCullN(void)
112 TestApplication application;
113 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
114 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
115 drawTrace.Enable( true );
117 CreateMeshActorToStage( application );
120 application.SendNotification();
121 application.Render( 16 );
123 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
128 int UtcFrustumLeftCullP(void)
130 TestApplication application;
131 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
132 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
133 drawTrace.Enable( true );
135 float offset = -0.01f;
136 Actor meshActor = CreateMeshActorToStage( application, Vector3( offset, 0.5f, 0.5f ), AnchorPoint::CENTER_RIGHT );
138 float radius = meshActor.GetTargetSize().Length() * 0.5f;
139 Vector2 stageSize = Stage::GetCurrent().GetSize();
140 meshActor.SetParentOrigin( Vector3( -radius / stageSize.width + offset, 0.5f, 0.5f ) );
141 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
144 application.SendNotification();
145 application.Render( 16 );
147 // This will be sphere culled
148 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
153 int UtcFrustumLeftCullN(void)
155 TestApplication application;
156 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
157 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
158 drawTrace.Enable( true );
160 float offset = 0.01f;
161 Actor meshActor = CreateMeshActorToStage( application, Vector3( offset, 0.5f, 0.5f ), AnchorPoint::CENTER_RIGHT );
164 application.SendNotification();
165 application.Render( 16 );
167 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
172 int UtcFrustumRightCullP(void)
174 TestApplication application;
175 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
176 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
177 drawTrace.Enable( true );
179 float offset = 1.01f;
180 Actor meshActor = CreateMeshActorToStage( application, Vector3( offset, 0.5f, 0.5f ), AnchorPoint::CENTER_LEFT );
182 float radius = meshActor.GetTargetSize().Length() * 0.5f;
183 Vector2 stageSize = Stage::GetCurrent().GetSize();
185 meshActor.SetParentOrigin( Vector3( radius / stageSize.width + offset, 0.5f, 0.5f ) );
186 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
189 application.SendNotification();
190 application.Render( 16 );
192 // This will be sphere culled
193 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
198 int UtcFrustumRightCullN(void)
200 TestApplication application;
201 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
202 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
203 drawTrace.Enable( true );
205 float offset = 0.99f;
206 Actor meshActor = CreateMeshActorToStage( application, Vector3( offset, 0.5f, 0.5f ), AnchorPoint::CENTER_LEFT );
209 application.SendNotification();
210 application.Render( 16 );
212 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
217 int UtcFrustumTopCullP(void)
219 TestApplication application;
220 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
221 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
222 drawTrace.Enable( true );
224 float offset = -0.01f;
225 Actor meshActor = CreateMeshActorToStage( application, Vector3( 0.5f, offset, 0.5f ), AnchorPoint::BOTTOM_CENTER );
227 float radius = meshActor.GetTargetSize().Length() * 0.5f;
228 Vector2 stageSize = Stage::GetCurrent().GetSize();
230 meshActor.SetParentOrigin( Vector3( 0.5f, -radius / stageSize.width + offset, 0.5f ) );
231 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
234 application.SendNotification();
235 application.Render( 16 );
237 // This will be sphere culled
238 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
243 int UtcFrustumTopCullN(void)
245 TestApplication application;
246 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
247 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
248 drawTrace.Enable( true );
250 float offset = 0.01f;
251 Actor meshActor = CreateMeshActorToStage( application, Vector3( 0.5f, offset, 0.5f ), AnchorPoint::BOTTOM_CENTER );
254 application.SendNotification();
255 application.Render( 16 );
257 // This will be box culled
258 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
263 int UtcFrustumBottomCullP(void)
265 TestApplication application;
266 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
267 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
268 drawTrace.Enable( true );
270 float offset = 1.01f;
271 Actor meshActor = CreateMeshActorToStage( application, Vector3( 0.5f, offset, 0.5f ), AnchorPoint::TOP_CENTER );
273 float radius = meshActor.GetTargetSize().Length() * 0.5f;
274 Vector2 stageSize = Stage::GetCurrent().GetSize();
276 meshActor.SetParentOrigin( Vector3( 0.5f, radius / stageSize.width + offset, 0.5f ) );
277 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
280 application.SendNotification();
281 application.Render( 16 );
283 // This will be sphere culled
284 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
289 int UtcFrustumBottomCullN(void)
291 TestApplication application;
292 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
293 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
294 drawTrace.Enable( true );
296 float offset = 0.99f;
297 Actor meshActor = CreateMeshActorToStage( application, Vector3( 0.5f, offset, 0.5f ), AnchorPoint::TOP_CENTER );
300 application.SendNotification();
301 application.Render( 16 );
303 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
308 int UtcFrustumNearCullP(void)
310 TestApplication application;
311 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
312 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
313 drawTrace.Enable( true );
315 float nearPlane, farPlane, cameraDepth;
316 DALI_TEST_CHECK( GetCameraDepths( application, nearPlane, farPlane, cameraDepth ) );
318 Actor meshActor = CreateMeshActorToStage( application );
319 Vector3 meshPosition = meshActor.GetCurrentPosition();
321 float radius = meshActor.GetTargetSize().Length() * 0.5f;
322 float offset = radius + 0.1f;
323 meshPosition.z = cameraDepth - nearPlane + offset;
324 meshActor.SetPosition( meshPosition );
327 application.SendNotification();
328 application.Render( 16 );
330 // This will be sphere culled
331 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
336 int UtcFrustumNearCullN(void)
338 TestApplication application;
339 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
340 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
341 drawTrace.Enable( true );
343 float nearPlane, farPlane, cameraDepth;
344 DALI_TEST_CHECK( GetCameraDepths( application, nearPlane, farPlane, cameraDepth ) );
346 Actor meshActor = CreateMeshActorToStage( application );
347 Vector3 meshPosition = meshActor.GetCurrentPosition();
349 float offset = meshActor.GetTargetSize().z - 0.1f;
350 meshPosition.z = cameraDepth - nearPlane + offset;
351 meshActor.SetPosition( meshPosition );
354 application.SendNotification();
355 application.Render( 16 );
357 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
362 int UtcFrustumFarCullP(void)
364 TestApplication application;
365 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
366 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
367 drawTrace.Enable( true );
369 float nearPlane, farPlane, cameraDepth;
370 DALI_TEST_CHECK( GetCameraDepths( application, nearPlane, farPlane, cameraDepth ) );
372 Actor meshActor = CreateMeshActorToStage( application );
373 Vector3 meshPosition = meshActor.GetCurrentPosition();
375 float radius = meshActor.GetTargetSize().Length() * 0.5f;
376 float offset = radius + 0.1f;
377 meshPosition.z = cameraDepth - farPlane - offset;
378 meshActor.SetPosition( meshPosition );
381 application.SendNotification();
382 application.Render( 16 );
384 // This will be sphere culled
385 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
390 int UtcFrustumFarCullN(void)
392 TestApplication application;
393 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
394 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
395 drawTrace.Enable( true );
397 float nearPlane, farPlane, cameraDepth;
398 DALI_TEST_CHECK( GetCameraDepths( application, nearPlane, farPlane, cameraDepth ) );
400 Actor meshActor = CreateMeshActorToStage( application );
401 Vector3 meshPosition = meshActor.GetCurrentPosition();
403 float offset = meshActor.GetTargetSize().z - 0.1f;
404 meshPosition.z = cameraDepth - farPlane - offset;
405 meshActor.SetPosition( meshPosition );
408 application.SendNotification();
409 application.Render( 16 );
411 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
416 int UtcFrustumCullDisabledP(void)
418 TestApplication application;
419 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
420 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
421 drawTrace.Enable( true );
423 CreateMeshActorToStage( application, Vector3( 7.0f, 0.5f, 0.5f ), AnchorPoint::CENTER, Shader::Hint::MODIFIES_GEOMETRY );
426 application.SendNotification();
427 application.Render( 16 );
429 // This should not be culled
430 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );