2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/rendering/renderer-devel.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/images/texture-set-image.h>
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 )
209 Geometry geometry = CreateQuadGeometry();
210 Shader shader = CreateShader();
211 Renderer renderer = Renderer::New(geometry, shader);
212 DALI_TEST_EQUALS( renderer.GetPropertyCount(), 25, TEST_LOCATION );
214 TEST_RENDERER_PROPERTY( renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION );
215 TEST_RENDERER_PROPERTY( renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION );
216 TEST_RENDERER_PROPERTY( renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION );
217 TEST_RENDERER_PROPERTY( renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION );
218 TEST_RENDERER_PROPERTY( renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION );
219 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION );
220 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION );
221 TEST_RENDERER_PROPERTY( renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION );
222 TEST_RENDERER_PROPERTY( renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION );
223 TEST_RENDERER_PROPERTY( renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION );
224 TEST_RENDERER_PROPERTY( renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION );
225 TEST_RENDERER_PROPERTY( renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION );
226 TEST_RENDERER_PROPERTY( renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION );
227 TEST_RENDERER_PROPERTY( renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION );
228 TEST_RENDERER_PROPERTY( renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION );
229 TEST_RENDERER_PROPERTY( renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION );
230 TEST_RENDERER_PROPERTY( renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION );
231 TEST_RENDERER_PROPERTY( renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION );
232 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION );
233 TEST_RENDERER_PROPERTY( renderer, "stencilFunctionReference",Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION );
234 TEST_RENDERER_PROPERTY( renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION );
235 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION );
236 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION );
237 TEST_RENDERER_PROPERTY( renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION );
238 TEST_RENDERER_PROPERTY( renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION );
243 int UtcDaliRendererSetGetGeometry(void)
245 TestApplication application;
246 tet_infoline( "Test SetGeometry, GetGeometry" );
248 Geometry geometry1 = CreateQuadGeometry();
249 Geometry geometry2 = CreateQuadGeometry();
251 Shader shader = CreateShader();
252 Renderer renderer = Renderer::New(geometry1, shader);
253 Actor actor = Actor::New();
254 actor.AddRenderer(renderer);
255 actor.SetSize(400, 400);
256 Stage::GetCurrent().Add(actor);
258 application.SendNotification();
259 application.Render(0);
260 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
262 // Set geometry2 to the renderer
263 renderer.SetGeometry( geometry2 );
265 application.SendNotification();
266 application.Render(0);
267 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
272 int UtcDaliRendererSetGetShader(void)
274 TestApplication application;
275 tet_infoline( "Test SetShader, GetShader" );
277 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
278 glAbstraction.EnableCullFaceCallTrace(true);
280 Shader shader1 = CreateShader();
281 shader1.RegisterProperty( "uFadeColor", Color::RED );
283 Shader shader2 = CreateShader();
284 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
286 Geometry geometry = CreateQuadGeometry();
287 Renderer renderer = Renderer::New(geometry, shader1);
288 Actor actor = Actor::New();
289 actor.AddRenderer(renderer);
290 actor.SetSize(400, 400);
291 Stage::GetCurrent().Add(actor);
293 TestGlAbstraction& gl = application.GetGlAbstraction();
294 application.SendNotification();
295 application.Render(0);
297 // Expect that the first shaders's fade color property is accessed
298 Vector4 actualValue(Vector4::ZERO);
299 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
300 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
302 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
304 // set the second shader to the renderer
305 renderer.SetShader( shader2 );
307 application.SendNotification();
308 application.Render(0);
310 // Expect that the second shader's fade color property is accessed
311 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
312 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
314 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
319 int UtcDaliRendererSetGetDepthIndex(void)
321 TestApplication application;
323 tet_infoline("Test SetDepthIndex, GetDepthIndex");
325 Shader shader = CreateShader();
326 Geometry geometry = CreateQuadGeometry();
327 Renderer renderer = Renderer::New(geometry, shader);
328 Actor actor = Actor::New();
329 actor.AddRenderer(renderer);
330 actor.SetSize(400, 400);
331 Stage::GetCurrent().Add(actor);
333 application.SendNotification();
334 application.Render(0);
335 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
337 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
339 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
340 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
342 application.SendNotification();
343 application.Render(0);
344 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
346 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
348 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
349 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
351 application.SendNotification();
352 application.Render(0);
353 DALI_TEST_EQUALS( renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
358 int UtcDaliRendererSetGetFaceCullingMode(void)
360 TestApplication application;
362 tet_infoline("Test SetFaceCullingMode(cullingMode)");
363 Geometry geometry = CreateQuadGeometry();
364 Shader shader = CreateShader();
365 Renderer renderer = Renderer::New( geometry, shader );
367 Actor actor = Actor::New();
368 actor.AddRenderer(renderer);
369 actor.SetSize(400, 400);
370 Stage::GetCurrent().Add(actor);
372 // By default, none of the faces should be culled
373 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
374 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
376 TestGlAbstraction& gl = application.GetGlAbstraction();
377 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
378 gl.EnableCullFaceCallTrace(true);
381 cullFaceStack.Reset();
382 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
383 application.SendNotification();
384 application.Render();
386 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
388 std::ostringstream cullModeString;
389 cullModeString << GL_FRONT_AND_BACK;
391 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
392 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
393 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
397 cullFaceStack.Reset();
398 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
399 application.SendNotification();
400 application.Render();
402 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
404 std::ostringstream cullModeString;
405 cullModeString << GL_BACK;
407 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
408 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
409 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
413 cullFaceStack.Reset();
414 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
415 application.SendNotification();
416 application.Render();
418 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
420 std::ostringstream cullModeString;
421 cullModeString << GL_FRONT;
423 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
424 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
425 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
429 cullFaceStack.Reset();
430 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
431 application.SendNotification();
432 application.Render();
434 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
435 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
436 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
442 int UtcDaliRendererBlendOptions01(void)
444 TestApplication application;
446 tet_infoline("Test BLEND_FACTOR properties ");
448 Geometry geometry = CreateQuadGeometry();
449 Shader shader = CreateShader();
450 Renderer renderer = Renderer::New( geometry, shader );
452 Actor actor = Actor::New();
453 // set a transparent actor color so that blending is enabled
454 actor.SetOpacity( 0.5f );
455 actor.AddRenderer(renderer);
456 actor.SetSize(400, 400);
457 Stage::GetCurrent().Add(actor);
459 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
460 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
461 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
462 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
464 // Test that Set was successful:
465 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
466 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
467 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
468 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
470 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
471 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
472 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
473 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
475 application.SendNotification();
476 application.Render();
478 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
480 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
481 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
482 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
483 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
488 int UtcDaliRendererBlendOptions02(void)
490 TestApplication application;
492 tet_infoline("Test BLEND_FACTOR properties ");
494 Geometry geometry = CreateQuadGeometry();
495 Shader shader = CreateShader();
496 Renderer renderer = Renderer::New( geometry, shader );
498 Actor actor = Actor::New();
499 actor.SetOpacity( 0.5f ); // enable blending
500 actor.AddRenderer(renderer);
501 actor.SetSize(400, 400);
502 Stage::GetCurrent().Add(actor);
504 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
505 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
506 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
507 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
509 // Test that Set was successful:
511 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
512 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
513 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
514 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
516 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
517 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
518 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
519 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
522 application.SendNotification();
523 application.Render();
525 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
526 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
527 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
528 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
529 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
534 int UtcDaliRendererBlendOptions03(void)
536 TestApplication application;
538 tet_infoline("Test GetBlendEquation() defaults ");
540 Geometry geometry = CreateQuadGeometry();
541 Shader shader = CreateShader();
542 Renderer renderer = Renderer::New( geometry, shader );
544 Actor actor = Actor::New();
545 actor.AddRenderer(renderer);
546 actor.SetSize(400, 400);
547 Stage::GetCurrent().Add(actor);
549 // Test the defaults as documented in blending.h
550 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
551 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
553 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
554 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
559 int UtcDaliRendererBlendOptions04(void)
561 TestApplication application;
563 tet_infoline("Test SetBlendEquation() ");
565 Geometry geometry = CreateQuadGeometry();
566 Shader shader = CreateShader();
567 Renderer renderer = Renderer::New( geometry, shader );
569 Actor actor = Actor::New();
570 actor.SetOpacity( 0.1f );
571 actor.AddRenderer(renderer);
572 actor.SetSize(400, 400);
573 Stage::GetCurrent().Add(actor);
575 // Test the single blending equation setting
577 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
578 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
579 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
582 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
583 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
585 // Test that Set was successful
587 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
588 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
589 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
590 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
593 // Render & check GL commands
594 application.SendNotification();
595 application.Render();
597 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
598 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
599 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
604 int UtcDaliRendererSetBlendMode01(void)
606 TestApplication application;
608 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
610 Geometry geometry = CreateQuadGeometry();
611 Shader shader = CreateShader();
612 Renderer renderer = Renderer::New( geometry, shader );
614 Actor actor = Actor::New();
615 actor.SetOpacity( 0.98f );
616 actor.AddRenderer(renderer);
617 actor.SetSize(400, 400);
618 Stage::GetCurrent().Add(actor);
620 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
622 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
623 glAbstraction.EnableEnableDisableCallTrace(true);
625 application.SendNotification();
626 application.Render();
628 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
629 std::ostringstream blendStr;
630 blendStr << GL_BLEND;
631 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
636 int UtcDaliRendererSetBlendMode01b(void)
638 TestApplication application;
640 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
642 Geometry geometry = CreateQuadGeometry();
643 Shader shader = CreateShader();
644 Renderer renderer = Renderer::New( geometry, shader );
646 Actor actor = Actor::New();
647 actor.SetOpacity( 0.0f );
648 actor.AddRenderer(renderer);
649 actor.SetSize(400, 400);
650 Stage::GetCurrent().Add(actor);
652 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
654 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
655 glAbstraction.EnableEnableDisableCallTrace(true);
656 glAbstraction.EnableDrawCallTrace( true );
658 application.SendNotification();
659 application.Render();
661 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
662 std::ostringstream blendStr;
663 blendStr << GL_BLEND;
664 DALI_TEST_CHECK( !glEnableStack.FindMethod( "Enable" ) );
666 DALI_TEST_CHECK( !glAbstraction.GetDrawTrace().FindMethod( "DrawElements" ) );
671 int UtcDaliRendererSetBlendMode02(void)
673 TestApplication application;
675 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
677 Geometry geometry = CreateQuadGeometry();
678 Shader shader = CreateShader();
679 Renderer renderer = Renderer::New( geometry, shader );
681 Actor actor = Actor::New();
682 actor.SetOpacity( 0.15f );
683 actor.AddRenderer(renderer);
684 actor.SetSize(400, 400);
685 Stage::GetCurrent().Add(actor);
687 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
689 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
690 glAbstraction.EnableEnableDisableCallTrace(true);
692 application.SendNotification();
693 application.Render();
695 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
696 std::ostringstream blendStr;
697 blendStr << GL_BLEND;
698 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
703 int UtcDaliRendererSetBlendMode03(void)
705 TestApplication application;
707 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
709 Geometry geometry = CreateQuadGeometry();
710 Shader shader = CreateShader();
711 Renderer renderer = Renderer::New( geometry, shader );
713 Actor actor = Actor::New();
714 actor.SetOpacity( 0.75f );
715 actor.AddRenderer(renderer);
716 actor.SetSize(400, 400);
717 Stage::GetCurrent().Add(actor);
719 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
721 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
722 glAbstraction.EnableEnableDisableCallTrace(true);
724 application.SendNotification();
725 application.Render();
727 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
728 std::ostringstream blendStr;
729 blendStr << GL_BLEND;
730 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
735 int UtcDaliRendererSetBlendMode04(void)
737 TestApplication application;
739 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
741 Geometry geometry = CreateQuadGeometry();
742 Shader shader = CreateShader();
743 Renderer renderer = Renderer::New( geometry, shader );
745 Actor actor = Actor::New();
746 actor.AddRenderer(renderer);
747 actor.SetSize(400, 400);
748 Stage::GetCurrent().Add(actor);
750 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
752 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
753 glAbstraction.EnableEnableDisableCallTrace(true);
755 application.SendNotification();
756 application.Render();
758 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
759 std::ostringstream blendStr;
760 blendStr << GL_BLEND;
761 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
766 int UtcDaliRendererSetBlendMode04b(void)
768 TestApplication application;
770 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
772 Geometry geometry = CreateQuadGeometry();
773 Shader shader = CreateShader();
774 Renderer renderer = Renderer::New( geometry, shader );
776 Actor actor = Actor::New();
777 actor.AddRenderer(renderer);
778 actor.SetSize(400, 400);
779 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
780 Stage::GetCurrent().Add(actor);
782 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
784 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
785 glAbstraction.EnableEnableDisableCallTrace(true);
787 application.SendNotification();
788 application.Render();
790 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
791 std::ostringstream blendStr;
792 blendStr << GL_BLEND;
793 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
798 int UtcDaliRendererSetBlendMode04c(void)
800 TestApplication application;
802 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
804 Geometry geometry = CreateQuadGeometry();
805 Shader shader = CreateShader();
806 Renderer renderer = Renderer::New( geometry, shader );
808 Actor actor = Actor::New();
809 actor.AddRenderer(renderer);
810 actor.SetSize(400, 400);
811 actor.SetColor( Color::MAGENTA );
812 Stage::GetCurrent().Add(actor);
814 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
816 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
817 glAbstraction.EnableEnableDisableCallTrace(true);
819 application.SendNotification();
820 application.Render();
822 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
823 std::ostringstream blendStr;
824 blendStr << GL_BLEND;
825 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
830 int UtcDaliRendererSetBlendMode05(void)
832 TestApplication application;
834 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
836 Geometry geometry = CreateQuadGeometry();
837 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
839 Shader shader = CreateShader();
840 TextureSet textureSet = CreateTextureSet( image );
841 Renderer renderer = Renderer::New( geometry, shader );
842 renderer.SetTextures( textureSet );
844 Actor actor = Actor::New();
845 actor.AddRenderer(renderer);
846 actor.SetSize(400, 400);
847 Stage::GetCurrent().Add(actor);
849 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
851 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
852 glAbstraction.EnableEnableDisableCallTrace(true);
854 application.SendNotification();
855 application.Render();
857 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
858 std::ostringstream blendStr;
859 blendStr << GL_BLEND;
860 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
865 int UtcDaliRendererSetBlendMode06(void)
867 TestApplication application;
868 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");
870 Geometry geometry = CreateQuadGeometry();
871 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
873 Renderer renderer = Renderer::New( geometry, shader );
875 Actor actor = Actor::New();
876 actor.AddRenderer(renderer);
877 actor.SetSize(400, 400);
878 Stage::GetCurrent().Add(actor);
880 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
882 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
883 glAbstraction.EnableEnableDisableCallTrace(true);
885 application.SendNotification();
886 application.Render();
888 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
889 std::ostringstream blendStr;
890 blendStr << GL_BLEND;
891 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
896 int UtcDaliRendererSetBlendMode07(void)
898 TestApplication application;
899 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");
901 Geometry geometry = CreateQuadGeometry();
902 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
904 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
905 TextureSet textureSet = CreateTextureSet( image );
906 Renderer renderer = Renderer::New( geometry, shader );
907 renderer.SetTextures( textureSet );
909 Actor actor = Actor::New();
910 actor.AddRenderer(renderer);
911 actor.SetSize(400, 400);
912 Stage::GetCurrent().Add(actor);
914 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
916 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
917 glAbstraction.EnableEnableDisableCallTrace(true);
919 application.SendNotification();
920 application.Render();
922 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
923 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
928 int UtcDaliRendererGetBlendMode(void)
930 TestApplication application;
932 tet_infoline("Test GetBlendMode()");
934 Geometry geometry = CreateQuadGeometry();
935 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
936 Renderer renderer = Renderer::New( geometry, shader );
939 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
940 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
943 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
944 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
945 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
948 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
949 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
950 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
955 int UtcDaliRendererSetBlendColor(void)
957 TestApplication application;
959 tet_infoline("Test SetBlendColor(color)");
961 Geometry geometry = CreateQuadGeometry();
962 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
963 TextureSet textureSet = TextureSet::New();
964 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
965 TextureSetImage( textureSet, 0u, image );
966 Renderer renderer = Renderer::New( geometry, shader );
967 renderer.SetTextures( textureSet );
969 Actor actor = Actor::New();
970 actor.AddRenderer(renderer);
971 actor.SetSize(400, 400);
972 Stage::GetCurrent().Add(actor);
974 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
976 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
978 application.SendNotification();
979 application.Render();
981 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
982 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
983 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
985 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
987 DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
988 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION );
990 application.SendNotification();
991 application.Render();
993 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION );
994 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
996 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
997 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
998 application.SendNotification();
999 application.Render();
1000 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
1005 int UtcDaliRendererGetBlendColor(void)
1007 TestApplication application;
1009 tet_infoline("Test GetBlendColor()");
1011 Geometry geometry = CreateQuadGeometry();
1012 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1013 Renderer renderer = Renderer::New( geometry, shader );
1015 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
1017 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
1018 application.SendNotification();
1019 application.Render();
1020 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
1022 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
1023 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
1024 application.SendNotification();
1025 application.Render();
1026 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
1031 int UtcDaliRendererPreMultipledAlpha(void)
1033 TestApplication application;
1035 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1037 Geometry geometry = CreateQuadGeometry();
1038 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
1039 Renderer renderer = Renderer::New( geometry, shader );
1041 Actor actor = Actor::New();
1042 actor.AddRenderer(renderer);
1043 actor.SetSize(400, 400);
1044 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
1045 Stage::GetCurrent().Add(actor);
1047 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1048 bool preMultipliedAlpha;
1049 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1050 DALI_TEST_CHECK( !preMultipliedAlpha );
1052 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1053 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1054 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1055 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1057 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
1058 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
1059 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
1060 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
1062 application.SendNotification();
1063 application.Render();
1065 Vector4 actualValue(Vector4::ZERO);
1066 TestGlAbstraction& gl = application.GetGlAbstraction();
1067 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1068 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
1070 // Enable pre-multiplied alpha
1071 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1073 application.SendNotification();
1074 application.Render();
1076 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1077 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1078 DALI_TEST_CHECK( preMultipliedAlpha );
1080 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1081 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1082 DALI_TEST_CHECK( preMultipliedAlpha );
1084 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1085 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1086 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1087 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1089 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
1090 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1091 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1092 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1094 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1095 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
1097 // Disable pre-multiplied alpha again
1098 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false );
1100 application.SendNotification();
1101 application.Render();
1103 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1104 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1105 DALI_TEST_CHECK( !preMultipliedAlpha );
1107 value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1108 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1109 DALI_TEST_CHECK( !preMultipliedAlpha );
1111 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1112 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1113 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1114 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1116 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1117 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1118 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1119 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1121 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1122 DALI_TEST_EQUALS( actualValue, Vector4( 1.0f, 0.0f, 1.0f, 0.5f ), TEST_LOCATION );
1127 int UtcDaliRendererConstraint01(void)
1129 TestApplication application;
1131 tet_infoline("Test that a non-uniform renderer property can be constrained");
1133 Shader shader = Shader::New("VertexSource", "FragmentSource");
1134 Geometry geometry = CreateQuadGeometry();
1135 Renderer renderer = Renderer::New( geometry, shader );
1137 Actor actor = Actor::New();
1138 actor.AddRenderer(renderer);
1139 actor.SetSize(400, 400);
1140 Stage::GetCurrent().Add(actor);
1142 Vector4 initialColor = Color::WHITE;
1143 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1145 application.SendNotification();
1146 application.Render(0);
1147 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1150 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1152 application.SendNotification();
1153 application.Render(0);
1155 // Expect no blue component in either buffer - yellow
1156 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1157 application.Render(0);
1158 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1160 renderer.RemoveConstraints();
1161 renderer.SetProperty(colorIndex, Color::WHITE );
1162 application.SendNotification();
1163 application.Render(0);
1164 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1169 int UtcDaliRendererConstraint02(void)
1171 TestApplication application;
1173 tet_infoline("Test that a uniform map renderer property can be constrained");
1175 Shader shader = Shader::New("VertexSource", "FragmentSource");
1176 Geometry geometry = CreateQuadGeometry();
1177 Renderer renderer = Renderer::New( geometry, shader );
1179 Actor actor = Actor::New();
1180 actor.AddRenderer(renderer);
1181 actor.SetSize(400, 400);
1182 Stage::GetCurrent().Add(actor);
1183 application.SendNotification();
1184 application.Render(0);
1186 Vector4 initialColor = Color::WHITE;
1187 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1189 TestGlAbstraction& gl = application.GetGlAbstraction();
1191 application.SendNotification();
1192 application.Render(0);
1194 Vector4 actualValue(Vector4::ZERO);
1195 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1196 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1199 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1201 application.SendNotification();
1202 application.Render(0);
1204 // Expect no blue component in either buffer - yellow
1205 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1206 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1208 application.Render(0);
1209 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1210 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1212 renderer.RemoveConstraints();
1213 renderer.SetProperty(colorIndex, Color::WHITE );
1214 application.SendNotification();
1215 application.Render(0);
1217 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1218 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1223 int UtcDaliRendererAnimatedProperty01(void)
1225 TestApplication application;
1227 tet_infoline("Test that a non-uniform renderer property can be animated");
1229 Shader shader = Shader::New("VertexSource", "FragmentSource");
1230 Geometry geometry = CreateQuadGeometry();
1231 Renderer renderer = Renderer::New( geometry, shader );
1233 Actor actor = Actor::New();
1234 actor.AddRenderer(renderer);
1235 actor.SetSize(400, 400);
1236 Stage::GetCurrent().Add(actor);
1238 Vector4 initialColor = Color::WHITE;
1239 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1241 application.SendNotification();
1242 application.Render(0);
1243 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1245 Animation animation = Animation::New(1.0f);
1246 KeyFrames keyFrames = KeyFrames::New();
1247 keyFrames.Add(0.0f, initialColor);
1248 keyFrames.Add(1.0f, Color::TRANSPARENT);
1249 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1252 application.SendNotification();
1253 application.Render(500);
1255 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1257 application.Render(500);
1259 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1264 int UtcDaliRendererAnimatedProperty02(void)
1266 TestApplication application;
1268 tet_infoline("Test that a uniform map renderer property can be animated");
1270 Shader shader = Shader::New("VertexSource", "FragmentSource");
1271 Geometry geometry = CreateQuadGeometry();
1272 Renderer renderer = Renderer::New( geometry, shader );
1274 Actor actor = Actor::New();
1275 actor.AddRenderer(renderer);
1276 actor.SetSize(400, 400);
1277 Stage::GetCurrent().Add(actor);
1278 application.SendNotification();
1279 application.Render(0);
1281 Vector4 initialColor = Color::WHITE;
1282 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1284 TestGlAbstraction& gl = application.GetGlAbstraction();
1286 application.SendNotification();
1287 application.Render(0);
1289 Vector4 actualValue(Vector4::ZERO);
1290 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1291 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1293 Animation animation = Animation::New(1.0f);
1294 KeyFrames keyFrames = KeyFrames::New();
1295 keyFrames.Add(0.0f, initialColor);
1296 keyFrames.Add(1.0f, Color::TRANSPARENT);
1297 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1300 application.SendNotification();
1301 application.Render(500);
1303 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1304 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1306 application.Render(500);
1307 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1308 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1313 int UtcDaliRendererUniformMapPrecendence01(void)
1315 TestApplication application;
1317 tet_infoline("Test the uniform map precedence is applied properly");
1319 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1321 Shader shader = Shader::New("VertexSource", "FragmentSource");
1322 TextureSet textureSet = CreateTextureSet( image );
1324 Geometry geometry = CreateQuadGeometry();
1325 Renderer renderer = Renderer::New( geometry, shader );
1326 renderer.SetTextures( textureSet );
1328 Actor actor = Actor::New();
1329 actor.AddRenderer(renderer);
1330 actor.SetSize(400, 400);
1331 Stage::GetCurrent().Add(actor);
1332 application.SendNotification();
1333 application.Render(0);
1335 renderer.RegisterProperty( "uFadeColor", Color::RED );
1336 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1337 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1339 TestGlAbstraction& gl = application.GetGlAbstraction();
1341 application.SendNotification();
1342 application.Render(0);
1344 // Expect that the actor's fade color property is accessed
1345 Vector4 actualValue(Vector4::ZERO);
1346 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1347 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1349 // Animate shader's fade color property. Should be no change to uniform
1350 Animation animation = Animation::New(1.0f);
1351 KeyFrames keyFrames = KeyFrames::New();
1352 keyFrames.Add(0.0f, Color::WHITE);
1353 keyFrames.Add(1.0f, Color::TRANSPARENT);
1354 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1357 application.SendNotification();
1358 application.Render(500);
1360 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1361 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1363 application.Render(500);
1364 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1365 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1370 int UtcDaliRendererUniformMapPrecendence02(void)
1372 TestApplication application;
1374 tet_infoline("Test the uniform map precedence is applied properly");
1376 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1378 Shader shader = Shader::New("VertexSource", "FragmentSource");
1379 TextureSet textureSet = CreateTextureSet( image );
1381 Geometry geometry = CreateQuadGeometry();
1382 Renderer renderer = Renderer::New( geometry, shader );
1383 renderer.SetTextures( textureSet );
1385 Actor actor = Actor::New();
1386 actor.AddRenderer(renderer);
1387 actor.SetSize(400, 400);
1388 Stage::GetCurrent().Add(actor);
1389 application.SendNotification();
1390 application.Render(0);
1392 // Don't add property / uniform map to renderer
1393 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1394 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1396 TestGlAbstraction& gl = application.GetGlAbstraction();
1398 application.SendNotification();
1399 application.Render(0);
1401 // Expect that the actor's fade color property is accessed
1402 Vector4 actualValue(Vector4::ZERO);
1403 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1404 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1406 // Animate texture set's fade color property. Should be no change to uniform
1407 Animation animation = Animation::New(1.0f);
1408 KeyFrames keyFrames = KeyFrames::New();
1409 keyFrames.Add(0.0f, Color::WHITE);
1410 keyFrames.Add(1.0f, Color::TRANSPARENT);
1411 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1414 application.SendNotification();
1415 application.Render(500);
1417 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1418 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1420 application.Render(500);
1421 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1422 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1428 int UtcDaliRendererUniformMapPrecendence03(void)
1430 TestApplication application;
1432 tet_infoline("Test the uniform map precedence is applied properly");
1434 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1436 Shader shader = Shader::New("VertexSource", "FragmentSource");
1437 TextureSet textureSet = CreateTextureSet( image );
1439 Geometry geometry = CreateQuadGeometry();
1440 Renderer renderer = Renderer::New( geometry, shader );
1441 renderer.SetTextures( textureSet );
1443 Actor actor = Actor::New();
1444 actor.AddRenderer(renderer);
1445 actor.SetSize(400, 400);
1446 Stage::GetCurrent().Add(actor);
1447 application.SendNotification();
1448 application.Render(0);
1450 // Don't add property / uniform map to renderer or actor
1451 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1453 TestGlAbstraction& gl = application.GetGlAbstraction();
1455 application.SendNotification();
1456 application.Render(0);
1458 // Expect that the shader's fade color property is accessed
1459 Vector4 actualValue(Vector4::ZERO);
1460 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1461 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1466 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1468 TestApplication application;
1470 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1472 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1474 Shader shader = Shader::New("VertexSource", "FragmentSource");
1475 TextureSet textureSet = CreateTextureSet( image );
1477 Geometry geometry = CreateQuadGeometry();
1478 Renderer renderer = Renderer::New( geometry, shader );
1479 renderer.SetTextures( textureSet );
1481 Actor actor = Actor::New();
1482 actor.AddRenderer(renderer);
1483 actor.SetSize(400, 400);
1484 Stage::GetCurrent().Add(actor);
1485 application.SendNotification();
1486 application.Render(0);
1488 renderer.RegisterProperty( "uUniform1", Color::RED );
1489 actor.RegisterProperty( "uUniform2", Color::GREEN );
1490 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1492 TestGlAbstraction& gl = application.GetGlAbstraction();
1494 application.SendNotification();
1495 application.Render(0);
1497 // Expect that each of the object's uniforms are set
1498 Vector4 uniform1Value(Vector4::ZERO);
1499 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1500 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1502 Vector4 uniform2Value(Vector4::ZERO);
1503 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1504 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1506 Vector4 uniform3Value(Vector4::ZERO);
1507 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1508 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1513 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1515 TestApplication application;
1517 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1519 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1521 Shader shader = Shader::New("VertexSource", "FragmentSource");
1522 TextureSet textureSet = CreateTextureSet( image );
1524 Geometry geometry = CreateQuadGeometry();
1525 Renderer renderer = Renderer::New( geometry, shader );
1526 renderer.SetTextures( textureSet );
1528 Actor actor = Actor::New();
1529 actor.AddRenderer(renderer);
1530 actor.SetSize(400, 400);
1531 Stage::GetCurrent().Add(actor);
1532 application.SendNotification();
1533 application.Render(0);
1535 Property::Value value1(Color::RED);
1536 renderer.RegisterProperty( "uFadeColor", value1 );
1538 Property::Value value2(1.0f);
1539 actor.RegisterProperty( "uFadeProgress", value2 );
1541 Property::Value value3(Matrix3::IDENTITY);
1542 shader.RegisterProperty( "uANormalMatrix", value3 );
1544 TestGlAbstraction& gl = application.GetGlAbstraction();
1546 application.SendNotification();
1547 application.Render(0);
1549 // Expect that each of the object's uniforms are set
1550 Vector4 uniform1Value(Vector4::ZERO);
1551 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1552 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1554 float uniform2Value(0.0f);
1555 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1556 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1558 Matrix3 uniform3Value;
1559 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1560 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1566 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1568 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1569 TextureSet textureSet0 = CreateTextureSet( image0 );
1570 Renderer renderer0 = Renderer::New( geometry, shader );
1571 renderer0.SetTextures( textureSet0 );
1572 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1573 actor.AddRenderer(renderer0);
1578 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1580 Actor actor = Actor::New();
1581 actor.SetAnchorPoint(AnchorPoint::CENTER);
1582 actor.SetParentOrigin(AnchorPoint::CENTER);
1583 actor.SetPosition(0.0f,0.0f);
1584 actor.SetSize(100, 100);
1586 actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1587 DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1592 int UtcDaliRendererRenderOrder2DLayer(void)
1594 TestApplication application;
1595 tet_infoline("Test the rendering order in a 2D layer is correct");
1597 Shader shader = Shader::New("VertexSource", "FragmentSource");
1598 Geometry geometry = CreateQuadGeometry();
1600 Actor root = Stage::GetCurrent().GetRootLayer();
1602 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1603 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1605 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1606 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1608 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1609 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1611 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1612 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1614 application.SendNotification();
1615 application.Render(0);
1618 * Create the following hierarchy:
1631 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1636 application.SendNotification();
1637 application.Render(0);
1639 TestGlAbstraction& gl = application.GetGlAbstraction();
1640 gl.EnableTextureCallTrace(true);
1641 application.SendNotification();
1642 application.Render(0);
1644 int textureBindIndex[4];
1645 for( unsigned int i(0); i<4; ++i )
1647 std::stringstream params;
1648 params << GL_TEXTURE_2D<<", "<<i+1;
1649 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1652 //Check that actor1 has been rendered after actor2
1653 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1655 //Check that actor0 has been rendered after actor1
1656 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1658 //Check that actor3 has been rendered after actor0
1659 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1664 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1666 TestApplication application;
1667 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1670 * Creates the following hierarchy:
1672 * actor0------------------------>actor1
1676 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1678 * renderer0 has depth index 2
1679 * renderer1 has depth index 0
1680 * renderer2 has depth index 1
1682 * renderer3 has depth index 1
1683 * renderer4 has depth index 0
1684 * renderer5 has depth index -1
1686 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1689 Shader shader = Shader::New("VertexSource", "FragmentSource");
1690 Geometry geometry = CreateQuadGeometry();
1692 Actor root = Stage::GetCurrent().GetRootLayer();
1694 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1695 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1696 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1697 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1698 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1699 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1700 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1701 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1703 application.SendNotification();
1704 application.Render(0);
1706 TestGlAbstraction& gl = application.GetGlAbstraction();
1707 gl.EnableTextureCallTrace(true);
1708 application.SendNotification();
1709 application.Render(0);
1711 int textureBindIndex[6];
1712 for( unsigned int i(0); i<6; ++i )
1714 std::stringstream params;
1715 params << GL_TEXTURE_2D<<", "<<i+1;
1716 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1719 //Check that renderer3 has been rendered after renderer4
1720 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1722 //Check that renderer0 has been rendered after renderer2
1723 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1725 //Check that renderer5 has been rendered after renderer2
1726 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1728 //Check that renderer0 has been rendered after renderer2
1729 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1731 //Check that renderer2 has been rendered after renderer1
1732 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1738 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1740 TestApplication application;
1741 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1744 * Creates the following hierarchy:
1752 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1756 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1757 * DI:2 DI:0 | DI:0 DI:1 DI:2
1762 * actor0 has sibling order 1
1763 * actor1 has sibling order 0
1764 * actor2 has sibling order 0
1766 * renderer0 has depth index 2
1767 * renderer1 has depth index 0
1769 * renderer2 has depth index 0
1770 * renderer3 has depth index 1
1771 * renderer4 has depth index 2
1773 * renderer5 has depth index -1
1775 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1778 Shader shader = Shader::New("VertexSource", "FragmentSource");
1779 Geometry geometry = CreateQuadGeometry();
1780 Actor root = Stage::GetCurrent().GetRootLayer();
1781 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1782 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1783 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1785 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1786 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1787 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1788 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1789 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1790 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1792 application.SendNotification();
1793 application.Render();
1795 TestGlAbstraction& gl = application.GetGlAbstraction();
1796 gl.EnableTextureCallTrace(true);
1797 application.SendNotification();
1798 application.Render(0);
1800 int textureBindIndex[6];
1801 for( unsigned int i(0); i<6; ++i )
1803 std::stringstream params;
1804 params << GL_TEXTURE_2D<<", "<<i+1;
1805 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1808 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1809 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1810 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1811 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1812 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1813 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1815 // Change sibling order of actor1
1816 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1817 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1819 gl.GetTextureTrace().Reset();
1820 application.SendNotification();
1821 application.Render(0);
1823 for( unsigned int i(0); i<6; ++i )
1825 std::stringstream params;
1826 params << GL_TEXTURE_2D<<", "<<i+1;
1827 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1830 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1831 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1832 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1833 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1834 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1835 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1840 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1842 TestApplication application;
1843 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1845 Shader shader = Shader::New("VertexSource", "FragmentSource");
1846 Geometry geometry = CreateQuadGeometry();
1847 Actor root = Stage::GetCurrent().GetRootLayer();
1850 * Create the following hierarchy:
1857 * (Overlay) (Regular actor)
1867 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1870 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1871 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1872 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1874 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1875 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1876 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1878 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1879 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1881 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1882 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1883 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1885 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1886 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1888 application.SendNotification();
1889 application.Render(0);
1896 TestGlAbstraction& gl = application.GetGlAbstraction();
1897 gl.EnableTextureCallTrace(true);
1898 application.SendNotification();
1899 application.Render(0);
1901 int textureBindIndex[5];
1902 for( unsigned int i(0); i<5; ++i )
1904 std::stringstream params;
1905 params << GL_TEXTURE_2D<<", "<<i+1;
1906 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1909 //Check that actor4 has been rendered after actor2
1910 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1912 //Check that actor1 has been rendered after actor4
1913 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1915 //Check that actor0 has been rendered after actor1
1916 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1918 //Check that actor3 has been rendered after actor0
1919 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1924 int UtcDaliRendererSetIndexRange(void)
1928 "attribute vec2 aPosition;\n"
1931 " gl_Position = aPosition;\n"
1937 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1941 TestApplication application;
1942 tet_infoline("Test setting the range of indices to draw");
1944 TestGlAbstraction& gl = application.GetGlAbstraction();
1945 gl.EnableDrawCallTrace( true );
1947 Actor actor = Actor::New();
1948 actor.SetSize( 100, 100 );
1951 Geometry geometry = Geometry::New();
1952 geometry.SetType( Geometry::LINE_LOOP );
1954 // --------------------------------------------------------------------------
1956 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1957 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1958 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1960 // --------------------------------------------------------------------------
1969 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1970 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1971 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1972 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1973 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1975 Property::Map vertexFormat;
1976 vertexFormat["aPosition"] = Property::VECTOR2;
1977 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1978 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1980 // --------------------------------------------------------------------------
1981 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1982 geometry.AddVertexBuffer( vertexBuffer );
1985 Shader shader = Shader::New( vertexShader,fragmentShader );
1986 Renderer renderer = Renderer::New( geometry, shader );
1987 actor.AddRenderer( renderer );
1989 Stage stage = Stage::GetCurrent();
1994 // LINE_LOOP, first 0, count 5
1996 renderer.SetIndexRange( 0, 5 );
1997 application.SendNotification();
1998 application.Render();
2000 Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST );
2002 DALI_TEST_CHECK( value.Get( convertedValue ) );
2003 DALI_TEST_CHECK( convertedValue == 0 );
2005 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST );
2006 DALI_TEST_CHECK( value.Get( convertedValue ) );
2007 DALI_TEST_CHECK( convertedValue == 0 );
2009 value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT );
2010 DALI_TEST_CHECK( value.Get( convertedValue ) );
2011 DALI_TEST_CHECK( convertedValue == 5 );
2013 value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT );
2014 DALI_TEST_CHECK( value.Get( convertedValue ) );
2015 DALI_TEST_CHECK( convertedValue == 5 );
2017 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2018 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2019 DALI_TEST_CHECK( result );
2022 // LINE_LOOP, first 5, count 10
2024 renderer.SetIndexRange( 5, 10 );
2025 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2026 application.SendNotification();
2027 application.Render();
2028 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2029 DALI_TEST_CHECK( result );
2032 // LINE_STRIP, first 15, count 6
2034 renderer.SetIndexRange( 15, 6 );
2035 geometry.SetType( Geometry::LINE_STRIP );
2036 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2037 application.SendNotification();
2038 application.Render();
2039 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2040 DALI_TEST_CHECK( result );
2043 // Index out of bounds
2045 renderer.SetIndexRange( 15, 30 );
2046 geometry.SetType( Geometry::LINE_STRIP );
2047 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2048 application.SendNotification();
2049 application.Render();
2050 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2051 DALI_TEST_CHECK( result );
2054 // drawing whole buffer starting from 15 ( last valid primitive )
2056 renderer.SetIndexRange( 15, 0 );
2057 geometry.SetType( Geometry::LINE_STRIP );
2058 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2059 application.SendNotification();
2060 application.Render();
2061 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2062 DALI_TEST_CHECK( result );
2069 int UtcDaliRendererSetDepthFunction(void)
2071 TestApplication application;
2073 tet_infoline("Test setting the depth function");
2075 Geometry geometry = CreateQuadGeometry();
2076 Shader shader = CreateShader();
2077 Renderer renderer = Renderer::New( geometry, shader );
2079 Actor actor = Actor::New();
2080 actor.AddRenderer(renderer);
2081 actor.SetSize(400, 400);
2082 Stage stage = Stage::GetCurrent();
2083 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2086 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2087 glAbstraction.EnableEnableDisableCallTrace(true);
2088 glAbstraction.EnableDepthFunctionCallTrace(true);
2090 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2091 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2093 std::ostringstream depthTestStr;
2094 depthTestStr << GL_DEPTH_TEST;
2098 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2100 glEnableDisableStack.Reset();
2101 glDepthFunctionStack.Reset();
2102 application.SendNotification();
2103 application.Render();
2105 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2106 std::ostringstream depthFunctionStr;
2107 depthFunctionStr << GL_NEVER;
2108 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2113 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2115 glDepthFunctionStack.Reset();
2116 application.SendNotification();
2117 application.Render();
2119 std::ostringstream depthFunctionStr;
2120 depthFunctionStr << GL_ALWAYS;
2121 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2126 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2128 glDepthFunctionStack.Reset();
2129 application.SendNotification();
2130 application.Render();
2132 std::ostringstream depthFunctionStr;
2133 depthFunctionStr << GL_LESS;
2134 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2139 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2141 glDepthFunctionStack.Reset();
2142 application.SendNotification();
2143 application.Render();
2145 std::ostringstream depthFunctionStr;
2146 depthFunctionStr << GL_GREATER;
2147 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2152 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2154 glDepthFunctionStack.Reset();
2155 application.SendNotification();
2156 application.Render();
2158 std::ostringstream depthFunctionStr;
2159 depthFunctionStr << GL_EQUAL;
2160 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2165 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2167 glDepthFunctionStack.Reset();
2168 application.SendNotification();
2169 application.Render();
2171 std::ostringstream depthFunctionStr;
2172 depthFunctionStr << GL_NOTEQUAL;
2173 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2178 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2180 glDepthFunctionStack.Reset();
2181 application.SendNotification();
2182 application.Render();
2184 std::ostringstream depthFunctionStr;
2185 depthFunctionStr << GL_LEQUAL;
2186 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2191 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2193 glDepthFunctionStack.Reset();
2194 application.SendNotification();
2195 application.Render();
2197 std::ostringstream depthFunctionStr;
2198 depthFunctionStr << GL_GEQUAL;
2199 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2206 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2207 * The checks performed are as follows:
2208 * - Check the initial/default value.
2209 * - Set a different value via enum.
2210 * - Check it was set.
2211 * - Set a different value via string.
2212 * - Check it was set.
2214 template< typename T >
2215 void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2217 application.SendNotification();
2218 application.Render();
2220 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2221 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2222 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2223 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2224 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( firstCheckEnumeration ) );
2226 application.SendNotification();
2227 application.Render();
2229 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2230 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2232 renderer.SetProperty( propertyIndex, secondCheckString );
2233 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2234 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( secondCheckEnumeration ) );
2236 application.SendNotification();
2237 application.Render();
2239 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2240 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2243 int UtcDaliRendererEnumProperties(void)
2245 TestApplication application;
2246 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2248 Geometry geometry = CreateQuadGeometry();
2249 Shader shader = CreateShader();
2250 Renderer renderer = Renderer::New( geometry, shader );
2252 Actor actor = Actor::New();
2253 actor.AddRenderer(renderer);
2254 actor.SetSize(400, 400);
2255 Stage::GetCurrent().Add(actor);
2258 * Here we use a templatized function to perform several checks on each enumeration property.
2259 * @see CheckEnumerationProperty for details of the checks performed.
2262 CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2263 CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2264 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2265 CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2266 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2267 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2268 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2269 CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2270 CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2271 CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2272 CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2273 CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2274 CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2275 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2276 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2277 CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2282 Renderer RendererTestFixture( TestApplication& application )
2284 Geometry geometry = CreateQuadGeometry();
2285 Shader shader = CreateShader();
2286 Renderer renderer = Renderer::New( geometry, shader );
2288 Actor actor = Actor::New();
2289 actor.AddRenderer( renderer );
2290 actor.SetSize( 400.0f, 400.0f );
2291 Stage stage = Stage::GetCurrent();
2292 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2298 int UtcDaliRendererSetDepthTestMode(void)
2300 TestApplication application;
2301 tet_infoline("Test setting the DepthTestMode");
2303 Renderer renderer = RendererTestFixture( application );
2304 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2305 glAbstraction.EnableEnableDisableCallTrace( true );
2306 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2308 glEnableDisableStack.Reset();
2309 application.SendNotification();
2310 application.Render();
2312 // Check depth-test is enabled by default.
2313 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2314 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2316 // 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.
2317 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2318 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2320 glEnableDisableStack.Reset();
2321 application.SendNotification();
2322 application.Render();
2324 // Check the depth buffer was disabled.
2325 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2327 // Turn on automatic mode depth-testing.
2328 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2329 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2331 glEnableDisableStack.Reset();
2332 application.SendNotification();
2333 application.Render();
2335 // Check depth-test is now enabled.
2336 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2337 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2339 // Change the layer behavior to LAYER_UI.
2340 // Note this will also disable depth testing for the layer by default, we test this first.
2341 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_UI );
2343 glEnableDisableStack.Reset();
2344 application.SendNotification();
2345 application.Render();
2347 // Check depth-test is disabled.
2348 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2350 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2351 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2353 glEnableDisableStack.Reset();
2354 application.SendNotification();
2355 application.Render();
2357 // Check depth-test is *still* disabled.
2358 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2363 int UtcDaliRendererSetDepthWriteMode(void)
2365 TestApplication application;
2366 tet_infoline("Test setting the DepthWriteMode");
2368 Renderer renderer = RendererTestFixture( application );
2369 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2371 application.SendNotification();
2372 application.Render();
2374 // Check the default depth-write status first.
2375 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2377 // Turn off depth-writing.
2378 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2380 application.SendNotification();
2381 application.Render();
2383 // Check depth-write is now disabled.
2384 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2386 // Test the AUTO mode for depth-writing.
2387 // As our renderer is opaque, depth-testing should be enabled.
2388 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2390 application.SendNotification();
2391 application.Render();
2393 // Check depth-write is now enabled.
2394 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2396 // Now make the renderer be treated as translucent by enabling blending.
2397 // The AUTO depth-write mode should turn depth-write off in this scenario.
2398 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2400 application.SendNotification();
2401 application.Render();
2403 // Check depth-write is now disabled.
2404 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2409 int UtcDaliRendererCheckStencilDefaults(void)
2411 TestApplication application;
2412 tet_infoline("Test the stencil defaults");
2414 Renderer renderer = RendererTestFixture( application );
2415 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2416 glAbstraction.EnableEnableDisableCallTrace( true );
2417 glAbstraction.EnableStencilFunctionCallTrace( true );
2418 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2419 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2421 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2423 // Check the defaults:
2424 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2425 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2426 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2427 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2428 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2429 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 );
2430 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 );
2435 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2437 TestApplication application;
2438 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2440 Renderer renderer = RendererTestFixture( application );
2441 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2442 glAbstraction.EnableEnableDisableCallTrace( true );
2443 glAbstraction.EnableStencilFunctionCallTrace( true );
2444 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2445 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2447 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2448 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2449 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2450 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2452 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2453 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2455 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2456 std::string methodString( "StencilFunc" );
2457 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2459 // Test the other RenderModes that will not enable the stencil buffer.
2460 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2461 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2462 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2464 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2465 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2466 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2468 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2469 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2470 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2472 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2473 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2475 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2476 // First set a mode to turn off the stencil buffer, so the enable is required.
2477 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2478 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2479 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2480 // Set a different stencil function as the last one is cached.
2481 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS );
2482 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2484 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2485 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2490 // Helper function for the SetRenderModeToUseColorBuffer test.
2491 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2493 // Set the RenderMode property to a value that should not allow color buffer writes.
2494 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2495 application.SendNotification();
2496 application.Render();
2498 // Check if ColorMask has been called, and that the values are correct.
2499 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2500 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2502 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2503 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2504 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2505 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2508 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2510 TestApplication application;
2511 tet_infoline("Test setting the RenderMode to use the color buffer");
2513 Renderer renderer = RendererTestFixture( application );
2515 // Set the RenderMode property to a value that should not allow color buffer writes.
2516 // Then check if ColorMask has been called, and that the values are correct.
2517 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2518 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2519 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2520 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2521 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2526 int UtcDaliRendererSetStencilFunction(void)
2528 TestApplication application;
2529 tet_infoline("Test setting the StencilFunction");
2531 Renderer renderer = RendererTestFixture( application );
2532 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2533 glAbstraction.EnableEnableDisableCallTrace( true );
2534 glAbstraction.EnableStencilFunctionCallTrace( true );
2535 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2536 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2538 // RenderMode must use the stencil for StencilFunction to operate.
2539 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2540 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2543 * Lookup table for testing StencilFunction.
2544 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2546 const int StencilFunctionLookupTable[] = {
2555 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2558 * Loop through all types of StencilFunction, checking:
2559 * - The value is cached (set in event thread side)
2560 * - Causes "glStencilFunc" to be called
2561 * - Checks the correct parameters to "glStencilFunc" were used
2563 std::string nonChangingParameters = "0, 255";
2564 std::string methodString( "StencilFunc" );
2565 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2567 // Set the property.
2568 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2570 // Check GetProperty returns the same value.
2571 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2573 // Reset the trace debug.
2574 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2576 // Check the function is called and the parameters are correct.
2577 std::stringstream parameterStream;
2578 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2580 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2583 // Change the Function Reference only and check the behavior is correct:
2584 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2585 int testValueReference = 170;
2586 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2588 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2590 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2592 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2594 std::stringstream parameterStream;
2595 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2597 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2600 // Change the Function Mask only and check the behavior is correct:
2601 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2602 int testValueMask = 85;
2603 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2605 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2607 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2609 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2611 // Clear the stringstream.
2612 parameterStream.str( std::string() );
2613 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2615 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2620 int UtcDaliRendererSetStencilOperation(void)
2622 TestApplication application;
2623 tet_infoline("Test setting the StencilOperation");
2625 Renderer renderer = RendererTestFixture( application );
2626 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2627 glAbstraction.EnableEnableDisableCallTrace( true );
2628 glAbstraction.EnableStencilFunctionCallTrace( true );
2629 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2630 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2632 // RenderMode must use the stencil for StencilOperation to operate.
2633 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2636 * Lookup table for testing StencilOperation.
2637 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2639 const int StencilOperationLookupTable[] = {
2648 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2650 // Set all 3 StencilOperation properties to a default.
2651 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP );
2652 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2653 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2655 // Set our expected parameter list to the equivalent result.
2656 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2658 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2661 * Loop through all types of StencilOperation, checking:
2662 * - The value is cached (set in event thread side)
2663 * - Causes "glStencilFunc" to be called
2664 * - Checks the correct parameters to "glStencilFunc" were used
2665 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2667 std::string methodString( "StencilOp" );
2669 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2671 for( int j = 0; j < StencilOperationLookupTableCount; ++j )
2673 for( int k = 0; k < StencilOperationLookupTableCount; ++k )
2675 // Set the property (outer loop causes all 3 different properties to be set separately).
2676 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>( i ) );
2677 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>( j ) );
2678 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>( k ) );
2680 // Check GetProperty returns the same value.
2681 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), i, TEST_LOCATION );
2682 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), j, TEST_LOCATION );
2683 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), k, TEST_LOCATION );
2685 // Reset the trace debug.
2686 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2688 // Check the function is called and the parameters are correct.
2689 // Set the expected parameter value at its correct index (only)
2690 parameters[ 0u ] = StencilOperationLookupTable[ i ];
2691 parameters[ 1u ] = StencilOperationLookupTable[ j ];
2692 parameters[ 2u ] = StencilOperationLookupTable[ k ];
2694 // Build the parameter list.
2695 std::stringstream parameterStream;
2696 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2698 parameterStream << parameters[ parameterBuild ];
2699 // Comma-separate the parameters.
2700 if( parameterBuild < 2 )
2702 parameterStream << ", ";
2706 // Check the function was called and the parameters were correct.
2707 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2715 int UtcDaliRendererSetStencilMask(void)
2717 TestApplication application;
2718 tet_infoline("Test setting the StencilMask");
2720 Renderer renderer = RendererTestFixture( application );
2721 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2722 glAbstraction.EnableEnableDisableCallTrace( true );
2723 glAbstraction.EnableStencilFunctionCallTrace( true );
2724 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2725 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2727 // RenderMode must use the stencil for StencilMask to operate.
2728 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2730 // Set the StencilMask property to a value.
2731 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2733 // Check GetProperty returns the same value.
2734 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2736 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2738 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2740 std::string methodString( "StencilMask" );
2741 std::string parameterString = "0";
2743 // Check the function was called and the parameters were correct.
2744 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2746 // Set the StencilMask property to another value to ensure it has changed.
2747 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2749 // Check GetProperty returns the same value.
2750 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2752 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2754 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2756 parameterString = "255";
2758 // Check the function was called and the parameters were correct.
2759 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2764 int UtcDaliRendererWrongNumberOfTextures(void)
2766 TestApplication application;
2767 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2769 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2770 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2771 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2772 TextureSet textureSet = CreateTextureSet();
2773 textureSet.SetTexture(0, texture );
2774 textureSet.SetTexture(1, texture );
2775 textureSet.SetTexture(2, texture );
2776 textureSet.SetTexture(3, texture );
2777 Shader shader = Shader::New("VertexSource", "FragmentSource");
2778 Geometry geometry = CreateQuadGeometry();
2779 Renderer renderer = Renderer::New( geometry, shader );
2780 renderer.SetTextures( textureSet );
2782 Actor actor= Actor::New();
2783 actor.AddRenderer(renderer);
2784 actor.SetPosition(0.0f,0.0f);
2785 actor.SetSize(100, 100);
2786 Stage::GetCurrent().Add(actor);
2788 TestGlAbstraction& gl = application.GetGlAbstraction();
2789 TraceCallStack& drawTrace = gl.GetDrawTrace();
2791 drawTrace.Enable(true);
2793 application.SendNotification();
2794 application.Render(0);
2796 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2797 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2799 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2800 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2801 textureSet = CreateTextureSet();
2802 renderer.SetTextures( textureSet );
2803 textureSet.SetTexture(0, texture );
2805 application.SendNotification();
2806 application.Render(0);
2808 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2809 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2814 int UtcDaliRendererOpacity(void)
2816 TestApplication application;
2818 tet_infoline( "Test OPACITY property" );
2820 Geometry geometry = CreateQuadGeometry();
2821 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2822 Renderer renderer = Renderer::New( geometry, shader );
2824 Actor actor = Actor::New();
2825 actor.AddRenderer( renderer );
2826 actor.SetSize( 400, 400 );
2827 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2828 Stage::GetCurrent().Add( actor );
2830 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2832 DALI_TEST_CHECK( value.Get( opacity ) );
2833 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2835 application.SendNotification();
2836 application.Render();
2838 Vector4 actualValue;
2839 TestGlAbstraction& gl = application.GetGlAbstraction();
2840 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2841 DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2843 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f );
2845 application.SendNotification();
2846 application.Render();
2848 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2849 DALI_TEST_CHECK( value.Get( opacity ) );
2850 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2852 value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY );
2853 DALI_TEST_CHECK( value.Get( opacity ) );
2854 DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2856 DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2857 DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2862 int UtcDaliRendererOpacityAnimation(void)
2864 TestApplication application;
2866 tet_infoline( "Test OPACITY property animation" );
2868 Geometry geometry = CreateQuadGeometry();
2869 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2870 Renderer renderer = Renderer::New( geometry, shader );
2872 Actor actor = Actor::New();
2873 actor.AddRenderer( renderer );
2874 actor.SetSize( 400, 400 );
2875 actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2876 Stage::GetCurrent().Add( actor );
2878 application.SendNotification();
2879 application.Render(0);
2881 Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2883 DALI_TEST_CHECK( value.Get( opacity ) );
2884 DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2886 Animation animation = Animation::New( 1.0f );
2887 animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f );
2890 application.SendNotification();
2891 application.Render( 1000 );
2893 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2894 DALI_TEST_CHECK( value.Get( opacity ) );
2895 DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2897 renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.1f );
2900 animation.AnimateBy( Property( renderer, DevelRenderer::Property::OPACITY ), 0.5f );
2903 application.SendNotification();
2904 application.Render( 1000 );
2906 value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2907 DALI_TEST_CHECK( value.Get( opacity ) );
2908 DALI_TEST_EQUALS( opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2913 int UtcDaliRendererInvalidProperty(void)
2915 TestApplication application;
2917 tet_infoline( "Test invalid property" );
2919 Geometry geometry = CreateQuadGeometry();
2920 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2921 Renderer renderer = Renderer::New( geometry, shader );
2923 Actor actor = Actor::New();
2924 actor.AddRenderer( renderer );
2925 actor.SetSize( 400, 400 );
2926 Stage::GetCurrent().Add( actor );
2928 application.SendNotification();
2929 application.Render(0);
2931 Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 );
2932 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2934 value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 );
2935 DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );