2 * Copyright (c) 2019 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/render-task-list-integ.h>
29 #include <dali-test-suite-utils.h>
30 #include <test-trace-call-stack.h>
31 #include <mesh-builder.h>
35 namespace // unnamed namespace
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
41 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
44 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
47 * @brief Get GL stencil test enumeration value as a string.
48 * @return The string representation of the value of GL_STENCIL_TEST
50 std::string GetStencilTestString(void)
52 std::stringstream stream;
53 stream << GL_STENCIL_TEST;
58 * @brief Get GL depth test enumeration value as a string.
59 * @return The string representation of the value of GL_DEPTH_TEST
61 std::string GetDepthTestString(void)
63 std::stringstream stream;
64 stream << GL_DEPTH_TEST;
68 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
70 glEnableDisableStack.Reset();
71 glStencilFunctionStack.Reset();
72 application.SendNotification();
76 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
81 } // unnamed namespace
83 void renderer_test_startup(void)
85 test_return_value = TET_UNDEF;
88 void renderer_test_cleanup(void)
90 test_return_value = TET_PASS;
93 int UtcDaliRendererNew01(void)
95 TestApplication application;
97 Geometry geometry = CreateQuadGeometry();
98 Shader shader = CreateShader();
99 Renderer renderer = Renderer::New(geometry, shader);
101 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
105 int UtcDaliRendererNew02(void)
107 TestApplication application;
109 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
113 int UtcDaliRendererCopyConstructor(void)
115 TestApplication application;
117 Geometry geometry = CreateQuadGeometry();
118 Shader shader = CreateShader();
119 Renderer renderer = Renderer::New(geometry, shader);
121 Renderer rendererCopy( renderer );
122 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
127 int UtcDaliRendererAssignmentOperator(void)
129 TestApplication application;
131 Geometry geometry = CreateQuadGeometry();
132 Shader shader = CreateShader();
133 Renderer renderer = Renderer::New(geometry, shader);
136 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
138 renderer2 = renderer;
139 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
143 int UtcDaliRendererDownCast01(void)
145 TestApplication application;
147 Geometry geometry = CreateQuadGeometry();
148 Shader shader = CreateShader();
149 Renderer renderer = Renderer::New(geometry, shader);
151 BaseHandle handle(renderer);
152 Renderer renderer2 = Renderer::DownCast(handle);
153 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
157 int UtcDaliRendererDownCast02(void)
159 TestApplication application;
161 Handle handle = Handle::New(); // Create a custom object
162 Renderer renderer = Renderer::DownCast(handle);
163 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
167 // using a template to auto deduce the parameter types
168 template< typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
169 void TEST_RENDERER_PROPERTY( P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION )
171 DALI_TEST_EQUALS( renderer.GetPropertyName( enumName ), stringName, LOCATION );
172 DALI_TEST_EQUALS( renderer.GetPropertyIndex( stringName ), static_cast<Property::Index>(enumName), LOCATION );
173 DALI_TEST_EQUALS( renderer.GetPropertyType( enumName ), type, LOCATION );
174 DALI_TEST_EQUALS( renderer.IsPropertyWritable( enumName ), isWriteable, LOCATION );
175 DALI_TEST_EQUALS( renderer.IsPropertyAnimatable( enumName ), isAnimateable, LOCATION );
176 DALI_TEST_EQUALS( renderer.IsPropertyAConstraintInput( enumName ), isConstraintInput, LOCATION );
179 int UtcDaliRendererDefaultProperties(void)
181 TestApplication application;
182 /* from renderer-impl.cpp
183 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
184 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
185 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
186 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
187 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
188 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
189 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
190 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
191 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
192 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
193 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
194 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
195 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
196 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
197 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
198 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
199 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
200 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
201 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
202 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
203 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
204 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
205 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
206 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
207 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
208 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
211 Geometry geometry = CreateQuadGeometry();
212 Shader shader = CreateShader();
213 Renderer renderer = Renderer::New(geometry, shader);
214 DALI_TEST_EQUALS( renderer.GetPropertyCount(), 26, TEST_LOCATION );
216 TEST_RENDERER_PROPERTY( renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION );
217 TEST_RENDERER_PROPERTY( renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION );
218 TEST_RENDERER_PROPERTY( renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION );
219 TEST_RENDERER_PROPERTY( renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION );
220 TEST_RENDERER_PROPERTY( renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION );
221 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION );
222 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION );
223 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION );
224 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION );
225 TEST_RENDERER_PROPERTY( renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION );
226 TEST_RENDERER_PROPERTY( renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION );
227 TEST_RENDERER_PROPERTY( renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION );
228 TEST_RENDERER_PROPERTY( renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION );
229 TEST_RENDERER_PROPERTY( renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION );
230 TEST_RENDERER_PROPERTY( renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION );
231 TEST_RENDERER_PROPERTY( renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION );
232 TEST_RENDERER_PROPERTY( renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION );
233 TEST_RENDERER_PROPERTY( renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION );
234 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION );
235 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionReference",Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION );
236 TEST_RENDERER_PROPERTY( renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION );
237 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION );
238 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION );
239 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION );
240 TEST_RENDERER_PROPERTY( renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION );
241 TEST_RENDERER_PROPERTY( renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION );
246 int UtcDaliRendererSetGetGeometry(void)
248 TestApplication application;
249 tet_infoline( "Test SetGeometry, GetGeometry" );
251 Geometry geometry1 = CreateQuadGeometry();
252 Geometry geometry2 = CreateQuadGeometry();
254 Shader shader = CreateShader();
255 Renderer renderer = Renderer::New(geometry1, shader);
256 Actor actor = Actor::New();
257 actor.AddRenderer(renderer);
258 actor.SetSize(400, 400);
259 Stage::GetCurrent().Add(actor);
261 application.SendNotification();
262 application.Render(0);
263 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
265 // Set geometry2 to the renderer
266 renderer.SetGeometry( geometry2 );
268 application.SendNotification();
269 application.Render(0);
270 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
275 int UtcDaliRendererSetGetShader(void)
277 TestApplication application;
278 tet_infoline( "Test SetShader, GetShader" );
280 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
281 glAbstraction.EnableCullFaceCallTrace(true);
283 Shader shader1 = CreateShader();
284 shader1.RegisterProperty( "uFadeColor", Color::RED );
286 Shader shader2 = CreateShader();
287 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
289 Geometry geometry = CreateQuadGeometry();
290 Renderer renderer = Renderer::New(geometry, shader1);
291 Actor actor = Actor::New();
292 actor.AddRenderer(renderer);
293 actor.SetSize(400, 400);
294 Stage::GetCurrent().Add(actor);
296 TestGlAbstraction& gl = application.GetGlAbstraction();
297 application.SendNotification();
298 application.Render(0);
300 // Expect that the first shaders's fade color property is accessed
301 Vector4 actualValue(Vector4::ZERO);
302 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
303 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
305 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
307 // set the second shader to the renderer
308 renderer.SetShader( shader2 );
310 application.SendNotification();
311 application.Render(0);
313 // Expect that the second shader's fade color property is accessed
314 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
315 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
317 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
322 int UtcDaliRendererSetGetDepthIndex(void)
324 TestApplication application;
326 tet_infoline("Test SetDepthIndex, GetDepthIndex");
328 Shader shader = CreateShader();
329 Geometry geometry = CreateQuadGeometry();
330 Renderer renderer = Renderer::New(geometry, shader);
331 Actor actor = Actor::New();
332 actor.AddRenderer(renderer);
333 actor.SetSize(400, 400);
334 Stage::GetCurrent().Add(actor);
336 application.SendNotification();
337 application.Render(0);
338 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
340 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
342 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
343 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
345 application.SendNotification();
346 application.Render(0);
347 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
349 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
351 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
352 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
354 application.SendNotification();
355 application.Render(0);
356 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
361 int UtcDaliRendererSetGetFaceCullingMode(void)
363 TestApplication application;
365 tet_infoline("Test SetFaceCullingMode(cullingMode)");
366 Geometry geometry = CreateQuadGeometry();
367 Shader shader = CreateShader();
368 Renderer renderer = Renderer::New( geometry, shader );
370 Actor actor = Actor::New();
371 actor.AddRenderer(renderer);
372 actor.SetSize(400, 400);
373 Stage::GetCurrent().Add(actor);
375 // By default, none of the faces should be culled
376 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
377 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
379 TestGlAbstraction& gl = application.GetGlAbstraction();
380 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
381 gl.EnableCullFaceCallTrace(true);
384 cullFaceStack.Reset();
385 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
386 application.SendNotification();
387 application.Render();
389 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
391 std::ostringstream cullModeString;
392 cullModeString << GL_FRONT_AND_BACK;
394 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
395 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
396 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
400 cullFaceStack.Reset();
401 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
402 application.SendNotification();
403 application.Render();
405 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
407 std::ostringstream cullModeString;
408 cullModeString << GL_BACK;
410 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
411 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
412 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
416 cullFaceStack.Reset();
417 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
418 application.SendNotification();
419 application.Render();
421 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
423 std::ostringstream cullModeString;
424 cullModeString << GL_FRONT;
426 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
427 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
428 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
432 cullFaceStack.Reset();
433 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
434 application.SendNotification();
435 application.Render();
437 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
438 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
439 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
445 int UtcDaliRendererBlendOptions01(void)
447 TestApplication application;
449 tet_infoline("Test BLEND_FACTOR properties ");
451 Geometry geometry = CreateQuadGeometry();
452 Shader shader = CreateShader();
453 Renderer renderer = Renderer::New( geometry, shader );
455 Actor actor = Actor::New();
456 // set a transparent actor color so that blending is enabled
457 actor.SetOpacity( 0.5f );
458 actor.AddRenderer(renderer);
459 actor.SetSize(400, 400);
460 Stage::GetCurrent().Add(actor);
462 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
463 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
464 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
465 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
467 // Test that Set was successful:
468 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
469 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
470 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
471 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
473 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
474 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
475 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
476 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
478 application.SendNotification();
479 application.Render();
481 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
483 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
484 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
485 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
486 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
491 int UtcDaliRendererBlendOptions02(void)
493 TestApplication application;
495 tet_infoline("Test BLEND_FACTOR properties ");
497 Geometry geometry = CreateQuadGeometry();
498 Shader shader = CreateShader();
499 Renderer renderer = Renderer::New( geometry, shader );
501 Actor actor = Actor::New();
502 actor.SetOpacity( 0.5f ); // enable blending
503 actor.AddRenderer(renderer);
504 actor.SetSize(400, 400);
505 Stage::GetCurrent().Add(actor);
507 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
508 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
509 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
510 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
512 // Test that Set was successful:
514 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
515 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
516 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
517 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
519 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
520 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
521 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
522 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
525 application.SendNotification();
526 application.Render();
528 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
529 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
530 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
531 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
532 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
537 int UtcDaliRendererBlendOptions03(void)
539 TestApplication application;
541 tet_infoline("Test GetBlendEquation() defaults ");
543 Geometry geometry = CreateQuadGeometry();
544 Shader shader = CreateShader();
545 Renderer renderer = Renderer::New( geometry, shader );
547 Actor actor = Actor::New();
548 actor.AddRenderer(renderer);
549 actor.SetSize(400, 400);
550 Stage::GetCurrent().Add(actor);
552 // Test the defaults as documented in blending.h
553 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
554 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
556 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
557 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
562 int UtcDaliRendererBlendOptions04(void)
564 TestApplication application;
566 tet_infoline("Test SetBlendEquation() ");
568 Geometry geometry = CreateQuadGeometry();
569 Shader shader = CreateShader();
570 Renderer renderer = Renderer::New( geometry, shader );
572 Actor actor = Actor::New();
573 actor.SetOpacity( 0.1f );
574 actor.AddRenderer(renderer);
575 actor.SetSize(400, 400);
576 Stage::GetCurrent().Add(actor);
578 // Test the single blending equation setting
580 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
581 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
582 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
585 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
586 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
588 // Test that Set was successful
590 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
591 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
592 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
593 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
596 // Render & check GL commands
597 application.SendNotification();
598 application.Render();
600 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
601 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
602 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
607 int UtcDaliRendererSetBlendMode01(void)
609 TestApplication application;
611 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
613 Geometry geometry = CreateQuadGeometry();
614 Shader shader = CreateShader();
615 Renderer renderer = Renderer::New( geometry, shader );
617 Actor actor = Actor::New();
618 actor.SetOpacity( 0.98f );
619 actor.AddRenderer(renderer);
620 actor.SetSize(400, 400);
621 Stage::GetCurrent().Add(actor);
623 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
625 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
626 glAbstraction.EnableEnableDisableCallTrace(true);
628 application.SendNotification();
629 application.Render();
631 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
632 std::ostringstream blendStr;
633 blendStr << GL_BLEND;
634 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
639 int UtcDaliRendererSetBlendMode01b(void)
641 TestApplication application;
643 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
645 Geometry geometry = CreateQuadGeometry();
646 Shader shader = CreateShader();
647 Renderer renderer = Renderer::New( geometry, shader );
649 Actor actor = Actor::New();
650 actor.SetOpacity( 0.0f );
651 actor.AddRenderer(renderer);
652 actor.SetSize(400, 400);
653 Stage::GetCurrent().Add(actor);
655 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
657 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
658 glAbstraction.EnableEnableDisableCallTrace(true);
659 glAbstraction.EnableDrawCallTrace( true );
661 application.SendNotification();
662 application.Render();
664 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
665 std::ostringstream blendStr;
666 blendStr << GL_BLEND;
667 DALI_TEST_CHECK( !glEnableStack.FindMethod( "Enable" ) );
669 DALI_TEST_CHECK( !glAbstraction.GetDrawTrace().FindMethod( "DrawElements" ) );
674 int UtcDaliRendererSetBlendMode02(void)
676 TestApplication application;
678 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
680 Geometry geometry = CreateQuadGeometry();
681 Shader shader = CreateShader();
682 Renderer renderer = Renderer::New( geometry, shader );
684 Actor actor = Actor::New();
685 actor.SetOpacity( 0.15f );
686 actor.AddRenderer(renderer);
687 actor.SetSize(400, 400);
688 Stage::GetCurrent().Add(actor);
690 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
692 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
693 glAbstraction.EnableEnableDisableCallTrace(true);
695 application.SendNotification();
696 application.Render();
698 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
699 std::ostringstream blendStr;
700 blendStr << GL_BLEND;
701 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
706 int UtcDaliRendererSetBlendMode03(void)
708 TestApplication application;
710 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
712 Geometry geometry = CreateQuadGeometry();
713 Shader shader = CreateShader();
714 Renderer renderer = Renderer::New( geometry, shader );
716 Actor actor = Actor::New();
717 actor.SetOpacity( 0.75f );
718 actor.AddRenderer(renderer);
719 actor.SetSize(400, 400);
720 Stage::GetCurrent().Add(actor);
722 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
724 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
725 glAbstraction.EnableEnableDisableCallTrace(true);
727 application.SendNotification();
728 application.Render();
730 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
731 std::ostringstream blendStr;
732 blendStr << GL_BLEND;
733 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
738 int UtcDaliRendererSetBlendMode04(void)
740 TestApplication application;
742 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
744 Geometry geometry = CreateQuadGeometry();
745 Shader shader = CreateShader();
746 Renderer renderer = Renderer::New( geometry, shader );
748 Actor actor = Actor::New();
749 actor.AddRenderer(renderer);
750 actor.SetSize(400, 400);
751 Stage::GetCurrent().Add(actor);
753 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
755 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
756 glAbstraction.EnableEnableDisableCallTrace(true);
758 application.SendNotification();
759 application.Render();
761 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
762 std::ostringstream blendStr;
763 blendStr << GL_BLEND;
764 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
769 int UtcDaliRendererSetBlendMode04b(void)
771 TestApplication application;
773 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
775 Geometry geometry = CreateQuadGeometry();
776 Shader shader = CreateShader();
777 Renderer renderer = Renderer::New( geometry, shader );
779 Actor actor = Actor::New();
780 actor.AddRenderer(renderer);
781 actor.SetSize(400, 400);
782 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
783 Stage::GetCurrent().Add(actor);
785 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
787 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
788 glAbstraction.EnableEnableDisableCallTrace(true);
790 application.SendNotification();
791 application.Render();
793 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
794 std::ostringstream blendStr;
795 blendStr << GL_BLEND;
796 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
801 int UtcDaliRendererSetBlendMode04c(void)
803 TestApplication application;
805 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
807 Geometry geometry = CreateQuadGeometry();
808 Shader shader = CreateShader();
809 Renderer renderer = Renderer::New( geometry, shader );
811 Actor actor = Actor::New();
812 actor.AddRenderer(renderer);
813 actor.SetSize(400, 400);
814 actor.SetColor( Color::MAGENTA );
815 Stage::GetCurrent().Add(actor);
817 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
819 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
820 glAbstraction.EnableEnableDisableCallTrace(true);
822 application.SendNotification();
823 application.Render();
825 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
826 std::ostringstream blendStr;
827 blendStr << GL_BLEND;
828 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
833 int UtcDaliRendererSetBlendMode05(void)
835 TestApplication application;
837 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
839 Geometry geometry = CreateQuadGeometry();
840 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
842 Shader shader = CreateShader();
843 TextureSet textureSet = CreateTextureSet( image );
844 Renderer renderer = Renderer::New( geometry, shader );
845 renderer.SetTextures( textureSet );
847 Actor actor = Actor::New();
848 actor.AddRenderer(renderer);
849 actor.SetSize(400, 400);
850 Stage::GetCurrent().Add(actor);
852 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
854 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
855 glAbstraction.EnableEnableDisableCallTrace(true);
857 application.SendNotification();
858 application.Render();
860 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
861 std::ostringstream blendStr;
862 blendStr << GL_BLEND;
863 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
868 int UtcDaliRendererSetBlendMode06(void)
870 TestApplication application;
871 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");
873 Geometry geometry = CreateQuadGeometry();
874 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
876 Renderer renderer = Renderer::New( geometry, shader );
878 Actor actor = Actor::New();
879 actor.AddRenderer(renderer);
880 actor.SetSize(400, 400);
881 Stage::GetCurrent().Add(actor);
883 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
885 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
886 glAbstraction.EnableEnableDisableCallTrace(true);
888 application.SendNotification();
889 application.Render();
891 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
892 std::ostringstream blendStr;
893 blendStr << GL_BLEND;
894 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
899 int UtcDaliRendererSetBlendMode07(void)
901 TestApplication application;
902 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");
904 Geometry geometry = CreateQuadGeometry();
905 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
907 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
908 TextureSet textureSet = CreateTextureSet( image );
909 Renderer renderer = Renderer::New( geometry, shader );
910 renderer.SetTextures( textureSet );
912 Actor actor = Actor::New();
913 actor.AddRenderer(renderer);
914 actor.SetSize(400, 400);
915 Stage::GetCurrent().Add(actor);
917 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
919 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
920 glAbstraction.EnableEnableDisableCallTrace(true);
922 application.SendNotification();
923 application.Render();
925 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
926 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
931 int UtcDaliRendererGetBlendMode(void)
933 TestApplication application;
935 tet_infoline("Test GetBlendMode()");
937 Geometry geometry = CreateQuadGeometry();
938 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
939 Renderer renderer = Renderer::New( geometry, shader );
942 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
943 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
946 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
947 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
948 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
951 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
952 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
953 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
958 int UtcDaliRendererSetBlendColor(void)
960 TestApplication application;
962 tet_infoline("Test SetBlendColor(color)");
964 Geometry geometry = CreateQuadGeometry();
965 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
966 TextureSet textureSet = TextureSet::New();
967 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
968 TextureSetImage( textureSet, 0u, image );
969 Renderer renderer = Renderer::New( geometry, shader );
970 renderer.SetTextures( textureSet );
972 Actor actor = Actor::New();
973 actor.AddRenderer(renderer);
974 actor.SetSize(400, 400);
975 Stage::GetCurrent().Add(actor);
977 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
979 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
981 application.SendNotification();
982 application.Render();
984 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
985 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
986 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
988 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
990 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
991 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
993 application.SendNotification();
994 application.Render();
996 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
997 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
999 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1000 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1001 application.SendNotification();
1002 application.Render();
1003 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
1008 int UtcDaliRendererGetBlendColor(void)
1010 TestApplication application;
1012 tet_infoline("Test GetBlendColor()");
1014 Geometry geometry = CreateQuadGeometry();
1015 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1016 Renderer renderer = Renderer::New( geometry, shader );
1018 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
1020 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
1021 application.SendNotification();
1022 application.Render();
1023 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
1025 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1026 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1027 application.SendNotification();
1028 application.Render();
1029 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
1034 int UtcDaliRendererPreMultipledAlpha(void)
1036 TestApplication application;
1038 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1040 Geometry geometry = CreateQuadGeometry();
1041 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1042 Renderer renderer = Renderer::New( geometry, shader );
1044 Actor actor = Actor::New();
1045 actor.AddRenderer(renderer);
1046 actor.SetSize(400, 400);
1047 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
1048 Stage::GetCurrent().Add(actor);
1050 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1051 bool preMultipliedAlpha;
1052 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1053 DALI_TEST_CHECK( !preMultipliedAlpha );
1055 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1056 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1057 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1058 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1060 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
1061 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
1062 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
1063 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
1065 application.SendNotification();
1066 application.Render();
1068 Vector4 actualValue(Vector4::ZERO);
1069 TestGlAbstraction& gl = application.GetGlAbstraction();
1070 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1071 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
1073 // Enable pre-multiplied alpha
1074 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1076 application.SendNotification();
1077 application.Render();
1079 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1080 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1081 DALI_TEST_CHECK( preMultipliedAlpha );
1083 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1084 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1085 DALI_TEST_CHECK( preMultipliedAlpha );
1087 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1088 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1089 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1090 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1092 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
1093 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1094 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1095 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1097 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1098 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
1100 // Disable pre-multiplied alpha again
1101 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false );
1103 application.SendNotification();
1104 application.Render();
1106 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1107 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1108 DALI_TEST_CHECK( !preMultipliedAlpha );
1110 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1111 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1112 DALI_TEST_CHECK( !preMultipliedAlpha );
1114 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1115 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1116 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1117 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1119 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1120 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1121 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1122 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1124 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1125 DALI_TEST_EQUALS( actualValue, Vector4( 1.0f, 0.0f, 1.0f, 0.5f ), TEST_LOCATION );
1130 int UtcDaliRendererConstraint01(void)
1132 TestApplication application;
1134 tet_infoline("Test that a non-uniform renderer property can be constrained");
1136 Shader shader = Shader::New("VertexSource", "FragmentSource");
1137 Geometry geometry = CreateQuadGeometry();
1138 Renderer renderer = Renderer::New( geometry, shader );
1140 Actor actor = Actor::New();
1141 actor.AddRenderer(renderer);
1142 actor.SetSize(400, 400);
1143 Stage::GetCurrent().Add(actor);
1145 Vector4 initialColor = Color::WHITE;
1146 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1148 application.SendNotification();
1149 application.Render(0);
1150 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1153 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1155 application.SendNotification();
1156 application.Render(0);
1158 // Expect no blue component in either buffer - yellow
1159 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1160 application.Render(0);
1161 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1163 renderer.RemoveConstraints();
1164 renderer.SetProperty(colorIndex, Color::WHITE );
1165 application.SendNotification();
1166 application.Render(0);
1167 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1172 int UtcDaliRendererConstraint02(void)
1174 TestApplication application;
1176 tet_infoline("Test that a uniform map renderer property can be constrained");
1178 Shader shader = Shader::New("VertexSource", "FragmentSource");
1179 Geometry geometry = CreateQuadGeometry();
1180 Renderer renderer = Renderer::New( geometry, shader );
1182 Actor actor = Actor::New();
1183 actor.AddRenderer(renderer);
1184 actor.SetSize(400, 400);
1185 Stage::GetCurrent().Add(actor);
1186 application.SendNotification();
1187 application.Render(0);
1189 Vector4 initialColor = Color::WHITE;
1190 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1192 TestGlAbstraction& gl = application.GetGlAbstraction();
1194 application.SendNotification();
1195 application.Render(0);
1197 Vector4 actualValue(Vector4::ZERO);
1198 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1199 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1202 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1204 application.SendNotification();
1205 application.Render(0);
1207 // Expect no blue component in either buffer - yellow
1208 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1209 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1211 application.Render(0);
1212 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1213 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1215 renderer.RemoveConstraints();
1216 renderer.SetProperty(colorIndex, Color::WHITE );
1217 application.SendNotification();
1218 application.Render(0);
1220 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1221 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1226 int UtcDaliRendererAnimatedProperty01(void)
1228 TestApplication application;
1230 tet_infoline("Test that a non-uniform renderer property can be animated");
1232 Shader shader = Shader::New("VertexSource", "FragmentSource");
1233 Geometry geometry = CreateQuadGeometry();
1234 Renderer renderer = Renderer::New( geometry, shader );
1236 Actor actor = Actor::New();
1237 actor.AddRenderer(renderer);
1238 actor.SetSize(400, 400);
1239 Stage::GetCurrent().Add(actor);
1241 Vector4 initialColor = Color::WHITE;
1242 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1244 application.SendNotification();
1245 application.Render(0);
1246 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1248 Animation animation = Animation::New(1.0f);
1249 KeyFrames keyFrames = KeyFrames::New();
1250 keyFrames.Add(0.0f, initialColor);
1251 keyFrames.Add(1.0f, Color::TRANSPARENT);
1252 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1255 application.SendNotification();
1256 application.Render(500);
1258 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1260 application.Render(500);
1262 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1267 int UtcDaliRendererAnimatedProperty02(void)
1269 TestApplication application;
1271 tet_infoline("Test that a uniform map renderer property can be animated");
1273 Shader shader = Shader::New("VertexSource", "FragmentSource");
1274 Geometry geometry = CreateQuadGeometry();
1275 Renderer renderer = Renderer::New( geometry, shader );
1277 Actor actor = Actor::New();
1278 actor.AddRenderer(renderer);
1279 actor.SetSize(400, 400);
1280 Stage::GetCurrent().Add(actor);
1281 application.SendNotification();
1282 application.Render(0);
1284 Vector4 initialColor = Color::WHITE;
1285 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1287 TestGlAbstraction& gl = application.GetGlAbstraction();
1289 application.SendNotification();
1290 application.Render(0);
1292 Vector4 actualValue(Vector4::ZERO);
1293 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1294 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1296 Animation animation = Animation::New(1.0f);
1297 KeyFrames keyFrames = KeyFrames::New();
1298 keyFrames.Add(0.0f, initialColor);
1299 keyFrames.Add(1.0f, Color::TRANSPARENT);
1300 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1303 application.SendNotification();
1304 application.Render(500);
1306 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1307 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1309 application.Render(500);
1310 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1311 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1316 int UtcDaliRendererUniformMapPrecendence01(void)
1318 TestApplication application;
1320 tet_infoline("Test the uniform map precedence is applied properly");
1322 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1324 Shader shader = Shader::New("VertexSource", "FragmentSource");
1325 TextureSet textureSet = CreateTextureSet( image );
1327 Geometry geometry = CreateQuadGeometry();
1328 Renderer renderer = Renderer::New( geometry, shader );
1329 renderer.SetTextures( textureSet );
1331 Actor actor = Actor::New();
1332 actor.AddRenderer(renderer);
1333 actor.SetSize(400, 400);
1334 Stage::GetCurrent().Add(actor);
1335 application.SendNotification();
1336 application.Render(0);
1338 renderer.RegisterProperty( "uFadeColor", Color::RED );
1339 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1340 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1342 TestGlAbstraction& gl = application.GetGlAbstraction();
1344 application.SendNotification();
1345 application.Render(0);
1347 // Expect that the actor's fade color property is accessed
1348 Vector4 actualValue(Vector4::ZERO);
1349 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1350 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1352 // Animate shader's fade color property. Should be no change to uniform
1353 Animation animation = Animation::New(1.0f);
1354 KeyFrames keyFrames = KeyFrames::New();
1355 keyFrames.Add(0.0f, Color::WHITE);
1356 keyFrames.Add(1.0f, Color::TRANSPARENT);
1357 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1360 application.SendNotification();
1361 application.Render(500);
1363 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1364 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1366 application.Render(500);
1367 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1368 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1373 int UtcDaliRendererUniformMapPrecendence02(void)
1375 TestApplication application;
1377 tet_infoline("Test the uniform map precedence is applied properly");
1379 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1381 Shader shader = Shader::New("VertexSource", "FragmentSource");
1382 TextureSet textureSet = CreateTextureSet( image );
1384 Geometry geometry = CreateQuadGeometry();
1385 Renderer renderer = Renderer::New( geometry, shader );
1386 renderer.SetTextures( textureSet );
1388 Actor actor = Actor::New();
1389 actor.AddRenderer(renderer);
1390 actor.SetSize(400, 400);
1391 Stage::GetCurrent().Add(actor);
1392 application.SendNotification();
1393 application.Render(0);
1395 // Don't add property / uniform map to renderer
1396 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1397 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1399 TestGlAbstraction& gl = application.GetGlAbstraction();
1401 application.SendNotification();
1402 application.Render(0);
1404 // Expect that the actor's fade color property is accessed
1405 Vector4 actualValue(Vector4::ZERO);
1406 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1407 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1409 // Animate texture set's fade color property. Should be no change to uniform
1410 Animation animation = Animation::New(1.0f);
1411 KeyFrames keyFrames = KeyFrames::New();
1412 keyFrames.Add(0.0f, Color::WHITE);
1413 keyFrames.Add(1.0f, Color::TRANSPARENT);
1414 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1417 application.SendNotification();
1418 application.Render(500);
1420 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1421 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1423 application.Render(500);
1424 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1425 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1431 int UtcDaliRendererUniformMapPrecendence03(void)
1433 TestApplication application;
1435 tet_infoline("Test the uniform map precedence is applied properly");
1437 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1439 Shader shader = Shader::New("VertexSource", "FragmentSource");
1440 TextureSet textureSet = CreateTextureSet( image );
1442 Geometry geometry = CreateQuadGeometry();
1443 Renderer renderer = Renderer::New( geometry, shader );
1444 renderer.SetTextures( textureSet );
1446 Actor actor = Actor::New();
1447 actor.AddRenderer(renderer);
1448 actor.SetSize(400, 400);
1449 Stage::GetCurrent().Add(actor);
1450 application.SendNotification();
1451 application.Render(0);
1453 // Don't add property / uniform map to renderer or actor
1454 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1456 TestGlAbstraction& gl = application.GetGlAbstraction();
1458 application.SendNotification();
1459 application.Render(0);
1461 // Expect that the shader's fade color property is accessed
1462 Vector4 actualValue(Vector4::ZERO);
1463 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1464 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1469 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1471 TestApplication application;
1473 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1475 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1477 Shader shader = Shader::New("VertexSource", "FragmentSource");
1478 TextureSet textureSet = CreateTextureSet( image );
1480 Geometry geometry = CreateQuadGeometry();
1481 Renderer renderer = Renderer::New( geometry, shader );
1482 renderer.SetTextures( textureSet );
1484 Actor actor = Actor::New();
1485 actor.AddRenderer(renderer);
1486 actor.SetSize(400, 400);
1487 Stage::GetCurrent().Add(actor);
1488 application.SendNotification();
1489 application.Render(0);
1491 renderer.RegisterProperty( "uUniform1", Color::RED );
1492 actor.RegisterProperty( "uUniform2", Color::GREEN );
1493 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1495 TestGlAbstraction& gl = application.GetGlAbstraction();
1497 application.SendNotification();
1498 application.Render(0);
1500 // Expect that each of the object's uniforms are set
1501 Vector4 uniform1Value(Vector4::ZERO);
1502 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1503 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1505 Vector4 uniform2Value(Vector4::ZERO);
1506 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1507 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1509 Vector4 uniform3Value(Vector4::ZERO);
1510 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1511 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1516 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1518 TestApplication application;
1520 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1522 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1524 Shader shader = Shader::New("VertexSource", "FragmentSource");
1525 TextureSet textureSet = CreateTextureSet( image );
1527 Geometry geometry = CreateQuadGeometry();
1528 Renderer renderer = Renderer::New( geometry, shader );
1529 renderer.SetTextures( textureSet );
1531 Actor actor = Actor::New();
1532 actor.AddRenderer(renderer);
1533 actor.SetSize(400, 400);
1534 Stage::GetCurrent().Add(actor);
1535 application.SendNotification();
1536 application.Render(0);
1538 Property::Value value1(Color::RED);
1539 renderer.RegisterProperty( "uFadeColor", value1 );
1541 Property::Value value2(1.0f);
1542 actor.RegisterProperty( "uFadeProgress", value2 );
1544 Property::Value value3(Matrix3::IDENTITY);
1545 shader.RegisterProperty( "uANormalMatrix", value3 );
1547 TestGlAbstraction& gl = application.GetGlAbstraction();
1549 application.SendNotification();
1550 application.Render(0);
1552 // Expect that each of the object's uniforms are set
1553 Vector4 uniform1Value(Vector4::ZERO);
1554 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1555 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1557 float uniform2Value(0.0f);
1558 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1559 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1561 Matrix3 uniform3Value;
1562 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1563 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1569 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1571 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1572 TextureSet textureSet0 = CreateTextureSet( image0 );
1573 Renderer renderer0 = Renderer::New( geometry, shader );
1574 renderer0.SetTextures( textureSet0 );
1575 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1576 actor.AddRenderer(renderer0);
1581 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1583 Actor actor = Actor::New();
1584 actor.SetAnchorPoint(AnchorPoint::CENTER);
1585 actor.SetParentOrigin(AnchorPoint::CENTER);
1586 actor.SetPosition(0.0f,0.0f);
1587 actor.SetSize(100, 100);
1589 actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1590 DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1595 int UtcDaliRendererRenderOrder2DLayer(void)
1597 TestApplication application;
1598 tet_infoline("Test the rendering order in a 2D layer is correct");
1600 Shader shader = Shader::New("VertexSource", "FragmentSource");
1601 Geometry geometry = CreateQuadGeometry();
1603 Actor root = Stage::GetCurrent().GetRootLayer();
1605 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1606 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1608 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1609 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1611 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1612 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1614 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1615 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1617 application.SendNotification();
1618 application.Render(0);
1621 * Create the following hierarchy:
1634 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1639 application.SendNotification();
1640 application.Render(0);
1642 TestGlAbstraction& gl = application.GetGlAbstraction();
1643 gl.EnableTextureCallTrace(true);
1644 application.SendNotification();
1645 application.Render(0);
1647 int textureBindIndex[4];
1648 for( unsigned int i(0); i<4; ++i )
1650 std::stringstream params;
1651 params << GL_TEXTURE_2D<<", "<<i+1;
1652 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1655 //Check that actor1 has been rendered after actor2
1656 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1658 //Check that actor0 has been rendered after actor1
1659 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1661 //Check that actor3 has been rendered after actor0
1662 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1667 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1669 TestApplication application;
1670 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1673 * Creates the following hierarchy:
1675 * actor0------------------------>actor1
1679 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1681 * renderer0 has depth index 2
1682 * renderer1 has depth index 0
1683 * renderer2 has depth index 1
1685 * renderer3 has depth index 1
1686 * renderer4 has depth index 0
1687 * renderer5 has depth index -1
1689 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1692 Shader shader = Shader::New("VertexSource", "FragmentSource");
1693 Geometry geometry = CreateQuadGeometry();
1695 Actor root = Stage::GetCurrent().GetRootLayer();
1697 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1698 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1699 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1700 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1701 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1702 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1703 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1704 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1706 application.SendNotification();
1707 application.Render(0);
1709 TestGlAbstraction& gl = application.GetGlAbstraction();
1710 gl.EnableTextureCallTrace(true);
1711 application.SendNotification();
1712 application.Render(0);
1714 int textureBindIndex[6];
1715 for( unsigned int i(0); i<6; ++i )
1717 std::stringstream params;
1718 params << GL_TEXTURE_2D<<", "<<i+1;
1719 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1722 //Check that renderer3 has been rendered after renderer4
1723 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1725 //Check that renderer0 has been rendered after renderer2
1726 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1728 //Check that renderer5 has been rendered after renderer2
1729 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1731 //Check that renderer0 has been rendered after renderer2
1732 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1734 //Check that renderer2 has been rendered after renderer1
1735 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1741 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1743 TestApplication application;
1744 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1747 * Creates the following hierarchy:
1755 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1759 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1760 * DI:2 DI:0 | DI:0 DI:1 DI:2
1765 * actor0 has sibling order 1
1766 * actor1 has sibling order 0
1767 * actor2 has sibling order 0
1769 * renderer0 has depth index 2
1770 * renderer1 has depth index 0
1772 * renderer2 has depth index 0
1773 * renderer3 has depth index 1
1774 * renderer4 has depth index 2
1776 * renderer5 has depth index -1
1778 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1781 Shader shader = Shader::New("VertexSource", "FragmentSource");
1782 Geometry geometry = CreateQuadGeometry();
1783 Actor root = Stage::GetCurrent().GetRootLayer();
1784 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1785 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1786 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1788 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1789 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1790 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1791 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1792 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1793 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1795 application.SendNotification();
1796 application.Render();
1798 TestGlAbstraction& gl = application.GetGlAbstraction();
1799 gl.EnableTextureCallTrace(true);
1800 application.SendNotification();
1801 application.Render(0);
1803 int textureBindIndex[6];
1804 for( unsigned int i(0); i<6; ++i )
1806 std::stringstream params;
1807 params << GL_TEXTURE_2D<<", "<<i+1;
1808 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1811 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1812 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1813 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1814 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1815 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1816 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1818 // Change sibling order of actor1
1819 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1820 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1822 gl.GetTextureTrace().Reset();
1823 application.SendNotification();
1824 application.Render(0);
1826 for( unsigned int i(0); i<6; ++i )
1828 std::stringstream params;
1829 params << GL_TEXTURE_2D<<", "<<i+1;
1830 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1833 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1834 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1835 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1836 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1837 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1838 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1843 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1845 TestApplication application;
1846 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1848 Shader shader = Shader::New("VertexSource", "FragmentSource");
1849 Geometry geometry = CreateQuadGeometry();
1850 Actor root = Stage::GetCurrent().GetRootLayer();
1853 * Create the following hierarchy:
1860 * (Overlay) (Regular actor)
1870 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1873 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1874 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1875 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1877 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1878 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1879 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1881 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1882 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1884 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1885 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1886 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1888 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1889 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1891 application.SendNotification();
1892 application.Render(0);
1899 TestGlAbstraction& gl = application.GetGlAbstraction();
1900 gl.EnableTextureCallTrace(true);
1901 application.SendNotification();
1902 application.Render(0);
1904 int textureBindIndex[5];
1905 for( unsigned int i(0); i<5; ++i )
1907 std::stringstream params;
1908 params << GL_TEXTURE_2D<<", "<<i+1;
1909 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1912 //Check that actor4 has been rendered after actor2
1913 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1915 //Check that actor1 has been rendered after actor4
1916 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1918 //Check that actor0 has been rendered after actor1
1919 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1921 //Check that actor3 has been rendered after actor0
1922 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1927 int UtcDaliRendererSetIndexRange(void)
1931 "attribute vec2 aPosition;\n"
1934 " gl_Position = aPosition;\n"
1940 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1944 TestApplication application;
1945 tet_infoline("Test setting the range of indices to draw");
1947 TestGlAbstraction& gl = application.GetGlAbstraction();
1948 gl.EnableDrawCallTrace( true );
1950 Actor actor = Actor::New();
1951 actor.SetSize( 100, 100 );
1954 Geometry geometry = Geometry::New();
1955 geometry.SetType( Geometry::LINE_LOOP );
1957 // --------------------------------------------------------------------------
1959 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1960 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1961 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1963 // --------------------------------------------------------------------------
1972 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1973 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1974 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1975 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1976 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1978 Property::Map vertexFormat;
1979 vertexFormat["aPosition"] = Property::VECTOR2;
1980 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1981 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1983 // --------------------------------------------------------------------------
1984 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1985 geometry.AddVertexBuffer( vertexBuffer );
1988 Shader shader = Shader::New( vertexShader,fragmentShader );
1989 Renderer renderer = Renderer::New( geometry, shader );
1990 actor.AddRenderer( renderer );
1992 Stage stage = Stage::GetCurrent();
1997 // LINE_LOOP, first 0, count 5
1999 renderer.SetIndexRange( 0, 5 );
2000 application.SendNotification();
2001 application.Render();
2003 Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST );
2005 DALI_TEST_CHECK( value.Get( convertedValue ) );
2006 DALI_TEST_CHECK( convertedValue == 0 );
2008 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST );
2009 DALI_TEST_CHECK( value.Get( convertedValue ) );
2010 DALI_TEST_CHECK( convertedValue == 0 );
2012 value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT );
2013 DALI_TEST_CHECK( value.Get( convertedValue ) );
2014 DALI_TEST_CHECK( convertedValue == 5 );
2016 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT );
2017 DALI_TEST_CHECK( value.Get( convertedValue ) );
2018 DALI_TEST_CHECK( convertedValue == 5 );
2020 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2021 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2022 DALI_TEST_CHECK( result );
2025 // LINE_LOOP, first 5, count 10
2027 renderer.SetIndexRange( 5, 10 );
2028 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2029 application.SendNotification();
2030 application.Render();
2031 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2032 DALI_TEST_CHECK( result );
2035 // LINE_STRIP, first 15, count 6
2037 renderer.SetIndexRange( 15, 6 );
2038 geometry.SetType( Geometry::LINE_STRIP );
2039 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2040 application.SendNotification();
2041 application.Render();
2042 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2043 DALI_TEST_CHECK( result );
2046 // Index out of bounds
2048 renderer.SetIndexRange( 15, 30 );
2049 geometry.SetType( Geometry::LINE_STRIP );
2050 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2051 application.SendNotification();
2052 application.Render();
2053 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2054 DALI_TEST_CHECK( result );
2057 // drawing whole buffer starting from 15 ( last valid primitive )
2059 renderer.SetIndexRange( 15, 0 );
2060 geometry.SetType( Geometry::LINE_STRIP );
2061 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2062 application.SendNotification();
2063 application.Render();
2064 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2065 DALI_TEST_CHECK( result );
2072 int UtcDaliRendererSetDepthFunction(void)
2074 TestApplication application;
2076 tet_infoline("Test setting the depth function");
2078 Geometry geometry = CreateQuadGeometry();
2079 Shader shader = CreateShader();
2080 Renderer renderer = Renderer::New( geometry, shader );
2082 Actor actor = Actor::New();
2083 actor.AddRenderer(renderer);
2084 actor.SetSize(400, 400);
2085 Stage stage = Stage::GetCurrent();
2086 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2089 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2090 glAbstraction.EnableEnableDisableCallTrace(true);
2091 glAbstraction.EnableDepthFunctionCallTrace(true);
2093 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2094 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2096 std::ostringstream depthTestStr;
2097 depthTestStr << GL_DEPTH_TEST;
2101 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2103 glEnableDisableStack.Reset();
2104 glDepthFunctionStack.Reset();
2105 application.SendNotification();
2106 application.Render();
2108 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2109 std::ostringstream depthFunctionStr;
2110 depthFunctionStr << GL_NEVER;
2111 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2116 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2118 glDepthFunctionStack.Reset();
2119 application.SendNotification();
2120 application.Render();
2122 std::ostringstream depthFunctionStr;
2123 depthFunctionStr << GL_ALWAYS;
2124 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2129 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2131 glDepthFunctionStack.Reset();
2132 application.SendNotification();
2133 application.Render();
2135 std::ostringstream depthFunctionStr;
2136 depthFunctionStr << GL_LESS;
2137 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2142 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2144 glDepthFunctionStack.Reset();
2145 application.SendNotification();
2146 application.Render();
2148 std::ostringstream depthFunctionStr;
2149 depthFunctionStr << GL_GREATER;
2150 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2155 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2157 glDepthFunctionStack.Reset();
2158 application.SendNotification();
2159 application.Render();
2161 std::ostringstream depthFunctionStr;
2162 depthFunctionStr << GL_EQUAL;
2163 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2168 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2170 glDepthFunctionStack.Reset();
2171 application.SendNotification();
2172 application.Render();
2174 std::ostringstream depthFunctionStr;
2175 depthFunctionStr << GL_NOTEQUAL;
2176 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2181 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2183 glDepthFunctionStack.Reset();
2184 application.SendNotification();
2185 application.Render();
2187 std::ostringstream depthFunctionStr;
2188 depthFunctionStr << GL_LEQUAL;
2189 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2194 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2196 glDepthFunctionStack.Reset();
2197 application.SendNotification();
2198 application.Render();
2200 std::ostringstream depthFunctionStr;
2201 depthFunctionStr << GL_GEQUAL;
2202 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2209 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2210 * The checks performed are as follows:
2211 * - Check the initial/default value.
2212 * - Set a different value via enum.
2213 * - Check it was set.
2214 * - Set a different value via string.
2215 * - Check it was set.
2217 template< typename T >
2218 void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2220 application.SendNotification();
2221 application.Render();
2223 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2224 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2225 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2226 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2227 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( firstCheckEnumeration ) );
2229 application.SendNotification();
2230 application.Render();
2232 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2233 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2235 renderer.SetProperty( propertyIndex, secondCheckString );
2236 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2237 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( secondCheckEnumeration ) );
2239 application.SendNotification();
2240 application.Render();
2242 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2243 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2246 int UtcDaliRendererEnumProperties(void)
2248 TestApplication application;
2249 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2251 Geometry geometry = CreateQuadGeometry();
2252 Shader shader = CreateShader();
2253 Renderer renderer = Renderer::New( geometry, shader );
2255 Actor actor = Actor::New();
2256 actor.AddRenderer(renderer);
2257 actor.SetSize(400, 400);
2258 Stage::GetCurrent().Add(actor);
2261 * Here we use a templatized function to perform several checks on each enumeration property.
2262 * @see CheckEnumerationProperty for details of the checks performed.
2265 CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2266 CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2267 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2268 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2269 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2270 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2271 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2272 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2273 CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2274 CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2275 CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2276 CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2277 CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2278 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2279 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2280 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2285 Renderer RendererTestFixture( TestApplication& application )
2287 Geometry geometry = CreateQuadGeometry();
2288 Shader shader = CreateShader();
2289 Renderer renderer = Renderer::New( geometry, shader );
2291 Actor actor = Actor::New();
2292 actor.AddRenderer( renderer );
2293 actor.SetSize( 400.0f, 400.0f );
2294 Stage stage = Stage::GetCurrent();
2295 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2301 int UtcDaliRendererSetDepthTestMode(void)
2303 TestApplication application;
2304 tet_infoline("Test setting the DepthTestMode");
2306 Renderer renderer = RendererTestFixture( application );
2307 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2308 glAbstraction.EnableEnableDisableCallTrace( true );
2309 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2311 glEnableDisableStack.Reset();
2312 application.SendNotification();
2313 application.Render();
2315 // Check depth-test is enabled by default.
2316 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2317 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2319 // 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.
2320 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2321 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2323 glEnableDisableStack.Reset();
2324 application.SendNotification();
2325 application.Render();
2327 // Check the depth buffer was disabled.
2328 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2330 // Turn on automatic mode depth-testing.
2331 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2332 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2334 glEnableDisableStack.Reset();
2335 application.SendNotification();
2336 application.Render();
2338 // Check depth-test is now enabled.
2339 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2340 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2342 // Change the layer behavior to LAYER_UI.
2343 // Note this will also disable depth testing for the layer by default, we test this first.
2344 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_UI );
2346 glEnableDisableStack.Reset();
2347 application.SendNotification();
2348 application.Render();
2350 // Check depth-test is disabled.
2351 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2353 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2354 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2356 glEnableDisableStack.Reset();
2357 application.SendNotification();
2358 application.Render();
2360 // Check depth-test is *still* disabled.
2361 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2366 int UtcDaliRendererSetDepthWriteMode(void)
2368 TestApplication application;
2369 tet_infoline("Test setting the DepthWriteMode");
2371 Renderer renderer = RendererTestFixture( application );
2372 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2374 application.SendNotification();
2375 application.Render();
2377 // Check the default depth-write status first.
2378 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2380 // Turn off depth-writing.
2381 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2383 application.SendNotification();
2384 application.Render();
2386 // Check depth-write is now disabled.
2387 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2389 // Test the AUTO mode for depth-writing.
2390 // As our renderer is opaque, depth-testing should be enabled.
2391 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2393 application.SendNotification();
2394 application.Render();
2396 // Check depth-write is now enabled.
2397 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2399 // Now make the renderer be treated as translucent by enabling blending.
2400 // The AUTO depth-write mode should turn depth-write off in this scenario.
2401 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2403 application.SendNotification();
2404 application.Render();
2406 // Check depth-write is now disabled.
2407 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2412 int UtcDaliRendererCheckStencilDefaults(void)
2414 TestApplication application;
2415 tet_infoline("Test the stencil defaults");
2417 Renderer renderer = RendererTestFixture( application );
2418 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2419 glAbstraction.EnableEnableDisableCallTrace( true );
2420 glAbstraction.EnableStencilFunctionCallTrace( true );
2421 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2422 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2424 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2426 // Check the defaults:
2427 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2428 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2429 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2430 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2431 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2432 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 );
2433 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 );
2438 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2440 TestApplication application;
2441 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2443 Renderer renderer = RendererTestFixture( application );
2444 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2445 glAbstraction.EnableEnableDisableCallTrace( true );
2446 glAbstraction.EnableStencilFunctionCallTrace( true );
2447 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2448 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2450 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2451 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2452 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2453 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2455 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2456 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2458 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2459 std::string methodString( "StencilFunc" );
2460 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2462 // Test the other RenderModes that will not enable the stencil buffer.
2463 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2464 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2465 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2467 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2468 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2469 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2471 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2472 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2473 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2475 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2476 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2478 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2479 // First set a mode to turn off the stencil buffer, so the enable is required.
2480 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2481 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2482 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2483 // Set a different stencil function as the last one is cached.
2484 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS );
2485 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2487 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2488 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2493 // Helper function for the SetRenderModeToUseColorBuffer test.
2494 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2496 // Set the RenderMode property to a value that should not allow color buffer writes.
2497 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2498 application.SendNotification();
2499 application.Render();
2501 // Check if ColorMask has been called, and that the values are correct.
2502 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2503 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2505 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2506 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2507 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2508 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2511 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2513 TestApplication application;
2514 tet_infoline("Test setting the RenderMode to use the color buffer");
2516 Renderer renderer = RendererTestFixture( application );
2518 // Set the RenderMode property to a value that should not allow color buffer writes.
2519 // Then check if ColorMask has been called, and that the values are correct.
2520 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2521 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2522 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2523 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2524 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2529 int UtcDaliRendererSetStencilFunction(void)
2531 TestApplication application;
2532 tet_infoline("Test setting the StencilFunction");
2534 Renderer renderer = RendererTestFixture( application );
2535 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2536 glAbstraction.EnableEnableDisableCallTrace( true );
2537 glAbstraction.EnableStencilFunctionCallTrace( true );
2538 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2539 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2541 // RenderMode must use the stencil for StencilFunction to operate.
2542 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2543 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2546 * Lookup table for testing StencilFunction.
2547 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2549 const int StencilFunctionLookupTable[] = {
2558 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2561 * Loop through all types of StencilFunction, checking:
2562 * - The value is cached (set in event thread side)
2563 * - Causes "glStencilFunc" to be called
2564 * - Checks the correct parameters to "glStencilFunc" were used
2566 std::string nonChangingParameters = "0, 255";
2567 std::string methodString( "StencilFunc" );
2568 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2570 // Set the property.
2571 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2573 // Check GetProperty returns the same value.
2574 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2576 // Reset the trace debug.
2577 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2579 // Check the function is called and the parameters are correct.
2580 std::stringstream parameterStream;
2581 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2583 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2586 // Change the Function Reference only and check the behavior is correct:
2587 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2588 int testValueReference = 170;
2589 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2591 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2593 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2595 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2597 std::stringstream parameterStream;
2598 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2600 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2603 // Change the Function Mask only and check the behavior is correct:
2604 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2605 int testValueMask = 85;
2606 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2608 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2610 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2612 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2614 // Clear the stringstream.
2615 parameterStream.str( std::string() );
2616 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2618 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2623 int UtcDaliRendererSetStencilOperation(void)
2625 TestApplication application;
2626 tet_infoline("Test setting the StencilOperation");
2628 Renderer renderer = RendererTestFixture( application );
2629 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2630 glAbstraction.EnableEnableDisableCallTrace( true );
2631 glAbstraction.EnableStencilFunctionCallTrace( true );
2632 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2633 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2635 // RenderMode must use the stencil for StencilOperation to operate.
2636 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2639 * Lookup table for testing StencilOperation.
2640 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2642 const int StencilOperationLookupTable[] = {
2651 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2653 // Set all 3 StencilOperation properties to a default.
2654 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP );
2655 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2656 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2658 // Set our expected parameter list to the equivalent result.
2659 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2661 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2664 * Loop through all types of StencilOperation, checking:
2665 * - The value is cached (set in event thread side)
2666 * - Causes "glStencilFunc" to be called
2667 * - Checks the correct parameters to "glStencilFunc" were used
2668 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2670 std::string methodString( "StencilOp" );
2672 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2674 for( int j = 0; j < StencilOperationLookupTableCount; ++j )
2676 for( int k = 0; k < StencilOperationLookupTableCount; ++k )
2678 // Set the property (outer loop causes all 3 different properties to be set separately).
2679 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>( i ) );
2680 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>( j ) );
2681 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>( k ) );
2683 // Check GetProperty returns the same value.
2684 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), i, TEST_LOCATION );
2685 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), j, TEST_LOCATION );
2686 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), k, TEST_LOCATION );
2688 // Reset the trace debug.
2689 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2691 // Check the function is called and the parameters are correct.
2692 // Set the expected parameter value at its correct index (only)
2693 parameters[ 0u ] = StencilOperationLookupTable[ i ];
2694 parameters[ 1u ] = StencilOperationLookupTable[ j ];
2695 parameters[ 2u ] = StencilOperationLookupTable[ k ];
2697 // Build the parameter list.
2698 std::stringstream parameterStream;
2699 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2701 parameterStream << parameters[ parameterBuild ];
2702 // Comma-separate the parameters.
2703 if( parameterBuild < 2 )
2705 parameterStream << ", ";
2709 // Check the function was called and the parameters were correct.
2710 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2718 int UtcDaliRendererSetStencilMask(void)
2720 TestApplication application;
2721 tet_infoline("Test setting the StencilMask");
2723 Renderer renderer = RendererTestFixture( application );
2724 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2725 glAbstraction.EnableEnableDisableCallTrace( true );
2726 glAbstraction.EnableStencilFunctionCallTrace( true );
2727 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2728 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2730 // RenderMode must use the stencil for StencilMask to operate.
2731 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2733 // Set the StencilMask property to a value.
2734 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2736 // Check GetProperty returns the same value.
2737 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2739 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2741 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2743 std::string methodString( "StencilMask" );
2744 std::string parameterString = "0";
2746 // Check the function was called and the parameters were correct.
2747 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2749 // Set the StencilMask property to another value to ensure it has changed.
2750 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2752 // Check GetProperty returns the same value.
2753 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2755 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2757 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2759 parameterString = "255";
2761 // Check the function was called and the parameters were correct.
2762 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2767 int UtcDaliRendererWrongNumberOfTextures(void)
2769 TestApplication application;
2770 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2772 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2773 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2774 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2775 TextureSet textureSet = CreateTextureSet();
2776 textureSet.SetTexture(0, texture );
2777 textureSet.SetTexture(1, texture );
2778 textureSet.SetTexture(2, texture );
2779 textureSet.SetTexture(3, texture );
2780 Shader shader = Shader::New("VertexSource", "FragmentSource");
2781 Geometry geometry = CreateQuadGeometry();
2782 Renderer renderer = Renderer::New( geometry, shader );
2783 renderer.SetTextures( textureSet );
2785 Actor actor= Actor::New();
2786 actor.AddRenderer(renderer);
2787 actor.SetPosition(0.0f,0.0f);
2788 actor.SetSize(100, 100);
2789 Stage::GetCurrent().Add(actor);
2791 TestGlAbstraction& gl = application.GetGlAbstraction();
2792 TraceCallStack& drawTrace = gl.GetDrawTrace();
2794 drawTrace.Enable(true);
2796 application.SendNotification();
2797 application.Render(0);
2799 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2800 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2802 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2803 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2804 textureSet = CreateTextureSet();
2805 renderer.SetTextures( textureSet );
2806 textureSet.SetTexture(0, texture );
2808 application.SendNotification();
2809 application.Render(0);
2811 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2812 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2817 int UtcDaliRendererOpacity(void)
2819 TestApplication application;
2821 tet_infoline( "Test OPACITY property" );
2823 Geometry geometry = CreateQuadGeometry();
2824 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2825 Renderer renderer = Renderer::New( geometry, shader );
2827 Actor actor = Actor::New();
2828 actor.AddRenderer( renderer );
2829 actor.SetSize( 400, 400 );
2830 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2831 Stage::GetCurrent().Add( actor );
2833 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2835 DALI_TEST_CHECK( value.Get( opacity ) );
2836 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2838 application.SendNotification();
2839 application.Render();
2841 Vector4 actualValue;
2842 TestGlAbstraction& gl = application.GetGlAbstraction();
2843 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2844 DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2846 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f );
2848 application.SendNotification();
2849 application.Render();
2851 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2852 DALI_TEST_CHECK( value.Get( opacity ) );
2853 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2855 value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY );
2856 DALI_TEST_CHECK( value.Get( opacity ) );
2857 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2859 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2860 DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2865 int UtcDaliRendererOpacityAnimation(void)
2867 TestApplication application;
2869 tet_infoline( "Test OPACITY property animation" );
2871 Geometry geometry = CreateQuadGeometry();
2872 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2873 Renderer renderer = Renderer::New( geometry, shader );
2875 Actor actor = Actor::New();
2876 actor.AddRenderer( renderer );
2877 actor.SetSize( 400, 400 );
2878 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2879 Stage::GetCurrent().Add( actor );
2881 application.SendNotification();
2882 application.Render(0);
2884 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2886 DALI_TEST_CHECK( value.Get( opacity ) );
2887 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2889 Animation animation = Animation::New( 1.0f );
2890 animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f );
2893 application.SendNotification();
2894 application.Render( 1000 );
2896 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2897 DALI_TEST_CHECK( value.Get( opacity ) );
2898 DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2900 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
2902 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 );
2913 DALI_TEST_EQUALS( opacity, renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY ).Get< float >(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2918 int UtcDaliRendererInvalidProperty(void)
2920 TestApplication application;
2922 tet_infoline( "Test invalid property" );
2924 Geometry geometry = CreateQuadGeometry();
2925 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2926 Renderer renderer = Renderer::New( geometry, shader );
2928 Actor actor = Actor::New();
2929 actor.AddRenderer( renderer );
2930 actor.SetSize( 400, 400 );
2931 Stage::GetCurrent().Add( actor );
2933 application.SendNotification();
2934 application.Render(0);
2936 Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 );
2937 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2939 value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 );
2940 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2945 int UtcDaliRendererRenderingBehavior(void)
2947 TestApplication application;
2949 tet_infoline( "Test RENDERING_BEHAVIOR property" );
2951 Geometry geometry = CreateQuadGeometry();
2952 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2953 Renderer renderer = Renderer::New( geometry, shader );
2955 Actor actor = Actor::New();
2956 actor.AddRenderer( renderer );
2957 actor.SetSize( 400, 400 );
2958 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2959 Stage::GetCurrent().Add( actor );
2961 Property::Value value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2962 int renderingBehavior;
2963 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2964 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION );
2966 application.SendNotification();
2967 application.Render();
2969 uint32_t updateStatus = application.GetUpdateStatus();
2971 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
2973 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY );
2975 value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2976 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2977 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2979 // Render and check the update status
2980 application.SendNotification();
2981 application.Render();
2983 updateStatus = application.GetUpdateStatus();
2985 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2987 value = renderer.GetCurrentProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2988 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2989 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2991 // Render again and check the update status
2992 application.SendNotification();
2993 application.Render();
2995 updateStatus = application.GetUpdateStatus();
2997 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2999 // Change rendering behavior
3000 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
3002 // Render and check the update status
3003 application.SendNotification();
3004 application.Render();
3006 updateStatus = application.GetUpdateStatus();
3008 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
3013 int UtcDaliRendererRegenerateUniformMap(void)
3015 TestApplication application;
3017 tet_infoline( "Test regenerating uniform map when attaching renderer to the node" );
3019 Geometry geometry = CreateQuadGeometry();
3020 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
3021 Renderer renderer = Renderer::New( geometry, shader );
3023 Actor actor = Actor::New();
3024 actor.AddRenderer( renderer );
3025 actor.SetSize( 400, 400 );
3026 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
3027 Stage::GetCurrent().Add( actor );
3029 application.SendNotification();
3030 application.Render();
3032 actor.RemoveRenderer( renderer );
3033 shader = Shader::New( "vertexSrc", "fragmentSrc" );
3034 shader.RegisterProperty( "opacity", 0.5f );
3035 renderer.SetShader( shader );
3037 Stage::GetCurrent().KeepRendering( 1.0f );
3039 // Update for several frames
3040 application.SendNotification();
3041 application.Render();
3042 application.SendNotification();
3043 application.Render();
3044 application.SendNotification();
3045 application.Render();
3046 application.SendNotification();
3047 application.Render();
3050 actor.AddRenderer( renderer );
3051 application.SendNotification();
3052 application.Render();
3054 // Nothing to test here, the test must not crash
3055 auto updateStatus = application.GetUpdateStatus();
3056 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );