2 * Copyright (c) 2018 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/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/rendering/renderer-devel.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/images/texture-set-image.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali/integration-api/render-task-list-integ.h>
30 #include <dali-test-suite-utils.h>
31 #include <test-trace-call-stack.h>
32 #include <mesh-builder.h>
36 namespace // unnamed namespace
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
41 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
42 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
44 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
45 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
48 * @brief Get GL stencil test enumeration value as a string.
49 * @return The string representation of the value of GL_STENCIL_TEST
51 std::string GetStencilTestString(void)
53 std::stringstream stream;
54 stream << GL_STENCIL_TEST;
59 * @brief Get GL depth test enumeration value as a string.
60 * @return The string representation of the value of GL_DEPTH_TEST
62 std::string GetDepthTestString(void)
64 std::stringstream stream;
65 stream << GL_DEPTH_TEST;
69 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
71 glEnableDisableStack.Reset();
72 glStencilFunctionStack.Reset();
73 application.SendNotification();
77 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
82 } // unnamed namespace
84 void renderer_test_startup(void)
86 test_return_value = TET_UNDEF;
89 void renderer_test_cleanup(void)
91 test_return_value = TET_PASS;
94 int UtcDaliRendererNew01(void)
96 TestApplication application;
98 Geometry geometry = CreateQuadGeometry();
99 Shader shader = CreateShader();
100 Renderer renderer = Renderer::New(geometry, shader);
102 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
106 int UtcDaliRendererNew02(void)
108 TestApplication application;
110 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
114 int UtcDaliRendererCopyConstructor(void)
116 TestApplication application;
118 Geometry geometry = CreateQuadGeometry();
119 Shader shader = CreateShader();
120 Renderer renderer = Renderer::New(geometry, shader);
122 Renderer rendererCopy( renderer );
123 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
128 int UtcDaliRendererAssignmentOperator(void)
130 TestApplication application;
132 Geometry geometry = CreateQuadGeometry();
133 Shader shader = CreateShader();
134 Renderer renderer = Renderer::New(geometry, shader);
137 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
139 renderer2 = renderer;
140 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
144 int UtcDaliRendererDownCast01(void)
146 TestApplication application;
148 Geometry geometry = CreateQuadGeometry();
149 Shader shader = CreateShader();
150 Renderer renderer = Renderer::New(geometry, shader);
152 BaseHandle handle(renderer);
153 Renderer renderer2 = Renderer::DownCast(handle);
154 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
158 int UtcDaliRendererDownCast02(void)
160 TestApplication application;
162 Handle handle = Handle::New(); // Create a custom object
163 Renderer renderer = Renderer::DownCast(handle);
164 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
168 // using a template to auto deduce the parameter types
169 template< typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
170 void TEST_RENDERER_PROPERTY( P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION )
172 DALI_TEST_EQUALS( renderer.GetPropertyName( enumName ), stringName, LOCATION );
173 DALI_TEST_EQUALS( renderer.GetPropertyIndex( stringName ), static_cast<Property::Index>(enumName), LOCATION );
174 DALI_TEST_EQUALS( renderer.GetPropertyType( enumName ), type, LOCATION );
175 DALI_TEST_EQUALS( renderer.IsPropertyWritable( enumName ), isWriteable, LOCATION );
176 DALI_TEST_EQUALS( renderer.IsPropertyAnimatable( enumName ), isAnimateable, LOCATION );
177 DALI_TEST_EQUALS( renderer.IsPropertyAConstraintInput( enumName ), isConstraintInput, LOCATION );
180 int UtcDaliRendererDefaultProperties(void)
182 TestApplication application;
183 /* from renderer-impl.cpp
184 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
185 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
186 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
187 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
188 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
189 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
190 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
191 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
192 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
193 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
194 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
195 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
196 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
197 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
198 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
199 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
200 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
201 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
202 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
203 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
204 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
205 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
206 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
207 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
208 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
209 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
212 Geometry geometry = CreateQuadGeometry();
213 Shader shader = CreateShader();
214 Renderer renderer = Renderer::New(geometry, shader);
215 DALI_TEST_EQUALS( renderer.GetPropertyCount(), 26, TEST_LOCATION );
217 TEST_RENDERER_PROPERTY( renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION );
218 TEST_RENDERER_PROPERTY( renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION );
219 TEST_RENDERER_PROPERTY( renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION );
220 TEST_RENDERER_PROPERTY( renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION );
221 TEST_RENDERER_PROPERTY( renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION );
222 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION );
223 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION );
224 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION );
225 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION );
226 TEST_RENDERER_PROPERTY( renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION );
227 TEST_RENDERER_PROPERTY( renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION );
228 TEST_RENDERER_PROPERTY( renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION );
229 TEST_RENDERER_PROPERTY( renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION );
230 TEST_RENDERER_PROPERTY( renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION );
231 TEST_RENDERER_PROPERTY( renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION );
232 TEST_RENDERER_PROPERTY( renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION );
233 TEST_RENDERER_PROPERTY( renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION );
234 TEST_RENDERER_PROPERTY( renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION );
235 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION );
236 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionReference",Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION );
237 TEST_RENDERER_PROPERTY( renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION );
238 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION );
239 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION );
240 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION );
241 TEST_RENDERER_PROPERTY( renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION );
242 TEST_RENDERER_PROPERTY( renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION );
247 int UtcDaliRendererSetGetGeometry(void)
249 TestApplication application;
250 tet_infoline( "Test SetGeometry, GetGeometry" );
252 Geometry geometry1 = CreateQuadGeometry();
253 Geometry geometry2 = CreateQuadGeometry();
255 Shader shader = CreateShader();
256 Renderer renderer = Renderer::New(geometry1, shader);
257 Actor actor = Actor::New();
258 actor.AddRenderer(renderer);
259 actor.SetSize(400, 400);
260 Stage::GetCurrent().Add(actor);
262 application.SendNotification();
263 application.Render(0);
264 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
266 // Set geometry2 to the renderer
267 renderer.SetGeometry( geometry2 );
269 application.SendNotification();
270 application.Render(0);
271 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
276 int UtcDaliRendererSetGetShader(void)
278 TestApplication application;
279 tet_infoline( "Test SetShader, GetShader" );
281 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
282 glAbstraction.EnableCullFaceCallTrace(true);
284 Shader shader1 = CreateShader();
285 shader1.RegisterProperty( "uFadeColor", Color::RED );
287 Shader shader2 = CreateShader();
288 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
290 Geometry geometry = CreateQuadGeometry();
291 Renderer renderer = Renderer::New(geometry, shader1);
292 Actor actor = Actor::New();
293 actor.AddRenderer(renderer);
294 actor.SetSize(400, 400);
295 Stage::GetCurrent().Add(actor);
297 TestGlAbstraction& gl = application.GetGlAbstraction();
298 application.SendNotification();
299 application.Render(0);
301 // Expect that the first shaders's fade color property is accessed
302 Vector4 actualValue(Vector4::ZERO);
303 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
304 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
306 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
308 // set the second shader to the renderer
309 renderer.SetShader( shader2 );
311 application.SendNotification();
312 application.Render(0);
314 // Expect that the second shader's fade color property is accessed
315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
316 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
318 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
323 int UtcDaliRendererSetGetDepthIndex(void)
325 TestApplication application;
327 tet_infoline("Test SetDepthIndex, GetDepthIndex");
329 Shader shader = CreateShader();
330 Geometry geometry = CreateQuadGeometry();
331 Renderer renderer = Renderer::New(geometry, shader);
332 Actor actor = Actor::New();
333 actor.AddRenderer(renderer);
334 actor.SetSize(400, 400);
335 Stage::GetCurrent().Add(actor);
337 application.SendNotification();
338 application.Render(0);
339 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
341 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
343 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
344 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
346 application.SendNotification();
347 application.Render(0);
348 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
350 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
352 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
353 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
355 application.SendNotification();
356 application.Render(0);
357 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
362 int UtcDaliRendererSetGetFaceCullingMode(void)
364 TestApplication application;
366 tet_infoline("Test SetFaceCullingMode(cullingMode)");
367 Geometry geometry = CreateQuadGeometry();
368 Shader shader = CreateShader();
369 Renderer renderer = Renderer::New( geometry, shader );
371 Actor actor = Actor::New();
372 actor.AddRenderer(renderer);
373 actor.SetSize(400, 400);
374 Stage::GetCurrent().Add(actor);
376 // By default, none of the faces should be culled
377 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
378 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
380 TestGlAbstraction& gl = application.GetGlAbstraction();
381 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
382 gl.EnableCullFaceCallTrace(true);
385 cullFaceStack.Reset();
386 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
387 application.SendNotification();
388 application.Render();
390 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
392 std::ostringstream cullModeString;
393 cullModeString << GL_FRONT_AND_BACK;
395 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
396 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
397 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
401 cullFaceStack.Reset();
402 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
403 application.SendNotification();
404 application.Render();
406 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
408 std::ostringstream cullModeString;
409 cullModeString << GL_BACK;
411 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
412 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
413 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
417 cullFaceStack.Reset();
418 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
419 application.SendNotification();
420 application.Render();
422 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
424 std::ostringstream cullModeString;
425 cullModeString << GL_FRONT;
427 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
428 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
429 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
433 cullFaceStack.Reset();
434 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
435 application.SendNotification();
436 application.Render();
438 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
439 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
440 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
446 int UtcDaliRendererBlendOptions01(void)
448 TestApplication application;
450 tet_infoline("Test BLEND_FACTOR properties ");
452 Geometry geometry = CreateQuadGeometry();
453 Shader shader = CreateShader();
454 Renderer renderer = Renderer::New( geometry, shader );
456 Actor actor = Actor::New();
457 // set a transparent actor color so that blending is enabled
458 actor.SetOpacity( 0.5f );
459 actor.AddRenderer(renderer);
460 actor.SetSize(400, 400);
461 Stage::GetCurrent().Add(actor);
463 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
464 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
465 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
466 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
468 // Test that Set was successful:
469 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
470 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
471 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
472 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
474 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
475 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
476 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
477 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
479 application.SendNotification();
480 application.Render();
482 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
484 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
485 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
486 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
487 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
492 int UtcDaliRendererBlendOptions02(void)
494 TestApplication application;
496 tet_infoline("Test BLEND_FACTOR properties ");
498 Geometry geometry = CreateQuadGeometry();
499 Shader shader = CreateShader();
500 Renderer renderer = Renderer::New( geometry, shader );
502 Actor actor = Actor::New();
503 actor.SetOpacity( 0.5f ); // enable blending
504 actor.AddRenderer(renderer);
505 actor.SetSize(400, 400);
506 Stage::GetCurrent().Add(actor);
508 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
509 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
510 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
511 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
513 // Test that Set was successful:
515 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
516 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
517 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
518 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
520 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
521 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
522 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
523 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
526 application.SendNotification();
527 application.Render();
529 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
530 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
531 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
532 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
533 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
538 int UtcDaliRendererBlendOptions03(void)
540 TestApplication application;
542 tet_infoline("Test GetBlendEquation() defaults ");
544 Geometry geometry = CreateQuadGeometry();
545 Shader shader = CreateShader();
546 Renderer renderer = Renderer::New( geometry, shader );
548 Actor actor = Actor::New();
549 actor.AddRenderer(renderer);
550 actor.SetSize(400, 400);
551 Stage::GetCurrent().Add(actor);
553 // Test the defaults as documented in blending.h
554 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
555 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
557 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
558 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
563 int UtcDaliRendererBlendOptions04(void)
565 TestApplication application;
567 tet_infoline("Test SetBlendEquation() ");
569 Geometry geometry = CreateQuadGeometry();
570 Shader shader = CreateShader();
571 Renderer renderer = Renderer::New( geometry, shader );
573 Actor actor = Actor::New();
574 actor.SetOpacity( 0.1f );
575 actor.AddRenderer(renderer);
576 actor.SetSize(400, 400);
577 Stage::GetCurrent().Add(actor);
579 // Test the single blending equation setting
581 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
582 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
583 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
586 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
587 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
589 // Test that Set was successful
591 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
592 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
593 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
594 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
597 // Render & check GL commands
598 application.SendNotification();
599 application.Render();
601 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
602 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
603 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
608 int UtcDaliRendererSetBlendMode01(void)
610 TestApplication application;
612 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
614 Geometry geometry = CreateQuadGeometry();
615 Shader shader = CreateShader();
616 Renderer renderer = Renderer::New( geometry, shader );
618 Actor actor = Actor::New();
619 actor.SetOpacity( 0.98f );
620 actor.AddRenderer(renderer);
621 actor.SetSize(400, 400);
622 Stage::GetCurrent().Add(actor);
624 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
626 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
627 glAbstraction.EnableEnableDisableCallTrace(true);
629 application.SendNotification();
630 application.Render();
632 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
633 std::ostringstream blendStr;
634 blendStr << GL_BLEND;
635 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
640 int UtcDaliRendererSetBlendMode01b(void)
642 TestApplication application;
644 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
646 Geometry geometry = CreateQuadGeometry();
647 Shader shader = CreateShader();
648 Renderer renderer = Renderer::New( geometry, shader );
650 Actor actor = Actor::New();
651 actor.SetOpacity( 0.0f );
652 actor.AddRenderer(renderer);
653 actor.SetSize(400, 400);
654 Stage::GetCurrent().Add(actor);
656 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
658 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
659 glAbstraction.EnableEnableDisableCallTrace(true);
660 glAbstraction.EnableDrawCallTrace( true );
662 application.SendNotification();
663 application.Render();
665 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
666 std::ostringstream blendStr;
667 blendStr << GL_BLEND;
668 DALI_TEST_CHECK( !glEnableStack.FindMethod( "Enable" ) );
670 DALI_TEST_CHECK( !glAbstraction.GetDrawTrace().FindMethod( "DrawElements" ) );
675 int UtcDaliRendererSetBlendMode02(void)
677 TestApplication application;
679 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
681 Geometry geometry = CreateQuadGeometry();
682 Shader shader = CreateShader();
683 Renderer renderer = Renderer::New( geometry, shader );
685 Actor actor = Actor::New();
686 actor.SetOpacity( 0.15f );
687 actor.AddRenderer(renderer);
688 actor.SetSize(400, 400);
689 Stage::GetCurrent().Add(actor);
691 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
693 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
694 glAbstraction.EnableEnableDisableCallTrace(true);
696 application.SendNotification();
697 application.Render();
699 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
700 std::ostringstream blendStr;
701 blendStr << GL_BLEND;
702 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
707 int UtcDaliRendererSetBlendMode03(void)
709 TestApplication application;
711 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
713 Geometry geometry = CreateQuadGeometry();
714 Shader shader = CreateShader();
715 Renderer renderer = Renderer::New( geometry, shader );
717 Actor actor = Actor::New();
718 actor.SetOpacity( 0.75f );
719 actor.AddRenderer(renderer);
720 actor.SetSize(400, 400);
721 Stage::GetCurrent().Add(actor);
723 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
725 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
726 glAbstraction.EnableEnableDisableCallTrace(true);
728 application.SendNotification();
729 application.Render();
731 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
732 std::ostringstream blendStr;
733 blendStr << GL_BLEND;
734 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
739 int UtcDaliRendererSetBlendMode04(void)
741 TestApplication application;
743 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
745 Geometry geometry = CreateQuadGeometry();
746 Shader shader = CreateShader();
747 Renderer renderer = Renderer::New( geometry, shader );
749 Actor actor = Actor::New();
750 actor.AddRenderer(renderer);
751 actor.SetSize(400, 400);
752 Stage::GetCurrent().Add(actor);
754 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
756 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
757 glAbstraction.EnableEnableDisableCallTrace(true);
759 application.SendNotification();
760 application.Render();
762 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
763 std::ostringstream blendStr;
764 blendStr << GL_BLEND;
765 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
770 int UtcDaliRendererSetBlendMode04b(void)
772 TestApplication application;
774 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
776 Geometry geometry = CreateQuadGeometry();
777 Shader shader = CreateShader();
778 Renderer renderer = Renderer::New( geometry, shader );
780 Actor actor = Actor::New();
781 actor.AddRenderer(renderer);
782 actor.SetSize(400, 400);
783 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
784 Stage::GetCurrent().Add(actor);
786 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
788 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
789 glAbstraction.EnableEnableDisableCallTrace(true);
791 application.SendNotification();
792 application.Render();
794 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
795 std::ostringstream blendStr;
796 blendStr << GL_BLEND;
797 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
802 int UtcDaliRendererSetBlendMode04c(void)
804 TestApplication application;
806 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
808 Geometry geometry = CreateQuadGeometry();
809 Shader shader = CreateShader();
810 Renderer renderer = Renderer::New( geometry, shader );
812 Actor actor = Actor::New();
813 actor.AddRenderer(renderer);
814 actor.SetSize(400, 400);
815 actor.SetColor( Color::MAGENTA );
816 Stage::GetCurrent().Add(actor);
818 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
820 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
821 glAbstraction.EnableEnableDisableCallTrace(true);
823 application.SendNotification();
824 application.Render();
826 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
827 std::ostringstream blendStr;
828 blendStr << GL_BLEND;
829 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
834 int UtcDaliRendererSetBlendMode05(void)
836 TestApplication application;
838 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
840 Geometry geometry = CreateQuadGeometry();
841 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
843 Shader shader = CreateShader();
844 TextureSet textureSet = CreateTextureSet( image );
845 Renderer renderer = Renderer::New( geometry, shader );
846 renderer.SetTextures( textureSet );
848 Actor actor = Actor::New();
849 actor.AddRenderer(renderer);
850 actor.SetSize(400, 400);
851 Stage::GetCurrent().Add(actor);
853 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
855 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
856 glAbstraction.EnableEnableDisableCallTrace(true);
858 application.SendNotification();
859 application.Render();
861 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
862 std::ostringstream blendStr;
863 blendStr << GL_BLEND;
864 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
869 int UtcDaliRendererSetBlendMode06(void)
871 TestApplication application;
872 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
874 Geometry geometry = CreateQuadGeometry();
875 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
877 Renderer renderer = Renderer::New( geometry, shader );
879 Actor actor = Actor::New();
880 actor.AddRenderer(renderer);
881 actor.SetSize(400, 400);
882 Stage::GetCurrent().Add(actor);
884 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
886 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
887 glAbstraction.EnableEnableDisableCallTrace(true);
889 application.SendNotification();
890 application.Render();
892 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
893 std::ostringstream blendStr;
894 blendStr << GL_BLEND;
895 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
900 int UtcDaliRendererSetBlendMode07(void)
902 TestApplication application;
903 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
905 Geometry geometry = CreateQuadGeometry();
906 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
908 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
909 TextureSet textureSet = CreateTextureSet( image );
910 Renderer renderer = Renderer::New( geometry, shader );
911 renderer.SetTextures( textureSet );
913 Actor actor = Actor::New();
914 actor.AddRenderer(renderer);
915 actor.SetSize(400, 400);
916 Stage::GetCurrent().Add(actor);
918 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
920 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
921 glAbstraction.EnableEnableDisableCallTrace(true);
923 application.SendNotification();
924 application.Render();
926 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
927 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
932 int UtcDaliRendererGetBlendMode(void)
934 TestApplication application;
936 tet_infoline("Test GetBlendMode()");
938 Geometry geometry = CreateQuadGeometry();
939 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
940 Renderer renderer = Renderer::New( geometry, shader );
943 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
944 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
947 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
948 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
949 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
952 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
953 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
954 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
959 int UtcDaliRendererSetBlendColor(void)
961 TestApplication application;
963 tet_infoline("Test SetBlendColor(color)");
965 Geometry geometry = CreateQuadGeometry();
966 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
967 TextureSet textureSet = TextureSet::New();
968 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
969 TextureSetImage( textureSet, 0u, image );
970 Renderer renderer = Renderer::New( geometry, shader );
971 renderer.SetTextures( textureSet );
973 Actor actor = Actor::New();
974 actor.AddRenderer(renderer);
975 actor.SetSize(400, 400);
976 Stage::GetCurrent().Add(actor);
978 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
980 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
982 application.SendNotification();
983 application.Render();
985 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
986 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
987 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
989 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
991 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
992 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
994 application.SendNotification();
995 application.Render();
997 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
998 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
1000 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1001 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1002 application.SendNotification();
1003 application.Render();
1004 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
1009 int UtcDaliRendererGetBlendColor(void)
1011 TestApplication application;
1013 tet_infoline("Test GetBlendColor()");
1015 Geometry geometry = CreateQuadGeometry();
1016 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1017 Renderer renderer = Renderer::New( geometry, shader );
1019 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
1021 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
1022 application.SendNotification();
1023 application.Render();
1024 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
1026 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1027 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1028 application.SendNotification();
1029 application.Render();
1030 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
1035 int UtcDaliRendererPreMultipledAlpha(void)
1037 TestApplication application;
1039 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1041 Geometry geometry = CreateQuadGeometry();
1042 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1043 Renderer renderer = Renderer::New( geometry, shader );
1045 Actor actor = Actor::New();
1046 actor.AddRenderer(renderer);
1047 actor.SetSize(400, 400);
1048 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
1049 Stage::GetCurrent().Add(actor);
1051 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1052 bool preMultipliedAlpha;
1053 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1054 DALI_TEST_CHECK( !preMultipliedAlpha );
1056 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1057 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1058 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1059 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1061 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
1062 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
1063 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
1064 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
1066 application.SendNotification();
1067 application.Render();
1069 Vector4 actualValue(Vector4::ZERO);
1070 TestGlAbstraction& gl = application.GetGlAbstraction();
1071 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1072 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
1074 // Enable pre-multiplied alpha
1075 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1077 application.SendNotification();
1078 application.Render();
1080 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1081 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1082 DALI_TEST_CHECK( preMultipliedAlpha );
1084 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1085 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1086 DALI_TEST_CHECK( preMultipliedAlpha );
1088 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1089 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1090 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1091 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1093 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
1094 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1095 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1096 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1098 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1099 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
1101 // Disable pre-multiplied alpha again
1102 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false );
1104 application.SendNotification();
1105 application.Render();
1107 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1108 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1109 DALI_TEST_CHECK( !preMultipliedAlpha );
1111 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1112 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1113 DALI_TEST_CHECK( !preMultipliedAlpha );
1115 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1116 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1117 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1118 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1120 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1121 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1122 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1123 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1125 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1126 DALI_TEST_EQUALS( actualValue, Vector4( 1.0f, 0.0f, 1.0f, 0.5f ), TEST_LOCATION );
1131 int UtcDaliRendererConstraint01(void)
1133 TestApplication application;
1135 tet_infoline("Test that a non-uniform renderer property can be constrained");
1137 Shader shader = Shader::New("VertexSource", "FragmentSource");
1138 Geometry geometry = CreateQuadGeometry();
1139 Renderer renderer = Renderer::New( geometry, shader );
1141 Actor actor = Actor::New();
1142 actor.AddRenderer(renderer);
1143 actor.SetSize(400, 400);
1144 Stage::GetCurrent().Add(actor);
1146 Vector4 initialColor = Color::WHITE;
1147 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1149 application.SendNotification();
1150 application.Render(0);
1151 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1154 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1156 application.SendNotification();
1157 application.Render(0);
1159 // Expect no blue component in either buffer - yellow
1160 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1161 application.Render(0);
1162 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1164 renderer.RemoveConstraints();
1165 renderer.SetProperty(colorIndex, Color::WHITE );
1166 application.SendNotification();
1167 application.Render(0);
1168 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1173 int UtcDaliRendererConstraint02(void)
1175 TestApplication application;
1177 tet_infoline("Test that a uniform map renderer property can be constrained");
1179 Shader shader = Shader::New("VertexSource", "FragmentSource");
1180 Geometry geometry = CreateQuadGeometry();
1181 Renderer renderer = Renderer::New( geometry, shader );
1183 Actor actor = Actor::New();
1184 actor.AddRenderer(renderer);
1185 actor.SetSize(400, 400);
1186 Stage::GetCurrent().Add(actor);
1187 application.SendNotification();
1188 application.Render(0);
1190 Vector4 initialColor = Color::WHITE;
1191 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1193 TestGlAbstraction& gl = application.GetGlAbstraction();
1195 application.SendNotification();
1196 application.Render(0);
1198 Vector4 actualValue(Vector4::ZERO);
1199 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1200 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1203 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1205 application.SendNotification();
1206 application.Render(0);
1208 // Expect no blue component in either buffer - yellow
1209 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1210 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1212 application.Render(0);
1213 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1214 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1216 renderer.RemoveConstraints();
1217 renderer.SetProperty(colorIndex, Color::WHITE );
1218 application.SendNotification();
1219 application.Render(0);
1221 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1222 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1227 int UtcDaliRendererAnimatedProperty01(void)
1229 TestApplication application;
1231 tet_infoline("Test that a non-uniform renderer property can be animated");
1233 Shader shader = Shader::New("VertexSource", "FragmentSource");
1234 Geometry geometry = CreateQuadGeometry();
1235 Renderer renderer = Renderer::New( geometry, shader );
1237 Actor actor = Actor::New();
1238 actor.AddRenderer(renderer);
1239 actor.SetSize(400, 400);
1240 Stage::GetCurrent().Add(actor);
1242 Vector4 initialColor = Color::WHITE;
1243 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1245 application.SendNotification();
1246 application.Render(0);
1247 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1249 Animation animation = Animation::New(1.0f);
1250 KeyFrames keyFrames = KeyFrames::New();
1251 keyFrames.Add(0.0f, initialColor);
1252 keyFrames.Add(1.0f, Color::TRANSPARENT);
1253 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1256 application.SendNotification();
1257 application.Render(500);
1259 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1261 application.Render(500);
1263 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1268 int UtcDaliRendererAnimatedProperty02(void)
1270 TestApplication application;
1272 tet_infoline("Test that a uniform map renderer property can be animated");
1274 Shader shader = Shader::New("VertexSource", "FragmentSource");
1275 Geometry geometry = CreateQuadGeometry();
1276 Renderer renderer = Renderer::New( geometry, shader );
1278 Actor actor = Actor::New();
1279 actor.AddRenderer(renderer);
1280 actor.SetSize(400, 400);
1281 Stage::GetCurrent().Add(actor);
1282 application.SendNotification();
1283 application.Render(0);
1285 Vector4 initialColor = Color::WHITE;
1286 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1288 TestGlAbstraction& gl = application.GetGlAbstraction();
1290 application.SendNotification();
1291 application.Render(0);
1293 Vector4 actualValue(Vector4::ZERO);
1294 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1295 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1297 Animation animation = Animation::New(1.0f);
1298 KeyFrames keyFrames = KeyFrames::New();
1299 keyFrames.Add(0.0f, initialColor);
1300 keyFrames.Add(1.0f, Color::TRANSPARENT);
1301 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1304 application.SendNotification();
1305 application.Render(500);
1307 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1308 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1310 application.Render(500);
1311 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1312 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1317 int UtcDaliRendererUniformMapPrecendence01(void)
1319 TestApplication application;
1321 tet_infoline("Test the uniform map precedence is applied properly");
1323 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1325 Shader shader = Shader::New("VertexSource", "FragmentSource");
1326 TextureSet textureSet = CreateTextureSet( image );
1328 Geometry geometry = CreateQuadGeometry();
1329 Renderer renderer = Renderer::New( geometry, shader );
1330 renderer.SetTextures( textureSet );
1332 Actor actor = Actor::New();
1333 actor.AddRenderer(renderer);
1334 actor.SetSize(400, 400);
1335 Stage::GetCurrent().Add(actor);
1336 application.SendNotification();
1337 application.Render(0);
1339 renderer.RegisterProperty( "uFadeColor", Color::RED );
1340 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1341 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1343 TestGlAbstraction& gl = application.GetGlAbstraction();
1345 application.SendNotification();
1346 application.Render(0);
1348 // Expect that the actor's fade color property is accessed
1349 Vector4 actualValue(Vector4::ZERO);
1350 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1351 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1353 // Animate shader's fade color property. Should be no change to uniform
1354 Animation animation = Animation::New(1.0f);
1355 KeyFrames keyFrames = KeyFrames::New();
1356 keyFrames.Add(0.0f, Color::WHITE);
1357 keyFrames.Add(1.0f, Color::TRANSPARENT);
1358 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1361 application.SendNotification();
1362 application.Render(500);
1364 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1365 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1367 application.Render(500);
1368 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1369 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1374 int UtcDaliRendererUniformMapPrecendence02(void)
1376 TestApplication application;
1378 tet_infoline("Test the uniform map precedence is applied properly");
1380 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1382 Shader shader = Shader::New("VertexSource", "FragmentSource");
1383 TextureSet textureSet = CreateTextureSet( image );
1385 Geometry geometry = CreateQuadGeometry();
1386 Renderer renderer = Renderer::New( geometry, shader );
1387 renderer.SetTextures( textureSet );
1389 Actor actor = Actor::New();
1390 actor.AddRenderer(renderer);
1391 actor.SetSize(400, 400);
1392 Stage::GetCurrent().Add(actor);
1393 application.SendNotification();
1394 application.Render(0);
1396 // Don't add property / uniform map to renderer
1397 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1398 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1400 TestGlAbstraction& gl = application.GetGlAbstraction();
1402 application.SendNotification();
1403 application.Render(0);
1405 // Expect that the actor's fade color property is accessed
1406 Vector4 actualValue(Vector4::ZERO);
1407 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1408 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1410 // Animate texture set's fade color property. Should be no change to uniform
1411 Animation animation = Animation::New(1.0f);
1412 KeyFrames keyFrames = KeyFrames::New();
1413 keyFrames.Add(0.0f, Color::WHITE);
1414 keyFrames.Add(1.0f, Color::TRANSPARENT);
1415 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1418 application.SendNotification();
1419 application.Render(500);
1421 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1422 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1424 application.Render(500);
1425 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1426 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1432 int UtcDaliRendererUniformMapPrecendence03(void)
1434 TestApplication application;
1436 tet_infoline("Test the uniform map precedence is applied properly");
1438 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1440 Shader shader = Shader::New("VertexSource", "FragmentSource");
1441 TextureSet textureSet = CreateTextureSet( image );
1443 Geometry geometry = CreateQuadGeometry();
1444 Renderer renderer = Renderer::New( geometry, shader );
1445 renderer.SetTextures( textureSet );
1447 Actor actor = Actor::New();
1448 actor.AddRenderer(renderer);
1449 actor.SetSize(400, 400);
1450 Stage::GetCurrent().Add(actor);
1451 application.SendNotification();
1452 application.Render(0);
1454 // Don't add property / uniform map to renderer or actor
1455 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1457 TestGlAbstraction& gl = application.GetGlAbstraction();
1459 application.SendNotification();
1460 application.Render(0);
1462 // Expect that the shader's fade color property is accessed
1463 Vector4 actualValue(Vector4::ZERO);
1464 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1465 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1470 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1472 TestApplication application;
1474 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1476 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1478 Shader shader = Shader::New("VertexSource", "FragmentSource");
1479 TextureSet textureSet = CreateTextureSet( image );
1481 Geometry geometry = CreateQuadGeometry();
1482 Renderer renderer = Renderer::New( geometry, shader );
1483 renderer.SetTextures( textureSet );
1485 Actor actor = Actor::New();
1486 actor.AddRenderer(renderer);
1487 actor.SetSize(400, 400);
1488 Stage::GetCurrent().Add(actor);
1489 application.SendNotification();
1490 application.Render(0);
1492 renderer.RegisterProperty( "uUniform1", Color::RED );
1493 actor.RegisterProperty( "uUniform2", Color::GREEN );
1494 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1496 TestGlAbstraction& gl = application.GetGlAbstraction();
1498 application.SendNotification();
1499 application.Render(0);
1501 // Expect that each of the object's uniforms are set
1502 Vector4 uniform1Value(Vector4::ZERO);
1503 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1504 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1506 Vector4 uniform2Value(Vector4::ZERO);
1507 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1508 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1510 Vector4 uniform3Value(Vector4::ZERO);
1511 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1512 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1517 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1519 TestApplication application;
1521 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1523 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1525 Shader shader = Shader::New("VertexSource", "FragmentSource");
1526 TextureSet textureSet = CreateTextureSet( image );
1528 Geometry geometry = CreateQuadGeometry();
1529 Renderer renderer = Renderer::New( geometry, shader );
1530 renderer.SetTextures( textureSet );
1532 Actor actor = Actor::New();
1533 actor.AddRenderer(renderer);
1534 actor.SetSize(400, 400);
1535 Stage::GetCurrent().Add(actor);
1536 application.SendNotification();
1537 application.Render(0);
1539 Property::Value value1(Color::RED);
1540 renderer.RegisterProperty( "uFadeColor", value1 );
1542 Property::Value value2(1.0f);
1543 actor.RegisterProperty( "uFadeProgress", value2 );
1545 Property::Value value3(Matrix3::IDENTITY);
1546 shader.RegisterProperty( "uANormalMatrix", value3 );
1548 TestGlAbstraction& gl = application.GetGlAbstraction();
1550 application.SendNotification();
1551 application.Render(0);
1553 // Expect that each of the object's uniforms are set
1554 Vector4 uniform1Value(Vector4::ZERO);
1555 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1556 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1558 float uniform2Value(0.0f);
1559 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1560 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1562 Matrix3 uniform3Value;
1563 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1564 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1570 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1572 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1573 TextureSet textureSet0 = CreateTextureSet( image0 );
1574 Renderer renderer0 = Renderer::New( geometry, shader );
1575 renderer0.SetTextures( textureSet0 );
1576 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1577 actor.AddRenderer(renderer0);
1582 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1584 Actor actor = Actor::New();
1585 actor.SetAnchorPoint(AnchorPoint::CENTER);
1586 actor.SetParentOrigin(AnchorPoint::CENTER);
1587 actor.SetPosition(0.0f,0.0f);
1588 actor.SetSize(100, 100);
1590 actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1591 DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1596 int UtcDaliRendererRenderOrder2DLayer(void)
1598 TestApplication application;
1599 tet_infoline("Test the rendering order in a 2D layer is correct");
1601 Shader shader = Shader::New("VertexSource", "FragmentSource");
1602 Geometry geometry = CreateQuadGeometry();
1604 Actor root = Stage::GetCurrent().GetRootLayer();
1606 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1607 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1609 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1610 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1612 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1613 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1615 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1616 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1618 application.SendNotification();
1619 application.Render(0);
1622 * Create the following hierarchy:
1635 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1640 application.SendNotification();
1641 application.Render(0);
1643 TestGlAbstraction& gl = application.GetGlAbstraction();
1644 gl.EnableTextureCallTrace(true);
1645 application.SendNotification();
1646 application.Render(0);
1648 int textureBindIndex[4];
1649 for( unsigned int i(0); i<4; ++i )
1651 std::stringstream params;
1652 params << GL_TEXTURE_2D<<", "<<i+1;
1653 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1656 //Check that actor1 has been rendered after actor2
1657 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1659 //Check that actor0 has been rendered after actor1
1660 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1662 //Check that actor3 has been rendered after actor0
1663 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1668 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1670 TestApplication application;
1671 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1674 * Creates the following hierarchy:
1676 * actor0------------------------>actor1
1680 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1682 * renderer0 has depth index 2
1683 * renderer1 has depth index 0
1684 * renderer2 has depth index 1
1686 * renderer3 has depth index 1
1687 * renderer4 has depth index 0
1688 * renderer5 has depth index -1
1690 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1693 Shader shader = Shader::New("VertexSource", "FragmentSource");
1694 Geometry geometry = CreateQuadGeometry();
1696 Actor root = Stage::GetCurrent().GetRootLayer();
1698 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1699 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1700 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1701 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1702 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1703 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1704 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1705 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1707 application.SendNotification();
1708 application.Render(0);
1710 TestGlAbstraction& gl = application.GetGlAbstraction();
1711 gl.EnableTextureCallTrace(true);
1712 application.SendNotification();
1713 application.Render(0);
1715 int textureBindIndex[6];
1716 for( unsigned int i(0); i<6; ++i )
1718 std::stringstream params;
1719 params << GL_TEXTURE_2D<<", "<<i+1;
1720 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1723 //Check that renderer3 has been rendered after renderer4
1724 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1726 //Check that renderer0 has been rendered after renderer2
1727 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1729 //Check that renderer5 has been rendered after renderer2
1730 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1732 //Check that renderer0 has been rendered after renderer2
1733 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1735 //Check that renderer2 has been rendered after renderer1
1736 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1742 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1744 TestApplication application;
1745 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1748 * Creates the following hierarchy:
1756 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1760 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1761 * DI:2 DI:0 | DI:0 DI:1 DI:2
1766 * actor0 has sibling order 1
1767 * actor1 has sibling order 0
1768 * actor2 has sibling order 0
1770 * renderer0 has depth index 2
1771 * renderer1 has depth index 0
1773 * renderer2 has depth index 0
1774 * renderer3 has depth index 1
1775 * renderer4 has depth index 2
1777 * renderer5 has depth index -1
1779 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1782 Shader shader = Shader::New("VertexSource", "FragmentSource");
1783 Geometry geometry = CreateQuadGeometry();
1784 Actor root = Stage::GetCurrent().GetRootLayer();
1785 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1786 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1787 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1789 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1790 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1791 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1792 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1793 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1794 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1796 application.SendNotification();
1797 application.Render();
1799 TestGlAbstraction& gl = application.GetGlAbstraction();
1800 gl.EnableTextureCallTrace(true);
1801 application.SendNotification();
1802 application.Render(0);
1804 int textureBindIndex[6];
1805 for( unsigned int i(0); i<6; ++i )
1807 std::stringstream params;
1808 params << GL_TEXTURE_2D<<", "<<i+1;
1809 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1812 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1813 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1814 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1815 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1816 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1817 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1819 // Change sibling order of actor1
1820 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1821 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1823 gl.GetTextureTrace().Reset();
1824 application.SendNotification();
1825 application.Render(0);
1827 for( unsigned int i(0); i<6; ++i )
1829 std::stringstream params;
1830 params << GL_TEXTURE_2D<<", "<<i+1;
1831 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1834 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1835 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1836 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1837 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1838 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1839 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1844 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1846 TestApplication application;
1847 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1849 Shader shader = Shader::New("VertexSource", "FragmentSource");
1850 Geometry geometry = CreateQuadGeometry();
1851 Actor root = Stage::GetCurrent().GetRootLayer();
1854 * Create the following hierarchy:
1861 * (Overlay) (Regular actor)
1871 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1874 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1875 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1876 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1878 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1879 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1880 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1882 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1883 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1885 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1886 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1887 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1889 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1890 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1892 application.SendNotification();
1893 application.Render(0);
1900 TestGlAbstraction& gl = application.GetGlAbstraction();
1901 gl.EnableTextureCallTrace(true);
1902 application.SendNotification();
1903 application.Render(0);
1905 int textureBindIndex[5];
1906 for( unsigned int i(0); i<5; ++i )
1908 std::stringstream params;
1909 params << GL_TEXTURE_2D<<", "<<i+1;
1910 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1913 //Check that actor4 has been rendered after actor2
1914 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1916 //Check that actor1 has been rendered after actor4
1917 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1919 //Check that actor0 has been rendered after actor1
1920 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1922 //Check that actor3 has been rendered after actor0
1923 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1928 int UtcDaliRendererSetIndexRange(void)
1932 "attribute vec2 aPosition;\n"
1935 " gl_Position = aPosition;\n"
1941 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1945 TestApplication application;
1946 tet_infoline("Test setting the range of indices to draw");
1948 TestGlAbstraction& gl = application.GetGlAbstraction();
1949 gl.EnableDrawCallTrace( true );
1951 Actor actor = Actor::New();
1952 actor.SetSize( 100, 100 );
1955 Geometry geometry = Geometry::New();
1956 geometry.SetType( Geometry::LINE_LOOP );
1958 // --------------------------------------------------------------------------
1960 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1961 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1962 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1964 // --------------------------------------------------------------------------
1973 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1974 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1975 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1976 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1977 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1979 Property::Map vertexFormat;
1980 vertexFormat["aPosition"] = Property::VECTOR2;
1981 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1982 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1984 // --------------------------------------------------------------------------
1985 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1986 geometry.AddVertexBuffer( vertexBuffer );
1989 Shader shader = Shader::New( vertexShader,fragmentShader );
1990 Renderer renderer = Renderer::New( geometry, shader );
1991 actor.AddRenderer( renderer );
1993 Stage stage = Stage::GetCurrent();
1998 // LINE_LOOP, first 0, count 5
2000 renderer.SetIndexRange( 0, 5 );
2001 application.SendNotification();
2002 application.Render();
2004 Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST );
2006 DALI_TEST_CHECK( value.Get( convertedValue ) );
2007 DALI_TEST_CHECK( convertedValue == 0 );
2009 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST );
2010 DALI_TEST_CHECK( value.Get( convertedValue ) );
2011 DALI_TEST_CHECK( convertedValue == 0 );
2013 value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT );
2014 DALI_TEST_CHECK( value.Get( convertedValue ) );
2015 DALI_TEST_CHECK( convertedValue == 5 );
2017 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT );
2018 DALI_TEST_CHECK( value.Get( convertedValue ) );
2019 DALI_TEST_CHECK( convertedValue == 5 );
2021 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2022 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2023 DALI_TEST_CHECK( result );
2026 // LINE_LOOP, first 5, count 10
2028 renderer.SetIndexRange( 5, 10 );
2029 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2030 application.SendNotification();
2031 application.Render();
2032 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2033 DALI_TEST_CHECK( result );
2036 // LINE_STRIP, first 15, count 6
2038 renderer.SetIndexRange( 15, 6 );
2039 geometry.SetType( Geometry::LINE_STRIP );
2040 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2041 application.SendNotification();
2042 application.Render();
2043 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2044 DALI_TEST_CHECK( result );
2047 // Index out of bounds
2049 renderer.SetIndexRange( 15, 30 );
2050 geometry.SetType( Geometry::LINE_STRIP );
2051 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2052 application.SendNotification();
2053 application.Render();
2054 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2055 DALI_TEST_CHECK( result );
2058 // drawing whole buffer starting from 15 ( last valid primitive )
2060 renderer.SetIndexRange( 15, 0 );
2061 geometry.SetType( Geometry::LINE_STRIP );
2062 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2063 application.SendNotification();
2064 application.Render();
2065 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2066 DALI_TEST_CHECK( result );
2073 int UtcDaliRendererSetDepthFunction(void)
2075 TestApplication application;
2077 tet_infoline("Test setting the depth function");
2079 Geometry geometry = CreateQuadGeometry();
2080 Shader shader = CreateShader();
2081 Renderer renderer = Renderer::New( geometry, shader );
2083 Actor actor = Actor::New();
2084 actor.AddRenderer(renderer);
2085 actor.SetSize(400, 400);
2086 Stage stage = Stage::GetCurrent();
2087 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2090 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2091 glAbstraction.EnableEnableDisableCallTrace(true);
2092 glAbstraction.EnableDepthFunctionCallTrace(true);
2094 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2095 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2097 std::ostringstream depthTestStr;
2098 depthTestStr << GL_DEPTH_TEST;
2102 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2104 glEnableDisableStack.Reset();
2105 glDepthFunctionStack.Reset();
2106 application.SendNotification();
2107 application.Render();
2109 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2110 std::ostringstream depthFunctionStr;
2111 depthFunctionStr << GL_NEVER;
2112 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2117 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2119 glDepthFunctionStack.Reset();
2120 application.SendNotification();
2121 application.Render();
2123 std::ostringstream depthFunctionStr;
2124 depthFunctionStr << GL_ALWAYS;
2125 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2130 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2132 glDepthFunctionStack.Reset();
2133 application.SendNotification();
2134 application.Render();
2136 std::ostringstream depthFunctionStr;
2137 depthFunctionStr << GL_LESS;
2138 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2143 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2145 glDepthFunctionStack.Reset();
2146 application.SendNotification();
2147 application.Render();
2149 std::ostringstream depthFunctionStr;
2150 depthFunctionStr << GL_GREATER;
2151 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2156 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2158 glDepthFunctionStack.Reset();
2159 application.SendNotification();
2160 application.Render();
2162 std::ostringstream depthFunctionStr;
2163 depthFunctionStr << GL_EQUAL;
2164 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2169 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2171 glDepthFunctionStack.Reset();
2172 application.SendNotification();
2173 application.Render();
2175 std::ostringstream depthFunctionStr;
2176 depthFunctionStr << GL_NOTEQUAL;
2177 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2182 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2184 glDepthFunctionStack.Reset();
2185 application.SendNotification();
2186 application.Render();
2188 std::ostringstream depthFunctionStr;
2189 depthFunctionStr << GL_LEQUAL;
2190 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2195 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2197 glDepthFunctionStack.Reset();
2198 application.SendNotification();
2199 application.Render();
2201 std::ostringstream depthFunctionStr;
2202 depthFunctionStr << GL_GEQUAL;
2203 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2210 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2211 * The checks performed are as follows:
2212 * - Check the initial/default value.
2213 * - Set a different value via enum.
2214 * - Check it was set.
2215 * - Set a different value via string.
2216 * - Check it was set.
2218 template< typename T >
2219 void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2221 application.SendNotification();
2222 application.Render();
2224 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2225 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2226 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2227 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2228 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( firstCheckEnumeration ) );
2230 application.SendNotification();
2231 application.Render();
2233 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2234 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2236 renderer.SetProperty( propertyIndex, secondCheckString );
2237 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2238 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( secondCheckEnumeration ) );
2240 application.SendNotification();
2241 application.Render();
2243 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2244 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2247 int UtcDaliRendererEnumProperties(void)
2249 TestApplication application;
2250 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2252 Geometry geometry = CreateQuadGeometry();
2253 Shader shader = CreateShader();
2254 Renderer renderer = Renderer::New( geometry, shader );
2256 Actor actor = Actor::New();
2257 actor.AddRenderer(renderer);
2258 actor.SetSize(400, 400);
2259 Stage::GetCurrent().Add(actor);
2262 * Here we use a templatized function to perform several checks on each enumeration property.
2263 * @see CheckEnumerationProperty for details of the checks performed.
2266 CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2267 CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2268 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2269 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2270 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2271 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2272 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2273 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2274 CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2275 CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2276 CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2277 CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2278 CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2279 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2280 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2281 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2286 Renderer RendererTestFixture( TestApplication& application )
2288 Geometry geometry = CreateQuadGeometry();
2289 Shader shader = CreateShader();
2290 Renderer renderer = Renderer::New( geometry, shader );
2292 Actor actor = Actor::New();
2293 actor.AddRenderer( renderer );
2294 actor.SetSize( 400.0f, 400.0f );
2295 Stage stage = Stage::GetCurrent();
2296 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2302 int UtcDaliRendererSetDepthTestMode(void)
2304 TestApplication application;
2305 tet_infoline("Test setting the DepthTestMode");
2307 Renderer renderer = RendererTestFixture( application );
2308 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2309 glAbstraction.EnableEnableDisableCallTrace( true );
2310 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2312 glEnableDisableStack.Reset();
2313 application.SendNotification();
2314 application.Render();
2316 // Check depth-test is enabled by default.
2317 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2318 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2320 // Turn off depth-testing. We want to check if the depth buffer has been disabled, so we need to turn off depth-write as well for this case.
2321 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2322 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2324 glEnableDisableStack.Reset();
2325 application.SendNotification();
2326 application.Render();
2328 // Check the depth buffer was disabled.
2329 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2331 // Turn on automatic mode depth-testing.
2332 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2333 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2335 glEnableDisableStack.Reset();
2336 application.SendNotification();
2337 application.Render();
2339 // Check depth-test is now enabled.
2340 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2341 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2343 // Change the layer behavior to LAYER_UI.
2344 // Note this will also disable depth testing for the layer by default, we test this first.
2345 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_UI );
2347 glEnableDisableStack.Reset();
2348 application.SendNotification();
2349 application.Render();
2351 // Check depth-test is disabled.
2352 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2354 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2355 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2357 glEnableDisableStack.Reset();
2358 application.SendNotification();
2359 application.Render();
2361 // Check depth-test is *still* disabled.
2362 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2367 int UtcDaliRendererSetDepthWriteMode(void)
2369 TestApplication application;
2370 tet_infoline("Test setting the DepthWriteMode");
2372 Renderer renderer = RendererTestFixture( application );
2373 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2375 application.SendNotification();
2376 application.Render();
2378 // Check the default depth-write status first.
2379 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2381 // Turn off depth-writing.
2382 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2384 application.SendNotification();
2385 application.Render();
2387 // Check depth-write is now disabled.
2388 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2390 // Test the AUTO mode for depth-writing.
2391 // As our renderer is opaque, depth-testing should be enabled.
2392 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2394 application.SendNotification();
2395 application.Render();
2397 // Check depth-write is now enabled.
2398 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2400 // Now make the renderer be treated as translucent by enabling blending.
2401 // The AUTO depth-write mode should turn depth-write off in this scenario.
2402 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2404 application.SendNotification();
2405 application.Render();
2407 // Check depth-write is now disabled.
2408 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2413 int UtcDaliRendererCheckStencilDefaults(void)
2415 TestApplication application;
2416 tet_infoline("Test the stencil defaults");
2418 Renderer renderer = RendererTestFixture( application );
2419 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2420 glAbstraction.EnableEnableDisableCallTrace( true );
2421 glAbstraction.EnableStencilFunctionCallTrace( true );
2422 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2423 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2425 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2427 // Check the defaults:
2428 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2429 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2430 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2431 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2432 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2433 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2434 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2439 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2441 TestApplication application;
2442 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2444 Renderer renderer = RendererTestFixture( application );
2445 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2446 glAbstraction.EnableEnableDisableCallTrace( true );
2447 glAbstraction.EnableStencilFunctionCallTrace( true );
2448 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2449 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2451 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2452 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2453 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2454 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2456 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2457 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2459 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2460 std::string methodString( "StencilFunc" );
2461 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2463 // Test the other RenderModes that will not enable the stencil buffer.
2464 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2465 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2466 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2468 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2469 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2470 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2472 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2473 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2474 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2476 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2477 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2479 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2480 // First set a mode to turn off the stencil buffer, so the enable is required.
2481 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2482 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2483 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2484 // Set a different stencil function as the last one is cached.
2485 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS );
2486 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2488 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2489 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2494 // Helper function for the SetRenderModeToUseColorBuffer test.
2495 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2497 // Set the RenderMode property to a value that should not allow color buffer writes.
2498 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2499 application.SendNotification();
2500 application.Render();
2502 // Check if ColorMask has been called, and that the values are correct.
2503 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2504 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2506 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2507 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2508 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2509 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2512 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2514 TestApplication application;
2515 tet_infoline("Test setting the RenderMode to use the color buffer");
2517 Renderer renderer = RendererTestFixture( application );
2519 // Set the RenderMode property to a value that should not allow color buffer writes.
2520 // Then check if ColorMask has been called, and that the values are correct.
2521 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2522 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2523 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2524 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2525 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2530 int UtcDaliRendererSetStencilFunction(void)
2532 TestApplication application;
2533 tet_infoline("Test setting the StencilFunction");
2535 Renderer renderer = RendererTestFixture( application );
2536 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2537 glAbstraction.EnableEnableDisableCallTrace( true );
2538 glAbstraction.EnableStencilFunctionCallTrace( true );
2539 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2540 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2542 // RenderMode must use the stencil for StencilFunction to operate.
2543 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2544 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2547 * Lookup table for testing StencilFunction.
2548 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2550 const int StencilFunctionLookupTable[] = {
2559 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2562 * Loop through all types of StencilFunction, checking:
2563 * - The value is cached (set in event thread side)
2564 * - Causes "glStencilFunc" to be called
2565 * - Checks the correct parameters to "glStencilFunc" were used
2567 std::string nonChangingParameters = "0, 255";
2568 std::string methodString( "StencilFunc" );
2569 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2571 // Set the property.
2572 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2574 // Check GetProperty returns the same value.
2575 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2577 // Reset the trace debug.
2578 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2580 // Check the function is called and the parameters are correct.
2581 std::stringstream parameterStream;
2582 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2584 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2587 // Change the Function Reference only and check the behavior is correct:
2588 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2589 int testValueReference = 170;
2590 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2592 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2594 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2596 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2598 std::stringstream parameterStream;
2599 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2601 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2604 // Change the Function Mask only and check the behavior is correct:
2605 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2606 int testValueMask = 85;
2607 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2609 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2611 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2613 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2615 // Clear the stringstream.
2616 parameterStream.str( std::string() );
2617 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2619 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2624 int UtcDaliRendererSetStencilOperation(void)
2626 TestApplication application;
2627 tet_infoline("Test setting the StencilOperation");
2629 Renderer renderer = RendererTestFixture( application );
2630 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2631 glAbstraction.EnableEnableDisableCallTrace( true );
2632 glAbstraction.EnableStencilFunctionCallTrace( true );
2633 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2634 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2636 // RenderMode must use the stencil for StencilOperation to operate.
2637 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2640 * Lookup table for testing StencilOperation.
2641 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2643 const int StencilOperationLookupTable[] = {
2652 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2654 // Set all 3 StencilOperation properties to a default.
2655 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP );
2656 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2657 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2659 // Set our expected parameter list to the equivalent result.
2660 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2662 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2665 * Loop through all types of StencilOperation, checking:
2666 * - The value is cached (set in event thread side)
2667 * - Causes "glStencilFunc" to be called
2668 * - Checks the correct parameters to "glStencilFunc" were used
2669 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2671 std::string methodString( "StencilOp" );
2673 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2675 for( int j = 0; j < StencilOperationLookupTableCount; ++j )
2677 for( int k = 0; k < StencilOperationLookupTableCount; ++k )
2679 // Set the property (outer loop causes all 3 different properties to be set separately).
2680 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>( i ) );
2681 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>( j ) );
2682 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>( k ) );
2684 // Check GetProperty returns the same value.
2685 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), i, TEST_LOCATION );
2686 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), j, TEST_LOCATION );
2687 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), k, TEST_LOCATION );
2689 // Reset the trace debug.
2690 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2692 // Check the function is called and the parameters are correct.
2693 // Set the expected parameter value at its correct index (only)
2694 parameters[ 0u ] = StencilOperationLookupTable[ i ];
2695 parameters[ 1u ] = StencilOperationLookupTable[ j ];
2696 parameters[ 2u ] = StencilOperationLookupTable[ k ];
2698 // Build the parameter list.
2699 std::stringstream parameterStream;
2700 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2702 parameterStream << parameters[ parameterBuild ];
2703 // Comma-separate the parameters.
2704 if( parameterBuild < 2 )
2706 parameterStream << ", ";
2710 // Check the function was called and the parameters were correct.
2711 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2719 int UtcDaliRendererSetStencilMask(void)
2721 TestApplication application;
2722 tet_infoline("Test setting the StencilMask");
2724 Renderer renderer = RendererTestFixture( application );
2725 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2726 glAbstraction.EnableEnableDisableCallTrace( true );
2727 glAbstraction.EnableStencilFunctionCallTrace( true );
2728 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2729 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2731 // RenderMode must use the stencil for StencilMask to operate.
2732 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2734 // Set the StencilMask property to a value.
2735 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2737 // Check GetProperty returns the same value.
2738 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2740 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2742 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2744 std::string methodString( "StencilMask" );
2745 std::string parameterString = "0";
2747 // Check the function was called and the parameters were correct.
2748 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2750 // Set the StencilMask property to another value to ensure it has changed.
2751 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2753 // Check GetProperty returns the same value.
2754 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2756 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2758 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2760 parameterString = "255";
2762 // Check the function was called and the parameters were correct.
2763 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2768 int UtcDaliRendererWrongNumberOfTextures(void)
2770 TestApplication application;
2771 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2773 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2774 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2775 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2776 TextureSet textureSet = CreateTextureSet();
2777 textureSet.SetTexture(0, texture );
2778 textureSet.SetTexture(1, texture );
2779 textureSet.SetTexture(2, texture );
2780 textureSet.SetTexture(3, texture );
2781 Shader shader = Shader::New("VertexSource", "FragmentSource");
2782 Geometry geometry = CreateQuadGeometry();
2783 Renderer renderer = Renderer::New( geometry, shader );
2784 renderer.SetTextures( textureSet );
2786 Actor actor= Actor::New();
2787 actor.AddRenderer(renderer);
2788 actor.SetPosition(0.0f,0.0f);
2789 actor.SetSize(100, 100);
2790 Stage::GetCurrent().Add(actor);
2792 TestGlAbstraction& gl = application.GetGlAbstraction();
2793 TraceCallStack& drawTrace = gl.GetDrawTrace();
2795 drawTrace.Enable(true);
2797 application.SendNotification();
2798 application.Render(0);
2800 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2801 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2803 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2804 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2805 textureSet = CreateTextureSet();
2806 renderer.SetTextures( textureSet );
2807 textureSet.SetTexture(0, texture );
2809 application.SendNotification();
2810 application.Render(0);
2812 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2813 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2818 int UtcDaliRendererOpacity(void)
2820 TestApplication application;
2822 tet_infoline( "Test OPACITY property" );
2824 Geometry geometry = CreateQuadGeometry();
2825 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2826 Renderer renderer = Renderer::New( geometry, shader );
2828 Actor actor = Actor::New();
2829 actor.AddRenderer( renderer );
2830 actor.SetSize( 400, 400 );
2831 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2832 Stage::GetCurrent().Add( actor );
2834 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2836 DALI_TEST_CHECK( value.Get( opacity ) );
2837 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2839 application.SendNotification();
2840 application.Render();
2842 Vector4 actualValue;
2843 TestGlAbstraction& gl = application.GetGlAbstraction();
2844 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2845 DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2847 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f );
2849 application.SendNotification();
2850 application.Render();
2852 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2853 DALI_TEST_CHECK( value.Get( opacity ) );
2854 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2856 value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY );
2857 DALI_TEST_CHECK( value.Get( opacity ) );
2858 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2860 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2861 DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2866 int UtcDaliRendererOpacityAnimation(void)
2868 TestApplication application;
2870 tet_infoline( "Test OPACITY property animation" );
2872 Geometry geometry = CreateQuadGeometry();
2873 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2874 Renderer renderer = Renderer::New( geometry, shader );
2876 Actor actor = Actor::New();
2877 actor.AddRenderer( renderer );
2878 actor.SetSize( 400, 400 );
2879 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2880 Stage::GetCurrent().Add( actor );
2882 application.SendNotification();
2883 application.Render(0);
2885 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2887 DALI_TEST_CHECK( value.Get( opacity ) );
2888 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2890 Animation animation = Animation::New( 1.0f );
2891 animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f );
2894 application.SendNotification();
2895 application.Render( 1000 );
2897 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2898 DALI_TEST_CHECK( value.Get( opacity ) );
2899 DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2901 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.1f );
2904 animation.AnimateBy( Property( renderer, DevelRenderer::Property::OPACITY ), 0.5f );
2907 application.SendNotification();
2908 application.Render( 1000 );
2910 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2911 DALI_TEST_CHECK( value.Get( opacity ) );
2912 DALI_TEST_EQUALS( opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2917 int UtcDaliRendererInvalidProperty(void)
2919 TestApplication application;
2921 tet_infoline( "Test invalid property" );
2923 Geometry geometry = CreateQuadGeometry();
2924 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2925 Renderer renderer = Renderer::New( geometry, shader );
2927 Actor actor = Actor::New();
2928 actor.AddRenderer( renderer );
2929 actor.SetSize( 400, 400 );
2930 Stage::GetCurrent().Add( actor );
2932 application.SendNotification();
2933 application.Render(0);
2935 Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 );
2936 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2938 value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 );
2939 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2944 int UtcDaliRendererRenderingBehavior(void)
2946 TestApplication application;
2948 tet_infoline( "Test RENDERING_BEHAVIOR property" );
2950 Geometry geometry = CreateQuadGeometry();
2951 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2952 Renderer renderer = Renderer::New( geometry, shader );
2954 Actor actor = Actor::New();
2955 actor.AddRenderer( renderer );
2956 actor.SetSize( 400, 400 );
2957 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2958 Stage::GetCurrent().Add( actor );
2960 Property::Value value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2961 int renderingBehavior;
2962 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2963 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION );
2965 application.SendNotification();
2966 application.Render();
2968 uint32_t updateStatus = application.GetUpdateStatus();
2970 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
2972 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY );
2974 value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2975 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2976 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2978 // Render and check the update status
2979 application.SendNotification();
2980 application.Render();
2982 updateStatus = application.GetUpdateStatus();
2984 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2986 value = renderer.GetCurrentProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2987 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2988 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2990 // Render again and check the update status
2991 application.SendNotification();
2992 application.Render();
2994 updateStatus = application.GetUpdateStatus();
2996 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2998 // Change rendering behavior
2999 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
3001 // Render and check the update status
3002 application.SendNotification();
3003 application.Render();
3005 updateStatus = application.GetUpdateStatus();
3007 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
3009 // For test coverage
3010 Dali::Integration::Core& core( application.GetCore() );
3011 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
3013 Dali::RenderTaskList additionalRenderTaskList = Integration::RenderTaskList::New();
3014 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
3015 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
3017 // Render and check the update status
3018 application.SendNotification();
3019 application.Render();