2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/common/stage.h>
21 #include <dali/devel-api/rendering/renderer-devel.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
24 #include <dali/devel-api/common/capabilities.h>
29 #include <dali-test-suite-utils.h>
30 #include <mesh-builder.h>
31 #include <test-trace-call-stack.h>
35 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 UtcDaliRendererMoveConstructor(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
148 Renderer renderer = Renderer::New(geometry, shader);
149 DALI_TEST_CHECK(renderer);
150 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
151 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
153 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
154 application.SendNotification();
155 application.Render();
156 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
158 Renderer move = std::move(renderer);
159 DALI_TEST_CHECK(move);
160 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
161 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
162 DALI_TEST_CHECK(!renderer);
167 int UtcDaliRendererMoveAssignment(void)
169 TestApplication application;
171 Geometry geometry = CreateQuadGeometry();
172 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
173 Renderer renderer = Renderer::New(geometry, shader);
174 DALI_TEST_CHECK(renderer);
175 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
176 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
178 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
179 application.SendNotification();
180 application.Render();
181 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
184 move = std::move(renderer);
185 DALI_TEST_CHECK(move);
186 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
188 DALI_TEST_CHECK(!renderer);
193 int UtcDaliRendererDownCast01(void)
195 TestApplication application;
197 Geometry geometry = CreateQuadGeometry();
198 Shader shader = CreateShader();
199 Renderer renderer = Renderer::New(geometry, shader);
201 BaseHandle handle(renderer);
202 Renderer renderer2 = Renderer::DownCast(handle);
203 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
207 int UtcDaliRendererDownCast02(void)
209 TestApplication application;
211 Handle handle = Handle::New(); // Create a custom object
212 Renderer renderer = Renderer::DownCast(handle);
213 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
217 // using a template to auto deduce the parameter types
218 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
219 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
221 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
222 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
223 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
224 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
225 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
226 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
229 int UtcDaliRendererDefaultProperties(void)
231 TestApplication application;
232 /* from renderer-impl.cpp
233 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
234 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
235 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
236 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
237 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
238 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
239 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
240 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
241 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
242 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
243 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
244 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
245 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
246 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
247 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
248 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
249 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
250 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
251 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
252 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
253 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
254 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
255 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
256 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
257 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
258 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
259 DALI_PROPERTY( "blendEquation", INTEGER, true, false, false, Dali::DevelRenderer::Property::BLEND_EQUATION )
262 Geometry geometry = CreateQuadGeometry();
263 Shader shader = CreateShader();
264 Renderer renderer = Renderer::New(geometry, shader);
265 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27, TEST_LOCATION);
267 TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
268 TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
269 TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
270 TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
271 TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
272 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
273 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
274 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
275 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
276 TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
277 TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
278 TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
279 TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
280 TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
281 TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
282 TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
283 TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
284 TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
285 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
286 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
287 TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
288 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
289 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
290 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
291 TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
292 TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
293 TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
298 int UtcDaliRendererSetGetGeometry(void)
300 TestApplication application;
301 tet_infoline("Test SetGeometry, GetGeometry");
303 Geometry geometry1 = CreateQuadGeometry();
304 Geometry geometry2 = CreateQuadGeometry();
306 Shader shader = CreateShader();
307 Renderer renderer = Renderer::New(geometry1, shader);
308 Actor actor = Actor::New();
309 actor.AddRenderer(renderer);
310 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
311 application.GetScene().Add(actor);
313 application.SendNotification();
314 application.Render(0);
315 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
317 // Set geometry2 to the renderer
318 renderer.SetGeometry(geometry2);
320 application.SendNotification();
321 application.Render(0);
322 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
327 int UtcDaliRendererSetGetShader(void)
329 TestApplication application;
330 tet_infoline("Test SetShader, GetShader");
332 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
333 glAbstraction.EnableCullFaceCallTrace(true);
335 Shader shader1 = CreateShader();
336 shader1.RegisterProperty("uFadeColor", Color::RED);
338 Shader shader2 = CreateShader();
339 shader2.RegisterProperty("uFadeColor", Color::GREEN);
341 Geometry geometry = CreateQuadGeometry();
342 Renderer renderer = Renderer::New(geometry, shader1);
343 Actor actor = Actor::New();
344 actor.AddRenderer(renderer);
345 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
346 application.GetScene().Add(actor);
348 TestGlAbstraction& gl = application.GetGlAbstraction();
349 application.SendNotification();
350 application.Render(0);
352 // Expect that the first shaders's fade color property is accessed
353 Vector4 actualValue(Vector4::ZERO);
354 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
355 DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
357 DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
359 // set the second shader to the renderer
360 renderer.SetShader(shader2);
362 application.SendNotification();
363 application.Render(0);
365 // Expect that the second shader's fade color property is accessed
366 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
367 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
369 DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
374 int UtcDaliRendererSetGetDepthIndex(void)
376 TestApplication application;
378 tet_infoline("Test SetDepthIndex, GetDepthIndex");
380 Shader shader = CreateShader();
381 Geometry geometry = CreateQuadGeometry();
382 Renderer renderer = Renderer::New(geometry, shader);
383 Actor actor = Actor::New();
384 actor.AddRenderer(renderer);
385 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
386 application.GetScene().Add(actor);
388 application.SendNotification();
389 application.Render(0);
390 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
392 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
394 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
395 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
397 application.SendNotification();
398 application.Render(0);
399 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
401 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
403 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
404 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
406 application.SendNotification();
407 application.Render(0);
408 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
413 int UtcDaliRendererSetGetFaceCullingMode(void)
415 TestApplication application;
417 tet_infoline("Test SetFaceCullingMode(cullingMode)");
418 Geometry geometry = CreateQuadGeometry();
419 Shader shader = CreateShader();
420 Renderer renderer = Renderer::New(geometry, shader);
422 Actor actor = Actor::New();
423 actor.AddRenderer(renderer);
424 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
425 application.GetScene().Add(actor);
427 // By default, none of the faces should be culled
428 unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
429 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
431 TestGlAbstraction& gl = application.GetGlAbstraction();
432 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
433 gl.EnableCullFaceCallTrace(true);
436 cullFaceStack.Reset();
437 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
438 application.SendNotification();
439 application.Render();
441 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
443 std::ostringstream cullModeString;
444 cullModeString << GL_FRONT_AND_BACK;
446 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
447 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
448 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
452 cullFaceStack.Reset();
453 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
454 application.SendNotification();
455 application.Render();
457 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
459 std::ostringstream cullModeString;
460 cullModeString << GL_BACK;
462 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
463 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
464 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
468 cullFaceStack.Reset();
469 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
470 application.SendNotification();
471 application.Render();
473 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
475 std::ostringstream cullModeString;
476 cullModeString << GL_FRONT;
478 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
479 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
480 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
484 cullFaceStack.Reset();
485 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
486 application.SendNotification();
487 application.Render();
489 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
490 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
491 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
497 int UtcDaliRendererBlendOptions01(void)
499 TestApplication application;
501 tet_infoline("Test BLEND_FACTOR properties ");
503 Geometry geometry = CreateQuadGeometry();
504 Shader shader = CreateShader();
505 Renderer renderer = Renderer::New(geometry, shader);
507 Actor actor = Actor::New();
508 // set a transparent actor color so that blending is enabled
509 actor.SetProperty(Actor::Property::OPACITY, 0.5f);
510 actor.AddRenderer(renderer);
511 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
512 application.GetScene().Add(actor);
514 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
515 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
516 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
517 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
519 // Test that Set was successful:
520 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
521 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
522 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
523 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
525 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
526 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
527 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
528 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
530 application.SendNotification();
531 application.Render();
533 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
535 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
536 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
537 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
538 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
543 int UtcDaliRendererBlendOptions02(void)
545 TestApplication application;
547 tet_infoline("Test BLEND_FACTOR properties ");
549 Geometry geometry = CreateQuadGeometry();
550 Shader shader = CreateShader();
551 Renderer renderer = Renderer::New(geometry, shader);
553 Actor actor = Actor::New();
554 actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
555 actor.AddRenderer(renderer);
556 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
557 application.GetScene().Add(actor);
559 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
560 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
561 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
562 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
564 // Test that Set was successful:
566 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
567 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
568 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
569 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
571 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
572 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
573 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
574 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
577 application.SendNotification();
578 application.Render();
580 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
581 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
582 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
583 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
584 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
589 int UtcDaliRendererBlendOptions03(void)
591 TestApplication application;
593 tet_infoline("Test GetBlendEquation() defaults ");
595 Geometry geometry = CreateQuadGeometry();
596 Shader shader = CreateShader();
597 Renderer renderer = Renderer::New(geometry, shader);
599 Actor actor = Actor::New();
600 actor.AddRenderer(renderer);
601 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
602 application.GetScene().Add(actor);
604 // Test the defaults as documented in blending.h
605 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
606 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
608 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
609 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
614 int UtcDaliRendererBlendOptions04(void)
616 TestApplication application;
618 tet_infoline("Test SetBlendEquation() ");
620 Geometry geometry = CreateQuadGeometry();
621 Shader shader = CreateShader();
622 Renderer renderer = Renderer::New(geometry, shader);
624 Actor actor = Actor::New();
625 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
626 actor.AddRenderer(renderer);
627 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
628 application.GetScene().Add(actor);
630 // Test the single blending equation setting
632 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
633 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
634 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
637 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
638 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
640 // Test that Set was successful
642 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
643 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
644 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
645 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
648 // Render & check GL commands
649 application.SendNotification();
650 application.Render();
652 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
653 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
654 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
659 int UtcDaliRendererBlendOptions05(void)
661 TestApplication application;
663 tet_infoline("Test SetAdvancedBlendEquation ");
665 Geometry geometry = CreateQuadGeometry();
666 Shader shader = CreateShader();
667 Renderer renderer = Renderer::New( geometry, shader );
669 Actor actor = Actor::New();
670 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
672 actor.AddRenderer(renderer);
673 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
674 application.GetScene().Add(actor);
676 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MAX ) )
678 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX );
679 int equationRgb = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION );
680 DALI_TEST_EQUALS( (int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION );
683 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
685 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
686 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
687 int equation = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION );
689 DALI_TEST_EQUALS( (int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION );
690 DALI_TEST_EQUALS( DevelRenderer::IsAdvancedBlendEquationApplied( renderer ), true, TEST_LOCATION );
692 application.SendNotification();
693 application.Render();
696 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) &&
697 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MULTIPLY ) )
699 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD );
700 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
701 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN );
702 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY );
703 int equationRgb = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION_RGB );
704 int equationAlpha = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION_ALPHA );
706 DALI_TEST_EQUALS( (int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION );
707 DALI_TEST_EQUALS( (int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION );
708 DALI_TEST_EQUALS( DevelRenderer::IsAdvancedBlendEquationApplied( renderer ), false, TEST_LOCATION );
710 application.SendNotification();
711 application.Render();
714 tet_infoline("Error Checking\n");
715 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MULTIPLY ) &&
716 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) &&
717 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::OVERLAY ) &&
718 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::DARKEN ) &&
719 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::LIGHTEN ) &&
720 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR_DODGE ) &&
721 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR_BURN ) &&
722 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::HARD_LIGHT ) &&
723 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SOFT_LIGHT ) &&
724 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::DIFFERENCE ) &&
725 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::EXCLUSION ) &&
726 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::HUE ) &&
727 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SATURATION ) &&
728 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR ) &&
729 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::LUMINOSITY ) )
731 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY );
732 DALI_TEST_EQUALS( (int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
734 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
735 DALI_TEST_EQUALS( (int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
737 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY );
738 DALI_TEST_EQUALS( (int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
740 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN );
741 DALI_TEST_EQUALS( (int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
743 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN );
744 DALI_TEST_EQUALS( (int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
746 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE );
747 DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
749 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN );
750 DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
752 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT );
753 DALI_TEST_EQUALS( (int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
755 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT );
756 DALI_TEST_EQUALS( (int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
758 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE );
759 DALI_TEST_EQUALS( (int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
761 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION );
762 DALI_TEST_EQUALS( (int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
764 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE );
765 DALI_TEST_EQUALS( (int)DevelBlendEquation::HUE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
767 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION );
768 DALI_TEST_EQUALS( (int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
770 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR );
771 DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
773 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY );
774 DALI_TEST_EQUALS( (int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
780 int UtcDaliRendererSetBlendMode01(void)
782 TestApplication application;
784 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
786 Geometry geometry = CreateQuadGeometry();
787 Shader shader = CreateShader();
788 Renderer renderer = Renderer::New(geometry, shader);
790 Actor actor = Actor::New();
791 actor.SetProperty(Actor::Property::OPACITY, 0.98f);
792 actor.AddRenderer(renderer);
793 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
794 application.GetScene().Add(actor);
796 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
798 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
799 glAbstraction.EnableEnableDisableCallTrace(true);
801 application.SendNotification();
802 application.Render();
804 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
805 std::ostringstream blendStr;
806 blendStr << GL_BLEND;
807 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
812 int UtcDaliRendererSetBlendMode01b(void)
814 TestApplication application;
816 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
818 Geometry geometry = CreateQuadGeometry();
819 Shader shader = CreateShader();
820 Renderer renderer = Renderer::New(geometry, shader);
822 Actor actor = Actor::New();
823 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
824 actor.AddRenderer(renderer);
825 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
826 application.GetScene().Add(actor);
828 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
830 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
831 glAbstraction.EnableEnableDisableCallTrace(true);
832 glAbstraction.EnableDrawCallTrace(true);
834 application.SendNotification();
835 application.Render();
837 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
838 std::ostringstream blendStr;
839 blendStr << GL_BLEND;
840 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
842 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
847 int UtcDaliRendererSetBlendMode02(void)
849 TestApplication application;
851 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
853 Geometry geometry = CreateQuadGeometry();
854 Shader shader = CreateShader();
855 Renderer renderer = Renderer::New(geometry, shader);
857 Actor actor = Actor::New();
858 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
859 actor.AddRenderer(renderer);
860 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
861 application.GetScene().Add(actor);
863 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
865 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
866 glAbstraction.EnableEnableDisableCallTrace(true);
868 application.SendNotification();
869 application.Render();
871 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
872 std::ostringstream blendStr;
873 blendStr << GL_BLEND;
874 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
879 int UtcDaliRendererSetBlendMode03(void)
881 TestApplication application;
883 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
885 Geometry geometry = CreateQuadGeometry();
886 Shader shader = CreateShader();
887 Renderer renderer = Renderer::New(geometry, shader);
889 Actor actor = Actor::New();
890 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
891 actor.AddRenderer(renderer);
892 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
893 application.GetScene().Add(actor);
895 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
897 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
898 glAbstraction.EnableEnableDisableCallTrace(true);
900 application.SendNotification();
901 application.Render();
903 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
904 std::ostringstream blendStr;
905 blendStr << GL_BLEND;
906 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
911 int UtcDaliRendererSetBlendMode04(void)
913 TestApplication application;
915 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
917 Geometry geometry = CreateQuadGeometry();
918 Shader shader = CreateShader();
919 Renderer renderer = Renderer::New(geometry, shader);
921 Actor actor = Actor::New();
922 actor.AddRenderer(renderer);
923 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
924 application.GetScene().Add(actor);
926 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
928 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
929 glAbstraction.EnableEnableDisableCallTrace(true);
931 application.SendNotification();
932 application.Render();
934 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
935 std::ostringstream blendStr;
936 blendStr << GL_BLEND;
937 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
942 int UtcDaliRendererSetBlendMode04b(void)
944 TestApplication application;
946 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
948 Geometry geometry = CreateQuadGeometry();
949 Shader shader = CreateShader();
950 Renderer renderer = Renderer::New(geometry, shader);
952 Actor actor = Actor::New();
953 actor.AddRenderer(renderer);
954 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
955 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
956 application.GetScene().Add(actor);
958 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
960 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
961 glAbstraction.EnableEnableDisableCallTrace(true);
963 application.SendNotification();
964 application.Render();
966 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
967 std::ostringstream blendStr;
968 blendStr << GL_BLEND;
969 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
974 int UtcDaliRendererSetBlendMode04c(void)
976 TestApplication application;
978 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
980 Geometry geometry = CreateQuadGeometry();
981 Shader shader = CreateShader();
982 Renderer renderer = Renderer::New(geometry, shader);
984 Actor actor = Actor::New();
985 actor.AddRenderer(renderer);
986 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
987 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
988 application.GetScene().Add(actor);
990 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
992 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
993 glAbstraction.EnableEnableDisableCallTrace(true);
995 application.SendNotification();
996 application.Render();
998 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
999 std::ostringstream blendStr;
1000 blendStr << GL_BLEND;
1001 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1006 int UtcDaliRendererSetBlendMode05(void)
1008 TestApplication application;
1010 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1012 Geometry geometry = CreateQuadGeometry();
1013 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1015 Shader shader = CreateShader();
1016 TextureSet textureSet = CreateTextureSet(image);
1017 Renderer renderer = Renderer::New(geometry, shader);
1018 renderer.SetTextures(textureSet);
1020 Actor actor = Actor::New();
1021 actor.AddRenderer(renderer);
1022 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1023 application.GetScene().Add(actor);
1025 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1027 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1028 glAbstraction.EnableEnableDisableCallTrace(true);
1030 application.SendNotification();
1031 application.Render();
1033 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1034 std::ostringstream blendStr;
1035 blendStr << GL_BLEND;
1036 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1041 int UtcDaliRendererSetBlendMode06(void)
1043 TestApplication application;
1044 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");
1046 Geometry geometry = CreateQuadGeometry();
1047 Shader shader = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1049 Renderer renderer = Renderer::New(geometry, shader);
1051 Actor actor = Actor::New();
1052 actor.AddRenderer(renderer);
1053 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1054 application.GetScene().Add(actor);
1056 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1058 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1059 glAbstraction.EnableEnableDisableCallTrace(true);
1061 application.SendNotification();
1062 application.Render();
1064 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1065 std::ostringstream blendStr;
1066 blendStr << GL_BLEND;
1067 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1072 int UtcDaliRendererSetBlendMode07(void)
1074 TestApplication application;
1075 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");
1077 Geometry geometry = CreateQuadGeometry();
1078 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1080 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1081 TextureSet textureSet = CreateTextureSet(image);
1082 Renderer renderer = Renderer::New(geometry, shader);
1083 renderer.SetTextures(textureSet);
1085 Actor actor = Actor::New();
1086 actor.AddRenderer(renderer);
1087 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1088 application.GetScene().Add(actor);
1090 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1092 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1093 glAbstraction.EnableEnableDisableCallTrace(true);
1095 application.SendNotification();
1096 application.Render();
1098 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1099 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", "GL_BLEND"));
1104 int UtcDaliRendererSetBlendMode08(void)
1106 TestApplication application;
1108 tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1110 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
1112 Geometry geometry = CreateQuadGeometry();
1113 Shader shader = CreateShader();
1114 Renderer renderer = Renderer::New(geometry, shader);
1116 Actor actor = Actor::New();
1117 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1118 actor.AddRenderer(renderer);
1119 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1120 application.GetScene().Add(actor);
1122 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1123 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1124 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
1126 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1127 glAbstraction.EnableEnableDisableCallTrace(true);
1129 application.SendNotification();
1130 application.Render();
1132 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1133 std::ostringstream blendStr;
1134 blendStr << GL_BLEND;
1135 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1141 int UtcDaliRendererSetBlendMode08b(void)
1143 TestApplication application;
1145 tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1147 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
1149 Geometry geometry = CreateQuadGeometry();
1150 Shader shader = CreateShader();
1151 Renderer renderer = Renderer::New(geometry, shader);
1153 Actor actor = Actor::New();
1154 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1155 actor.AddRenderer(renderer);
1156 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1157 application.GetScene().Add(actor);
1159 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1160 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
1161 renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
1163 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1164 glAbstraction.EnableEnableDisableCallTrace(true);
1166 application.SendNotification();
1167 application.Render();
1169 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1170 std::ostringstream blendStr;
1171 blendStr << GL_BLEND;
1172 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1178 int UtcDaliRendererGetBlendMode(void)
1180 TestApplication application;
1182 tet_infoline("Test GetBlendMode()");
1184 Geometry geometry = CreateQuadGeometry();
1185 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1186 Renderer renderer = Renderer::New(geometry, shader);
1189 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1190 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1193 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1194 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1195 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1198 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1199 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1200 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1205 int UtcDaliRendererSetBlendColor(void)
1207 TestApplication application;
1209 tet_infoline("Test SetBlendColor(color)");
1211 Geometry geometry = CreateQuadGeometry();
1212 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1213 TextureSet textureSet = TextureSet::New();
1214 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1215 textureSet.SetTexture(0u, image);
1216 Renderer renderer = Renderer::New(geometry, shader);
1217 renderer.SetTextures(textureSet);
1219 Actor actor = Actor::New();
1220 actor.AddRenderer(renderer);
1221 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1222 application.GetScene().Add(actor);
1224 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1226 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1228 application.SendNotification();
1229 application.Render();
1231 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1232 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1233 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1235 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1237 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1238 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1240 application.SendNotification();
1241 application.Render();
1243 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1244 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1246 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1247 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1248 application.SendNotification();
1249 application.Render();
1250 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1255 int UtcDaliRendererGetBlendColor(void)
1257 TestApplication application;
1259 tet_infoline("Test GetBlendColor()");
1261 Geometry geometry = CreateQuadGeometry();
1262 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1263 Renderer renderer = Renderer::New(geometry, shader);
1265 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1267 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1268 application.SendNotification();
1269 application.Render();
1270 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1272 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1273 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1274 application.SendNotification();
1275 application.Render();
1276 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1281 int UtcDaliRendererPreMultipledAlpha(void)
1283 TestApplication application;
1285 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1287 Geometry geometry = CreateQuadGeometry();
1288 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1289 Renderer renderer = Renderer::New(geometry, shader);
1291 Actor actor = Actor::New();
1292 actor.AddRenderer(renderer);
1293 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1294 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1295 application.GetScene().Add(actor);
1297 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1298 bool preMultipliedAlpha;
1299 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1300 DALI_TEST_CHECK(!preMultipliedAlpha);
1302 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1303 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1304 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1305 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1307 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1308 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1309 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1310 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1312 application.SendNotification();
1313 application.Render();
1315 Vector4 actualValue(Vector4::ZERO);
1316 TestGlAbstraction& gl = application.GetGlAbstraction();
1317 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1318 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1320 // Enable pre-multiplied alpha
1321 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1323 application.SendNotification();
1324 application.Render();
1326 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1327 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1328 DALI_TEST_CHECK(preMultipliedAlpha);
1330 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1331 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1332 DALI_TEST_CHECK(preMultipliedAlpha);
1334 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1335 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1336 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1337 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1339 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1340 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1341 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1342 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1344 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1345 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1347 // Disable pre-multiplied alpha again
1348 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1350 application.SendNotification();
1351 application.Render();
1353 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1354 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1355 DALI_TEST_CHECK(!preMultipliedAlpha);
1357 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1358 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1359 DALI_TEST_CHECK(!preMultipliedAlpha);
1361 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1362 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1363 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1364 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1366 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1367 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1368 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1369 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1371 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1372 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1377 int UtcDaliRendererConstraint01(void)
1379 TestApplication application;
1381 tet_infoline("Test that a non-uniform renderer property can be constrained");
1383 Shader shader = Shader::New("VertexSource", "FragmentSource");
1384 Geometry geometry = CreateQuadGeometry();
1385 Renderer renderer = Renderer::New(geometry, shader);
1387 Actor actor = Actor::New();
1388 actor.AddRenderer(renderer);
1389 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1390 application.GetScene().Add(actor);
1392 Vector4 initialColor = Color::WHITE;
1393 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1395 application.SendNotification();
1396 application.Render(0);
1397 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1400 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1402 application.SendNotification();
1403 application.Render(0);
1405 // Expect no blue component in either buffer - yellow
1406 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1407 application.Render(0);
1408 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1410 renderer.RemoveConstraints();
1411 renderer.SetProperty(colorIndex, Color::WHITE);
1412 application.SendNotification();
1413 application.Render(0);
1414 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1419 int UtcDaliRendererConstraint02(void)
1421 TestApplication application;
1423 tet_infoline("Test that a uniform map renderer property can be constrained");
1425 Shader shader = Shader::New("VertexSource", "FragmentSource");
1426 Geometry geometry = CreateQuadGeometry();
1427 Renderer renderer = Renderer::New(geometry, shader);
1429 Actor actor = Actor::New();
1430 actor.AddRenderer(renderer);
1431 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1432 application.GetScene().Add(actor);
1433 application.SendNotification();
1434 application.Render(0);
1436 Vector4 initialColor = Color::WHITE;
1437 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1439 TestGlAbstraction& gl = application.GetGlAbstraction();
1441 application.SendNotification();
1442 application.Render(0);
1444 Vector4 actualValue(Vector4::ZERO);
1445 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1446 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1449 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1451 application.SendNotification();
1452 application.Render(0);
1454 // Expect no blue component in either buffer - yellow
1455 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1456 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1458 application.Render(0);
1459 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1460 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1462 renderer.RemoveConstraints();
1463 renderer.SetProperty(colorIndex, Color::WHITE);
1464 application.SendNotification();
1465 application.Render(0);
1467 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1468 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1473 int UtcDaliRendererAnimatedProperty01(void)
1475 TestApplication application;
1477 tet_infoline("Test that a non-uniform renderer property can be animated");
1479 Shader shader = Shader::New("VertexSource", "FragmentSource");
1480 Geometry geometry = CreateQuadGeometry();
1481 Renderer renderer = Renderer::New(geometry, shader);
1483 Actor actor = Actor::New();
1484 actor.AddRenderer(renderer);
1485 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1486 application.GetScene().Add(actor);
1488 Vector4 initialColor = Color::WHITE;
1489 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1491 application.SendNotification();
1492 application.Render(0);
1493 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1495 Animation animation = Animation::New(1.0f);
1496 KeyFrames keyFrames = KeyFrames::New();
1497 keyFrames.Add(0.0f, initialColor);
1498 keyFrames.Add(1.0f, Color::TRANSPARENT);
1499 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1502 application.SendNotification();
1503 application.Render(500);
1505 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1507 application.Render(500);
1509 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1514 int UtcDaliRendererAnimatedProperty02(void)
1516 TestApplication application;
1518 tet_infoline("Test that a uniform map renderer property can be animated");
1520 Shader shader = Shader::New("VertexSource", "FragmentSource");
1521 Geometry geometry = CreateQuadGeometry();
1522 Renderer renderer = Renderer::New(geometry, shader);
1524 Actor actor = Actor::New();
1525 actor.AddRenderer(renderer);
1526 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1527 application.GetScene().Add(actor);
1528 application.SendNotification();
1529 application.Render(0);
1531 Vector4 initialColor = Color::WHITE;
1532 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1534 TestGlAbstraction& gl = application.GetGlAbstraction();
1536 application.SendNotification();
1537 application.Render(0);
1539 Vector4 actualValue(Vector4::ZERO);
1540 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1541 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1543 Animation animation = Animation::New(1.0f);
1544 KeyFrames keyFrames = KeyFrames::New();
1545 keyFrames.Add(0.0f, initialColor);
1546 keyFrames.Add(1.0f, Color::TRANSPARENT);
1547 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1550 application.SendNotification();
1551 application.Render(500);
1553 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1554 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1556 application.Render(500);
1557 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1558 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1563 int UtcDaliRendererUniformMapPrecendence01(void)
1565 TestApplication application;
1567 tet_infoline("Test the uniform map precedence is applied properly");
1569 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1571 Shader shader = Shader::New("VertexSource", "FragmentSource");
1572 TextureSet textureSet = CreateTextureSet(image);
1574 Geometry geometry = CreateQuadGeometry();
1575 Renderer renderer = Renderer::New(geometry, shader);
1576 renderer.SetTextures(textureSet);
1578 Actor actor = Actor::New();
1579 actor.AddRenderer(renderer);
1580 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1581 application.GetScene().Add(actor);
1582 application.SendNotification();
1583 application.Render(0);
1585 renderer.RegisterProperty("uFadeColor", Color::RED);
1586 actor.RegisterProperty("uFadeColor", Color::GREEN);
1587 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1589 TestGlAbstraction& gl = application.GetGlAbstraction();
1591 application.SendNotification();
1592 application.Render(0);
1594 // Expect that the actor's fade color property is accessed
1595 Vector4 actualValue(Vector4::ZERO);
1596 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1597 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1599 // Animate shader's fade color property. Should be no change to uniform
1600 Animation animation = Animation::New(1.0f);
1601 KeyFrames keyFrames = KeyFrames::New();
1602 keyFrames.Add(0.0f, Color::WHITE);
1603 keyFrames.Add(1.0f, Color::TRANSPARENT);
1604 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1607 application.SendNotification();
1608 application.Render(500);
1610 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1611 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1613 application.Render(500);
1614 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1615 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1620 int UtcDaliRendererUniformMapPrecendence02(void)
1622 TestApplication application;
1624 tet_infoline("Test the uniform map precedence is applied properly");
1626 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1628 Shader shader = Shader::New("VertexSource", "FragmentSource");
1629 TextureSet textureSet = CreateTextureSet(image);
1631 Geometry geometry = CreateQuadGeometry();
1632 Renderer renderer = Renderer::New(geometry, shader);
1633 renderer.SetTextures(textureSet);
1635 Actor actor = Actor::New();
1636 actor.AddRenderer(renderer);
1637 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1638 application.GetScene().Add(actor);
1639 application.SendNotification();
1640 application.Render(0);
1642 // Don't add property / uniform map to renderer
1643 actor.RegisterProperty("uFadeColor", Color::GREEN);
1644 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1646 TestGlAbstraction& gl = application.GetGlAbstraction();
1648 application.SendNotification();
1649 application.Render(0);
1651 // Expect that the actor's fade color property is accessed
1652 Vector4 actualValue(Vector4::ZERO);
1653 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1654 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1656 // Animate texture set's fade color property. Should be no change to uniform
1657 Animation animation = Animation::New(1.0f);
1658 KeyFrames keyFrames = KeyFrames::New();
1659 keyFrames.Add(0.0f, Color::WHITE);
1660 keyFrames.Add(1.0f, Color::TRANSPARENT);
1661 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1664 application.SendNotification();
1665 application.Render(500);
1667 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1668 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1670 application.Render(500);
1671 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1672 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1677 int UtcDaliRendererUniformMapPrecendence03(void)
1679 TestApplication application;
1681 tet_infoline("Test the uniform map precedence is applied properly");
1683 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1685 Shader shader = Shader::New("VertexSource", "FragmentSource");
1686 TextureSet textureSet = CreateTextureSet(image);
1688 Geometry geometry = CreateQuadGeometry();
1689 Renderer renderer = Renderer::New(geometry, shader);
1690 renderer.SetTextures(textureSet);
1692 Actor actor = Actor::New();
1693 actor.AddRenderer(renderer);
1694 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1695 application.GetScene().Add(actor);
1696 application.SendNotification();
1697 application.Render(0);
1699 // Don't add property / uniform map to renderer or actor
1700 shader.RegisterProperty("uFadeColor", Color::BLACK);
1702 TestGlAbstraction& gl = application.GetGlAbstraction();
1704 application.SendNotification();
1705 application.Render(0);
1707 // Expect that the shader's fade color property is accessed
1708 Vector4 actualValue(Vector4::ZERO);
1709 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1710 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1715 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1717 TestApplication application;
1719 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1721 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1723 Shader shader = Shader::New("VertexSource", "FragmentSource");
1724 TextureSet textureSet = CreateTextureSet(image);
1726 Geometry geometry = CreateQuadGeometry();
1727 Renderer renderer = Renderer::New(geometry, shader);
1728 renderer.SetTextures(textureSet);
1730 Actor actor = Actor::New();
1731 actor.AddRenderer(renderer);
1732 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1733 application.GetScene().Add(actor);
1734 application.SendNotification();
1735 application.Render(0);
1737 renderer.RegisterProperty("uUniform1", Color::RED);
1738 actor.RegisterProperty("uUniform2", Color::GREEN);
1739 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1741 TestGlAbstraction& gl = application.GetGlAbstraction();
1743 application.SendNotification();
1744 application.Render(0);
1746 // Expect that each of the object's uniforms are set
1747 Vector4 uniform1Value(Vector4::ZERO);
1748 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1749 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1751 Vector4 uniform2Value(Vector4::ZERO);
1752 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1753 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1755 Vector4 uniform3Value(Vector4::ZERO);
1756 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1757 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1762 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1764 TestApplication application;
1766 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1768 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1770 Shader shader = Shader::New("VertexSource", "FragmentSource");
1771 TextureSet textureSet = CreateTextureSet(image);
1773 Geometry geometry = CreateQuadGeometry();
1774 Renderer renderer = Renderer::New(geometry, shader);
1775 renderer.SetTextures(textureSet);
1777 Actor actor = Actor::New();
1778 actor.AddRenderer(renderer);
1779 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1780 application.GetScene().Add(actor);
1781 application.SendNotification();
1782 application.Render(0);
1784 Property::Value value1(Color::RED);
1785 renderer.RegisterProperty("uFadeColor", value1);
1787 Property::Value value2(1.0f);
1788 actor.RegisterProperty("uFadeProgress", value2);
1790 Property::Value value3(Matrix3::IDENTITY);
1791 shader.RegisterProperty("uANormalMatrix", value3);
1793 TestGlAbstraction& gl = application.GetGlAbstraction();
1795 application.SendNotification();
1796 application.Render(0);
1798 // Expect that each of the object's uniforms are set
1799 Vector4 uniform1Value(Vector4::ZERO);
1800 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1801 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1803 float uniform2Value(0.0f);
1804 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1805 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1807 Matrix3 uniform3Value;
1808 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1809 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1814 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
1816 Texture image0 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
1817 TextureSet textureSet0 = CreateTextureSet(image0);
1818 Renderer renderer0 = Renderer::New(geometry, shader);
1819 renderer0.SetTextures(textureSet0);
1820 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
1821 actor.AddRenderer(renderer0);
1825 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
1827 Actor actor = Actor::New();
1828 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1829 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
1830 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1831 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1833 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
1834 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
1839 int UtcDaliRendererRenderOrder2DLayer(void)
1841 TestApplication application;
1842 tet_infoline("Test the rendering order in a 2D layer is correct");
1844 Shader shader = Shader::New("VertexSource", "FragmentSource");
1845 Geometry geometry = CreateQuadGeometry();
1847 Actor root = application.GetScene().GetRootLayer();
1849 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1850 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1852 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1853 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1855 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1856 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1858 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1859 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1861 application.SendNotification();
1862 application.Render(0);
1865 * Create the following hierarchy:
1878 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1883 application.SendNotification();
1884 application.Render(0);
1886 TestGlAbstraction& gl = application.GetGlAbstraction();
1887 gl.EnableTextureCallTrace(true);
1888 application.SendNotification();
1889 application.Render(0);
1891 int textureBindIndex[4];
1892 for(unsigned int i(0); i < 4; ++i)
1894 std::stringstream params;
1895 params << GL_TEXTURE_2D << ", " << i + 1;
1896 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1899 //Check that actor1 has been rendered after actor2
1900 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1902 //Check that actor0 has been rendered after actor1
1903 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1905 //Check that actor3 has been rendered after actor0
1906 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1911 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1913 TestApplication application;
1914 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1917 * Creates the following hierarchy:
1919 * actor0------------------------>actor1
1923 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1925 * renderer0 has depth index 2
1926 * renderer1 has depth index 0
1927 * renderer2 has depth index 1
1929 * renderer3 has depth index 1
1930 * renderer4 has depth index 0
1931 * renderer5 has depth index -1
1933 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1936 Shader shader = Shader::New("VertexSource", "FragmentSource");
1937 Geometry geometry = CreateQuadGeometry();
1939 Actor root = application.GetScene().GetRootLayer();
1941 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1942 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
1943 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1944 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1945 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1946 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1947 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1948 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1950 application.SendNotification();
1951 application.Render(0);
1953 TestGlAbstraction& gl = application.GetGlAbstraction();
1954 gl.EnableTextureCallTrace(true);
1955 application.SendNotification();
1956 application.Render(0);
1958 int textureBindIndex[6];
1959 for(unsigned int i(0); i < 6; ++i)
1961 std::stringstream params;
1962 params << GL_TEXTURE_2D << ", " << i + 1;
1963 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1966 //Check that renderer3 has been rendered after renderer4
1967 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1969 //Check that renderer0 has been rendered after renderer2
1970 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1972 //Check that renderer5 has been rendered after renderer2
1973 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1975 //Check that renderer0 has been rendered after renderer2
1976 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1978 //Check that renderer2 has been rendered after renderer1
1979 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1984 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1986 TestApplication application;
1987 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1990 * Creates the following hierarchy:
1998 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
2002 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
2003 * DI:2 DI:0 | DI:0 DI:1 DI:2
2008 * actor0 has sibling order 1
2009 * actor1 has sibling order 0
2010 * actor2 has sibling order 0
2012 * renderer0 has depth index 2
2013 * renderer1 has depth index 0
2015 * renderer2 has depth index 0
2016 * renderer3 has depth index 1
2017 * renderer4 has depth index 2
2019 * renderer5 has depth index -1
2021 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2024 Shader shader = Shader::New("VertexSource", "FragmentSource");
2025 Geometry geometry = CreateQuadGeometry();
2026 Actor root = application.GetScene().GetRootLayer();
2027 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
2028 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2029 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
2031 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2032 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2033 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2034 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2035 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2036 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2038 application.SendNotification();
2039 application.Render();
2041 TestGlAbstraction& gl = application.GetGlAbstraction();
2042 gl.EnableTextureCallTrace(true);
2043 application.SendNotification();
2044 application.Render(0);
2046 int textureBindIndex[6];
2047 for(unsigned int i(0); i < 6; ++i)
2049 std::stringstream params;
2050 params << GL_TEXTURE_2D << ", " << i + 1;
2051 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2054 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2055 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2056 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2057 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2058 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2059 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2061 // Change sibling order of actor1
2062 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2063 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2065 gl.GetTextureTrace().Reset();
2066 application.SendNotification();
2067 application.Render(0);
2069 for(unsigned int i(0); i < 6; ++i)
2071 std::stringstream params;
2072 params << GL_TEXTURE_2D << ", " << i + 1;
2073 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2076 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2077 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2078 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2079 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2080 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2081 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2086 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2088 TestApplication application;
2089 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2091 Shader shader = Shader::New("VertexSource", "FragmentSource");
2092 Geometry geometry = CreateQuadGeometry();
2093 Actor root = application.GetScene().GetRootLayer();
2096 * Create the following hierarchy:
2103 * (Overlay) (Regular actor)
2113 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2116 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2117 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2118 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2120 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2121 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2122 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2124 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2125 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2127 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2128 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2129 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2131 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2132 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2134 application.SendNotification();
2135 application.Render(0);
2142 TestGlAbstraction& gl = application.GetGlAbstraction();
2143 gl.EnableTextureCallTrace(true);
2144 application.SendNotification();
2145 application.Render(0);
2147 int textureBindIndex[5];
2148 for(unsigned int i(0); i < 5; ++i)
2150 std::stringstream params;
2151 params << GL_TEXTURE_2D << ", " << i + 1;
2152 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2155 //Check that actor4 has been rendered after actor2
2156 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2158 //Check that actor1 has been rendered after actor4
2159 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2161 //Check that actor0 has been rendered after actor1
2162 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2164 //Check that actor3 has been rendered after actor0
2165 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2170 int UtcDaliRendererSetIndexRange(void)
2174 "attribute vec2 aPosition;\n"
2177 " gl_Position = aPosition;\n"
2182 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2185 TestApplication application;
2186 tet_infoline("Test setting the range of indices to draw");
2188 TestGlAbstraction& gl = application.GetGlAbstraction();
2189 gl.EnableDrawCallTrace(true);
2191 Actor actor = Actor::New();
2192 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2195 Geometry geometry = Geometry::New();
2196 geometry.SetType(Geometry::LINE_LOOP);
2198 // --------------------------------------------------------------------------
2200 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2210 9, // offset = 5, count = 10
2216 1}; // offset = 15, count = 6 // line strip
2218 // --------------------------------------------------------------------------
2227 {Vector2(0.0f, 1.00f)},
2228 {Vector2(0.0f, -1.00f)},
2229 {Vector2(-0.95f, 0.31f)},
2230 {Vector2(0.59f, 0.81f)},
2231 {Vector2(-0.59f, -0.81f)},
2232 {Vector2(-0.95f, -0.31f)},
2233 {Vector2(0.59f, -0.81f)},
2234 {Vector2(0.95f, -0.31f)},
2235 {Vector2(0.95f, 0.31f)},
2236 {Vector2(-0.59f, 0.81f)},
2238 Property::Map vertexFormat;
2239 vertexFormat["aPosition"] = Property::VECTOR2;
2240 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2241 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2243 // --------------------------------------------------------------------------
2244 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2245 geometry.AddVertexBuffer(vertexBuffer);
2248 Shader shader = Shader::New(vertexShader, fragmentShader);
2249 Renderer renderer = Renderer::New(geometry, shader);
2250 actor.AddRenderer(renderer);
2252 Integration::Scene scene = application.GetScene();
2257 // LINE_LOOP, first 0, count 5
2259 renderer.SetIndexRange(0, 5);
2260 application.SendNotification();
2261 application.Render();
2263 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2265 DALI_TEST_CHECK(value.Get(convertedValue));
2266 DALI_TEST_CHECK(convertedValue == 0);
2268 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2269 DALI_TEST_CHECK(value.Get(convertedValue));
2270 DALI_TEST_CHECK(convertedValue == 0);
2272 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2273 DALI_TEST_CHECK(value.Get(convertedValue));
2274 DALI_TEST_CHECK(convertedValue == 5);
2276 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2277 DALI_TEST_CHECK(value.Get(convertedValue));
2278 DALI_TEST_CHECK(convertedValue == 5);
2280 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2281 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2282 DALI_TEST_CHECK(result);
2285 // LINE_LOOP, first 5, count 10
2287 renderer.SetIndexRange(5, 10);
2288 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2289 application.SendNotification();
2290 application.Render();
2291 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2292 DALI_TEST_CHECK(result);
2295 // LINE_STRIP, first 15, count 6
2297 renderer.SetIndexRange(15, 6);
2298 geometry.SetType(Geometry::LINE_STRIP);
2299 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2300 application.SendNotification();
2301 application.Render();
2302 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2303 DALI_TEST_CHECK(result);
2306 // Index out of bounds
2308 renderer.SetIndexRange(15, 30);
2309 geometry.SetType(Geometry::LINE_STRIP);
2310 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2311 application.SendNotification();
2312 application.Render();
2313 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2314 DALI_TEST_CHECK(result);
2317 // drawing whole buffer starting from 15 ( last valid primitive )
2319 renderer.SetIndexRange(15, 0);
2320 geometry.SetType(Geometry::LINE_STRIP);
2321 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2322 application.SendNotification();
2323 application.Render();
2324 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2325 DALI_TEST_CHECK(result);
2331 int UtcDaliRendererSetDepthFunction(void)
2333 TestApplication application;
2335 tet_infoline("Test setting the depth function");
2337 Geometry geometry = CreateQuadGeometry();
2338 Shader shader = CreateShader();
2339 Renderer renderer = Renderer::New(geometry, shader);
2341 Actor actor = Actor::New();
2342 actor.AddRenderer(renderer);
2343 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2344 Integration::Scene scene = application.GetScene();
2345 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2348 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2349 glAbstraction.EnableEnableDisableCallTrace(true);
2350 glAbstraction.EnableDepthFunctionCallTrace(true);
2352 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2353 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2355 std::ostringstream depthTestStr;
2356 depthTestStr << GL_DEPTH_TEST;
2360 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2362 glEnableDisableStack.Reset();
2363 glDepthFunctionStack.Reset();
2364 application.SendNotification();
2365 application.Render();
2367 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2368 std::ostringstream depthFunctionStr;
2369 depthFunctionStr << GL_NEVER;
2370 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2375 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2377 glDepthFunctionStack.Reset();
2378 application.SendNotification();
2379 application.Render();
2381 std::ostringstream depthFunctionStr;
2382 depthFunctionStr << GL_ALWAYS;
2383 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2388 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2390 glDepthFunctionStack.Reset();
2391 application.SendNotification();
2392 application.Render();
2394 std::ostringstream depthFunctionStr;
2395 depthFunctionStr << GL_LESS;
2396 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2401 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2403 glDepthFunctionStack.Reset();
2404 application.SendNotification();
2405 application.Render();
2407 std::ostringstream depthFunctionStr;
2408 depthFunctionStr << GL_GREATER;
2409 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2414 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2416 glDepthFunctionStack.Reset();
2417 application.SendNotification();
2418 application.Render();
2420 std::ostringstream depthFunctionStr;
2421 depthFunctionStr << GL_EQUAL;
2422 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2427 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2429 glDepthFunctionStack.Reset();
2430 application.SendNotification();
2431 application.Render();
2433 std::ostringstream depthFunctionStr;
2434 depthFunctionStr << GL_NOTEQUAL;
2435 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2440 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2442 glDepthFunctionStack.Reset();
2443 application.SendNotification();
2444 application.Render();
2446 std::ostringstream depthFunctionStr;
2447 depthFunctionStr << GL_LEQUAL;
2448 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2453 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2455 glDepthFunctionStack.Reset();
2456 application.SendNotification();
2457 application.Render();
2459 std::ostringstream depthFunctionStr;
2460 depthFunctionStr << GL_GEQUAL;
2461 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2468 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2469 * The checks performed are as follows:
2470 * - Check the initial/default value.
2471 * - Set a different value via enum.
2472 * - Check it was set.
2473 * - Set a different value via string.
2474 * - Check it was set.
2476 template<typename T>
2477 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2479 application.SendNotification();
2480 application.Render();
2482 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2483 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2484 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2485 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2486 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2488 application.SendNotification();
2489 application.Render();
2491 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2492 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2494 renderer.SetProperty(propertyIndex, secondCheckString);
2495 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2496 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2498 application.SendNotification();
2499 application.Render();
2501 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2502 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2505 int UtcDaliRendererEnumProperties(void)
2507 TestApplication application;
2508 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2510 Geometry geometry = CreateQuadGeometry();
2511 Shader shader = CreateShader();
2512 Renderer renderer = Renderer::New(geometry, shader);
2514 Actor actor = Actor::New();
2515 actor.AddRenderer(renderer);
2516 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2517 application.GetScene().Add(actor);
2520 * Here we use a templatized function to perform several checks on each enumeration property.
2521 * @see CheckEnumerationProperty for details of the checks performed.
2524 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2525 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2526 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2527 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2528 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2529 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2530 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2531 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2532 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2533 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2534 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2535 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2536 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2537 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2538 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2539 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2541 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MAX ) &&
2542 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MIN ) )
2544 application.SendNotification();
2545 application.Render();
2546 CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN" );
2549 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
2551 application.SendNotification();
2552 application.Render();
2553 CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN" );
2559 Renderer RendererTestFixture(TestApplication& application)
2561 Geometry geometry = CreateQuadGeometry();
2562 Shader shader = CreateShader();
2563 Renderer renderer = Renderer::New(geometry, shader);
2565 Actor actor = Actor::New();
2566 actor.AddRenderer(renderer);
2567 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2568 Integration::Scene scene = application.GetScene();
2569 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2575 int UtcDaliRendererSetDepthTestMode(void)
2577 TestApplication application;
2578 tet_infoline("Test setting the DepthTestMode");
2580 Renderer renderer = RendererTestFixture(application);
2581 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2582 glAbstraction.EnableEnableDisableCallTrace(true);
2583 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2585 glEnableDisableStack.Reset();
2586 application.SendNotification();
2587 application.Render();
2589 // Check depth-test is enabled by default.
2590 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2591 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2593 // 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.
2594 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2595 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2597 glEnableDisableStack.Reset();
2598 application.SendNotification();
2599 application.Render();
2601 // Check the depth buffer was disabled.
2602 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2604 // Turn on automatic mode depth-testing.
2605 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2606 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2608 glEnableDisableStack.Reset();
2609 application.SendNotification();
2610 application.Render();
2612 // Check depth-test is now enabled.
2613 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2614 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2616 // Change the layer behavior to LAYER_UI.
2617 // Note this will also disable depth testing for the layer by default, we test this first.
2618 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2620 glEnableDisableStack.Reset();
2621 application.SendNotification();
2622 application.Render();
2624 // Check depth-test is disabled.
2625 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2627 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2628 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2630 glEnableDisableStack.Reset();
2631 application.SendNotification();
2632 application.Render();
2634 // Check depth-test is *still* disabled.
2635 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2640 int UtcDaliRendererSetDepthWriteMode(void)
2642 TestApplication application;
2643 tet_infoline("Test setting the DepthWriteMode");
2645 Renderer renderer = RendererTestFixture(application);
2646 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2648 application.SendNotification();
2649 application.Render();
2651 // Check the default depth-write status first.
2652 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2654 // Turn off depth-writing.
2655 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2657 application.SendNotification();
2658 application.Render();
2660 // Check depth-write is now disabled.
2661 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2663 // Test the AUTO mode for depth-writing.
2664 // As our renderer is opaque, depth-testing should be enabled.
2665 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2667 application.SendNotification();
2668 application.Render();
2670 // Check depth-write is now enabled.
2671 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2673 // Now make the renderer be treated as translucent by enabling blending.
2674 // The AUTO depth-write mode should turn depth-write off in this scenario.
2675 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2677 application.SendNotification();
2678 application.Render();
2680 // Check depth-write is now disabled.
2681 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2686 int UtcDaliRendererCheckStencilDefaults(void)
2688 TestApplication application;
2689 tet_infoline("Test the stencil defaults");
2691 Renderer renderer = RendererTestFixture(application);
2692 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2693 glAbstraction.EnableEnableDisableCallTrace(true);
2694 glAbstraction.EnableStencilFunctionCallTrace(true);
2695 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2696 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2698 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2700 // Check the defaults:
2701 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2702 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2703 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2704 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2705 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2706 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);
2707 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);
2712 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2714 TestApplication application;
2715 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2717 Renderer renderer = RendererTestFixture(application);
2718 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2719 glAbstraction.EnableEnableDisableCallTrace(true);
2720 glAbstraction.EnableStencilFunctionCallTrace(true);
2721 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2722 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2724 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2725 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2726 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2727 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2729 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2730 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2732 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2733 std::string methodString("StencilFunc");
2734 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2736 // Test the other RenderModes that will not enable the stencil buffer.
2737 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2738 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2739 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2741 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2742 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2743 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2745 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2746 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2747 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2749 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2750 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2752 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2753 // First set a mode to turn off the stencil buffer, so the enable is required.
2754 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2755 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2756 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2757 // Set a different stencil function as the last one is cached.
2758 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2759 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2761 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2762 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2767 // Helper function for the SetRenderModeToUseColorBuffer test.
2768 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2770 // Set the RenderMode property to a value that should not allow color buffer writes.
2771 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2772 application.SendNotification();
2773 application.Render();
2775 // Check if ColorMask has been called, and that the values are correct.
2776 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2777 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2779 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2780 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2781 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2782 DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2785 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2787 TestApplication application;
2788 tet_infoline("Test setting the RenderMode to use the color buffer");
2790 Renderer renderer = RendererTestFixture(application);
2792 // Set the RenderMode property to a value that should not allow color buffer writes.
2793 // Then check if ColorMask has been called, and that the values are correct.
2794 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2795 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2796 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2797 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2798 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2803 int UtcDaliRendererSetStencilFunction(void)
2805 TestApplication application;
2806 tet_infoline("Test setting the StencilFunction");
2808 Renderer renderer = RendererTestFixture(application);
2809 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2810 glAbstraction.EnableEnableDisableCallTrace(true);
2811 glAbstraction.EnableStencilFunctionCallTrace(true);
2812 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2813 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2815 // RenderMode must use the stencil for StencilFunction to operate.
2816 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2817 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2820 * Lookup table for testing StencilFunction.
2821 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2823 const int StencilFunctionLookupTable[] = {
2832 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2835 * Loop through all types of StencilFunction, checking:
2836 * - The value is cached (set in event thread side)
2837 * - Causes "glStencilFunc" to be called
2838 * - Checks the correct parameters to "glStencilFunc" were used
2840 std::string nonChangingParameters = "0, 255";
2841 std::string methodString("StencilFunc");
2842 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2844 // Set the property.
2845 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2847 // Check GetProperty returns the same value.
2848 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2850 // Reset the trace debug.
2851 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2853 // Check the function is called and the parameters are correct.
2854 std::stringstream parameterStream;
2855 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2857 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2860 // Change the Function Reference only and check the behavior is correct:
2861 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2862 int testValueReference = 170;
2863 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2865 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2867 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2869 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2871 std::stringstream parameterStream;
2872 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2874 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2876 // Change the Function Mask only and check the behavior is correct:
2877 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2878 int testValueMask = 85;
2879 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2881 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2883 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2885 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2887 // Clear the stringstream.
2888 parameterStream.str(std::string());
2889 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2891 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2896 int UtcDaliRendererSetStencilOperation(void)
2898 TestApplication application;
2899 tet_infoline("Test setting the StencilOperation");
2901 Renderer renderer = RendererTestFixture(application);
2902 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2903 glAbstraction.EnableEnableDisableCallTrace(true);
2904 glAbstraction.EnableStencilFunctionCallTrace(true);
2905 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2906 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2908 // RenderMode must use the stencil for StencilOperation to operate.
2909 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2912 * Lookup table for testing StencilOperation.
2913 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2915 const int StencilOperationLookupTable[] = {
2924 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2926 // Set all 3 StencilOperation properties to a default.
2927 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2928 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2929 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2931 // Set our expected parameter list to the equivalent result.
2932 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2934 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2937 * Loop through all types of StencilOperation, checking:
2938 * - The value is cached (set in event thread side)
2939 * - Causes "glStencilFunc" to be called
2940 * - Checks the correct parameters to "glStencilFunc" were used
2941 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2943 std::string methodString("StencilOp");
2945 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2947 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2949 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2951 // Set the property (outer loop causes all 3 different properties to be set separately).
2952 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2953 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2954 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2956 // Check GetProperty returns the same value.
2957 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2958 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2959 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2961 // Reset the trace debug.
2962 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2964 // Check the function is called and the parameters are correct.
2965 // Set the expected parameter value at its correct index (only)
2966 parameters[0u] = StencilOperationLookupTable[i];
2967 parameters[1u] = StencilOperationLookupTable[j];
2968 parameters[2u] = StencilOperationLookupTable[k];
2970 // Build the parameter list.
2971 std::stringstream parameterStream;
2972 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
2974 parameterStream << parameters[parameterBuild];
2975 // Comma-separate the parameters.
2976 if(parameterBuild < 2)
2978 parameterStream << ", ";
2982 // Check the function was called and the parameters were correct.
2983 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2991 int UtcDaliRendererSetStencilMask(void)
2993 TestApplication application;
2994 tet_infoline("Test setting the StencilMask");
2996 Renderer renderer = RendererTestFixture(application);
2997 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2998 glAbstraction.EnableEnableDisableCallTrace(true);
2999 glAbstraction.EnableStencilFunctionCallTrace(true);
3000 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3001 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3003 // RenderMode must use the stencil for StencilMask to operate.
3004 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3006 // Set the StencilMask property to a value.
3007 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3009 // Check GetProperty returns the same value.
3010 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3012 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3014 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3016 std::string methodString("StencilMask");
3017 std::string parameterString = "0";
3019 // Check the function was called and the parameters were correct.
3020 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3022 // Set the StencilMask property to another value to ensure it has changed.
3023 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3025 // Check GetProperty returns the same value.
3026 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3028 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3030 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3032 parameterString = "255";
3034 // Check the function was called and the parameters were correct.
3035 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3040 int UtcDaliRendererWrongNumberOfTextures(void)
3042 TestApplication application;
3043 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3045 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3046 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3047 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3048 TextureSet textureSet = CreateTextureSet();
3049 textureSet.SetTexture(0, texture);
3050 textureSet.SetTexture(1, texture);
3051 textureSet.SetTexture(2, texture);
3052 textureSet.SetTexture(3, texture);
3053 Shader shader = Shader::New("VertexSource", "FragmentSource");
3054 Geometry geometry = CreateQuadGeometry();
3055 Renderer renderer = Renderer::New(geometry, shader);
3056 renderer.SetTextures(textureSet);
3058 Actor actor = Actor::New();
3059 actor.AddRenderer(renderer);
3060 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3061 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3062 application.GetScene().Add(actor);
3064 TestGlAbstraction& gl = application.GetGlAbstraction();
3065 TraceCallStack& drawTrace = gl.GetDrawTrace();
3067 drawTrace.Enable(true);
3069 application.SendNotification();
3070 application.Render(0);
3072 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3073 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3075 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3076 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3077 textureSet = CreateTextureSet();
3078 renderer.SetTextures(textureSet);
3079 textureSet.SetTexture(0, texture);
3081 application.SendNotification();
3082 application.Render(0);
3084 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3085 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3090 int UtcDaliRendererOpacity(void)
3092 TestApplication application;
3094 tet_infoline("Test OPACITY property");
3096 Geometry geometry = CreateQuadGeometry();
3097 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3098 Renderer renderer = Renderer::New(geometry, shader);
3100 Actor actor = Actor::New();
3101 actor.AddRenderer(renderer);
3102 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3103 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3104 application.GetScene().Add(actor);
3106 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3108 DALI_TEST_CHECK(value.Get(opacity));
3109 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3111 application.SendNotification();
3112 application.Render();
3114 Vector4 actualValue;
3115 TestGlAbstraction& gl = application.GetGlAbstraction();
3116 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3117 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3119 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3121 application.SendNotification();
3122 application.Render();
3124 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3125 DALI_TEST_CHECK(value.Get(opacity));
3126 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3128 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3129 DALI_TEST_CHECK(value.Get(opacity));
3130 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3132 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3133 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3138 int UtcDaliRendererOpacityAnimation(void)
3140 TestApplication application;
3142 tet_infoline("Test OPACITY property animation");
3144 Geometry geometry = CreateQuadGeometry();
3145 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3146 Renderer renderer = Renderer::New(geometry, shader);
3148 Actor actor = Actor::New();
3149 actor.AddRenderer(renderer);
3150 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3151 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3152 application.GetScene().Add(actor);
3154 application.SendNotification();
3155 application.Render(0);
3157 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3159 DALI_TEST_CHECK(value.Get(opacity));
3160 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3162 Animation animation = Animation::New(1.0f);
3163 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3166 application.SendNotification();
3167 application.Render(1000);
3169 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3170 DALI_TEST_CHECK(value.Get(opacity));
3171 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3173 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3175 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3177 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3180 application.SendNotification();
3181 application.Render(1000);
3183 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3184 DALI_TEST_CHECK(value.Get(opacity));
3185 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3186 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3191 int UtcDaliRendererInvalidProperty(void)
3193 TestApplication application;
3195 tet_infoline("Test invalid property");
3197 Geometry geometry = CreateQuadGeometry();
3198 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3199 Renderer renderer = Renderer::New(geometry, shader);
3201 Actor actor = Actor::New();
3202 actor.AddRenderer(renderer);
3203 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3204 application.GetScene().Add(actor);
3206 application.SendNotification();
3207 application.Render(0);
3209 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3210 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3212 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3213 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3218 int UtcDaliRendererRenderingBehavior(void)
3220 TestApplication application;
3222 tet_infoline("Test RENDERING_BEHAVIOR property");
3224 Geometry geometry = CreateQuadGeometry();
3225 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3226 Renderer renderer = Renderer::New(geometry, shader);
3228 Actor actor = Actor::New();
3229 actor.AddRenderer(renderer);
3230 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3231 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3232 application.GetScene().Add(actor);
3234 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3235 int renderingBehavior;
3236 DALI_TEST_CHECK(value.Get(renderingBehavior));
3237 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3239 application.SendNotification();
3240 application.Render();
3242 uint32_t updateStatus = application.GetUpdateStatus();
3244 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3246 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3248 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3249 DALI_TEST_CHECK(value.Get(renderingBehavior));
3250 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3252 // Render and check the update status
3253 application.SendNotification();
3254 application.Render();
3256 updateStatus = application.GetUpdateStatus();
3258 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3260 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3261 DALI_TEST_CHECK(value.Get(renderingBehavior));
3262 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3264 // Render again and check the update status
3265 application.SendNotification();
3266 application.Render();
3268 updateStatus = application.GetUpdateStatus();
3270 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3272 // Change rendering behavior
3273 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3275 // Render and check the update status
3276 application.SendNotification();
3277 application.Render();
3279 updateStatus = application.GetUpdateStatus();
3281 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3286 int UtcDaliRendererRegenerateUniformMap(void)
3288 TestApplication application;
3290 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3292 Geometry geometry = CreateQuadGeometry();
3293 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3294 Renderer renderer = Renderer::New(geometry, shader);
3296 Actor actor = Actor::New();
3297 actor.AddRenderer(renderer);
3298 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3299 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3300 application.GetScene().Add(actor);
3302 application.SendNotification();
3303 application.Render();
3305 actor.RemoveRenderer(renderer);
3306 shader = Shader::New("vertexSrc", "fragmentSrc");
3307 shader.RegisterProperty("opacity", 0.5f);
3308 renderer.SetShader(shader);
3310 Stage::GetCurrent().KeepRendering(1.0f);
3312 // Update for several frames
3313 application.SendNotification();
3314 application.Render();
3315 application.SendNotification();
3316 application.Render();
3317 application.SendNotification();
3318 application.Render();
3319 application.SendNotification();
3320 application.Render();
3323 actor.AddRenderer(renderer);
3324 application.SendNotification();
3325 application.Render();
3327 // Nothing to test here, the test must not crash
3328 auto updateStatus = application.GetUpdateStatus();
3329 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3334 int UtcDaliRendererAddDrawCommands(void)
3336 TestApplication application;
3338 tet_infoline("Test adding draw commands to the renderer");
3340 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3341 glAbstraction.EnableEnableDisableCallTrace(true);
3343 Geometry geometry = CreateQuadGeometry();
3344 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3345 Renderer renderer = Renderer::New(geometry, shader);
3347 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3348 Actor actor = Actor::New();
3349 actor.AddRenderer(renderer);
3350 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3351 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3352 application.GetScene().Add(actor);
3354 // Expect delivering a single draw call
3355 auto& drawTrace = glAbstraction.GetDrawTrace();
3357 drawTrace.Enable(true);
3358 application.SendNotification();
3359 application.Render();
3361 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3363 auto drawCommand1 = DevelRenderer::DrawCommand{};
3364 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3365 drawCommand1.firstIndex = 0;
3366 drawCommand1.elementCount = 2;
3367 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3369 auto drawCommand2 = DevelRenderer::DrawCommand{};
3370 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3371 drawCommand2.firstIndex = 2;
3372 drawCommand2.elementCount = 2;
3373 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3375 auto drawCommand3 = DevelRenderer::DrawCommand{};
3376 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3377 drawCommand3.firstIndex = 2;
3378 drawCommand3.elementCount = 2;
3379 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3381 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3382 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3383 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3386 drawTrace.Enable(true);
3387 application.SendNotification();
3388 application.Render();
3390 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3394 int UtcDaliRendererSetGeometryNegative(void)
3396 TestApplication application;
3397 Dali::Renderer instance;
3400 Dali::Geometry arg1;
3401 instance.SetGeometry(arg1);
3402 DALI_TEST_CHECK(false); // Should not get here
3406 DALI_TEST_CHECK(true); // We expect an assert
3411 int UtcDaliRendererSetTexturesNegative(void)
3413 TestApplication application;
3414 Dali::Renderer instance;
3417 Dali::TextureSet arg1;
3418 instance.SetTextures(arg1);
3419 DALI_TEST_CHECK(false); // Should not get here
3423 DALI_TEST_CHECK(true); // We expect an assert
3428 int UtcDaliRendererSetShaderNegative(void)
3430 TestApplication application;
3431 Dali::Renderer instance;
3435 instance.SetShader(arg1);
3436 DALI_TEST_CHECK(false); // Should not get here
3440 DALI_TEST_CHECK(true); // We expect an assert
3445 int UtcDaliRendererGetGeometryNegative(void)
3447 TestApplication application;
3448 Dali::Renderer instance;
3451 instance.GetGeometry();
3452 DALI_TEST_CHECK(false); // Should not get here
3456 DALI_TEST_CHECK(true); // We expect an assert
3461 int UtcDaliRendererGetTexturesNegative(void)
3463 TestApplication application;
3464 Dali::Renderer instance;
3467 instance.GetTextures();
3468 DALI_TEST_CHECK(false); // Should not get here
3472 DALI_TEST_CHECK(true); // We expect an assert
3477 int UtcDaliRendererGetShaderNegative(void)
3479 TestApplication application;
3480 Dali::Renderer instance;
3483 instance.GetShader();
3484 DALI_TEST_CHECK(false); // Should not get here
3488 DALI_TEST_CHECK(true); // We expect an assert