2 * Copyright (c) 2014 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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/devel-api/object/property-buffer.h>
24 #include <dali/devel-api/rendering/geometry.h>
25 #include <dali/devel-api/rendering/material.h>
26 #include <dali/devel-api/rendering/renderer.h>
27 #include <dali/devel-api/rendering/sampler.h>
28 #include <dali/devel-api/rendering/shader.h>
32 #define MAKE_SHADER(A)#A
34 const char* VERTEX_SHADER = MAKE_SHADER(
35 attribute mediump vec2 aPosition;
36 attribute mediump vec2 aTexCoord;
37 uniform mediump mat4 uMvpMatrix;
38 uniform mediump vec3 uSize;
39 varying mediump vec2 vTexCoord;
43 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
44 vertexPosition.xyz *= uSize;
45 vertexPosition = uMvpMatrix * vertexPosition;
46 vTexCoord = aTexCoord;
47 gl_Position = vertexPosition;
51 const char* FRAGMENT_SHADER = MAKE_SHADER(
52 uniform Sampler2D sTexture;
53 varying mediump vec2 vTexCoord;
56 gl_FragColor = texture2D( sTexture, vTexCoord );
60 Geometry CreateGeometry()
62 const float halfQuadSize = .5f;
63 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
64 TexturedQuadVertex texturedQuadVertexData[4] = {
65 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
66 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
67 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
68 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
70 Property::Map texturedQuadVertexFormat;
71 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
72 texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
73 PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
74 texturedQuadVertices.SetData(texturedQuadVertexData);
77 unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
78 Property::Map indexFormat;
79 indexFormat["indices"] = Property::INTEGER;
80 PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) );
81 indices.SetData(indexData);
83 // Create the geometry object
84 Geometry texturedQuadGeometry = Geometry::New();
85 texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
86 texturedQuadGeometry.SetIndexBuffer( indices );
88 return texturedQuadGeometry;
91 int UtcFrustumCullN(void)
93 TestApplication application;
94 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
95 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
96 drawTrace.Enable(true);
98 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
99 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
101 Geometry geometry = CreateGeometry();
102 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
103 Sampler sampler = Sampler::New( image, "sTexture" );
104 material.AddSampler( sampler );
105 Renderer renderer = Renderer::New( geometry, material );
107 Actor meshActor = Actor::New();
108 meshActor.AddRenderer( renderer );
109 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
112 meshActor.SetParentOrigin( ParentOrigin::CENTER );
113 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
114 Stage::GetCurrent().Add( meshActor );
116 application.SendNotification();
117 application.Render(16);
118 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
122 int UtcFrustumLeftCullP(void)
124 TestApplication application;
125 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
126 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
127 drawTrace.Enable(true);
129 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
130 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
132 Geometry geometry = CreateGeometry();
133 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
134 Sampler sampler = Sampler::New( image, "sTexture" );
135 material.AddSampler( sampler );
136 Renderer renderer = Renderer::New( geometry, material );
138 Actor meshActor = Actor::New();
139 meshActor.AddRenderer( renderer );
140 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
143 float offset = -0.01f;
145 meshActor.SetParentOrigin( Vector3( offset, 0.5f, 0.5f ) );
146 meshActor.SetAnchorPoint( AnchorPoint::CENTER_RIGHT );
147 Stage::GetCurrent().Add( meshActor );
149 application.SendNotification();
150 application.Render(16);
152 // This will be box culled
153 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
155 float radius = meshActor.GetTargetSize().Length() * 0.5f;
156 Vector2 stageSize = Stage::GetCurrent().GetSize();
159 meshActor.SetParentOrigin( Vector3( -radius/stageSize.width + offset, 0.5f, 0.5f ) );
160 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
161 application.SendNotification();
162 application.Render(16);
164 // This will be sphere culled
165 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
170 int UtcFrustumRightCullP(void)
172 TestApplication application;
173 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
174 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
175 drawTrace.Enable(true);
177 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
178 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
180 Geometry geometry = CreateGeometry();
181 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
182 Sampler sampler = Sampler::New( image, "sTexture" );
183 material.AddSampler( sampler );
184 Renderer renderer = Renderer::New( geometry, material );
186 Actor meshActor = Actor::New();
187 meshActor.AddRenderer( renderer );
188 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
191 float offset = 1.01f;
193 meshActor.SetParentOrigin( Vector3( offset, 0.5f, 0.5f ) );
194 meshActor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
195 Stage::GetCurrent().Add( meshActor );
197 application.SendNotification();
198 application.Render(16);
200 // This will be box culled
201 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
203 float radius = meshActor.GetTargetSize().Length() * 0.5f;
204 Vector2 stageSize = Stage::GetCurrent().GetSize();
207 meshActor.SetParentOrigin( Vector3( radius/stageSize.width + offset, 0.5f, 0.5f ) );
208 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
209 application.SendNotification();
210 application.Render(16);
212 // This will be sphere culled
213 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
218 int UtcFrustumTopCullP(void)
220 TestApplication application;
221 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
222 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
223 drawTrace.Enable(true);
225 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
226 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
228 Geometry geometry = CreateGeometry();
229 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
230 Sampler sampler = Sampler::New( image, "sTexture" );
231 material.AddSampler( sampler );
232 Renderer renderer = Renderer::New( geometry, material );
234 Actor meshActor = Actor::New();
235 meshActor.AddRenderer( renderer );
236 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
239 float offset = -0.01f;
241 meshActor.SetParentOrigin( Vector3( 0.5f, offset, 0.5f ) );
242 meshActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
243 Stage::GetCurrent().Add( meshActor );
245 application.SendNotification();
246 application.Render(16);
248 // This will be box culled
249 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
251 float radius = meshActor.GetTargetSize().Length() * 0.5f;
252 Vector2 stageSize = Stage::GetCurrent().GetSize();
255 meshActor.SetParentOrigin( Vector3( 0.5f, -radius/stageSize.width + offset, 0.5f ) );
256 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
257 application.SendNotification();
258 application.Render(16);
260 // This will be sphere culled
261 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
266 int UtcFrustumBottomCullP(void)
268 TestApplication application;
269 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
270 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
271 drawTrace.Enable(true);
273 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
274 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
276 Geometry geometry = CreateGeometry();
277 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
278 Sampler sampler = Sampler::New( image, "sTexture" );
279 material.AddSampler( sampler );
280 Renderer renderer = Renderer::New( geometry, material );
282 Actor meshActor = Actor::New();
283 meshActor.AddRenderer( renderer );
284 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
287 float offset = 1.01f;
289 meshActor.SetParentOrigin( Vector3( 0.5f, offset, 0.5f ) );
290 meshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
291 Stage::GetCurrent().Add( meshActor );
293 application.SendNotification();
294 application.Render(16);
296 // This will be box culled
297 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
299 float radius = meshActor.GetTargetSize().Length() * 0.5f;
300 Vector2 stageSize = Stage::GetCurrent().GetSize();
303 meshActor.SetParentOrigin( Vector3( 0.5f, radius/stageSize.width + offset, 0.5f ) );
304 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
305 application.SendNotification();
306 application.Render(16);
308 // This will be sphere culled
309 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
314 int UtcFrustumNearCullP(void)
316 TestApplication application;
317 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
318 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
319 drawTrace.Enable(true);
321 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
322 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
324 Geometry geometry = CreateGeometry();
325 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
326 Sampler sampler = Sampler::New( image, "sTexture" );
327 material.AddSampler( sampler );
328 Renderer renderer = Renderer::New( geometry, material );
330 Actor meshActor = Actor::New();
331 meshActor.AddRenderer( renderer );
332 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
335 meshActor.SetParentOrigin( Vector3( 0.5f, 0.5f, 7.0f ) );
336 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
337 Stage::GetCurrent().Add( meshActor );
339 application.SendNotification();
340 application.Render(16);
342 // This will be sphere culled
343 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
347 int UtcFrustumFarCullP(void)
349 TestApplication application;
350 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
351 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
352 drawTrace.Enable(true);
354 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
355 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
357 Geometry geometry = CreateGeometry();
358 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
359 Sampler sampler = Sampler::New( image, "sTexture" );
360 material.AddSampler( sampler );
361 Renderer renderer = Renderer::New( geometry, material );
363 Actor meshActor = Actor::New();
364 meshActor.AddRenderer( renderer );
365 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
368 meshActor.SetParentOrigin( Vector3( 0.5f, 0.5f, -7.0f ) );
369 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
370 Stage::GetCurrent().Add( meshActor );
372 application.SendNotification();
373 application.Render(16);
375 // This will be sphere culled
376 DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
380 int UtcFrustumCullDisabledP(void)
382 TestApplication application;
383 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
384 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
385 drawTrace.Enable(true);
387 PixelBuffer* pixelBuffer = new PixelBuffer[ 4 ];
388 BufferImage image = BufferImage::New( pixelBuffer, 1, 1 );
390 Geometry geometry = CreateGeometry();
391 Material material = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Shader::HINT_MODIFIES_GEOMETRY ) );
392 Sampler sampler = Sampler::New( image, "sTexture" );
393 material.AddSampler( sampler );
394 Renderer renderer = Renderer::New( geometry, material );
396 Actor meshActor = Actor::New();
397 meshActor.AddRenderer( renderer );
398 meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
401 meshActor.SetParentOrigin( ParentOrigin::CENTER );
402 meshActor.SetAnchorPoint( AnchorPoint::CENTER );
403 Stage::GetCurrent().Add( meshActor );
405 application.SendNotification();
406 application.Render(16);
408 // This should not be culled
409 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );