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 UtcDaliRendererGetBlendMode(void)
1106 TestApplication application;
1108 tet_infoline("Test GetBlendMode()");
1110 Geometry geometry = CreateQuadGeometry();
1111 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1112 Renderer renderer = Renderer::New(geometry, shader);
1115 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1116 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1119 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1120 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1121 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1124 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1125 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1126 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1131 int UtcDaliRendererSetBlendColor(void)
1133 TestApplication application;
1135 tet_infoline("Test SetBlendColor(color)");
1137 Geometry geometry = CreateQuadGeometry();
1138 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1139 TextureSet textureSet = TextureSet::New();
1140 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1141 textureSet.SetTexture(0u, image);
1142 Renderer renderer = Renderer::New(geometry, shader);
1143 renderer.SetTextures(textureSet);
1145 Actor actor = Actor::New();
1146 actor.AddRenderer(renderer);
1147 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1148 application.GetScene().Add(actor);
1150 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1152 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1154 application.SendNotification();
1155 application.Render();
1157 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1158 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1159 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1161 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1163 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1164 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1166 application.SendNotification();
1167 application.Render();
1169 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1170 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1172 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1173 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1174 application.SendNotification();
1175 application.Render();
1176 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1181 int UtcDaliRendererGetBlendColor(void)
1183 TestApplication application;
1185 tet_infoline("Test GetBlendColor()");
1187 Geometry geometry = CreateQuadGeometry();
1188 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1189 Renderer renderer = Renderer::New(geometry, shader);
1191 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1193 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1194 application.SendNotification();
1195 application.Render();
1196 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1198 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1199 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1200 application.SendNotification();
1201 application.Render();
1202 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1207 int UtcDaliRendererPreMultipledAlpha(void)
1209 TestApplication application;
1211 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1213 Geometry geometry = CreateQuadGeometry();
1214 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1215 Renderer renderer = Renderer::New(geometry, shader);
1217 Actor actor = Actor::New();
1218 actor.AddRenderer(renderer);
1219 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1220 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1221 application.GetScene().Add(actor);
1223 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1224 bool preMultipliedAlpha;
1225 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1226 DALI_TEST_CHECK(!preMultipliedAlpha);
1228 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1229 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1230 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1231 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1233 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1234 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1235 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1236 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1238 application.SendNotification();
1239 application.Render();
1241 Vector4 actualValue(Vector4::ZERO);
1242 TestGlAbstraction& gl = application.GetGlAbstraction();
1243 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1244 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1246 // Enable pre-multiplied alpha
1247 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1249 application.SendNotification();
1250 application.Render();
1252 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1253 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1254 DALI_TEST_CHECK(preMultipliedAlpha);
1256 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1257 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1258 DALI_TEST_CHECK(preMultipliedAlpha);
1260 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1261 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1262 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1263 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1265 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1266 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1267 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1268 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1270 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1271 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1273 // Disable pre-multiplied alpha again
1274 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1276 application.SendNotification();
1277 application.Render();
1279 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1280 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1281 DALI_TEST_CHECK(!preMultipliedAlpha);
1283 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1284 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1285 DALI_TEST_CHECK(!preMultipliedAlpha);
1287 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1288 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1289 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1290 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1292 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1293 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1294 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1295 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1297 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1298 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1303 int UtcDaliRendererConstraint01(void)
1305 TestApplication application;
1307 tet_infoline("Test that a non-uniform renderer property can be constrained");
1309 Shader shader = Shader::New("VertexSource", "FragmentSource");
1310 Geometry geometry = CreateQuadGeometry();
1311 Renderer renderer = Renderer::New(geometry, shader);
1313 Actor actor = Actor::New();
1314 actor.AddRenderer(renderer);
1315 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1316 application.GetScene().Add(actor);
1318 Vector4 initialColor = Color::WHITE;
1319 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1321 application.SendNotification();
1322 application.Render(0);
1323 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1326 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1328 application.SendNotification();
1329 application.Render(0);
1331 // Expect no blue component in either buffer - yellow
1332 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1333 application.Render(0);
1334 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1336 renderer.RemoveConstraints();
1337 renderer.SetProperty(colorIndex, Color::WHITE);
1338 application.SendNotification();
1339 application.Render(0);
1340 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1345 int UtcDaliRendererConstraint02(void)
1347 TestApplication application;
1349 tet_infoline("Test that a uniform map renderer property can be constrained");
1351 Shader shader = Shader::New("VertexSource", "FragmentSource");
1352 Geometry geometry = CreateQuadGeometry();
1353 Renderer renderer = Renderer::New(geometry, shader);
1355 Actor actor = Actor::New();
1356 actor.AddRenderer(renderer);
1357 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1358 application.GetScene().Add(actor);
1359 application.SendNotification();
1360 application.Render(0);
1362 Vector4 initialColor = Color::WHITE;
1363 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1365 TestGlAbstraction& gl = application.GetGlAbstraction();
1367 application.SendNotification();
1368 application.Render(0);
1370 Vector4 actualValue(Vector4::ZERO);
1371 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1372 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1375 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1377 application.SendNotification();
1378 application.Render(0);
1380 // Expect no blue component in either buffer - yellow
1381 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1382 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1384 application.Render(0);
1385 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1386 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1388 renderer.RemoveConstraints();
1389 renderer.SetProperty(colorIndex, Color::WHITE);
1390 application.SendNotification();
1391 application.Render(0);
1393 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1394 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1399 int UtcDaliRendererAnimatedProperty01(void)
1401 TestApplication application;
1403 tet_infoline("Test that a non-uniform renderer property can be animated");
1405 Shader shader = Shader::New("VertexSource", "FragmentSource");
1406 Geometry geometry = CreateQuadGeometry();
1407 Renderer renderer = Renderer::New(geometry, shader);
1409 Actor actor = Actor::New();
1410 actor.AddRenderer(renderer);
1411 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1412 application.GetScene().Add(actor);
1414 Vector4 initialColor = Color::WHITE;
1415 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1417 application.SendNotification();
1418 application.Render(0);
1419 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1421 Animation animation = Animation::New(1.0f);
1422 KeyFrames keyFrames = KeyFrames::New();
1423 keyFrames.Add(0.0f, initialColor);
1424 keyFrames.Add(1.0f, Color::TRANSPARENT);
1425 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1428 application.SendNotification();
1429 application.Render(500);
1431 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1433 application.Render(500);
1435 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1440 int UtcDaliRendererAnimatedProperty02(void)
1442 TestApplication application;
1444 tet_infoline("Test that a uniform map renderer property can be animated");
1446 Shader shader = Shader::New("VertexSource", "FragmentSource");
1447 Geometry geometry = CreateQuadGeometry();
1448 Renderer renderer = Renderer::New(geometry, shader);
1450 Actor actor = Actor::New();
1451 actor.AddRenderer(renderer);
1452 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1453 application.GetScene().Add(actor);
1454 application.SendNotification();
1455 application.Render(0);
1457 Vector4 initialColor = Color::WHITE;
1458 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1460 TestGlAbstraction& gl = application.GetGlAbstraction();
1462 application.SendNotification();
1463 application.Render(0);
1465 Vector4 actualValue(Vector4::ZERO);
1466 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1467 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1469 Animation animation = Animation::New(1.0f);
1470 KeyFrames keyFrames = KeyFrames::New();
1471 keyFrames.Add(0.0f, initialColor);
1472 keyFrames.Add(1.0f, Color::TRANSPARENT);
1473 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1476 application.SendNotification();
1477 application.Render(500);
1479 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1480 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1482 application.Render(500);
1483 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1484 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1489 int UtcDaliRendererUniformMapPrecendence01(void)
1491 TestApplication application;
1493 tet_infoline("Test the uniform map precedence is applied properly");
1495 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1497 Shader shader = Shader::New("VertexSource", "FragmentSource");
1498 TextureSet textureSet = CreateTextureSet(image);
1500 Geometry geometry = CreateQuadGeometry();
1501 Renderer renderer = Renderer::New(geometry, shader);
1502 renderer.SetTextures(textureSet);
1504 Actor actor = Actor::New();
1505 actor.AddRenderer(renderer);
1506 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1507 application.GetScene().Add(actor);
1508 application.SendNotification();
1509 application.Render(0);
1511 renderer.RegisterProperty("uFadeColor", Color::RED);
1512 actor.RegisterProperty("uFadeColor", Color::GREEN);
1513 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1515 TestGlAbstraction& gl = application.GetGlAbstraction();
1517 application.SendNotification();
1518 application.Render(0);
1520 // Expect that the actor's fade color property is accessed
1521 Vector4 actualValue(Vector4::ZERO);
1522 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1523 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1525 // Animate shader's fade color property. Should be no change to uniform
1526 Animation animation = Animation::New(1.0f);
1527 KeyFrames keyFrames = KeyFrames::New();
1528 keyFrames.Add(0.0f, Color::WHITE);
1529 keyFrames.Add(1.0f, Color::TRANSPARENT);
1530 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1533 application.SendNotification();
1534 application.Render(500);
1536 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1537 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1539 application.Render(500);
1540 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1541 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1546 int UtcDaliRendererUniformMapPrecendence02(void)
1548 TestApplication application;
1550 tet_infoline("Test the uniform map precedence is applied properly");
1552 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1554 Shader shader = Shader::New("VertexSource", "FragmentSource");
1555 TextureSet textureSet = CreateTextureSet(image);
1557 Geometry geometry = CreateQuadGeometry();
1558 Renderer renderer = Renderer::New(geometry, shader);
1559 renderer.SetTextures(textureSet);
1561 Actor actor = Actor::New();
1562 actor.AddRenderer(renderer);
1563 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1564 application.GetScene().Add(actor);
1565 application.SendNotification();
1566 application.Render(0);
1568 // Don't add property / uniform map to renderer
1569 actor.RegisterProperty("uFadeColor", Color::GREEN);
1570 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1572 TestGlAbstraction& gl = application.GetGlAbstraction();
1574 application.SendNotification();
1575 application.Render(0);
1577 // Expect that the actor's fade color property is accessed
1578 Vector4 actualValue(Vector4::ZERO);
1579 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1580 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1582 // Animate texture set's fade color property. Should be no change to uniform
1583 Animation animation = Animation::New(1.0f);
1584 KeyFrames keyFrames = KeyFrames::New();
1585 keyFrames.Add(0.0f, Color::WHITE);
1586 keyFrames.Add(1.0f, Color::TRANSPARENT);
1587 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1590 application.SendNotification();
1591 application.Render(500);
1593 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1594 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1596 application.Render(500);
1597 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1598 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1603 int UtcDaliRendererUniformMapPrecendence03(void)
1605 TestApplication application;
1607 tet_infoline("Test the uniform map precedence is applied properly");
1609 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1611 Shader shader = Shader::New("VertexSource", "FragmentSource");
1612 TextureSet textureSet = CreateTextureSet(image);
1614 Geometry geometry = CreateQuadGeometry();
1615 Renderer renderer = Renderer::New(geometry, shader);
1616 renderer.SetTextures(textureSet);
1618 Actor actor = Actor::New();
1619 actor.AddRenderer(renderer);
1620 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1621 application.GetScene().Add(actor);
1622 application.SendNotification();
1623 application.Render(0);
1625 // Don't add property / uniform map to renderer or actor
1626 shader.RegisterProperty("uFadeColor", Color::BLACK);
1628 TestGlAbstraction& gl = application.GetGlAbstraction();
1630 application.SendNotification();
1631 application.Render(0);
1633 // Expect that the shader's fade color property is accessed
1634 Vector4 actualValue(Vector4::ZERO);
1635 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1636 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1641 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1643 TestApplication application;
1645 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1647 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1649 Shader shader = Shader::New("VertexSource", "FragmentSource");
1650 TextureSet textureSet = CreateTextureSet(image);
1652 Geometry geometry = CreateQuadGeometry();
1653 Renderer renderer = Renderer::New(geometry, shader);
1654 renderer.SetTextures(textureSet);
1656 Actor actor = Actor::New();
1657 actor.AddRenderer(renderer);
1658 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1659 application.GetScene().Add(actor);
1660 application.SendNotification();
1661 application.Render(0);
1663 renderer.RegisterProperty("uUniform1", Color::RED);
1664 actor.RegisterProperty("uUniform2", Color::GREEN);
1665 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1667 TestGlAbstraction& gl = application.GetGlAbstraction();
1669 application.SendNotification();
1670 application.Render(0);
1672 // Expect that each of the object's uniforms are set
1673 Vector4 uniform1Value(Vector4::ZERO);
1674 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1675 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1677 Vector4 uniform2Value(Vector4::ZERO);
1678 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1679 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1681 Vector4 uniform3Value(Vector4::ZERO);
1682 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1683 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1688 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1690 TestApplication application;
1692 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1694 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1696 Shader shader = Shader::New("VertexSource", "FragmentSource");
1697 TextureSet textureSet = CreateTextureSet(image);
1699 Geometry geometry = CreateQuadGeometry();
1700 Renderer renderer = Renderer::New(geometry, shader);
1701 renderer.SetTextures(textureSet);
1703 Actor actor = Actor::New();
1704 actor.AddRenderer(renderer);
1705 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1706 application.GetScene().Add(actor);
1707 application.SendNotification();
1708 application.Render(0);
1710 Property::Value value1(Color::RED);
1711 renderer.RegisterProperty("uFadeColor", value1);
1713 Property::Value value2(1.0f);
1714 actor.RegisterProperty("uFadeProgress", value2);
1716 Property::Value value3(Matrix3::IDENTITY);
1717 shader.RegisterProperty("uANormalMatrix", value3);
1719 TestGlAbstraction& gl = application.GetGlAbstraction();
1721 application.SendNotification();
1722 application.Render(0);
1724 // Expect that each of the object's uniforms are set
1725 Vector4 uniform1Value(Vector4::ZERO);
1726 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1727 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1729 float uniform2Value(0.0f);
1730 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1731 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1733 Matrix3 uniform3Value;
1734 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1735 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1740 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
1742 Texture image0 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
1743 TextureSet textureSet0 = CreateTextureSet(image0);
1744 Renderer renderer0 = Renderer::New(geometry, shader);
1745 renderer0.SetTextures(textureSet0);
1746 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
1747 actor.AddRenderer(renderer0);
1751 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
1753 Actor actor = Actor::New();
1754 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1755 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
1756 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1757 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1759 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
1760 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
1765 int UtcDaliRendererRenderOrder2DLayer(void)
1767 TestApplication application;
1768 tet_infoline("Test the rendering order in a 2D layer is correct");
1770 Shader shader = Shader::New("VertexSource", "FragmentSource");
1771 Geometry geometry = CreateQuadGeometry();
1773 Actor root = application.GetScene().GetRootLayer();
1775 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1776 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1778 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1779 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1781 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1782 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1784 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1785 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1787 application.SendNotification();
1788 application.Render(0);
1791 * Create the following hierarchy:
1804 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1809 application.SendNotification();
1810 application.Render(0);
1812 TestGlAbstraction& gl = application.GetGlAbstraction();
1813 gl.EnableTextureCallTrace(true);
1814 application.SendNotification();
1815 application.Render(0);
1817 int textureBindIndex[4];
1818 for(unsigned int i(0); i < 4; ++i)
1820 std::stringstream params;
1821 params << GL_TEXTURE_2D << ", " << i + 1;
1822 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1825 //Check that actor1 has been rendered after actor2
1826 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1828 //Check that actor0 has been rendered after actor1
1829 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1831 //Check that actor3 has been rendered after actor0
1832 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1837 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1839 TestApplication application;
1840 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1843 * Creates the following hierarchy:
1845 * actor0------------------------>actor1
1849 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1851 * renderer0 has depth index 2
1852 * renderer1 has depth index 0
1853 * renderer2 has depth index 1
1855 * renderer3 has depth index 1
1856 * renderer4 has depth index 0
1857 * renderer5 has depth index -1
1859 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1862 Shader shader = Shader::New("VertexSource", "FragmentSource");
1863 Geometry geometry = CreateQuadGeometry();
1865 Actor root = application.GetScene().GetRootLayer();
1867 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1868 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
1869 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1870 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1871 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1872 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1873 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1874 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1876 application.SendNotification();
1877 application.Render(0);
1879 TestGlAbstraction& gl = application.GetGlAbstraction();
1880 gl.EnableTextureCallTrace(true);
1881 application.SendNotification();
1882 application.Render(0);
1884 int textureBindIndex[6];
1885 for(unsigned int i(0); i < 6; ++i)
1887 std::stringstream params;
1888 params << GL_TEXTURE_2D << ", " << i + 1;
1889 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1892 //Check that renderer3 has been rendered after renderer4
1893 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1895 //Check that renderer0 has been rendered after renderer2
1896 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1898 //Check that renderer5 has been rendered after renderer2
1899 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1901 //Check that renderer0 has been rendered after renderer2
1902 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1904 //Check that renderer2 has been rendered after renderer1
1905 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1910 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1912 TestApplication application;
1913 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1916 * Creates the following hierarchy:
1924 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1928 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1929 * DI:2 DI:0 | DI:0 DI:1 DI:2
1934 * actor0 has sibling order 1
1935 * actor1 has sibling order 0
1936 * actor2 has sibling order 0
1938 * renderer0 has depth index 2
1939 * renderer1 has depth index 0
1941 * renderer2 has depth index 0
1942 * renderer3 has depth index 1
1943 * renderer4 has depth index 2
1945 * renderer5 has depth index -1
1947 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1950 Shader shader = Shader::New("VertexSource", "FragmentSource");
1951 Geometry geometry = CreateQuadGeometry();
1952 Actor root = application.GetScene().GetRootLayer();
1953 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
1954 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1955 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
1957 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1958 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1959 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
1960 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1961 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
1962 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
1964 application.SendNotification();
1965 application.Render();
1967 TestGlAbstraction& gl = application.GetGlAbstraction();
1968 gl.EnableTextureCallTrace(true);
1969 application.SendNotification();
1970 application.Render(0);
1972 int textureBindIndex[6];
1973 for(unsigned int i(0); i < 6; ++i)
1975 std::stringstream params;
1976 params << GL_TEXTURE_2D << ", " << i + 1;
1977 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1980 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
1981 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
1982 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
1983 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
1984 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
1985 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
1987 // Change sibling order of actor1
1988 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1989 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
1991 gl.GetTextureTrace().Reset();
1992 application.SendNotification();
1993 application.Render(0);
1995 for(unsigned int i(0); i < 6; ++i)
1997 std::stringstream params;
1998 params << GL_TEXTURE_2D << ", " << i + 1;
1999 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2002 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2003 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2004 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2005 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2006 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2007 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2012 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2014 TestApplication application;
2015 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2017 Shader shader = Shader::New("VertexSource", "FragmentSource");
2018 Geometry geometry = CreateQuadGeometry();
2019 Actor root = application.GetScene().GetRootLayer();
2022 * Create the following hierarchy:
2029 * (Overlay) (Regular actor)
2039 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2042 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2043 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2044 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2046 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2047 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2048 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2050 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2051 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2053 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2054 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2055 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2057 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2058 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2060 application.SendNotification();
2061 application.Render(0);
2068 TestGlAbstraction& gl = application.GetGlAbstraction();
2069 gl.EnableTextureCallTrace(true);
2070 application.SendNotification();
2071 application.Render(0);
2073 int textureBindIndex[5];
2074 for(unsigned int i(0); i < 5; ++i)
2076 std::stringstream params;
2077 params << GL_TEXTURE_2D << ", " << i + 1;
2078 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2081 //Check that actor4 has been rendered after actor2
2082 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2084 //Check that actor1 has been rendered after actor4
2085 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2087 //Check that actor0 has been rendered after actor1
2088 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2090 //Check that actor3 has been rendered after actor0
2091 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2096 int UtcDaliRendererSetIndexRange(void)
2100 "attribute vec2 aPosition;\n"
2103 " gl_Position = aPosition;\n"
2108 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2111 TestApplication application;
2112 tet_infoline("Test setting the range of indices to draw");
2114 TestGlAbstraction& gl = application.GetGlAbstraction();
2115 gl.EnableDrawCallTrace(true);
2117 Actor actor = Actor::New();
2118 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2121 Geometry geometry = Geometry::New();
2122 geometry.SetType(Geometry::LINE_LOOP);
2124 // --------------------------------------------------------------------------
2126 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2136 9, // offset = 5, count = 10
2142 1}; // offset = 15, count = 6 // line strip
2144 // --------------------------------------------------------------------------
2153 {Vector2(0.0f, 1.00f)},
2154 {Vector2(0.0f, -1.00f)},
2155 {Vector2(-0.95f, 0.31f)},
2156 {Vector2(0.59f, 0.81f)},
2157 {Vector2(-0.59f, -0.81f)},
2158 {Vector2(-0.95f, -0.31f)},
2159 {Vector2(0.59f, -0.81f)},
2160 {Vector2(0.95f, -0.31f)},
2161 {Vector2(0.95f, 0.31f)},
2162 {Vector2(-0.59f, 0.81f)},
2164 Property::Map vertexFormat;
2165 vertexFormat["aPosition"] = Property::VECTOR2;
2166 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2167 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2169 // --------------------------------------------------------------------------
2170 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2171 geometry.AddVertexBuffer(vertexBuffer);
2174 Shader shader = Shader::New(vertexShader, fragmentShader);
2175 Renderer renderer = Renderer::New(geometry, shader);
2176 actor.AddRenderer(renderer);
2178 Integration::Scene scene = application.GetScene();
2183 // LINE_LOOP, first 0, count 5
2185 renderer.SetIndexRange(0, 5);
2186 application.SendNotification();
2187 application.Render();
2189 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2191 DALI_TEST_CHECK(value.Get(convertedValue));
2192 DALI_TEST_CHECK(convertedValue == 0);
2194 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2195 DALI_TEST_CHECK(value.Get(convertedValue));
2196 DALI_TEST_CHECK(convertedValue == 0);
2198 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2199 DALI_TEST_CHECK(value.Get(convertedValue));
2200 DALI_TEST_CHECK(convertedValue == 5);
2202 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2203 DALI_TEST_CHECK(value.Get(convertedValue));
2204 DALI_TEST_CHECK(convertedValue == 5);
2206 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2207 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2208 DALI_TEST_CHECK(result);
2211 // LINE_LOOP, first 5, count 10
2213 renderer.SetIndexRange(5, 10);
2214 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2215 application.SendNotification();
2216 application.Render();
2217 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2218 DALI_TEST_CHECK(result);
2221 // LINE_STRIP, first 15, count 6
2223 renderer.SetIndexRange(15, 6);
2224 geometry.SetType(Geometry::LINE_STRIP);
2225 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2226 application.SendNotification();
2227 application.Render();
2228 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2229 DALI_TEST_CHECK(result);
2232 // Index out of bounds
2234 renderer.SetIndexRange(15, 30);
2235 geometry.SetType(Geometry::LINE_STRIP);
2236 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2237 application.SendNotification();
2238 application.Render();
2239 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2240 DALI_TEST_CHECK(result);
2243 // drawing whole buffer starting from 15 ( last valid primitive )
2245 renderer.SetIndexRange(15, 0);
2246 geometry.SetType(Geometry::LINE_STRIP);
2247 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2248 application.SendNotification();
2249 application.Render();
2250 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2251 DALI_TEST_CHECK(result);
2257 int UtcDaliRendererSetDepthFunction(void)
2259 TestApplication application;
2261 tet_infoline("Test setting the depth function");
2263 Geometry geometry = CreateQuadGeometry();
2264 Shader shader = CreateShader();
2265 Renderer renderer = Renderer::New(geometry, shader);
2267 Actor actor = Actor::New();
2268 actor.AddRenderer(renderer);
2269 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2270 Integration::Scene scene = application.GetScene();
2271 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2274 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2275 glAbstraction.EnableEnableDisableCallTrace(true);
2276 glAbstraction.EnableDepthFunctionCallTrace(true);
2278 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2279 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2281 std::ostringstream depthTestStr;
2282 depthTestStr << GL_DEPTH_TEST;
2286 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2288 glEnableDisableStack.Reset();
2289 glDepthFunctionStack.Reset();
2290 application.SendNotification();
2291 application.Render();
2293 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2294 std::ostringstream depthFunctionStr;
2295 depthFunctionStr << GL_NEVER;
2296 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2301 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2303 glDepthFunctionStack.Reset();
2304 application.SendNotification();
2305 application.Render();
2307 std::ostringstream depthFunctionStr;
2308 depthFunctionStr << GL_ALWAYS;
2309 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2314 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2316 glDepthFunctionStack.Reset();
2317 application.SendNotification();
2318 application.Render();
2320 std::ostringstream depthFunctionStr;
2321 depthFunctionStr << GL_LESS;
2322 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2327 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2329 glDepthFunctionStack.Reset();
2330 application.SendNotification();
2331 application.Render();
2333 std::ostringstream depthFunctionStr;
2334 depthFunctionStr << GL_GREATER;
2335 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2340 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2342 glDepthFunctionStack.Reset();
2343 application.SendNotification();
2344 application.Render();
2346 std::ostringstream depthFunctionStr;
2347 depthFunctionStr << GL_EQUAL;
2348 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2353 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2355 glDepthFunctionStack.Reset();
2356 application.SendNotification();
2357 application.Render();
2359 std::ostringstream depthFunctionStr;
2360 depthFunctionStr << GL_NOTEQUAL;
2361 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2366 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2368 glDepthFunctionStack.Reset();
2369 application.SendNotification();
2370 application.Render();
2372 std::ostringstream depthFunctionStr;
2373 depthFunctionStr << GL_LEQUAL;
2374 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2379 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2381 glDepthFunctionStack.Reset();
2382 application.SendNotification();
2383 application.Render();
2385 std::ostringstream depthFunctionStr;
2386 depthFunctionStr << GL_GEQUAL;
2387 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2394 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2395 * The checks performed are as follows:
2396 * - Check the initial/default value.
2397 * - Set a different value via enum.
2398 * - Check it was set.
2399 * - Set a different value via string.
2400 * - Check it was set.
2402 template<typename T>
2403 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2405 application.SendNotification();
2406 application.Render();
2408 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2409 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2410 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2411 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2412 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2414 application.SendNotification();
2415 application.Render();
2417 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2418 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2420 renderer.SetProperty(propertyIndex, secondCheckString);
2421 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2422 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2424 application.SendNotification();
2425 application.Render();
2427 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2428 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2431 int UtcDaliRendererEnumProperties(void)
2433 TestApplication application;
2434 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2436 Geometry geometry = CreateQuadGeometry();
2437 Shader shader = CreateShader();
2438 Renderer renderer = Renderer::New(geometry, shader);
2440 Actor actor = Actor::New();
2441 actor.AddRenderer(renderer);
2442 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2443 application.GetScene().Add(actor);
2446 * Here we use a templatized function to perform several checks on each enumeration property.
2447 * @see CheckEnumerationProperty for details of the checks performed.
2450 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2451 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2452 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2453 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2454 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2455 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2456 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2457 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2458 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2459 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2460 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2461 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2462 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2463 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2464 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2465 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2467 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MAX ) &&
2468 Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MIN ) )
2470 application.SendNotification();
2471 application.Render();
2472 CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN" );
2475 if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
2477 application.SendNotification();
2478 application.Render();
2479 CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN" );
2485 Renderer RendererTestFixture(TestApplication& application)
2487 Geometry geometry = CreateQuadGeometry();
2488 Shader shader = CreateShader();
2489 Renderer renderer = Renderer::New(geometry, shader);
2491 Actor actor = Actor::New();
2492 actor.AddRenderer(renderer);
2493 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2494 Integration::Scene scene = application.GetScene();
2495 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2501 int UtcDaliRendererSetDepthTestMode(void)
2503 TestApplication application;
2504 tet_infoline("Test setting the DepthTestMode");
2506 Renderer renderer = RendererTestFixture(application);
2507 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2508 glAbstraction.EnableEnableDisableCallTrace(true);
2509 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2511 glEnableDisableStack.Reset();
2512 application.SendNotification();
2513 application.Render();
2515 // Check depth-test is enabled by default.
2516 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2517 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2519 // 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.
2520 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2521 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2523 glEnableDisableStack.Reset();
2524 application.SendNotification();
2525 application.Render();
2527 // Check the depth buffer was disabled.
2528 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2530 // Turn on automatic mode depth-testing.
2531 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2532 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2534 glEnableDisableStack.Reset();
2535 application.SendNotification();
2536 application.Render();
2538 // Check depth-test is now enabled.
2539 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2540 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2542 // Change the layer behavior to LAYER_UI.
2543 // Note this will also disable depth testing for the layer by default, we test this first.
2544 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2546 glEnableDisableStack.Reset();
2547 application.SendNotification();
2548 application.Render();
2550 // Check depth-test is disabled.
2551 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2553 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2554 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2556 glEnableDisableStack.Reset();
2557 application.SendNotification();
2558 application.Render();
2560 // Check depth-test is *still* disabled.
2561 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2566 int UtcDaliRendererSetDepthWriteMode(void)
2568 TestApplication application;
2569 tet_infoline("Test setting the DepthWriteMode");
2571 Renderer renderer = RendererTestFixture(application);
2572 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2574 application.SendNotification();
2575 application.Render();
2577 // Check the default depth-write status first.
2578 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2580 // Turn off depth-writing.
2581 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2583 application.SendNotification();
2584 application.Render();
2586 // Check depth-write is now disabled.
2587 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2589 // Test the AUTO mode for depth-writing.
2590 // As our renderer is opaque, depth-testing should be enabled.
2591 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2593 application.SendNotification();
2594 application.Render();
2596 // Check depth-write is now enabled.
2597 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2599 // Now make the renderer be treated as translucent by enabling blending.
2600 // The AUTO depth-write mode should turn depth-write off in this scenario.
2601 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2603 application.SendNotification();
2604 application.Render();
2606 // Check depth-write is now disabled.
2607 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2612 int UtcDaliRendererCheckStencilDefaults(void)
2614 TestApplication application;
2615 tet_infoline("Test the stencil defaults");
2617 Renderer renderer = RendererTestFixture(application);
2618 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2619 glAbstraction.EnableEnableDisableCallTrace(true);
2620 glAbstraction.EnableStencilFunctionCallTrace(true);
2621 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2622 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2624 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2626 // Check the defaults:
2627 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2628 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2629 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2630 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2631 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2632 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);
2633 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);
2638 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2640 TestApplication application;
2641 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2643 Renderer renderer = RendererTestFixture(application);
2644 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2645 glAbstraction.EnableEnableDisableCallTrace(true);
2646 glAbstraction.EnableStencilFunctionCallTrace(true);
2647 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2648 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2650 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2651 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2652 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2653 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2655 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2656 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2658 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2659 std::string methodString("StencilFunc");
2660 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2662 // Test the other RenderModes that will not enable the stencil buffer.
2663 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2664 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2665 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2667 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2668 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2669 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2671 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2672 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2673 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2675 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2676 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2678 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2679 // First set a mode to turn off the stencil buffer, so the enable is required.
2680 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2681 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2682 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2683 // Set a different stencil function as the last one is cached.
2684 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2685 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2687 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2688 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2693 // Helper function for the SetRenderModeToUseColorBuffer test.
2694 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2696 // Set the RenderMode property to a value that should not allow color buffer writes.
2697 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2698 application.SendNotification();
2699 application.Render();
2701 // Check if ColorMask has been called, and that the values are correct.
2702 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2703 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2705 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2706 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2707 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2708 DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2711 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2713 TestApplication application;
2714 tet_infoline("Test setting the RenderMode to use the color buffer");
2716 Renderer renderer = RendererTestFixture(application);
2718 // Set the RenderMode property to a value that should not allow color buffer writes.
2719 // Then check if ColorMask has been called, and that the values are correct.
2720 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2721 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2722 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2723 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2724 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2729 int UtcDaliRendererSetStencilFunction(void)
2731 TestApplication application;
2732 tet_infoline("Test setting the StencilFunction");
2734 Renderer renderer = RendererTestFixture(application);
2735 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2736 glAbstraction.EnableEnableDisableCallTrace(true);
2737 glAbstraction.EnableStencilFunctionCallTrace(true);
2738 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2739 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2741 // RenderMode must use the stencil for StencilFunction to operate.
2742 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2743 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2746 * Lookup table for testing StencilFunction.
2747 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2749 const int StencilFunctionLookupTable[] = {
2758 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2761 * Loop through all types of StencilFunction, checking:
2762 * - The value is cached (set in event thread side)
2763 * - Causes "glStencilFunc" to be called
2764 * - Checks the correct parameters to "glStencilFunc" were used
2766 std::string nonChangingParameters = "0, 255";
2767 std::string methodString("StencilFunc");
2768 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2770 // Set the property.
2771 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2773 // Check GetProperty returns the same value.
2774 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2776 // Reset the trace debug.
2777 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2779 // Check the function is called and the parameters are correct.
2780 std::stringstream parameterStream;
2781 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2783 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2786 // Change the Function Reference only and check the behavior is correct:
2787 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2788 int testValueReference = 170;
2789 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2791 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2793 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2795 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2797 std::stringstream parameterStream;
2798 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2800 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2802 // Change the Function Mask only and check the behavior is correct:
2803 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2804 int testValueMask = 85;
2805 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2807 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2809 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2811 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2813 // Clear the stringstream.
2814 parameterStream.str(std::string());
2815 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2817 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2822 int UtcDaliRendererSetStencilOperation(void)
2824 TestApplication application;
2825 tet_infoline("Test setting the StencilOperation");
2827 Renderer renderer = RendererTestFixture(application);
2828 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2829 glAbstraction.EnableEnableDisableCallTrace(true);
2830 glAbstraction.EnableStencilFunctionCallTrace(true);
2831 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2832 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2834 // RenderMode must use the stencil for StencilOperation to operate.
2835 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2838 * Lookup table for testing StencilOperation.
2839 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2841 const int StencilOperationLookupTable[] = {
2850 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2852 // Set all 3 StencilOperation properties to a default.
2853 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2854 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2855 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2857 // Set our expected parameter list to the equivalent result.
2858 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2860 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2863 * Loop through all types of StencilOperation, checking:
2864 * - The value is cached (set in event thread side)
2865 * - Causes "glStencilFunc" to be called
2866 * - Checks the correct parameters to "glStencilFunc" were used
2867 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2869 std::string methodString("StencilOp");
2871 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2873 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2875 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2877 // Set the property (outer loop causes all 3 different properties to be set separately).
2878 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2879 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2880 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2882 // Check GetProperty returns the same value.
2883 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2884 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2885 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2887 // Reset the trace debug.
2888 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2890 // Check the function is called and the parameters are correct.
2891 // Set the expected parameter value at its correct index (only)
2892 parameters[0u] = StencilOperationLookupTable[i];
2893 parameters[1u] = StencilOperationLookupTable[j];
2894 parameters[2u] = StencilOperationLookupTable[k];
2896 // Build the parameter list.
2897 std::stringstream parameterStream;
2898 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
2900 parameterStream << parameters[parameterBuild];
2901 // Comma-separate the parameters.
2902 if(parameterBuild < 2)
2904 parameterStream << ", ";
2908 // Check the function was called and the parameters were correct.
2909 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2917 int UtcDaliRendererSetStencilMask(void)
2919 TestApplication application;
2920 tet_infoline("Test setting the StencilMask");
2922 Renderer renderer = RendererTestFixture(application);
2923 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2924 glAbstraction.EnableEnableDisableCallTrace(true);
2925 glAbstraction.EnableStencilFunctionCallTrace(true);
2926 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2927 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2929 // RenderMode must use the stencil for StencilMask to operate.
2930 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2932 // Set the StencilMask property to a value.
2933 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
2935 // Check GetProperty returns the same value.
2936 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2938 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2940 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2942 std::string methodString("StencilMask");
2943 std::string parameterString = "0";
2945 // Check the function was called and the parameters were correct.
2946 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2948 // Set the StencilMask property to another value to ensure it has changed.
2949 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
2951 // Check GetProperty returns the same value.
2952 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2954 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2956 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2958 parameterString = "255";
2960 // Check the function was called and the parameters were correct.
2961 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2966 int UtcDaliRendererWrongNumberOfTextures(void)
2968 TestApplication application;
2969 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2971 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2972 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2973 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
2974 TextureSet textureSet = CreateTextureSet();
2975 textureSet.SetTexture(0, texture);
2976 textureSet.SetTexture(1, texture);
2977 textureSet.SetTexture(2, texture);
2978 textureSet.SetTexture(3, texture);
2979 Shader shader = Shader::New("VertexSource", "FragmentSource");
2980 Geometry geometry = CreateQuadGeometry();
2981 Renderer renderer = Renderer::New(geometry, shader);
2982 renderer.SetTextures(textureSet);
2984 Actor actor = Actor::New();
2985 actor.AddRenderer(renderer);
2986 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
2987 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2988 application.GetScene().Add(actor);
2990 TestGlAbstraction& gl = application.GetGlAbstraction();
2991 TraceCallStack& drawTrace = gl.GetDrawTrace();
2993 drawTrace.Enable(true);
2995 application.SendNotification();
2996 application.Render(0);
2998 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2999 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3001 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3002 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3003 textureSet = CreateTextureSet();
3004 renderer.SetTextures(textureSet);
3005 textureSet.SetTexture(0, texture);
3007 application.SendNotification();
3008 application.Render(0);
3010 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3011 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3016 int UtcDaliRendererOpacity(void)
3018 TestApplication application;
3020 tet_infoline("Test OPACITY property");
3022 Geometry geometry = CreateQuadGeometry();
3023 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3024 Renderer renderer = Renderer::New(geometry, shader);
3026 Actor actor = Actor::New();
3027 actor.AddRenderer(renderer);
3028 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3029 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3030 application.GetScene().Add(actor);
3032 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3034 DALI_TEST_CHECK(value.Get(opacity));
3035 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3037 application.SendNotification();
3038 application.Render();
3040 Vector4 actualValue;
3041 TestGlAbstraction& gl = application.GetGlAbstraction();
3042 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3043 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3045 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3047 application.SendNotification();
3048 application.Render();
3050 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3051 DALI_TEST_CHECK(value.Get(opacity));
3052 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3054 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3055 DALI_TEST_CHECK(value.Get(opacity));
3056 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3058 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3059 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3064 int UtcDaliRendererOpacityAnimation(void)
3066 TestApplication application;
3068 tet_infoline("Test OPACITY property animation");
3070 Geometry geometry = CreateQuadGeometry();
3071 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3072 Renderer renderer = Renderer::New(geometry, shader);
3074 Actor actor = Actor::New();
3075 actor.AddRenderer(renderer);
3076 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3077 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3078 application.GetScene().Add(actor);
3080 application.SendNotification();
3081 application.Render(0);
3083 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3085 DALI_TEST_CHECK(value.Get(opacity));
3086 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3088 Animation animation = Animation::New(1.0f);
3089 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3092 application.SendNotification();
3093 application.Render(1000);
3095 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3096 DALI_TEST_CHECK(value.Get(opacity));
3097 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3099 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3101 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3103 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3106 application.SendNotification();
3107 application.Render(1000);
3109 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3110 DALI_TEST_CHECK(value.Get(opacity));
3111 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3112 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3117 int UtcDaliRendererInvalidProperty(void)
3119 TestApplication application;
3121 tet_infoline("Test invalid property");
3123 Geometry geometry = CreateQuadGeometry();
3124 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3125 Renderer renderer = Renderer::New(geometry, shader);
3127 Actor actor = Actor::New();
3128 actor.AddRenderer(renderer);
3129 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3130 application.GetScene().Add(actor);
3132 application.SendNotification();
3133 application.Render(0);
3135 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3136 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3138 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3139 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3144 int UtcDaliRendererRenderingBehavior(void)
3146 TestApplication application;
3148 tet_infoline("Test RENDERING_BEHAVIOR property");
3150 Geometry geometry = CreateQuadGeometry();
3151 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3152 Renderer renderer = Renderer::New(geometry, shader);
3154 Actor actor = Actor::New();
3155 actor.AddRenderer(renderer);
3156 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3157 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3158 application.GetScene().Add(actor);
3160 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3161 int renderingBehavior;
3162 DALI_TEST_CHECK(value.Get(renderingBehavior));
3163 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3165 application.SendNotification();
3166 application.Render();
3168 uint32_t updateStatus = application.GetUpdateStatus();
3170 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3172 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3174 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3175 DALI_TEST_CHECK(value.Get(renderingBehavior));
3176 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3178 // Render and check the update status
3179 application.SendNotification();
3180 application.Render();
3182 updateStatus = application.GetUpdateStatus();
3184 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3186 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3187 DALI_TEST_CHECK(value.Get(renderingBehavior));
3188 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3190 // Render again and check the update status
3191 application.SendNotification();
3192 application.Render();
3194 updateStatus = application.GetUpdateStatus();
3196 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3198 // Change rendering behavior
3199 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3201 // Render and check the update status
3202 application.SendNotification();
3203 application.Render();
3205 updateStatus = application.GetUpdateStatus();
3207 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3212 int UtcDaliRendererRegenerateUniformMap(void)
3214 TestApplication application;
3216 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3218 Geometry geometry = CreateQuadGeometry();
3219 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3220 Renderer renderer = Renderer::New(geometry, shader);
3222 Actor actor = Actor::New();
3223 actor.AddRenderer(renderer);
3224 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3225 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3226 application.GetScene().Add(actor);
3228 application.SendNotification();
3229 application.Render();
3231 actor.RemoveRenderer(renderer);
3232 shader = Shader::New("vertexSrc", "fragmentSrc");
3233 shader.RegisterProperty("opacity", 0.5f);
3234 renderer.SetShader(shader);
3236 Stage::GetCurrent().KeepRendering(1.0f);
3238 // Update for several frames
3239 application.SendNotification();
3240 application.Render();
3241 application.SendNotification();
3242 application.Render();
3243 application.SendNotification();
3244 application.Render();
3245 application.SendNotification();
3246 application.Render();
3249 actor.AddRenderer(renderer);
3250 application.SendNotification();
3251 application.Render();
3253 // Nothing to test here, the test must not crash
3254 auto updateStatus = application.GetUpdateStatus();
3255 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3260 int UtcDaliRendererAddDrawCommands(void)
3262 TestApplication application;
3264 tet_infoline("Test adding draw commands to the renderer");
3266 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3267 glAbstraction.EnableEnableDisableCallTrace(true);
3269 Geometry geometry = CreateQuadGeometry();
3270 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3271 Renderer renderer = Renderer::New(geometry, shader);
3273 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3274 Actor actor = Actor::New();
3275 actor.AddRenderer(renderer);
3276 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3277 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3278 application.GetScene().Add(actor);
3280 // Expect delivering a single draw call
3281 auto& drawTrace = glAbstraction.GetDrawTrace();
3283 drawTrace.Enable(true);
3284 application.SendNotification();
3285 application.Render();
3287 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3289 auto drawCommand1 = DevelRenderer::DrawCommand{};
3290 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3291 drawCommand1.firstIndex = 0;
3292 drawCommand1.elementCount = 2;
3293 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3295 auto drawCommand2 = DevelRenderer::DrawCommand{};
3296 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3297 drawCommand2.firstIndex = 2;
3298 drawCommand2.elementCount = 2;
3299 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3301 auto drawCommand3 = DevelRenderer::DrawCommand{};
3302 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3303 drawCommand3.firstIndex = 2;
3304 drawCommand3.elementCount = 2;
3305 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3307 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3308 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3309 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3312 drawTrace.Enable(true);
3313 application.SendNotification();
3314 application.Render();
3316 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3320 int UtcDaliRendererSetGeometryNegative(void)
3322 TestApplication application;
3323 Dali::Renderer instance;
3326 Dali::Geometry arg1;
3327 instance.SetGeometry(arg1);
3328 DALI_TEST_CHECK(false); // Should not get here
3332 DALI_TEST_CHECK(true); // We expect an assert
3337 int UtcDaliRendererSetTexturesNegative(void)
3339 TestApplication application;
3340 Dali::Renderer instance;
3343 Dali::TextureSet arg1;
3344 instance.SetTextures(arg1);
3345 DALI_TEST_CHECK(false); // Should not get here
3349 DALI_TEST_CHECK(true); // We expect an assert
3354 int UtcDaliRendererSetShaderNegative(void)
3356 TestApplication application;
3357 Dali::Renderer instance;
3361 instance.SetShader(arg1);
3362 DALI_TEST_CHECK(false); // Should not get here
3366 DALI_TEST_CHECK(true); // We expect an assert
3371 int UtcDaliRendererGetGeometryNegative(void)
3373 TestApplication application;
3374 Dali::Renderer instance;
3377 instance.GetGeometry();
3378 DALI_TEST_CHECK(false); // Should not get here
3382 DALI_TEST_CHECK(true); // We expect an assert
3387 int UtcDaliRendererGetTexturesNegative(void)
3389 TestApplication application;
3390 Dali::Renderer instance;
3393 instance.GetTextures();
3394 DALI_TEST_CHECK(false); // Should not get here
3398 DALI_TEST_CHECK(true); // We expect an assert
3403 int UtcDaliRendererGetShaderNegative(void)
3405 TestApplication application;
3406 Dali::Renderer instance;
3409 instance.GetShader();
3410 DALI_TEST_CHECK(false); // Should not get here
3414 DALI_TEST_CHECK(true); // We expect an assert