2 * Copyright (c) 2020 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/integration-api/render-task-list-integ.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-trace-call-stack.h>
30 #include <mesh-builder.h>
34 namespace // unnamed namespace
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
46 * @brief Get GL stencil test enumeration value as a string.
47 * @return The string representation of the value of GL_STENCIL_TEST
49 std::string GetStencilTestString(void)
51 std::stringstream stream;
52 stream << GL_STENCIL_TEST;
57 * @brief Get GL depth test enumeration value as a string.
58 * @return The string representation of the value of GL_DEPTH_TEST
60 std::string GetDepthTestString(void)
62 std::stringstream stream;
63 stream << GL_DEPTH_TEST;
67 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
69 glEnableDisableStack.Reset();
70 glStencilFunctionStack.Reset();
71 application.SendNotification();
75 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
80 } // unnamed namespace
82 void renderer_test_startup(void)
84 test_return_value = TET_UNDEF;
87 void renderer_test_cleanup(void)
89 test_return_value = TET_PASS;
92 int UtcDaliRendererNew01(void)
94 TestApplication application;
96 Geometry geometry = CreateQuadGeometry();
97 Shader shader = CreateShader();
98 Renderer renderer = Renderer::New(geometry, shader);
100 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
104 int UtcDaliRendererNew02(void)
106 TestApplication application;
108 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
112 int UtcDaliRendererCopyConstructor(void)
114 TestApplication application;
116 Geometry geometry = CreateQuadGeometry();
117 Shader shader = CreateShader();
118 Renderer renderer = Renderer::New(geometry, shader);
120 Renderer rendererCopy( renderer );
121 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
126 int UtcDaliRendererAssignmentOperator(void)
128 TestApplication application;
130 Geometry geometry = CreateQuadGeometry();
131 Shader shader = CreateShader();
132 Renderer renderer = Renderer::New(geometry, shader);
135 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
137 renderer2 = renderer;
138 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
142 int UtcDaliRendererDownCast01(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = CreateShader();
148 Renderer renderer = Renderer::New(geometry, shader);
150 BaseHandle handle(renderer);
151 Renderer renderer2 = Renderer::DownCast(handle);
152 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
156 int UtcDaliRendererDownCast02(void)
158 TestApplication application;
160 Handle handle = Handle::New(); // Create a custom object
161 Renderer renderer = Renderer::DownCast(handle);
162 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
166 // using a template to auto deduce the parameter types
167 template< typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
168 void TEST_RENDERER_PROPERTY( P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION )
170 DALI_TEST_EQUALS( renderer.GetPropertyName( enumName ), stringName, LOCATION );
171 DALI_TEST_EQUALS( renderer.GetPropertyIndex( stringName ), static_cast<Property::Index>(enumName), LOCATION );
172 DALI_TEST_EQUALS( renderer.GetPropertyType( enumName ), type, LOCATION );
173 DALI_TEST_EQUALS( renderer.IsPropertyWritable( enumName ), isWriteable, LOCATION );
174 DALI_TEST_EQUALS( renderer.IsPropertyAnimatable( enumName ), isAnimateable, LOCATION );
175 DALI_TEST_EQUALS( renderer.IsPropertyAConstraintInput( enumName ), isConstraintInput, LOCATION );
178 int UtcDaliRendererDefaultProperties(void)
180 TestApplication application;
181 /* from renderer-impl.cpp
182 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
183 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
184 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
185 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
186 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
187 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
188 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
189 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
190 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
191 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
192 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
193 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
194 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
195 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
196 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
197 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
198 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
199 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
200 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
201 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
202 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
203 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
204 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
205 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
206 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
207 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
210 Geometry geometry = CreateQuadGeometry();
211 Shader shader = CreateShader();
212 Renderer renderer = Renderer::New(geometry, shader);
213 DALI_TEST_EQUALS( renderer.GetPropertyCount(), 26, TEST_LOCATION );
215 TEST_RENDERER_PROPERTY( renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION );
216 TEST_RENDERER_PROPERTY( renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION );
217 TEST_RENDERER_PROPERTY( renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION );
218 TEST_RENDERER_PROPERTY( renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION );
219 TEST_RENDERER_PROPERTY( renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION );
220 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION );
221 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION );
222 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION );
223 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION );
224 TEST_RENDERER_PROPERTY( renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION );
225 TEST_RENDERER_PROPERTY( renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION );
226 TEST_RENDERER_PROPERTY( renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION );
227 TEST_RENDERER_PROPERTY( renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION );
228 TEST_RENDERER_PROPERTY( renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION );
229 TEST_RENDERER_PROPERTY( renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION );
230 TEST_RENDERER_PROPERTY( renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION );
231 TEST_RENDERER_PROPERTY( renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION );
232 TEST_RENDERER_PROPERTY( renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION );
233 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION );
234 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionReference",Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION );
235 TEST_RENDERER_PROPERTY( renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION );
236 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION );
237 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION );
238 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION );
239 TEST_RENDERER_PROPERTY( renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION );
240 TEST_RENDERER_PROPERTY( renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION );
245 int UtcDaliRendererSetGetGeometry(void)
247 TestApplication application;
248 tet_infoline( "Test SetGeometry, GetGeometry" );
250 Geometry geometry1 = CreateQuadGeometry();
251 Geometry geometry2 = CreateQuadGeometry();
253 Shader shader = CreateShader();
254 Renderer renderer = Renderer::New(geometry1, shader);
255 Actor actor = Actor::New();
256 actor.AddRenderer(renderer);
257 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
258 Stage::GetCurrent().Add(actor);
260 application.SendNotification();
261 application.Render(0);
262 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
264 // Set geometry2 to the renderer
265 renderer.SetGeometry( geometry2 );
267 application.SendNotification();
268 application.Render(0);
269 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
274 int UtcDaliRendererSetGetShader(void)
276 TestApplication application;
277 tet_infoline( "Test SetShader, GetShader" );
279 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
280 glAbstraction.EnableCullFaceCallTrace(true);
282 Shader shader1 = CreateShader();
283 shader1.RegisterProperty( "uFadeColor", Color::RED );
285 Shader shader2 = CreateShader();
286 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
288 Geometry geometry = CreateQuadGeometry();
289 Renderer renderer = Renderer::New(geometry, shader1);
290 Actor actor = Actor::New();
291 actor.AddRenderer(renderer);
292 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
293 Stage::GetCurrent().Add(actor);
295 TestGlAbstraction& gl = application.GetGlAbstraction();
296 application.SendNotification();
297 application.Render(0);
299 // Expect that the first shaders's fade color property is accessed
300 Vector4 actualValue(Vector4::ZERO);
301 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
302 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
304 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
306 // set the second shader to the renderer
307 renderer.SetShader( shader2 );
309 application.SendNotification();
310 application.Render(0);
312 // Expect that the second shader's fade color property is accessed
313 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
314 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
316 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
321 int UtcDaliRendererSetGetDepthIndex(void)
323 TestApplication application;
325 tet_infoline("Test SetDepthIndex, GetDepthIndex");
327 Shader shader = CreateShader();
328 Geometry geometry = CreateQuadGeometry();
329 Renderer renderer = Renderer::New(geometry, shader);
330 Actor actor = Actor::New();
331 actor.AddRenderer(renderer);
332 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
333 Stage::GetCurrent().Add(actor);
335 application.SendNotification();
336 application.Render(0);
337 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
339 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
341 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
342 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
344 application.SendNotification();
345 application.Render(0);
346 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
348 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
350 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
351 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
353 application.SendNotification();
354 application.Render(0);
355 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
360 int UtcDaliRendererSetGetFaceCullingMode(void)
362 TestApplication application;
364 tet_infoline("Test SetFaceCullingMode(cullingMode)");
365 Geometry geometry = CreateQuadGeometry();
366 Shader shader = CreateShader();
367 Renderer renderer = Renderer::New( geometry, shader );
369 Actor actor = Actor::New();
370 actor.AddRenderer(renderer);
371 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
372 Stage::GetCurrent().Add(actor);
374 // By default, none of the faces should be culled
375 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
376 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
378 TestGlAbstraction& gl = application.GetGlAbstraction();
379 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
380 gl.EnableCullFaceCallTrace(true);
383 cullFaceStack.Reset();
384 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
385 application.SendNotification();
386 application.Render();
388 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
390 std::ostringstream cullModeString;
391 cullModeString << GL_FRONT_AND_BACK;
393 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
394 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
395 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
399 cullFaceStack.Reset();
400 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
401 application.SendNotification();
402 application.Render();
404 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
406 std::ostringstream cullModeString;
407 cullModeString << GL_BACK;
409 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
410 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
411 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
415 cullFaceStack.Reset();
416 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
417 application.SendNotification();
418 application.Render();
420 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
422 std::ostringstream cullModeString;
423 cullModeString << GL_FRONT;
425 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
426 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
427 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
431 cullFaceStack.Reset();
432 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
433 application.SendNotification();
434 application.Render();
436 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
437 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
438 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
444 int UtcDaliRendererBlendOptions01(void)
446 TestApplication application;
448 tet_infoline("Test BLEND_FACTOR properties ");
450 Geometry geometry = CreateQuadGeometry();
451 Shader shader = CreateShader();
452 Renderer renderer = Renderer::New( geometry, shader );
454 Actor actor = Actor::New();
455 // set a transparent actor color so that blending is enabled
456 actor.SetProperty( Actor::Property::OPACITY, 0.5f );
457 actor.AddRenderer(renderer);
458 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
459 Stage::GetCurrent().Add(actor);
461 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
462 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
463 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
464 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
466 // Test that Set was successful:
467 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
468 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
469 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
470 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
472 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
473 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
474 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
475 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
477 application.SendNotification();
478 application.Render();
480 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
482 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
483 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
484 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
485 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
490 int UtcDaliRendererBlendOptions02(void)
492 TestApplication application;
494 tet_infoline("Test BLEND_FACTOR properties ");
496 Geometry geometry = CreateQuadGeometry();
497 Shader shader = CreateShader();
498 Renderer renderer = Renderer::New( geometry, shader );
500 Actor actor = Actor::New();
501 actor.SetProperty( Actor::Property::OPACITY, 0.5f ); // enable blending
502 actor.AddRenderer(renderer);
503 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
504 Stage::GetCurrent().Add(actor);
506 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
507 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
508 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
509 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
511 // Test that Set was successful:
513 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
514 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
515 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
516 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
518 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
519 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
520 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
521 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
524 application.SendNotification();
525 application.Render();
527 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
528 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
529 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
530 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
531 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
536 int UtcDaliRendererBlendOptions03(void)
538 TestApplication application;
540 tet_infoline("Test GetBlendEquation() defaults ");
542 Geometry geometry = CreateQuadGeometry();
543 Shader shader = CreateShader();
544 Renderer renderer = Renderer::New( geometry, shader );
546 Actor actor = Actor::New();
547 actor.AddRenderer(renderer);
548 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
549 Stage::GetCurrent().Add(actor);
551 // Test the defaults as documented in blending.h
552 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
553 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
555 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
556 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
561 int UtcDaliRendererBlendOptions04(void)
563 TestApplication application;
565 tet_infoline("Test SetBlendEquation() ");
567 Geometry geometry = CreateQuadGeometry();
568 Shader shader = CreateShader();
569 Renderer renderer = Renderer::New( geometry, shader );
571 Actor actor = Actor::New();
572 actor.SetProperty( Actor::Property::OPACITY, 0.1f );
573 actor.AddRenderer(renderer);
574 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
575 Stage::GetCurrent().Add(actor);
577 // Test the single blending equation setting
579 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
580 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
581 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
584 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
585 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
587 // Test that Set was successful
589 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
590 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
591 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
592 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
595 // Render & check GL commands
596 application.SendNotification();
597 application.Render();
599 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
600 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
601 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
606 int UtcDaliRendererSetBlendMode01(void)
608 TestApplication application;
610 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
612 Geometry geometry = CreateQuadGeometry();
613 Shader shader = CreateShader();
614 Renderer renderer = Renderer::New( geometry, shader );
616 Actor actor = Actor::New();
617 actor.SetProperty( Actor::Property::OPACITY, 0.98f );
618 actor.AddRenderer(renderer);
619 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
620 Stage::GetCurrent().Add(actor);
622 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
624 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
625 glAbstraction.EnableEnableDisableCallTrace(true);
627 application.SendNotification();
628 application.Render();
630 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
631 std::ostringstream blendStr;
632 blendStr << GL_BLEND;
633 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
638 int UtcDaliRendererSetBlendMode01b(void)
640 TestApplication application;
642 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
644 Geometry geometry = CreateQuadGeometry();
645 Shader shader = CreateShader();
646 Renderer renderer = Renderer::New( geometry, shader );
648 Actor actor = Actor::New();
649 actor.SetProperty( Actor::Property::OPACITY, 0.0f );
650 actor.AddRenderer(renderer);
651 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
652 Stage::GetCurrent().Add(actor);
654 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
656 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
657 glAbstraction.EnableEnableDisableCallTrace(true);
658 glAbstraction.EnableDrawCallTrace( true );
660 application.SendNotification();
661 application.Render();
663 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
664 std::ostringstream blendStr;
665 blendStr << GL_BLEND;
666 DALI_TEST_CHECK( !glEnableStack.FindMethod( "Enable" ) );
668 DALI_TEST_CHECK( !glAbstraction.GetDrawTrace().FindMethod( "DrawElements" ) );
673 int UtcDaliRendererSetBlendMode02(void)
675 TestApplication application;
677 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
679 Geometry geometry = CreateQuadGeometry();
680 Shader shader = CreateShader();
681 Renderer renderer = Renderer::New( geometry, shader );
683 Actor actor = Actor::New();
684 actor.SetProperty( Actor::Property::OPACITY, 0.15f );
685 actor.AddRenderer(renderer);
686 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
687 Stage::GetCurrent().Add(actor);
689 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
691 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
692 glAbstraction.EnableEnableDisableCallTrace(true);
694 application.SendNotification();
695 application.Render();
697 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
698 std::ostringstream blendStr;
699 blendStr << GL_BLEND;
700 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
705 int UtcDaliRendererSetBlendMode03(void)
707 TestApplication application;
709 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
711 Geometry geometry = CreateQuadGeometry();
712 Shader shader = CreateShader();
713 Renderer renderer = Renderer::New( geometry, shader );
715 Actor actor = Actor::New();
716 actor.SetProperty( Actor::Property::OPACITY, 0.75f );
717 actor.AddRenderer(renderer);
718 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
719 Stage::GetCurrent().Add(actor);
721 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
723 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
724 glAbstraction.EnableEnableDisableCallTrace(true);
726 application.SendNotification();
727 application.Render();
729 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
730 std::ostringstream blendStr;
731 blendStr << GL_BLEND;
732 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
737 int UtcDaliRendererSetBlendMode04(void)
739 TestApplication application;
741 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
743 Geometry geometry = CreateQuadGeometry();
744 Shader shader = CreateShader();
745 Renderer renderer = Renderer::New( geometry, shader );
747 Actor actor = Actor::New();
748 actor.AddRenderer(renderer);
749 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
750 Stage::GetCurrent().Add(actor);
752 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
754 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
755 glAbstraction.EnableEnableDisableCallTrace(true);
757 application.SendNotification();
758 application.Render();
760 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
761 std::ostringstream blendStr;
762 blendStr << GL_BLEND;
763 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
768 int UtcDaliRendererSetBlendMode04b(void)
770 TestApplication application;
772 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
774 Geometry geometry = CreateQuadGeometry();
775 Shader shader = CreateShader();
776 Renderer renderer = Renderer::New( geometry, shader );
778 Actor actor = Actor::New();
779 actor.AddRenderer(renderer);
780 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
781 actor.SetProperty( Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
782 Stage::GetCurrent().Add(actor);
784 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
786 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
787 glAbstraction.EnableEnableDisableCallTrace(true);
789 application.SendNotification();
790 application.Render();
792 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
793 std::ostringstream blendStr;
794 blendStr << GL_BLEND;
795 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
800 int UtcDaliRendererSetBlendMode04c(void)
802 TestApplication application;
804 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
806 Geometry geometry = CreateQuadGeometry();
807 Shader shader = CreateShader();
808 Renderer renderer = Renderer::New( geometry, shader );
810 Actor actor = Actor::New();
811 actor.AddRenderer(renderer);
812 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
813 actor.SetProperty( Actor::Property::COLOR, Color::MAGENTA );
814 Stage::GetCurrent().Add(actor);
816 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
818 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
819 glAbstraction.EnableEnableDisableCallTrace(true);
821 application.SendNotification();
822 application.Render();
824 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
825 std::ostringstream blendStr;
826 blendStr << GL_BLEND;
827 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
832 int UtcDaliRendererSetBlendMode05(void)
834 TestApplication application;
836 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
838 Geometry geometry = CreateQuadGeometry();
839 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
841 Shader shader = CreateShader();
842 TextureSet textureSet = CreateTextureSet( image );
843 Renderer renderer = Renderer::New( geometry, shader );
844 renderer.SetTextures( textureSet );
846 Actor actor = Actor::New();
847 actor.AddRenderer(renderer);
848 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
849 Stage::GetCurrent().Add(actor);
851 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
853 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
854 glAbstraction.EnableEnableDisableCallTrace(true);
856 application.SendNotification();
857 application.Render();
859 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
860 std::ostringstream blendStr;
861 blendStr << GL_BLEND;
862 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
867 int UtcDaliRendererSetBlendMode06(void)
869 TestApplication application;
870 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");
872 Geometry geometry = CreateQuadGeometry();
873 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
875 Renderer renderer = Renderer::New( geometry, shader );
877 Actor actor = Actor::New();
878 actor.AddRenderer(renderer);
879 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
880 Stage::GetCurrent().Add(actor);
882 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
884 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
885 glAbstraction.EnableEnableDisableCallTrace(true);
887 application.SendNotification();
888 application.Render();
890 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
891 std::ostringstream blendStr;
892 blendStr << GL_BLEND;
893 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
898 int UtcDaliRendererSetBlendMode07(void)
900 TestApplication application;
901 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");
903 Geometry geometry = CreateQuadGeometry();
904 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
906 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
907 TextureSet textureSet = CreateTextureSet( image );
908 Renderer renderer = Renderer::New( geometry, shader );
909 renderer.SetTextures( textureSet );
911 Actor actor = Actor::New();
912 actor.AddRenderer(renderer);
913 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
914 Stage::GetCurrent().Add(actor);
916 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
918 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
919 glAbstraction.EnableEnableDisableCallTrace(true);
921 application.SendNotification();
922 application.Render();
924 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
925 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
930 int UtcDaliRendererGetBlendMode(void)
932 TestApplication application;
934 tet_infoline("Test GetBlendMode()");
936 Geometry geometry = CreateQuadGeometry();
937 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
938 Renderer renderer = Renderer::New( geometry, shader );
941 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
942 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
945 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
946 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
947 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
950 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
951 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
952 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
957 int UtcDaliRendererSetBlendColor(void)
959 TestApplication application;
961 tet_infoline("Test SetBlendColor(color)");
963 Geometry geometry = CreateQuadGeometry();
964 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
965 TextureSet textureSet = TextureSet::New();
966 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
967 textureSet.SetTexture(0u, image);
968 Renderer renderer = Renderer::New( geometry, shader );
969 renderer.SetTextures( textureSet );
971 Actor actor = Actor::New();
972 actor.AddRenderer(renderer);
973 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
974 Stage::GetCurrent().Add(actor);
976 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
978 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
980 application.SendNotification();
981 application.Render();
983 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
984 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
985 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
987 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
989 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
990 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
992 application.SendNotification();
993 application.Render();
995 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
996 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
998 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
999 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1000 application.SendNotification();
1001 application.Render();
1002 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
1007 int UtcDaliRendererGetBlendColor(void)
1009 TestApplication application;
1011 tet_infoline("Test GetBlendColor()");
1013 Geometry geometry = CreateQuadGeometry();
1014 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1015 Renderer renderer = Renderer::New( geometry, shader );
1017 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
1019 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
1020 application.SendNotification();
1021 application.Render();
1022 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
1024 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1025 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1026 application.SendNotification();
1027 application.Render();
1028 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
1033 int UtcDaliRendererPreMultipledAlpha(void)
1035 TestApplication application;
1037 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1039 Geometry geometry = CreateQuadGeometry();
1040 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1041 Renderer renderer = Renderer::New( geometry, shader );
1043 Actor actor = Actor::New();
1044 actor.AddRenderer(renderer);
1045 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1046 actor.SetProperty( Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
1047 Stage::GetCurrent().Add(actor);
1049 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1050 bool preMultipliedAlpha;
1051 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1052 DALI_TEST_CHECK( !preMultipliedAlpha );
1054 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1055 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1056 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1057 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1059 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
1060 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
1061 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
1062 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
1064 application.SendNotification();
1065 application.Render();
1067 Vector4 actualValue(Vector4::ZERO);
1068 TestGlAbstraction& gl = application.GetGlAbstraction();
1069 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1070 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
1072 // Enable pre-multiplied alpha
1073 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1075 application.SendNotification();
1076 application.Render();
1078 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1079 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1080 DALI_TEST_CHECK( preMultipliedAlpha );
1082 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1083 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1084 DALI_TEST_CHECK( preMultipliedAlpha );
1086 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1087 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1088 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1089 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1091 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
1092 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1093 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1094 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1096 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1097 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
1099 // Disable pre-multiplied alpha again
1100 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false );
1102 application.SendNotification();
1103 application.Render();
1105 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1106 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1107 DALI_TEST_CHECK( !preMultipliedAlpha );
1109 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1110 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1111 DALI_TEST_CHECK( !preMultipliedAlpha );
1113 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1114 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1115 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1116 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1118 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1119 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1120 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1121 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1123 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1124 DALI_TEST_EQUALS( actualValue, Vector4( 1.0f, 0.0f, 1.0f, 0.5f ), TEST_LOCATION );
1129 int UtcDaliRendererConstraint01(void)
1131 TestApplication application;
1133 tet_infoline("Test that a non-uniform renderer property can be constrained");
1135 Shader shader = Shader::New("VertexSource", "FragmentSource");
1136 Geometry geometry = CreateQuadGeometry();
1137 Renderer renderer = Renderer::New( geometry, shader );
1139 Actor actor = Actor::New();
1140 actor.AddRenderer(renderer);
1141 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1142 Stage::GetCurrent().Add(actor);
1144 Vector4 initialColor = Color::WHITE;
1145 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1147 application.SendNotification();
1148 application.Render(0);
1149 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1152 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1154 application.SendNotification();
1155 application.Render(0);
1157 // Expect no blue component in either buffer - yellow
1158 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1159 application.Render(0);
1160 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1162 renderer.RemoveConstraints();
1163 renderer.SetProperty(colorIndex, Color::WHITE );
1164 application.SendNotification();
1165 application.Render(0);
1166 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1171 int UtcDaliRendererConstraint02(void)
1173 TestApplication application;
1175 tet_infoline("Test that a uniform map renderer property can be constrained");
1177 Shader shader = Shader::New("VertexSource", "FragmentSource");
1178 Geometry geometry = CreateQuadGeometry();
1179 Renderer renderer = Renderer::New( geometry, shader );
1181 Actor actor = Actor::New();
1182 actor.AddRenderer(renderer);
1183 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1184 Stage::GetCurrent().Add(actor);
1185 application.SendNotification();
1186 application.Render(0);
1188 Vector4 initialColor = Color::WHITE;
1189 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1191 TestGlAbstraction& gl = application.GetGlAbstraction();
1193 application.SendNotification();
1194 application.Render(0);
1196 Vector4 actualValue(Vector4::ZERO);
1197 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1198 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1201 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1203 application.SendNotification();
1204 application.Render(0);
1206 // Expect no blue component in either buffer - yellow
1207 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1208 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1210 application.Render(0);
1211 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1212 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1214 renderer.RemoveConstraints();
1215 renderer.SetProperty(colorIndex, Color::WHITE );
1216 application.SendNotification();
1217 application.Render(0);
1219 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1220 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1225 int UtcDaliRendererAnimatedProperty01(void)
1227 TestApplication application;
1229 tet_infoline("Test that a non-uniform renderer property can be animated");
1231 Shader shader = Shader::New("VertexSource", "FragmentSource");
1232 Geometry geometry = CreateQuadGeometry();
1233 Renderer renderer = Renderer::New( geometry, shader );
1235 Actor actor = Actor::New();
1236 actor.AddRenderer(renderer);
1237 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1238 Stage::GetCurrent().Add(actor);
1240 Vector4 initialColor = Color::WHITE;
1241 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1243 application.SendNotification();
1244 application.Render(0);
1245 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1247 Animation animation = Animation::New(1.0f);
1248 KeyFrames keyFrames = KeyFrames::New();
1249 keyFrames.Add(0.0f, initialColor);
1250 keyFrames.Add(1.0f, Color::TRANSPARENT);
1251 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1254 application.SendNotification();
1255 application.Render(500);
1257 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1259 application.Render(500);
1261 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1266 int UtcDaliRendererAnimatedProperty02(void)
1268 TestApplication application;
1270 tet_infoline("Test that a uniform map renderer property can be animated");
1272 Shader shader = Shader::New("VertexSource", "FragmentSource");
1273 Geometry geometry = CreateQuadGeometry();
1274 Renderer renderer = Renderer::New( geometry, shader );
1276 Actor actor = Actor::New();
1277 actor.AddRenderer(renderer);
1278 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1279 Stage::GetCurrent().Add(actor);
1280 application.SendNotification();
1281 application.Render(0);
1283 Vector4 initialColor = Color::WHITE;
1284 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1286 TestGlAbstraction& gl = application.GetGlAbstraction();
1288 application.SendNotification();
1289 application.Render(0);
1291 Vector4 actualValue(Vector4::ZERO);
1292 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1293 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1295 Animation animation = Animation::New(1.0f);
1296 KeyFrames keyFrames = KeyFrames::New();
1297 keyFrames.Add(0.0f, initialColor);
1298 keyFrames.Add(1.0f, Color::TRANSPARENT);
1299 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1302 application.SendNotification();
1303 application.Render(500);
1305 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1306 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1308 application.Render(500);
1309 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1310 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1315 int UtcDaliRendererUniformMapPrecendence01(void)
1317 TestApplication application;
1319 tet_infoline("Test the uniform map precedence is applied properly");
1321 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1323 Shader shader = Shader::New("VertexSource", "FragmentSource");
1324 TextureSet textureSet = CreateTextureSet( image );
1326 Geometry geometry = CreateQuadGeometry();
1327 Renderer renderer = Renderer::New( geometry, shader );
1328 renderer.SetTextures( textureSet );
1330 Actor actor = Actor::New();
1331 actor.AddRenderer(renderer);
1332 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1333 Stage::GetCurrent().Add(actor);
1334 application.SendNotification();
1335 application.Render(0);
1337 renderer.RegisterProperty( "uFadeColor", Color::RED );
1338 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1339 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1341 TestGlAbstraction& gl = application.GetGlAbstraction();
1343 application.SendNotification();
1344 application.Render(0);
1346 // Expect that the actor's fade color property is accessed
1347 Vector4 actualValue(Vector4::ZERO);
1348 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1349 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1351 // Animate shader's fade color property. Should be no change to uniform
1352 Animation animation = Animation::New(1.0f);
1353 KeyFrames keyFrames = KeyFrames::New();
1354 keyFrames.Add(0.0f, Color::WHITE);
1355 keyFrames.Add(1.0f, Color::TRANSPARENT);
1356 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1359 application.SendNotification();
1360 application.Render(500);
1362 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1363 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1365 application.Render(500);
1366 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1367 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1372 int UtcDaliRendererUniformMapPrecendence02(void)
1374 TestApplication application;
1376 tet_infoline("Test the uniform map precedence is applied properly");
1378 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1380 Shader shader = Shader::New("VertexSource", "FragmentSource");
1381 TextureSet textureSet = CreateTextureSet( image );
1383 Geometry geometry = CreateQuadGeometry();
1384 Renderer renderer = Renderer::New( geometry, shader );
1385 renderer.SetTextures( textureSet );
1387 Actor actor = Actor::New();
1388 actor.AddRenderer(renderer);
1389 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1390 Stage::GetCurrent().Add(actor);
1391 application.SendNotification();
1392 application.Render(0);
1394 // Don't add property / uniform map to renderer
1395 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1396 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1398 TestGlAbstraction& gl = application.GetGlAbstraction();
1400 application.SendNotification();
1401 application.Render(0);
1403 // Expect that the actor's fade color property is accessed
1404 Vector4 actualValue(Vector4::ZERO);
1405 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1406 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1408 // Animate texture set's fade color property. Should be no change to uniform
1409 Animation animation = Animation::New(1.0f);
1410 KeyFrames keyFrames = KeyFrames::New();
1411 keyFrames.Add(0.0f, Color::WHITE);
1412 keyFrames.Add(1.0f, Color::TRANSPARENT);
1413 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1416 application.SendNotification();
1417 application.Render(500);
1419 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1420 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1422 application.Render(500);
1423 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1424 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1430 int UtcDaliRendererUniformMapPrecendence03(void)
1432 TestApplication application;
1434 tet_infoline("Test the uniform map precedence is applied properly");
1436 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1438 Shader shader = Shader::New("VertexSource", "FragmentSource");
1439 TextureSet textureSet = CreateTextureSet( image );
1441 Geometry geometry = CreateQuadGeometry();
1442 Renderer renderer = Renderer::New( geometry, shader );
1443 renderer.SetTextures( textureSet );
1445 Actor actor = Actor::New();
1446 actor.AddRenderer(renderer);
1447 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1448 Stage::GetCurrent().Add(actor);
1449 application.SendNotification();
1450 application.Render(0);
1452 // Don't add property / uniform map to renderer or actor
1453 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1455 TestGlAbstraction& gl = application.GetGlAbstraction();
1457 application.SendNotification();
1458 application.Render(0);
1460 // Expect that the shader's fade color property is accessed
1461 Vector4 actualValue(Vector4::ZERO);
1462 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1463 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1468 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1470 TestApplication application;
1472 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1474 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1476 Shader shader = Shader::New("VertexSource", "FragmentSource");
1477 TextureSet textureSet = CreateTextureSet( image );
1479 Geometry geometry = CreateQuadGeometry();
1480 Renderer renderer = Renderer::New( geometry, shader );
1481 renderer.SetTextures( textureSet );
1483 Actor actor = Actor::New();
1484 actor.AddRenderer(renderer);
1485 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1486 Stage::GetCurrent().Add(actor);
1487 application.SendNotification();
1488 application.Render(0);
1490 renderer.RegisterProperty( "uUniform1", Color::RED );
1491 actor.RegisterProperty( "uUniform2", Color::GREEN );
1492 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1494 TestGlAbstraction& gl = application.GetGlAbstraction();
1496 application.SendNotification();
1497 application.Render(0);
1499 // Expect that each of the object's uniforms are set
1500 Vector4 uniform1Value(Vector4::ZERO);
1501 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1502 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1504 Vector4 uniform2Value(Vector4::ZERO);
1505 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1506 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1508 Vector4 uniform3Value(Vector4::ZERO);
1509 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1510 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1515 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1517 TestApplication application;
1519 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1521 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1523 Shader shader = Shader::New("VertexSource", "FragmentSource");
1524 TextureSet textureSet = CreateTextureSet( image );
1526 Geometry geometry = CreateQuadGeometry();
1527 Renderer renderer = Renderer::New( geometry, shader );
1528 renderer.SetTextures( textureSet );
1530 Actor actor = Actor::New();
1531 actor.AddRenderer(renderer);
1532 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
1533 Stage::GetCurrent().Add(actor);
1534 application.SendNotification();
1535 application.Render(0);
1537 Property::Value value1(Color::RED);
1538 renderer.RegisterProperty( "uFadeColor", value1 );
1540 Property::Value value2(1.0f);
1541 actor.RegisterProperty( "uFadeProgress", value2 );
1543 Property::Value value3(Matrix3::IDENTITY);
1544 shader.RegisterProperty( "uANormalMatrix", value3 );
1546 TestGlAbstraction& gl = application.GetGlAbstraction();
1548 application.SendNotification();
1549 application.Render(0);
1551 // Expect that each of the object's uniforms are set
1552 Vector4 uniform1Value(Vector4::ZERO);
1553 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1554 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1556 float uniform2Value(0.0f);
1557 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1558 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1560 Matrix3 uniform3Value;
1561 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1562 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1568 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1570 Texture image0 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
1571 TextureSet textureSet0 = CreateTextureSet( image0 );
1572 Renderer renderer0 = Renderer::New( geometry, shader );
1573 renderer0.SetTextures( textureSet0 );
1574 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1575 actor.AddRenderer(renderer0);
1580 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1582 Actor actor = Actor::New();
1583 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
1584 actor.SetProperty( Actor::Property::PARENT_ORIGIN,AnchorPoint::CENTER);
1585 actor.SetProperty( Actor::Property::POSITION, Vector2(0.0f,0.0f));
1586 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1588 actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1589 DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1594 int UtcDaliRendererRenderOrder2DLayer(void)
1596 TestApplication application;
1597 tet_infoline("Test the rendering order in a 2D layer is correct");
1599 Shader shader = Shader::New("VertexSource", "FragmentSource");
1600 Geometry geometry = CreateQuadGeometry();
1602 Actor root = Stage::GetCurrent().GetRootLayer();
1604 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1605 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1607 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1608 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1610 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1611 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1613 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1614 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1616 application.SendNotification();
1617 application.Render(0);
1620 * Create the following hierarchy:
1633 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1638 application.SendNotification();
1639 application.Render(0);
1641 TestGlAbstraction& gl = application.GetGlAbstraction();
1642 gl.EnableTextureCallTrace(true);
1643 application.SendNotification();
1644 application.Render(0);
1646 int textureBindIndex[4];
1647 for( unsigned int i(0); i<4; ++i )
1649 std::stringstream params;
1650 params << GL_TEXTURE_2D<<", "<<i+1;
1651 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1654 //Check that actor1 has been rendered after actor2
1655 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1657 //Check that actor0 has been rendered after actor1
1658 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1660 //Check that actor3 has been rendered after actor0
1661 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1666 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1668 TestApplication application;
1669 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1672 * Creates the following hierarchy:
1674 * actor0------------------------>actor1
1678 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1680 * renderer0 has depth index 2
1681 * renderer1 has depth index 0
1682 * renderer2 has depth index 1
1684 * renderer3 has depth index 1
1685 * renderer4 has depth index 0
1686 * renderer5 has depth index -1
1688 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1691 Shader shader = Shader::New("VertexSource", "FragmentSource");
1692 Geometry geometry = CreateQuadGeometry();
1694 Actor root = Stage::GetCurrent().GetRootLayer();
1696 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1697 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1698 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1699 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1700 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1701 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1702 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1703 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1705 application.SendNotification();
1706 application.Render(0);
1708 TestGlAbstraction& gl = application.GetGlAbstraction();
1709 gl.EnableTextureCallTrace(true);
1710 application.SendNotification();
1711 application.Render(0);
1713 int textureBindIndex[6];
1714 for( unsigned int i(0); i<6; ++i )
1716 std::stringstream params;
1717 params << GL_TEXTURE_2D<<", "<<i+1;
1718 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1721 //Check that renderer3 has been rendered after renderer4
1722 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1724 //Check that renderer0 has been rendered after renderer2
1725 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1727 //Check that renderer5 has been rendered after renderer2
1728 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1730 //Check that renderer0 has been rendered after renderer2
1731 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1733 //Check that renderer2 has been rendered after renderer1
1734 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1740 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1742 TestApplication application;
1743 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1746 * Creates the following hierarchy:
1754 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1758 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1759 * DI:2 DI:0 | DI:0 DI:1 DI:2
1764 * actor0 has sibling order 1
1765 * actor1 has sibling order 0
1766 * actor2 has sibling order 0
1768 * renderer0 has depth index 2
1769 * renderer1 has depth index 0
1771 * renderer2 has depth index 0
1772 * renderer3 has depth index 1
1773 * renderer4 has depth index 2
1775 * renderer5 has depth index -1
1777 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1780 Shader shader = Shader::New("VertexSource", "FragmentSource");
1781 Geometry geometry = CreateQuadGeometry();
1782 Actor root = Stage::GetCurrent().GetRootLayer();
1783 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1784 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1785 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1787 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1788 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1789 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1790 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1791 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1792 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1794 application.SendNotification();
1795 application.Render();
1797 TestGlAbstraction& gl = application.GetGlAbstraction();
1798 gl.EnableTextureCallTrace(true);
1799 application.SendNotification();
1800 application.Render(0);
1802 int textureBindIndex[6];
1803 for( unsigned int i(0); i<6; ++i )
1805 std::stringstream params;
1806 params << GL_TEXTURE_2D<<", "<<i+1;
1807 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1810 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1811 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1812 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1813 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1814 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1815 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1817 // Change sibling order of actor1
1818 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1819 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1821 gl.GetTextureTrace().Reset();
1822 application.SendNotification();
1823 application.Render(0);
1825 for( unsigned int i(0); i<6; ++i )
1827 std::stringstream params;
1828 params << GL_TEXTURE_2D<<", "<<i+1;
1829 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1832 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1833 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1834 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1835 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1836 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1837 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1842 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1844 TestApplication application;
1845 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1847 Shader shader = Shader::New("VertexSource", "FragmentSource");
1848 Geometry geometry = CreateQuadGeometry();
1849 Actor root = Stage::GetCurrent().GetRootLayer();
1852 * Create the following hierarchy:
1859 * (Overlay) (Regular actor)
1869 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1872 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1873 actor0.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
1874 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1876 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1877 actor1.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
1878 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1880 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1881 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1883 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1884 actor3.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
1885 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1887 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1888 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1890 application.SendNotification();
1891 application.Render(0);
1898 TestGlAbstraction& gl = application.GetGlAbstraction();
1899 gl.EnableTextureCallTrace(true);
1900 application.SendNotification();
1901 application.Render(0);
1903 int textureBindIndex[5];
1904 for( unsigned int i(0); i<5; ++i )
1906 std::stringstream params;
1907 params << GL_TEXTURE_2D<<", "<<i+1;
1908 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1911 //Check that actor4 has been rendered after actor2
1912 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1914 //Check that actor1 has been rendered after actor4
1915 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1917 //Check that actor0 has been rendered after actor1
1918 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1920 //Check that actor3 has been rendered after actor0
1921 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1926 int UtcDaliRendererSetIndexRange(void)
1930 "attribute vec2 aPosition;\n"
1933 " gl_Position = aPosition;\n"
1939 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1943 TestApplication application;
1944 tet_infoline("Test setting the range of indices to draw");
1946 TestGlAbstraction& gl = application.GetGlAbstraction();
1947 gl.EnableDrawCallTrace( true );
1949 Actor actor = Actor::New();
1950 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1953 Geometry geometry = Geometry::New();
1954 geometry.SetType( Geometry::LINE_LOOP );
1956 // --------------------------------------------------------------------------
1958 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1959 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1960 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1962 // --------------------------------------------------------------------------
1971 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1972 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1973 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1974 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1975 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1977 Property::Map vertexFormat;
1978 vertexFormat["aPosition"] = Property::VECTOR2;
1979 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1980 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1982 // --------------------------------------------------------------------------
1983 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1984 geometry.AddVertexBuffer( vertexBuffer );
1987 Shader shader = Shader::New( vertexShader,fragmentShader );
1988 Renderer renderer = Renderer::New( geometry, shader );
1989 actor.AddRenderer( renderer );
1991 Stage stage = Stage::GetCurrent();
1996 // LINE_LOOP, first 0, count 5
1998 renderer.SetIndexRange( 0, 5 );
1999 application.SendNotification();
2000 application.Render();
2002 Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST );
2004 DALI_TEST_CHECK( value.Get( convertedValue ) );
2005 DALI_TEST_CHECK( convertedValue == 0 );
2007 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST );
2008 DALI_TEST_CHECK( value.Get( convertedValue ) );
2009 DALI_TEST_CHECK( convertedValue == 0 );
2011 value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT );
2012 DALI_TEST_CHECK( value.Get( convertedValue ) );
2013 DALI_TEST_CHECK( convertedValue == 5 );
2015 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT );
2016 DALI_TEST_CHECK( value.Get( convertedValue ) );
2017 DALI_TEST_CHECK( convertedValue == 5 );
2019 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2020 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2021 DALI_TEST_CHECK( result );
2024 // LINE_LOOP, first 5, count 10
2026 renderer.SetIndexRange( 5, 10 );
2027 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2028 application.SendNotification();
2029 application.Render();
2030 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2031 DALI_TEST_CHECK( result );
2034 // LINE_STRIP, first 15, count 6
2036 renderer.SetIndexRange( 15, 6 );
2037 geometry.SetType( Geometry::LINE_STRIP );
2038 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2039 application.SendNotification();
2040 application.Render();
2041 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2042 DALI_TEST_CHECK( result );
2045 // Index out of bounds
2047 renderer.SetIndexRange( 15, 30 );
2048 geometry.SetType( Geometry::LINE_STRIP );
2049 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2050 application.SendNotification();
2051 application.Render();
2052 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2053 DALI_TEST_CHECK( result );
2056 // drawing whole buffer starting from 15 ( last valid primitive )
2058 renderer.SetIndexRange( 15, 0 );
2059 geometry.SetType( Geometry::LINE_STRIP );
2060 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2061 application.SendNotification();
2062 application.Render();
2063 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2064 DALI_TEST_CHECK( result );
2071 int UtcDaliRendererSetDepthFunction(void)
2073 TestApplication application;
2075 tet_infoline("Test setting the depth function");
2077 Geometry geometry = CreateQuadGeometry();
2078 Shader shader = CreateShader();
2079 Renderer renderer = Renderer::New( geometry, shader );
2081 Actor actor = Actor::New();
2082 actor.AddRenderer(renderer);
2083 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2084 Stage stage = Stage::GetCurrent();
2085 stage.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
2088 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2089 glAbstraction.EnableEnableDisableCallTrace(true);
2090 glAbstraction.EnableDepthFunctionCallTrace(true);
2092 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2093 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2095 std::ostringstream depthTestStr;
2096 depthTestStr << GL_DEPTH_TEST;
2100 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2102 glEnableDisableStack.Reset();
2103 glDepthFunctionStack.Reset();
2104 application.SendNotification();
2105 application.Render();
2107 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2108 std::ostringstream depthFunctionStr;
2109 depthFunctionStr << GL_NEVER;
2110 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2115 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2117 glDepthFunctionStack.Reset();
2118 application.SendNotification();
2119 application.Render();
2121 std::ostringstream depthFunctionStr;
2122 depthFunctionStr << GL_ALWAYS;
2123 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2128 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2130 glDepthFunctionStack.Reset();
2131 application.SendNotification();
2132 application.Render();
2134 std::ostringstream depthFunctionStr;
2135 depthFunctionStr << GL_LESS;
2136 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2141 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2143 glDepthFunctionStack.Reset();
2144 application.SendNotification();
2145 application.Render();
2147 std::ostringstream depthFunctionStr;
2148 depthFunctionStr << GL_GREATER;
2149 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2154 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2156 glDepthFunctionStack.Reset();
2157 application.SendNotification();
2158 application.Render();
2160 std::ostringstream depthFunctionStr;
2161 depthFunctionStr << GL_EQUAL;
2162 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2167 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2169 glDepthFunctionStack.Reset();
2170 application.SendNotification();
2171 application.Render();
2173 std::ostringstream depthFunctionStr;
2174 depthFunctionStr << GL_NOTEQUAL;
2175 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2180 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2182 glDepthFunctionStack.Reset();
2183 application.SendNotification();
2184 application.Render();
2186 std::ostringstream depthFunctionStr;
2187 depthFunctionStr << GL_LEQUAL;
2188 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2193 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2195 glDepthFunctionStack.Reset();
2196 application.SendNotification();
2197 application.Render();
2199 std::ostringstream depthFunctionStr;
2200 depthFunctionStr << GL_GEQUAL;
2201 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2208 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2209 * The checks performed are as follows:
2210 * - Check the initial/default value.
2211 * - Set a different value via enum.
2212 * - Check it was set.
2213 * - Set a different value via string.
2214 * - Check it was set.
2216 template< typename T >
2217 void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2219 application.SendNotification();
2220 application.Render();
2222 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2223 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2224 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2225 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2226 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( firstCheckEnumeration ) );
2228 application.SendNotification();
2229 application.Render();
2231 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2232 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2234 renderer.SetProperty( propertyIndex, secondCheckString );
2235 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2236 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( secondCheckEnumeration ) );
2238 application.SendNotification();
2239 application.Render();
2241 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2242 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2245 int UtcDaliRendererEnumProperties(void)
2247 TestApplication application;
2248 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2250 Geometry geometry = CreateQuadGeometry();
2251 Shader shader = CreateShader();
2252 Renderer renderer = Renderer::New( geometry, shader );
2254 Actor actor = Actor::New();
2255 actor.AddRenderer(renderer);
2256 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2257 Stage::GetCurrent().Add(actor);
2260 * Here we use a templatized function to perform several checks on each enumeration property.
2261 * @see CheckEnumerationProperty for details of the checks performed.
2264 CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2265 CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2266 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2267 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2268 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2269 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2270 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2271 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2272 CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2273 CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2274 CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2275 CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2276 CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2277 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2278 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2279 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2284 Renderer RendererTestFixture( TestApplication& application )
2286 Geometry geometry = CreateQuadGeometry();
2287 Shader shader = CreateShader();
2288 Renderer renderer = Renderer::New( geometry, shader );
2290 Actor actor = Actor::New();
2291 actor.AddRenderer( renderer );
2292 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2293 Stage stage = Stage::GetCurrent();
2294 stage.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
2300 int UtcDaliRendererSetDepthTestMode(void)
2302 TestApplication application;
2303 tet_infoline("Test setting the DepthTestMode");
2305 Renderer renderer = RendererTestFixture( application );
2306 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2307 glAbstraction.EnableEnableDisableCallTrace( true );
2308 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2310 glEnableDisableStack.Reset();
2311 application.SendNotification();
2312 application.Render();
2314 // Check depth-test is enabled by default.
2315 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2316 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2318 // 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.
2319 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2320 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2322 glEnableDisableStack.Reset();
2323 application.SendNotification();
2324 application.Render();
2326 // Check the depth buffer was disabled.
2327 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2329 // Turn on automatic mode depth-testing.
2330 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2331 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2333 glEnableDisableStack.Reset();
2334 application.SendNotification();
2335 application.Render();
2337 // Check depth-test is now enabled.
2338 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2339 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2341 // Change the layer behavior to LAYER_UI.
2342 // Note this will also disable depth testing for the layer by default, we test this first.
2343 Stage::GetCurrent().GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI );
2345 glEnableDisableStack.Reset();
2346 application.SendNotification();
2347 application.Render();
2349 // Check depth-test is disabled.
2350 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2352 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2353 Stage::GetCurrent().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true );
2355 glEnableDisableStack.Reset();
2356 application.SendNotification();
2357 application.Render();
2359 // Check depth-test is *still* disabled.
2360 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2365 int UtcDaliRendererSetDepthWriteMode(void)
2367 TestApplication application;
2368 tet_infoline("Test setting the DepthWriteMode");
2370 Renderer renderer = RendererTestFixture( application );
2371 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2373 application.SendNotification();
2374 application.Render();
2376 // Check the default depth-write status first.
2377 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2379 // Turn off depth-writing.
2380 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2382 application.SendNotification();
2383 application.Render();
2385 // Check depth-write is now disabled.
2386 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2388 // Test the AUTO mode for depth-writing.
2389 // As our renderer is opaque, depth-testing should be enabled.
2390 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2392 application.SendNotification();
2393 application.Render();
2395 // Check depth-write is now enabled.
2396 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2398 // Now make the renderer be treated as translucent by enabling blending.
2399 // The AUTO depth-write mode should turn depth-write off in this scenario.
2400 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2402 application.SendNotification();
2403 application.Render();
2405 // Check depth-write is now disabled.
2406 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2411 int UtcDaliRendererCheckStencilDefaults(void)
2413 TestApplication application;
2414 tet_infoline("Test the stencil defaults");
2416 Renderer renderer = RendererTestFixture( application );
2417 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2418 glAbstraction.EnableEnableDisableCallTrace( true );
2419 glAbstraction.EnableStencilFunctionCallTrace( true );
2420 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2421 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2423 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2425 // Check the defaults:
2426 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2427 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2428 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2429 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2430 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2431 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 );
2432 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 );
2437 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2439 TestApplication application;
2440 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2442 Renderer renderer = RendererTestFixture( application );
2443 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2444 glAbstraction.EnableEnableDisableCallTrace( true );
2445 glAbstraction.EnableStencilFunctionCallTrace( true );
2446 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2447 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2449 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2450 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2451 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2452 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2454 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2455 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2457 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2458 std::string methodString( "StencilFunc" );
2459 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2461 // Test the other RenderModes that will not enable the stencil buffer.
2462 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2463 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2464 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2466 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2467 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2468 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2470 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2471 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2472 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2474 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2475 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2477 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2478 // First set a mode to turn off the stencil buffer, so the enable is required.
2479 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2480 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2481 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2482 // Set a different stencil function as the last one is cached.
2483 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS );
2484 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2486 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2487 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2492 // Helper function for the SetRenderModeToUseColorBuffer test.
2493 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2495 // Set the RenderMode property to a value that should not allow color buffer writes.
2496 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2497 application.SendNotification();
2498 application.Render();
2500 // Check if ColorMask has been called, and that the values are correct.
2501 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2502 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2504 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2505 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2506 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2507 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2510 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2512 TestApplication application;
2513 tet_infoline("Test setting the RenderMode to use the color buffer");
2515 Renderer renderer = RendererTestFixture( application );
2517 // Set the RenderMode property to a value that should not allow color buffer writes.
2518 // Then check if ColorMask has been called, and that the values are correct.
2519 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2520 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2521 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2522 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2523 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2528 int UtcDaliRendererSetStencilFunction(void)
2530 TestApplication application;
2531 tet_infoline("Test setting the StencilFunction");
2533 Renderer renderer = RendererTestFixture( application );
2534 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2535 glAbstraction.EnableEnableDisableCallTrace( true );
2536 glAbstraction.EnableStencilFunctionCallTrace( true );
2537 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2538 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2540 // RenderMode must use the stencil for StencilFunction to operate.
2541 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2542 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2545 * Lookup table for testing StencilFunction.
2546 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2548 const int StencilFunctionLookupTable[] = {
2557 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2560 * Loop through all types of StencilFunction, checking:
2561 * - The value is cached (set in event thread side)
2562 * - Causes "glStencilFunc" to be called
2563 * - Checks the correct parameters to "glStencilFunc" were used
2565 std::string nonChangingParameters = "0, 255";
2566 std::string methodString( "StencilFunc" );
2567 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2569 // Set the property.
2570 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2572 // Check GetProperty returns the same value.
2573 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2575 // Reset the trace debug.
2576 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2578 // Check the function is called and the parameters are correct.
2579 std::stringstream parameterStream;
2580 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2582 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2585 // Change the Function Reference only and check the behavior is correct:
2586 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2587 int testValueReference = 170;
2588 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2590 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2592 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2594 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2596 std::stringstream parameterStream;
2597 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2599 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2602 // Change the Function Mask only and check the behavior is correct:
2603 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2604 int testValueMask = 85;
2605 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2607 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2609 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2611 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2613 // Clear the stringstream.
2614 parameterStream.str( std::string() );
2615 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2617 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2622 int UtcDaliRendererSetStencilOperation(void)
2624 TestApplication application;
2625 tet_infoline("Test setting the StencilOperation");
2627 Renderer renderer = RendererTestFixture( application );
2628 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2629 glAbstraction.EnableEnableDisableCallTrace( true );
2630 glAbstraction.EnableStencilFunctionCallTrace( true );
2631 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2632 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2634 // RenderMode must use the stencil for StencilOperation to operate.
2635 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2638 * Lookup table for testing StencilOperation.
2639 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2641 const int StencilOperationLookupTable[] = {
2650 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2652 // Set all 3 StencilOperation properties to a default.
2653 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP );
2654 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2655 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2657 // Set our expected parameter list to the equivalent result.
2658 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2660 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2663 * Loop through all types of StencilOperation, checking:
2664 * - The value is cached (set in event thread side)
2665 * - Causes "glStencilFunc" to be called
2666 * - Checks the correct parameters to "glStencilFunc" were used
2667 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2669 std::string methodString( "StencilOp" );
2671 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2673 for( int j = 0; j < StencilOperationLookupTableCount; ++j )
2675 for( int k = 0; k < StencilOperationLookupTableCount; ++k )
2677 // Set the property (outer loop causes all 3 different properties to be set separately).
2678 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>( i ) );
2679 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>( j ) );
2680 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>( k ) );
2682 // Check GetProperty returns the same value.
2683 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), i, TEST_LOCATION );
2684 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), j, TEST_LOCATION );
2685 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), k, TEST_LOCATION );
2687 // Reset the trace debug.
2688 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2690 // Check the function is called and the parameters are correct.
2691 // Set the expected parameter value at its correct index (only)
2692 parameters[ 0u ] = StencilOperationLookupTable[ i ];
2693 parameters[ 1u ] = StencilOperationLookupTable[ j ];
2694 parameters[ 2u ] = StencilOperationLookupTable[ k ];
2696 // Build the parameter list.
2697 std::stringstream parameterStream;
2698 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2700 parameterStream << parameters[ parameterBuild ];
2701 // Comma-separate the parameters.
2702 if( parameterBuild < 2 )
2704 parameterStream << ", ";
2708 // Check the function was called and the parameters were correct.
2709 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2717 int UtcDaliRendererSetStencilMask(void)
2719 TestApplication application;
2720 tet_infoline("Test setting the StencilMask");
2722 Renderer renderer = RendererTestFixture( application );
2723 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2724 glAbstraction.EnableEnableDisableCallTrace( true );
2725 glAbstraction.EnableStencilFunctionCallTrace( true );
2726 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2727 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2729 // RenderMode must use the stencil for StencilMask to operate.
2730 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2732 // Set the StencilMask property to a value.
2733 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2735 // Check GetProperty returns the same value.
2736 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2738 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2740 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2742 std::string methodString( "StencilMask" );
2743 std::string parameterString = "0";
2745 // Check the function was called and the parameters were correct.
2746 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2748 // Set the StencilMask property to another value to ensure it has changed.
2749 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2751 // Check GetProperty returns the same value.
2752 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2754 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2756 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2758 parameterString = "255";
2760 // Check the function was called and the parameters were correct.
2761 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2766 int UtcDaliRendererWrongNumberOfTextures(void)
2768 TestApplication application;
2769 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2771 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2772 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2773 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2774 TextureSet textureSet = CreateTextureSet();
2775 textureSet.SetTexture(0, texture );
2776 textureSet.SetTexture(1, texture );
2777 textureSet.SetTexture(2, texture );
2778 textureSet.SetTexture(3, texture );
2779 Shader shader = Shader::New("VertexSource", "FragmentSource");
2780 Geometry geometry = CreateQuadGeometry();
2781 Renderer renderer = Renderer::New( geometry, shader );
2782 renderer.SetTextures( textureSet );
2784 Actor actor= Actor::New();
2785 actor.AddRenderer(renderer);
2786 actor.SetProperty( Actor::Property::POSITION, Vector2(0.0f,0.0f));
2787 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2788 Stage::GetCurrent().Add(actor);
2790 TestGlAbstraction& gl = application.GetGlAbstraction();
2791 TraceCallStack& drawTrace = gl.GetDrawTrace();
2793 drawTrace.Enable(true);
2795 application.SendNotification();
2796 application.Render(0);
2798 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2799 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2801 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2802 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2803 textureSet = CreateTextureSet();
2804 renderer.SetTextures( textureSet );
2805 textureSet.SetTexture(0, texture );
2807 application.SendNotification();
2808 application.Render(0);
2810 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2811 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2816 int UtcDaliRendererOpacity(void)
2818 TestApplication application;
2820 tet_infoline( "Test OPACITY property" );
2822 Geometry geometry = CreateQuadGeometry();
2823 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2824 Renderer renderer = Renderer::New( geometry, shader );
2826 Actor actor = Actor::New();
2827 actor.AddRenderer( renderer );
2828 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2829 actor.SetProperty( Actor::Property::COLOR, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2830 Stage::GetCurrent().Add( actor );
2832 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2834 DALI_TEST_CHECK( value.Get( opacity ) );
2835 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2837 application.SendNotification();
2838 application.Render();
2840 Vector4 actualValue;
2841 TestGlAbstraction& gl = application.GetGlAbstraction();
2842 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2843 DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2845 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f );
2847 application.SendNotification();
2848 application.Render();
2850 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2851 DALI_TEST_CHECK( value.Get( opacity ) );
2852 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2854 value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY );
2855 DALI_TEST_CHECK( value.Get( opacity ) );
2856 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2858 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2859 DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2864 int UtcDaliRendererOpacityAnimation(void)
2866 TestApplication application;
2868 tet_infoline( "Test OPACITY property animation" );
2870 Geometry geometry = CreateQuadGeometry();
2871 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2872 Renderer renderer = Renderer::New( geometry, shader );
2874 Actor actor = Actor::New();
2875 actor.AddRenderer( renderer );
2876 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2877 actor.SetProperty( Actor::Property::COLOR, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2878 Stage::GetCurrent().Add( actor );
2880 application.SendNotification();
2881 application.Render(0);
2883 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2885 DALI_TEST_CHECK( value.Get( opacity ) );
2886 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2888 Animation animation = Animation::New( 1.0f );
2889 animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f );
2892 application.SendNotification();
2893 application.Render( 1000 );
2895 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2896 DALI_TEST_CHECK( value.Get( opacity ) );
2897 DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2899 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
2901 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.1f );
2903 animation.AnimateBy( Property( renderer, DevelRenderer::Property::OPACITY ), 0.5f );
2906 application.SendNotification();
2907 application.Render( 1000 );
2909 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2910 DALI_TEST_CHECK( value.Get( opacity ) );
2911 DALI_TEST_EQUALS( opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2912 DALI_TEST_EQUALS( opacity, renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY ).Get< float >(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2917 int UtcDaliRendererInvalidProperty(void)
2919 TestApplication application;
2921 tet_infoline( "Test invalid property" );
2923 Geometry geometry = CreateQuadGeometry();
2924 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2925 Renderer renderer = Renderer::New( geometry, shader );
2927 Actor actor = Actor::New();
2928 actor.AddRenderer( renderer );
2929 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2930 Stage::GetCurrent().Add( actor );
2932 application.SendNotification();
2933 application.Render(0);
2935 Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 );
2936 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2938 value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 );
2939 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2944 int UtcDaliRendererRenderingBehavior(void)
2946 TestApplication application;
2948 tet_infoline( "Test RENDERING_BEHAVIOR property" );
2950 Geometry geometry = CreateQuadGeometry();
2951 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2952 Renderer renderer = Renderer::New( geometry, shader );
2954 Actor actor = Actor::New();
2955 actor.AddRenderer( renderer );
2956 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
2957 actor.SetProperty( Actor::Property::COLOR, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2958 Stage::GetCurrent().Add( actor );
2960 Property::Value value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2961 int renderingBehavior;
2962 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2963 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION );
2965 application.SendNotification();
2966 application.Render();
2968 uint32_t updateStatus = application.GetUpdateStatus();
2970 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
2972 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY );
2974 value = renderer.GetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2975 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2976 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2978 // Render and check the update status
2979 application.SendNotification();
2980 application.Render();
2982 updateStatus = application.GetUpdateStatus();
2984 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2986 value = renderer.GetCurrentProperty( DevelRenderer::Property::RENDERING_BEHAVIOR );
2987 DALI_TEST_CHECK( value.Get( renderingBehavior ) );
2988 DALI_TEST_EQUALS( static_cast< DevelRenderer::Rendering::Type >( renderingBehavior ), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION );
2990 // Render again and check the update status
2991 application.SendNotification();
2992 application.Render();
2994 updateStatus = application.GetUpdateStatus();
2996 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );
2998 // Change rendering behavior
2999 renderer.SetProperty( DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED );
3001 // Render and check the update status
3002 application.SendNotification();
3003 application.Render();
3005 updateStatus = application.GetUpdateStatus();
3007 DALI_TEST_CHECK( !( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING ) );
3012 int UtcDaliRendererRegenerateUniformMap(void)
3014 TestApplication application;
3016 tet_infoline( "Test regenerating uniform map when attaching renderer to the node" );
3018 Geometry geometry = CreateQuadGeometry();
3019 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
3020 Renderer renderer = Renderer::New( geometry, shader );
3022 Actor actor = Actor::New();
3023 actor.AddRenderer( renderer );
3024 actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
3025 actor.SetProperty( Actor::Property::COLOR, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
3026 Stage::GetCurrent().Add( actor );
3028 application.SendNotification();
3029 application.Render();
3031 actor.RemoveRenderer( renderer );
3032 shader = Shader::New( "vertexSrc", "fragmentSrc" );
3033 shader.RegisterProperty( "opacity", 0.5f );
3034 renderer.SetShader( shader );
3036 Stage::GetCurrent().KeepRendering( 1.0f );
3038 // Update for several frames
3039 application.SendNotification();
3040 application.Render();
3041 application.SendNotification();
3042 application.Render();
3043 application.SendNotification();
3044 application.Render();
3045 application.SendNotification();
3046 application.Render();
3049 actor.AddRenderer( renderer );
3050 application.SendNotification();
3051 application.Render();
3053 // Nothing to test here, the test must not crash
3054 auto updateStatus = application.GetUpdateStatus();
3055 DALI_TEST_CHECK( updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING );