2 * Copyright (c) 2024 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.
18 #define DEBUG_ENABLED 1
21 #include <dali/devel-api/actors/actor-devel.h>
22 #include <dali/devel-api/common/capabilities.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/render-task-list-integ.h>
27 #include <dali/public-api/dali-core.h>
32 #include <dali-test-suite-utils.h>
33 #include <mesh-builder.h>
34 #include <test-trace-call-stack.h>
35 #include "test-actor-utils.h"
36 #include "test-graphics-command-buffer.h"
40 namespace // unnamed namespace
42 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
43 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
44 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
45 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
47 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
48 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
51 * @brief Get GL stencil test enumeration value as a string.
52 * @return The string representation of the value of GL_STENCIL_TEST
54 std::string GetStencilTestString(void)
56 std::stringstream stream;
57 stream << std::hex << GL_STENCIL_TEST;
62 * @brief Get GL depth test enumeration value as a string.
63 * @return The string representation of the value of GL_DEPTH_TEST
65 std::string GetDepthTestString(void)
67 std::stringstream stream;
68 stream << std::hex << GL_DEPTH_TEST;
72 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
74 glEnableDisableStack.Reset();
75 glStencilFunctionStack.Reset();
76 application.SendNotification();
80 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
85 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
87 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
88 TextureSet textureSet0 = CreateTextureSet(image0);
89 Renderer renderer0 = Renderer::New(geometry, shader);
90 renderer0.SetTextures(textureSet0);
91 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
92 actor.AddRenderer(renderer0);
96 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
98 Actor actor = Actor::New();
99 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
100 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
101 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
102 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
104 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
105 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
110 } // unnamed namespace
112 void renderer_test_startup(void)
114 test_return_value = TET_UNDEF;
117 void renderer_test_cleanup(void)
119 test_return_value = TET_PASS;
122 int UtcDaliRendererNew01(void)
124 TestApplication application;
126 Geometry geometry = CreateQuadGeometry();
127 Shader shader = CreateShader();
128 Renderer renderer = Renderer::New(geometry, shader);
130 DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
134 int UtcDaliRendererNew02(void)
136 TestApplication application;
138 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
142 int UtcDaliRendererCopyConstructor(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = CreateShader();
148 Renderer renderer = Renderer::New(geometry, shader);
150 Renderer rendererCopy(renderer);
151 DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
156 int UtcDaliRendererAssignmentOperator(void)
158 TestApplication application;
160 Geometry geometry = CreateQuadGeometry();
161 Shader shader = CreateShader();
162 Renderer renderer = Renderer::New(geometry, shader);
165 DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
167 renderer2 = renderer;
168 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
172 int UtcDaliRendererMoveConstructor(void)
174 TestApplication application;
176 Geometry geometry = CreateQuadGeometry();
177 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
178 Renderer renderer = Renderer::New(geometry, shader);
179 DALI_TEST_CHECK(renderer);
180 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
181 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
183 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
184 application.SendNotification();
185 application.Render();
186 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
188 Renderer move = std::move(renderer);
189 DALI_TEST_CHECK(move);
190 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
191 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
192 DALI_TEST_CHECK(!renderer);
197 int UtcDaliRendererMoveAssignment(void)
199 TestApplication application;
201 Geometry geometry = CreateQuadGeometry();
202 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
203 Renderer renderer = Renderer::New(geometry, shader);
204 DALI_TEST_CHECK(renderer);
205 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
206 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
208 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
209 application.SendNotification();
210 application.Render();
211 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
214 move = std::move(renderer);
215 DALI_TEST_CHECK(move);
216 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
217 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
218 DALI_TEST_CHECK(!renderer);
223 int UtcDaliRendererDownCast01(void)
225 TestApplication application;
227 Geometry geometry = CreateQuadGeometry();
228 Shader shader = CreateShader();
229 Renderer renderer = Renderer::New(geometry, shader);
231 BaseHandle handle(renderer);
232 Renderer renderer2 = Renderer::DownCast(handle);
233 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
237 int UtcDaliRendererDownCast02(void)
239 TestApplication application;
241 Handle handle = Handle::New(); // Create a custom object
242 Renderer renderer = Renderer::DownCast(handle);
243 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
247 // using a template to auto deduce the parameter types
248 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
249 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
251 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
252 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
253 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
254 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
255 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
256 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
259 int UtcDaliRendererDefaultProperties(void)
261 TestApplication application;
262 /* from renderer-impl.cpp
263 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
264 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
265 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
266 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
267 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
268 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
269 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
270 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
271 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
272 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
273 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
274 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
275 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
276 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
277 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
278 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
279 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
280 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
281 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
282 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
283 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
284 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
285 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
286 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
287 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
288 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
289 DALI_PROPERTY( "blendEquation", INTEGER, true, false, false, Dali::DevelRenderer::Property::BLEND_EQUATION )
292 Geometry geometry = CreateQuadGeometry();
293 Shader shader = CreateShader();
294 Renderer renderer = Renderer::New(geometry, shader);
295 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 28, TEST_LOCATION);
297 TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
298 TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
299 TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
300 TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
301 TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
302 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
303 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
304 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
305 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
306 TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
307 TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
308 TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
309 TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
310 TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
311 TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
312 TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
313 TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
314 TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
315 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
316 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
317 TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
318 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
319 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
320 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
321 TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
322 TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
323 TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
324 TEST_RENDERER_PROPERTY(renderer, "instanceCount", Property::INTEGER, true, false, false, Dali::DevelRenderer::Property::INSTANCE_COUNT, TEST_LOCATION);
329 int UtcDaliRendererSetGetGeometry(void)
331 TestApplication application;
332 tet_infoline("Test SetGeometry, GetGeometry");
334 Geometry geometry1 = CreateQuadGeometry();
335 Geometry geometry2 = CreateQuadGeometry();
337 Shader shader = CreateShader();
338 Renderer renderer = Renderer::New(geometry1, shader);
339 Actor actor = Actor::New();
340 actor.AddRenderer(renderer);
341 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
342 application.GetScene().Add(actor);
344 application.SendNotification();
345 application.Render(0);
346 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
348 // Set geometry2 to the renderer
349 renderer.SetGeometry(geometry2);
351 application.SendNotification();
352 application.Render(0);
353 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
358 int UtcDaliRendererSetGetShader(void)
360 TestApplication application;
361 tet_infoline("Test SetShader, GetShader");
363 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
364 glAbstraction.EnableCullFaceCallTrace(true);
366 Shader shader1 = CreateShader();
367 shader1.RegisterProperty("uFadeColor", Color::RED);
369 Shader shader2 = CreateShader();
370 shader2.RegisterProperty("uFadeColor", Color::GREEN);
372 Geometry geometry = CreateQuadGeometry();
373 Renderer renderer = Renderer::New(geometry, shader1);
374 Actor actor = Actor::New();
375 actor.AddRenderer(renderer);
376 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
377 application.GetScene().Add(actor);
379 TestGlAbstraction& gl = application.GetGlAbstraction();
380 application.SendNotification();
381 application.Render(0);
383 // Expect that the first shaders's fade color property is accessed
384 Vector4 actualValue(Vector4::ZERO);
385 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
386 DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
388 DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
390 // set the second shader to the renderer
391 renderer.SetShader(shader2);
393 application.SendNotification();
394 application.Render(0);
396 // Expect that the second shader's fade color property is accessed
397 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
398 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
400 DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
405 int UtcDaliRendererSetGetDepthIndex(void)
407 TestApplication application;
409 tet_infoline("Test SetDepthIndex, GetDepthIndex");
411 Shader shader = CreateShader();
412 Geometry geometry = CreateQuadGeometry();
413 Renderer renderer = Renderer::New(geometry, shader);
414 Actor actor = Actor::New();
415 actor.AddRenderer(renderer);
416 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
417 application.GetScene().Add(actor);
419 application.SendNotification();
420 application.Render(0);
421 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
423 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
425 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
426 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
428 application.SendNotification();
429 application.Render(0);
430 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
432 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
434 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
435 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
437 application.SendNotification();
438 application.Render(0);
439 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
444 int UtcDaliRendererSetGetFaceCullingMode(void)
446 TestApplication application;
448 tet_infoline("Test SetFaceCullingMode(cullingMode)");
449 Geometry geometry = CreateQuadGeometry();
450 Shader shader = CreateShader();
451 Renderer renderer = Renderer::New(geometry, shader);
453 Actor actor = Actor::New();
454 actor.AddRenderer(renderer);
455 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
456 application.GetScene().Add(actor);
458 // By default, none of the faces should be culled
459 unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
460 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
462 TestGlAbstraction& gl = application.GetGlAbstraction();
463 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
464 gl.EnableCullFaceCallTrace(true);
467 cullFaceStack.Reset();
468 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
469 application.SendNotification();
470 application.Render();
472 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
474 std::ostringstream cullModeString;
475 cullModeString << std::hex << GL_FRONT_AND_BACK;
477 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
478 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
479 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
483 cullFaceStack.Reset();
484 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
485 application.SendNotification();
486 application.Render();
488 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
490 std::ostringstream cullModeString;
491 cullModeString << std::hex << GL_BACK;
493 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
494 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
495 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
499 cullFaceStack.Reset();
500 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
501 application.SendNotification();
502 application.Render();
504 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
506 std::ostringstream cullModeString;
507 cullModeString << std::hex << GL_FRONT;
509 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
510 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
511 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
515 cullFaceStack.Reset();
516 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
517 application.SendNotification();
518 application.Render();
520 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
521 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
522 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
528 int UtcDaliRendererBlendOptions01(void)
530 TestApplication application;
532 tet_infoline("Test BLEND_FACTOR properties ");
534 Geometry geometry = CreateQuadGeometry();
535 Shader shader = CreateShader();
536 Renderer renderer = Renderer::New(geometry, shader);
538 Actor actor = Actor::New();
539 // set a transparent actor color so that blending is enabled
540 actor.SetProperty(Actor::Property::OPACITY, 0.5f);
541 actor.AddRenderer(renderer);
542 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
543 application.GetScene().Add(actor);
545 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
546 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
547 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
548 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
550 // Test that Set was successful:
551 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
552 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
553 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
554 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
556 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
557 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
558 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
559 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
561 application.SendNotification();
562 application.Render();
564 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
566 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
567 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
568 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
569 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
574 int UtcDaliRendererBlendOptions02(void)
576 TestApplication application;
578 tet_infoline("Test BLEND_FACTOR properties ");
580 Geometry geometry = CreateQuadGeometry();
581 Shader shader = CreateShader();
582 Renderer renderer = Renderer::New(geometry, shader);
584 Actor actor = Actor::New();
585 actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
586 actor.AddRenderer(renderer);
587 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
588 application.GetScene().Add(actor);
590 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
591 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
592 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
593 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
595 // Test that Set was successful:
597 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
598 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
599 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
600 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
602 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
603 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
604 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
605 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
608 application.SendNotification();
609 application.Render();
611 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
612 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
613 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
614 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
615 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
620 int UtcDaliRendererBlendOptions03(void)
622 TestApplication application;
624 tet_infoline("Test GetBlendEquation() defaults ");
626 Geometry geometry = CreateQuadGeometry();
627 Shader shader = CreateShader();
628 Renderer renderer = Renderer::New(geometry, shader);
630 Actor actor = Actor::New();
631 actor.AddRenderer(renderer);
632 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
633 application.GetScene().Add(actor);
635 // Test the defaults as documented in blending.h
636 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
637 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
639 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
640 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
645 int UtcDaliRendererBlendOptions04(void)
647 TestApplication application;
649 tet_infoline("Test SetBlendEquation() ");
651 Geometry geometry = CreateQuadGeometry();
652 Shader shader = CreateShader();
653 Renderer renderer = Renderer::New(geometry, shader);
655 Actor actor = Actor::New();
656 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
657 actor.AddRenderer(renderer);
658 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
659 application.GetScene().Add(actor);
661 // Test the single blending equation setting
663 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
664 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
665 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
668 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
669 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
671 // Test that Set was successful
673 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
674 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
675 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
676 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
679 // Render & check GL commands
680 application.SendNotification();
681 application.Render();
683 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
684 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
685 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
690 int UtcDaliRendererBlendOptions05(void)
692 TestApplication application;
694 tet_infoline("Test SetAdvancedBlendEquation ");
696 Geometry geometry = CreateQuadGeometry();
697 Shader shader = CreateShader();
698 Renderer renderer = Renderer::New(geometry, shader);
700 Actor actor = Actor::New();
701 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
703 actor.AddRenderer(renderer);
704 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
705 application.GetScene().Add(actor);
706 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
707 glAbstraction.EnableEnableDisableCallTrace(true);
709 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
711 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX);
712 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
713 DALI_TEST_EQUALS((int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION);
716 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
718 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
719 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
720 int equation = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
722 DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION);
723 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), true, TEST_LOCATION);
725 application.SendNotification();
726 application.Render();
729 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
730 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY))
732 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD);
733 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
734 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN);
735 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY);
736 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_RGB);
737 int equationAlpha = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_ALPHA);
739 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION);
740 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION);
741 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), false, TEST_LOCATION);
743 application.SendNotification();
744 application.Render();
747 tet_infoline("Error Checking\n");
748 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY) &&
749 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
750 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::OVERLAY) &&
751 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DARKEN) &&
752 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LIGHTEN) &&
753 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_DODGE) &&
754 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_BURN) &&
755 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HARD_LIGHT) &&
756 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SOFT_LIGHT) &&
757 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DIFFERENCE) &&
758 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::EXCLUSION) &&
759 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HUE) &&
760 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SATURATION) &&
761 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR) &&
762 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LUMINOSITY))
764 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
765 DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
766 application.SendNotification();
767 application.Render();
768 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_MULTIPLY, TEST_LOCATION);
770 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
771 DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
772 application.SendNotification();
773 application.Render();
774 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SCREEN, TEST_LOCATION);
776 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
777 DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
778 application.SendNotification();
779 application.Render();
780 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_OVERLAY, TEST_LOCATION);
782 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
783 DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
784 application.SendNotification();
785 application.Render();
786 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DARKEN, TEST_LOCATION);
788 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
789 DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
790 application.SendNotification();
791 application.Render();
792 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_LIGHTEN, TEST_LOCATION);
794 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
795 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
796 application.SendNotification();
797 application.Render();
798 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORDODGE, TEST_LOCATION);
800 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
801 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
802 application.SendNotification();
803 application.Render();
804 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORBURN, TEST_LOCATION);
806 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
807 DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
808 application.SendNotification();
809 application.Render();
810 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HARDLIGHT, TEST_LOCATION);
812 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
813 DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
814 application.SendNotification();
815 application.Render();
816 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SOFTLIGHT, TEST_LOCATION);
818 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
819 DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
820 application.SendNotification();
821 application.Render();
822 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DIFFERENCE, TEST_LOCATION);
824 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
825 DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
826 application.SendNotification();
827 application.Render();
828 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_EXCLUSION, TEST_LOCATION);
830 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
831 DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
832 application.SendNotification();
833 application.Render();
834 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_HUE, TEST_LOCATION);
836 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
837 DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
838 application.SendNotification();
839 application.Render();
840 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_SATURATION, TEST_LOCATION);
842 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
843 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
844 application.SendNotification();
845 application.Render();
846 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_COLOR, TEST_LOCATION);
848 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
849 DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
850 application.SendNotification();
851 application.Render();
852 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_LUMINOSITY, TEST_LOCATION);
858 int UtcDaliRendererSetBlendMode01(void)
860 TestApplication application;
862 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
864 Geometry geometry = CreateQuadGeometry();
865 Shader shader = CreateShader();
866 Renderer renderer = Renderer::New(geometry, shader);
868 Actor actor = Actor::New();
869 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
870 actor.AddRenderer(renderer);
871 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
872 application.GetScene().Add(actor);
874 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
876 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
877 glAbstraction.EnableEnableDisableCallTrace(true);
879 application.SendNotification();
880 application.Render();
882 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
883 TraceCallStack::NamedParams params;
884 params["cap"] << std::hex << GL_BLEND;
885 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
890 int UtcDaliRendererSetBlendMode01b(void)
892 TestApplication application;
894 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
896 Geometry geometry = CreateQuadGeometry();
897 Shader shader = CreateShader();
898 Renderer renderer = Renderer::New(geometry, shader);
900 Actor actor = Actor::New();
901 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
902 actor.AddRenderer(renderer);
903 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
904 application.GetScene().Add(actor);
906 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
908 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
909 glAbstraction.EnableEnableDisableCallTrace(true);
910 glAbstraction.EnableDrawCallTrace(true);
912 application.SendNotification();
913 application.Render();
915 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
916 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
918 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
923 int UtcDaliRendererSetBlendMode02(void)
925 TestApplication application;
927 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
929 Geometry geometry = CreateQuadGeometry();
930 Shader shader = CreateShader();
931 Renderer renderer = Renderer::New(geometry, shader);
933 Actor actor = Actor::New();
934 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
935 actor.AddRenderer(renderer);
936 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
937 application.GetScene().Add(actor);
939 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
941 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
942 glAbstraction.EnableEnableDisableCallTrace(true);
944 application.SendNotification();
945 application.Render();
947 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
948 TraceCallStack::NamedParams params;
949 params["cap"] << std::hex << GL_BLEND;
950 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
955 int UtcDaliRendererSetBlendMode03(void)
957 TestApplication application;
959 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
961 Geometry geometry = CreateQuadGeometry();
962 Shader shader = CreateShader();
963 Renderer renderer = Renderer::New(geometry, shader);
965 Actor actor = Actor::New();
966 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
967 actor.AddRenderer(renderer);
968 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
969 application.GetScene().Add(actor);
971 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
973 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
974 glAbstraction.EnableEnableDisableCallTrace(true);
976 application.SendNotification();
977 application.Render();
979 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
980 TraceCallStack::NamedParams params;
981 params["cap"] << std::hex << GL_BLEND;
982 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
987 int UtcDaliRendererSetBlendMode04(void)
989 TestApplication application;
991 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
993 Geometry geometry = CreateQuadGeometry();
994 Shader shader = CreateShader();
995 Renderer renderer = Renderer::New(geometry, shader);
997 Actor actor = Actor::New();
998 actor.AddRenderer(renderer);
999 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1000 application.GetScene().Add(actor);
1002 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1004 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1005 glAbstraction.EnableEnableDisableCallTrace(true);
1007 application.SendNotification();
1008 application.Render();
1010 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1011 TraceCallStack::NamedParams params;
1012 params["cap"] << std::hex << GL_BLEND;
1013 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1014 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1019 int UtcDaliRendererSetBlendMode04b(void)
1021 TestApplication application;
1023 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
1025 Geometry geometry = CreateQuadGeometry();
1026 Shader shader = CreateShader();
1027 Renderer renderer = Renderer::New(geometry, shader);
1029 Actor actor = Actor::New();
1030 actor.AddRenderer(renderer);
1031 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1032 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1033 application.GetScene().Add(actor);
1035 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1037 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1038 glAbstraction.EnableEnableDisableCallTrace(true);
1040 application.SendNotification();
1041 application.Render();
1043 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1044 TraceCallStack::NamedParams params;
1045 params["cap"] << std::hex << GL_BLEND;
1046 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1051 int UtcDaliRendererSetBlendMode04c(void)
1053 TestApplication application;
1055 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1057 Geometry geometry = CreateQuadGeometry();
1058 Shader shader = CreateShader();
1059 Renderer renderer = Renderer::New(geometry, shader);
1061 Actor actor = Actor::New();
1062 actor.AddRenderer(renderer);
1063 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1064 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1065 application.GetScene().Add(actor);
1067 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1069 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1070 glAbstraction.EnableEnableDisableCallTrace(true);
1072 application.SendNotification();
1073 application.Render();
1075 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1076 TraceCallStack::NamedParams params;
1077 params["cap"] << std::hex << GL_BLEND;
1078 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1079 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1084 int UtcDaliRendererSetBlendMode05(void)
1086 TestApplication application;
1088 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1090 Geometry geometry = CreateQuadGeometry();
1091 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1093 Shader shader = CreateShader();
1094 TextureSet textureSet = CreateTextureSet(image);
1095 Renderer renderer = Renderer::New(geometry, shader);
1096 renderer.SetTextures(textureSet);
1098 Actor actor = Actor::New();
1099 actor.AddRenderer(renderer);
1100 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1101 application.GetScene().Add(actor);
1103 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1105 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1106 glAbstraction.EnableEnableDisableCallTrace(true);
1108 application.SendNotification();
1109 application.Render();
1111 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1112 TraceCallStack::NamedParams params;
1113 params["cap"] << std::hex << GL_BLEND;
1114 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1119 int UtcDaliRendererSetBlendMode06(void)
1121 TestApplication application;
1122 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");
1124 Geometry geometry = CreateQuadGeometry();
1125 Shader shader = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1127 Renderer renderer = Renderer::New(geometry, shader);
1129 Actor actor = Actor::New();
1130 actor.AddRenderer(renderer);
1131 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1132 application.GetScene().Add(actor);
1134 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1136 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1137 glAbstraction.EnableEnableDisableCallTrace(true);
1139 application.SendNotification();
1140 application.Render();
1142 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1143 TraceCallStack::NamedParams params;
1144 params["cap"] << std::hex << GL_BLEND;
1145 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1150 int UtcDaliRendererSetBlendMode07(void)
1152 TestApplication application;
1153 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");
1155 Geometry geometry = CreateQuadGeometry();
1156 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1158 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1159 TextureSet textureSet = CreateTextureSet(image);
1160 Renderer renderer = Renderer::New(geometry, shader);
1161 renderer.SetTextures(textureSet);
1163 Actor actor = Actor::New();
1164 actor.AddRenderer(renderer);
1165 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1166 application.GetScene().Add(actor);
1168 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1170 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1171 glAbstraction.EnableEnableDisableCallTrace(true);
1173 application.SendNotification();
1174 application.Render();
1176 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1177 TraceCallStack::NamedParams params;
1178 params["cap"] << std::hex << GL_BLEND;
1179 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1184 int UtcDaliRendererSetBlendMode08(void)
1186 TestApplication application;
1188 tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1190 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1192 Geometry geometry = CreateQuadGeometry();
1193 Shader shader = CreateShader();
1194 Renderer renderer = Renderer::New(geometry, shader);
1196 Actor actor = Actor::New();
1197 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1198 actor.AddRenderer(renderer);
1199 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1200 application.GetScene().Add(actor);
1202 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1203 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1204 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1206 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1207 glAbstraction.EnableEnableDisableCallTrace(true);
1209 application.SendNotification();
1210 application.Render();
1212 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1213 TraceCallStack::NamedParams params;
1214 params["cap"] << std::hex << GL_BLEND;
1215 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1221 int UtcDaliRendererSetBlendMode08b(void)
1223 TestApplication application;
1225 tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1227 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1229 Geometry geometry = CreateQuadGeometry();
1230 Shader shader = CreateShader();
1231 Renderer renderer = Renderer::New(geometry, shader);
1233 Actor actor = Actor::New();
1234 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1235 actor.AddRenderer(renderer);
1236 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1237 application.GetScene().Add(actor);
1239 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1240 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1241 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1243 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1244 glAbstraction.EnableEnableDisableCallTrace(true);
1246 application.SendNotification();
1247 application.Render();
1249 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1250 TraceCallStack::NamedParams params;
1251 params["cap"] << std::hex << GL_BLEND;
1252 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1258 int UtcDaliRendererSetBlendMode09(void)
1260 TestApplication application;
1262 tet_infoline("Test setting the blend mode to on_without_cull with an opaque color renders with blending enabled");
1264 Geometry geometry = CreateQuadGeometry();
1265 Shader shader = CreateShader();
1266 Renderer renderer = Renderer::New(geometry, shader);
1268 Actor actor = Actor::New();
1269 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1270 actor.AddRenderer(renderer);
1271 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1272 application.GetScene().Add(actor);
1274 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1276 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1277 glAbstraction.EnableEnableDisableCallTrace(true);
1279 application.SendNotification();
1280 application.Render();
1282 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1283 TraceCallStack::NamedParams params;
1284 params["cap"] << std::hex << GL_BLEND;
1285 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1290 int UtcDaliRendererSetBlendMode09b(void)
1292 TestApplication application;
1294 tet_infoline("Test setting the blend mode to on_without_cull with an transparent color renders with blending enabled");
1296 Geometry geometry = CreateQuadGeometry();
1297 Shader shader = CreateShader();
1298 Renderer renderer = Renderer::New(geometry, shader);
1300 Actor actor = Actor::New();
1301 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
1302 actor.AddRenderer(renderer);
1303 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1304 application.GetScene().Add(actor);
1306 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1308 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1309 glAbstraction.EnableEnableDisableCallTrace(true);
1310 glAbstraction.EnableDrawCallTrace(true);
1312 application.SendNotification();
1313 application.Render();
1315 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1316 DALI_TEST_CHECK(glEnableStack.FindMethod("Enable"));
1318 DALI_TEST_CHECK(glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
1323 int UtcDaliRendererGetBlendMode(void)
1325 TestApplication application;
1327 tet_infoline("Test GetBlendMode()");
1329 Geometry geometry = CreateQuadGeometry();
1330 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1331 Renderer renderer = Renderer::New(geometry, shader);
1334 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1335 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1338 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1339 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1340 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1343 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1344 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1345 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1348 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1349 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1350 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON_WITHOUT_CULL, TEST_LOCATION);
1355 int UtcDaliRendererSetBlendColor(void)
1357 TestApplication application;
1359 tet_infoline("Test SetBlendColor(color)");
1361 Geometry geometry = CreateQuadGeometry();
1362 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1363 TextureSet textureSet = TextureSet::New();
1364 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1365 textureSet.SetTexture(0u, image);
1366 Renderer renderer = Renderer::New(geometry, shader);
1367 renderer.SetTextures(textureSet);
1369 Actor actor = Actor::New();
1370 actor.AddRenderer(renderer);
1371 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1372 application.GetScene().Add(actor);
1374 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1376 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1378 application.SendNotification();
1379 application.Render();
1381 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1382 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1383 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1385 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1387 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1388 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1390 application.SendNotification();
1391 application.Render();
1393 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1394 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1396 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1397 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1398 application.SendNotification();
1399 application.Render();
1400 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1405 int UtcDaliRendererGetBlendColor(void)
1407 TestApplication application;
1409 tet_infoline("Test GetBlendColor()");
1411 Geometry geometry = CreateQuadGeometry();
1412 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1413 Renderer renderer = Renderer::New(geometry, shader);
1415 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1417 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1418 application.SendNotification();
1419 application.Render();
1420 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1422 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1423 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1424 application.SendNotification();
1425 application.Render();
1426 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1431 int UtcDaliRendererPreMultipledAlpha(void)
1433 TestApplication application;
1435 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1437 Geometry geometry = CreateQuadGeometry();
1438 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1439 Renderer renderer = Renderer::New(geometry, shader);
1441 Actor actor = Actor::New();
1442 actor.AddRenderer(renderer);
1443 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1444 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1445 application.GetScene().Add(actor);
1447 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1448 bool preMultipliedAlpha;
1449 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1450 DALI_TEST_CHECK(!preMultipliedAlpha);
1452 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1453 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1454 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1455 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1457 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1458 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1459 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1460 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1462 application.SendNotification();
1463 application.Render();
1465 Vector4 actualValue(Vector4::ZERO);
1466 Vector4 actualActorColor(Vector4::ZERO);
1467 TestGlAbstraction& gl = application.GetGlAbstraction();
1468 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1469 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1470 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1471 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1473 // Enable pre-multiplied alpha
1474 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1476 application.SendNotification();
1477 application.Render();
1479 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1480 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1481 DALI_TEST_CHECK(preMultipliedAlpha);
1483 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1484 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1485 DALI_TEST_CHECK(preMultipliedAlpha);
1487 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1488 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1489 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1490 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1492 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1493 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1494 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1495 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1497 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1498 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1499 // Note : uActorColor doesn't premultiplied.
1500 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1501 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1503 // Disable pre-multiplied alpha again
1504 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1506 application.SendNotification();
1507 application.Render();
1509 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1510 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1511 DALI_TEST_CHECK(!preMultipliedAlpha);
1513 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1514 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1515 DALI_TEST_CHECK(!preMultipliedAlpha);
1517 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1518 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1519 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1520 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1522 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1523 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1524 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1525 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1527 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1528 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1529 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1530 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1535 int UtcDaliRendererConstraint01(void)
1537 TestApplication application;
1539 tet_infoline("Test that a non-uniform renderer property can be constrained");
1541 Shader shader = Shader::New("VertexSource", "FragmentSource");
1542 Geometry geometry = CreateQuadGeometry();
1543 Renderer renderer = Renderer::New(geometry, shader);
1545 Actor actor = Actor::New();
1546 actor.AddRenderer(renderer);
1547 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1548 application.GetScene().Add(actor);
1550 Vector4 initialColor = Color::WHITE;
1551 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1553 application.SendNotification();
1554 application.Render(0);
1555 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1558 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1560 application.SendNotification();
1561 application.Render(0);
1563 // Expect no blue component in either buffer - yellow
1564 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1565 application.Render(0);
1566 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1568 renderer.RemoveConstraints();
1569 renderer.SetProperty(colorIndex, Color::WHITE);
1570 application.SendNotification();
1571 application.Render(0);
1572 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1577 int UtcDaliRendererConstraint02(void)
1579 TestApplication application;
1581 tet_infoline("Test that a uniform map renderer property can be constrained");
1583 Shader shader = Shader::New("VertexSource", "FragmentSource");
1584 Geometry geometry = CreateQuadGeometry();
1585 Renderer renderer = Renderer::New(geometry, shader);
1587 Actor actor = Actor::New();
1588 actor.AddRenderer(renderer);
1589 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1590 application.GetScene().Add(actor);
1591 application.SendNotification();
1592 application.Render(0);
1594 Vector4 initialColor = Color::WHITE;
1595 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1597 TestGlAbstraction& gl = application.GetGlAbstraction();
1599 application.SendNotification();
1600 application.Render(0);
1602 Vector4 actualValue(Vector4::ZERO);
1603 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1604 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1607 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1609 application.SendNotification();
1610 application.Render(0);
1612 // Expect no blue component in either buffer - yellow
1613 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1614 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1616 application.Render(0);
1617 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1618 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1620 renderer.RemoveConstraints();
1621 renderer.SetProperty(colorIndex, Color::WHITE);
1622 application.SendNotification();
1623 application.Render(0);
1625 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1626 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1631 int UtcDaliRendererAnimatedProperty01(void)
1633 TestApplication application;
1635 tet_infoline("Test that a non-uniform renderer property can be animated");
1637 Shader shader = Shader::New("VertexSource", "FragmentSource");
1638 Geometry geometry = CreateQuadGeometry();
1639 Renderer renderer = Renderer::New(geometry, shader);
1641 Actor actor = Actor::New();
1642 actor.AddRenderer(renderer);
1643 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1644 application.GetScene().Add(actor);
1646 Vector4 initialColor = Color::WHITE;
1647 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1649 application.SendNotification();
1650 application.Render(0);
1651 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1653 Animation animation = Animation::New(1.0f);
1654 KeyFrames keyFrames = KeyFrames::New();
1655 keyFrames.Add(0.0f, initialColor);
1656 keyFrames.Add(1.0f, Color::TRANSPARENT);
1657 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1660 application.SendNotification();
1661 application.Render(500);
1663 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1665 application.Render(500);
1667 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1672 int UtcDaliRendererAnimatedProperty02(void)
1674 TestApplication application;
1676 tet_infoline("Test that a uniform map renderer property can be animated");
1678 Shader shader = Shader::New("VertexSource", "FragmentSource");
1679 Geometry geometry = CreateQuadGeometry();
1680 Renderer renderer = Renderer::New(geometry, shader);
1682 Actor actor = Actor::New();
1683 actor.AddRenderer(renderer);
1684 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1685 application.GetScene().Add(actor);
1686 application.SendNotification();
1687 application.Render(0);
1689 Vector4 initialColor = Color::WHITE;
1690 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1692 TestGlAbstraction& gl = application.GetGlAbstraction();
1694 application.SendNotification();
1695 application.Render(0);
1697 Vector4 actualValue(Vector4::ZERO);
1698 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1699 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1701 Animation animation = Animation::New(1.0f);
1702 KeyFrames keyFrames = KeyFrames::New();
1703 keyFrames.Add(0.0f, initialColor);
1704 keyFrames.Add(1.0f, Color::TRANSPARENT);
1705 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1708 application.SendNotification();
1709 application.Render(500);
1711 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1712 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1714 application.Render(500);
1715 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1716 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1721 int UtcDaliRendererUniformMapPrecendence01(void)
1723 TestApplication application;
1725 tet_infoline("Test the uniform map precedence is applied properly");
1727 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1729 Shader shader = Shader::New("VertexSource", "FragmentSource");
1730 TextureSet textureSet = CreateTextureSet(image);
1732 Geometry geometry = CreateQuadGeometry();
1733 Renderer renderer = Renderer::New(geometry, shader);
1734 renderer.SetTextures(textureSet);
1736 Actor actor = Actor::New();
1737 actor.AddRenderer(renderer);
1738 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1739 application.GetScene().Add(actor);
1740 application.SendNotification();
1741 application.Render(0);
1743 renderer.RegisterProperty("uFadeColor", Color::RED);
1744 actor.RegisterProperty("uFadeColor", Color::GREEN);
1745 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1747 TestGlAbstraction& gl = application.GetGlAbstraction();
1749 application.SendNotification();
1750 application.Render(0);
1752 // Expect that the actor's fade color property is accessed
1753 Vector4 actualValue(Vector4::ZERO);
1754 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1755 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1757 // Animate shader's fade color property. Should be no change to uniform
1758 Animation animation = Animation::New(1.0f);
1759 KeyFrames keyFrames = KeyFrames::New();
1760 keyFrames.Add(0.0f, Color::WHITE);
1761 keyFrames.Add(1.0f, Color::TRANSPARENT);
1762 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1765 application.SendNotification();
1766 application.Render(500);
1768 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1769 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1771 application.Render(500);
1772 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1773 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1778 int UtcDaliRendererUniformMapPrecendence02(void)
1780 TestApplication application;
1782 tet_infoline("Test the uniform map precedence is applied properly");
1784 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1786 Shader shader = Shader::New("VertexSource", "FragmentSource");
1787 TextureSet textureSet = CreateTextureSet(image);
1789 Geometry geometry = CreateQuadGeometry();
1790 Renderer renderer = Renderer::New(geometry, shader);
1791 renderer.SetTextures(textureSet);
1793 Actor actor = Actor::New();
1794 actor.AddRenderer(renderer);
1795 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1796 application.GetScene().Add(actor);
1797 application.SendNotification();
1798 application.Render(0);
1800 // Don't add property / uniform map to renderer
1801 actor.RegisterProperty("uFadeColor", Color::GREEN);
1802 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1804 TestGlAbstraction& gl = application.GetGlAbstraction();
1806 application.SendNotification();
1807 application.Render(0);
1809 // Expect that the actor's fade color property is accessed
1810 Vector4 actualValue(Vector4::ZERO);
1811 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1812 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1814 // Animate texture set's fade color property. Should be no change to uniform
1815 Animation animation = Animation::New(1.0f);
1816 KeyFrames keyFrames = KeyFrames::New();
1817 keyFrames.Add(0.0f, Color::WHITE);
1818 keyFrames.Add(1.0f, Color::TRANSPARENT);
1819 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1822 application.SendNotification();
1823 application.Render(500);
1825 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1826 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1828 application.Render(500);
1829 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1830 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1835 int UtcDaliRendererUniformMapPrecendence03(void)
1837 TestApplication application;
1839 tet_infoline("Test the uniform map precedence is applied properly");
1841 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1843 Shader shader = Shader::New("VertexSource", "FragmentSource");
1844 TextureSet textureSet = CreateTextureSet(image);
1846 Geometry geometry = CreateQuadGeometry();
1847 Renderer renderer = Renderer::New(geometry, shader);
1848 renderer.SetTextures(textureSet);
1850 Actor actor = Actor::New();
1851 actor.AddRenderer(renderer);
1852 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1853 application.GetScene().Add(actor);
1854 application.SendNotification();
1855 application.Render(0);
1857 // Don't add property / uniform map to renderer or actor
1858 shader.RegisterProperty("uFadeColor", Color::BLACK);
1860 TestGlAbstraction& gl = application.GetGlAbstraction();
1862 application.SendNotification();
1863 application.Render(0);
1865 // Expect that the shader's fade color property is accessed
1866 Vector4 actualValue(Vector4::ZERO);
1867 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1868 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1873 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1875 TestApplication application;
1877 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1879 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1881 Shader shader = Shader::New("VertexSource", "FragmentSource");
1882 TextureSet textureSet = CreateTextureSet(image);
1884 Geometry geometry = CreateQuadGeometry();
1885 Renderer renderer = Renderer::New(geometry, shader);
1886 renderer.SetTextures(textureSet);
1888 Actor actor = Actor::New();
1889 actor.AddRenderer(renderer);
1890 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1891 application.GetScene().Add(actor);
1892 application.SendNotification();
1893 application.Render(0);
1895 renderer.RegisterProperty("uUniform1", Color::RED);
1896 actor.RegisterProperty("uUniform2", Color::GREEN);
1897 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1899 TestGlAbstraction& gl = application.GetGlAbstraction();
1901 application.SendNotification();
1902 application.Render(0);
1904 // Expect that each of the object's uniforms are set
1905 Vector4 uniform1Value(Vector4::ZERO);
1906 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1907 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1909 Vector4 uniform2Value(Vector4::ZERO);
1910 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1911 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1913 Vector4 uniform3Value(Vector4::ZERO);
1914 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1915 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1920 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1922 TestApplication application;
1924 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1926 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1928 Shader shader = Shader::New("VertexSource", "FragmentSource");
1929 TextureSet textureSet = CreateTextureSet(image);
1931 Geometry geometry = CreateQuadGeometry();
1932 Renderer renderer = Renderer::New(geometry, shader);
1933 renderer.SetTextures(textureSet);
1935 Actor actor = Actor::New();
1936 actor.AddRenderer(renderer);
1937 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1938 application.GetScene().Add(actor);
1939 application.SendNotification();
1940 application.Render(0);
1942 Property::Value value1(Color::RED);
1943 renderer.RegisterProperty("uFadeColor", value1);
1945 Property::Value value2(1.0f);
1946 actor.RegisterProperty("uFadeProgress", value2);
1948 Property::Value value3(Matrix3::IDENTITY);
1949 shader.RegisterProperty("uANormalMatrix", value3);
1951 TestGlAbstraction& gl = application.GetGlAbstraction();
1953 application.SendNotification();
1954 application.Render(0);
1956 // Expect that each of the object's uniforms are set
1957 Vector4 uniform1Value(Vector4::ZERO);
1958 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1959 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1961 float uniform2Value(0.0f);
1962 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1963 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1965 Matrix3 uniform3Value;
1966 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1967 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1972 int UtcDaliRendererRenderOrder2DLayer(void)
1974 TestApplication application;
1975 tet_infoline("Test the rendering order in a 2D layer is correct");
1977 Shader shader = Shader::New("VertexSource", "FragmentSource");
1978 Geometry geometry = CreateQuadGeometry();
1980 Actor root = application.GetScene().GetRootLayer();
1982 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1983 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1985 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1986 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1988 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1989 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1991 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1992 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1994 application.SendNotification();
1995 application.Render(0);
1998 * Create the following hierarchy:
2011 * Expected rendering order : actor2 - actor1 - actor0 - actor3
2016 application.SendNotification();
2017 application.Render(0);
2019 TestGlAbstraction& gl = application.GetGlAbstraction();
2020 gl.GetTextureTrace().Reset();
2021 gl.EnableTextureCallTrace(true);
2022 application.SendNotification();
2023 application.Render(0);
2025 int textureBindIndex[4];
2026 for(unsigned int i(0); i < 4; ++i)
2028 std::stringstream params;
2029 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2030 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2033 //Check that actor1 has been rendered after actor2
2034 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
2036 //Check that actor0 has been rendered after actor1
2037 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2039 //Check that actor3 has been rendered after actor0
2040 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2045 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
2047 TestApplication application;
2048 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
2051 * Creates the following hierarchy:
2053 * actor0------------------------>actor1
2057 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
2059 * renderer0 has depth index 2
2060 * renderer1 has depth index 0
2061 * renderer2 has depth index 1
2063 * renderer3 has depth index 1
2064 * renderer4 has depth index 0
2065 * renderer5 has depth index -1
2067 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
2070 Shader shader = Shader::New("VertexSource", "FragmentSource");
2071 Geometry geometry = CreateQuadGeometry();
2073 Actor root = application.GetScene().GetRootLayer();
2075 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2076 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
2077 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2078 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2079 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
2080 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2081 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
2082 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
2084 application.SendNotification();
2085 application.Render(0);
2087 TestGlAbstraction& gl = application.GetGlAbstraction();
2088 gl.GetTextureTrace().Reset();
2089 gl.EnableTextureCallTrace(true);
2090 application.SendNotification();
2091 application.Render(0);
2093 int textureBindIndex[6];
2094 for(unsigned int i(0); i < 6; ++i)
2096 std::stringstream params;
2097 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2098 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2101 //Check that renderer3 has been rendered after renderer4
2102 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
2104 //Check that renderer0 has been rendered after renderer2
2105 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
2107 //Check that renderer5 has been rendered after renderer2
2108 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
2110 //Check that renderer0 has been rendered after renderer2
2111 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
2113 //Check that renderer2 has been rendered after renderer1
2114 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
2119 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2121 TestApplication application;
2122 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2125 * Creates the following hierarchy:
2133 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
2137 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
2138 * DI:2 DI:0 | DI:0 DI:1 DI:2
2143 * actor0 has sibling order 1
2144 * actor1 has sibling order 0
2145 * actor2 has sibling order 0
2147 * renderer0 has depth index 2
2148 * renderer1 has depth index 0
2150 * renderer2 has depth index 0
2151 * renderer3 has depth index 1
2152 * renderer4 has depth index 2
2154 * renderer5 has depth index -1
2156 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2159 Shader shader = Shader::New("VertexSource", "FragmentSource");
2160 Geometry geometry = CreateQuadGeometry();
2161 Actor root = application.GetScene().GetRootLayer();
2162 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
2163 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2164 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
2166 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2167 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2168 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2169 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2170 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2171 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2173 application.SendNotification();
2174 application.Render();
2176 TestGlAbstraction& gl = application.GetGlAbstraction();
2177 gl.GetTextureTrace().Reset();
2178 gl.EnableTextureCallTrace(true);
2179 application.SendNotification();
2180 application.Render(0);
2182 int textureBindIndex[6];
2183 for(unsigned int i(0); i < 6; ++i)
2185 std::stringstream params;
2186 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2187 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2190 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2191 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2192 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2193 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2194 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2195 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2197 // Change sibling order of actor1
2198 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2199 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2201 gl.GetTextureTrace().Reset();
2202 application.SendNotification();
2203 application.Render(0);
2205 for(unsigned int i(0); i < 6; ++i)
2207 std::stringstream params;
2208 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2209 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2212 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2213 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2214 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2215 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2216 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2217 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2222 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2224 TestApplication application;
2225 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2227 Shader shader = Shader::New("VertexSource", "FragmentSource");
2228 Geometry geometry = CreateQuadGeometry();
2229 Actor root = application.GetScene().GetRootLayer();
2232 * Create the following hierarchy:
2239 * (Overlay) (Regular actor)
2249 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2252 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2253 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2254 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2256 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2257 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2258 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2260 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2261 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2263 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2264 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2265 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2267 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2268 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2270 application.SendNotification();
2271 application.Render(0);
2278 TestGlAbstraction& gl = application.GetGlAbstraction();
2279 gl.GetTextureTrace().Reset();
2280 gl.EnableTextureCallTrace(true);
2281 application.SendNotification();
2282 application.Render(0);
2284 int textureBindIndex[5];
2285 for(unsigned int i(0); i < 5; ++i)
2287 std::stringstream params;
2288 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2289 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2292 //Check that actor4 has been rendered after actor2
2293 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2295 //Check that actor1 has been rendered after actor4
2296 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2298 //Check that actor0 has been rendered after actor1
2299 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2301 //Check that actor3 has been rendered after actor0
2302 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2307 int UtcDaliRendererRenderOrder3DLayer(void)
2309 TestApplication application;
2310 tet_infoline("Test the rendering order in a 3D layer is correct");
2312 Shader shader = Shader::New("VertexSource", "FragmentSource");
2313 Geometry geometry = CreateQuadGeometry();
2315 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::Behavior::LAYER_3D);
2316 Actor root = application.GetScene().GetRootLayer();
2318 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2319 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 300);
2320 actor0.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2322 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2323 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 200);
2324 actor1.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2325 actor1.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2327 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2328 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 100);
2329 actor2.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2330 actor2.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2332 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2333 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2334 actor3.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2335 actor3.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2337 application.SendNotification();
2338 application.Render(0);
2341 * Create the following hierarchy:
2354 * Expected rendering order : actor0 - actor3 - actor2 - actor1
2359 application.SendNotification();
2360 application.Render(0);
2362 TestGlAbstraction& gl = application.GetGlAbstraction();
2363 gl.GetTextureTrace().Reset();
2364 gl.EnableTextureCallTrace(true);
2365 application.SendNotification();
2366 application.Render(0);
2368 int textureBindIndex[4];
2369 for(unsigned int i(0); i < 4; ++i)
2371 std::stringstream params;
2372 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2373 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2376 //Check that actor3 has been rendered after actor0
2377 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2379 //Check that actor2 has been rendered after actor3
2380 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[3], TEST_LOCATION);
2382 //Check that actor1 has been rendered after actor2
2383 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
2388 int UtcDaliRendererSetIndexRange(void)
2392 "attribute vec2 aPosition;\n"
2395 " gl_Position = aPosition;\n"
2400 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2403 TestApplication application;
2404 tet_infoline("Test setting the range of indices to draw");
2406 TestGlAbstraction& gl = application.GetGlAbstraction();
2407 gl.EnableDrawCallTrace(true);
2409 Actor actor = Actor::New();
2410 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2413 Geometry geometry = Geometry::New();
2414 geometry.SetType(Geometry::LINE_LOOP);
2416 // --------------------------------------------------------------------------
2418 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2428 9, // offset = 5, count = 10
2434 1}; // offset = 15, count = 6 // line strip
2436 // --------------------------------------------------------------------------
2445 {Vector2(0.0f, 1.00f)},
2446 {Vector2(0.0f, -1.00f)},
2447 {Vector2(-0.95f, 0.31f)},
2448 {Vector2(0.59f, 0.81f)},
2449 {Vector2(-0.59f, -0.81f)},
2450 {Vector2(-0.95f, -0.31f)},
2451 {Vector2(0.59f, -0.81f)},
2452 {Vector2(0.95f, -0.31f)},
2453 {Vector2(0.95f, 0.31f)},
2454 {Vector2(-0.59f, 0.81f)},
2456 Property::Map vertexFormat;
2457 vertexFormat["aPosition"] = Property::VECTOR2;
2458 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2459 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2461 // --------------------------------------------------------------------------
2462 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2463 geometry.AddVertexBuffer(vertexBuffer);
2466 Shader shader = Shader::New(vertexShader, fragmentShader);
2467 Renderer renderer = Renderer::New(geometry, shader);
2468 actor.AddRenderer(renderer);
2470 Integration::Scene scene = application.GetScene();
2475 // LINE_LOOP, first 0, count 5
2477 renderer.SetIndexRange(0, 5);
2478 application.SendNotification();
2479 application.Render();
2481 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2483 DALI_TEST_CHECK(value.Get(convertedValue));
2484 DALI_TEST_CHECK(convertedValue == 0);
2486 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2487 DALI_TEST_CHECK(value.Get(convertedValue));
2488 DALI_TEST_CHECK(convertedValue == 0);
2490 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2491 DALI_TEST_CHECK(value.Get(convertedValue));
2492 DALI_TEST_CHECK(convertedValue == 5);
2494 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2495 DALI_TEST_CHECK(value.Get(convertedValue));
2496 DALI_TEST_CHECK(convertedValue == 5);
2498 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2499 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2500 DALI_TEST_CHECK(result);
2503 // LINE_LOOP, first 5, count 10
2505 renderer.SetIndexRange(5, 10);
2506 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2507 application.SendNotification();
2508 application.Render();
2509 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2510 DALI_TEST_CHECK(result);
2513 // LINE_STRIP, first 15, count 6
2515 renderer.SetIndexRange(15, 6);
2516 geometry.SetType(Geometry::LINE_STRIP);
2517 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2518 application.SendNotification();
2519 application.Render();
2520 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2521 DALI_TEST_CHECK(result);
2524 // Index out of bounds
2526 renderer.SetIndexRange(15, 30);
2527 geometry.SetType(Geometry::LINE_STRIP);
2528 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2529 application.SendNotification();
2530 application.Render();
2531 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2532 DALI_TEST_CHECK(result);
2535 // drawing whole buffer starting from 15 ( last valid primitive )
2537 renderer.SetIndexRange(15, 0);
2538 geometry.SetType(Geometry::LINE_STRIP);
2539 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2540 application.SendNotification();
2541 application.Render();
2542 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2543 DALI_TEST_CHECK(result);
2549 int UtcDaliRendererSetDepthFunction(void)
2551 TestApplication application;
2553 tet_infoline("Test setting the depth function");
2555 Geometry geometry = CreateQuadGeometry();
2556 Shader shader = CreateShader();
2557 Renderer renderer = Renderer::New(geometry, shader);
2559 Actor actor = Actor::New();
2560 actor.AddRenderer(renderer);
2561 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2562 Integration::Scene scene = application.GetScene();
2563 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2566 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2567 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2568 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2570 glEnableDisableStack.Enable(true);
2571 glDepthFunctionStack.Enable(true);
2572 glEnableDisableStack.EnableLogging(true);
2573 glDepthFunctionStack.EnableLogging(true);
2575 std::ostringstream depthTestStr;
2576 depthTestStr << std::hex << GL_DEPTH_TEST;
2580 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2582 glEnableDisableStack.Reset();
2583 glDepthFunctionStack.Reset();
2584 application.SendNotification();
2585 application.Render();
2587 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2588 std::ostringstream depthFunctionStr;
2589 depthFunctionStr << std::hex << GL_NEVER;
2590 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2595 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2597 glDepthFunctionStack.Reset();
2598 application.SendNotification();
2599 application.Render();
2601 std::ostringstream depthFunctionStr;
2602 depthFunctionStr << std::hex << GL_ALWAYS;
2603 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2608 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2610 glDepthFunctionStack.Reset();
2611 application.SendNotification();
2612 application.Render();
2614 std::ostringstream depthFunctionStr;
2615 depthFunctionStr << std::hex << GL_LESS;
2616 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2621 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2623 glDepthFunctionStack.Reset();
2624 application.SendNotification();
2625 application.Render();
2627 std::ostringstream depthFunctionStr;
2628 depthFunctionStr << std::hex << GL_GREATER;
2629 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2634 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2636 glDepthFunctionStack.Reset();
2637 application.SendNotification();
2638 application.Render();
2640 std::ostringstream depthFunctionStr;
2641 depthFunctionStr << std::hex << GL_EQUAL;
2642 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2647 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2649 glDepthFunctionStack.Reset();
2650 application.SendNotification();
2651 application.Render();
2653 std::ostringstream depthFunctionStr;
2654 depthFunctionStr << std::hex << GL_NOTEQUAL;
2655 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2660 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2662 glDepthFunctionStack.Reset();
2663 application.SendNotification();
2664 application.Render();
2666 std::ostringstream depthFunctionStr;
2667 depthFunctionStr << std::hex << GL_LEQUAL;
2668 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2673 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2675 glDepthFunctionStack.Reset();
2676 application.SendNotification();
2677 application.Render();
2679 std::ostringstream depthFunctionStr;
2680 depthFunctionStr << std::hex << GL_GEQUAL;
2681 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2688 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2689 * The checks performed are as follows:
2690 * - Check the initial/default value.
2691 * - Set a different value via enum.
2692 * - Check it was set.
2693 * - Set a different value via string.
2694 * - Check it was set.
2696 template<typename T>
2697 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2699 application.SendNotification();
2700 application.Render();
2702 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2703 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2704 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2705 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2706 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2708 application.SendNotification();
2709 application.Render();
2711 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2712 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2714 renderer.SetProperty(propertyIndex, secondCheckString);
2715 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2716 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2718 application.SendNotification();
2719 application.Render();
2721 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2722 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2725 int UtcDaliRendererEnumProperties(void)
2727 TestApplication application;
2728 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2730 Geometry geometry = CreateQuadGeometry();
2731 Shader shader = CreateShader();
2732 Renderer renderer = Renderer::New(geometry, shader);
2734 Actor actor = Actor::New();
2735 actor.AddRenderer(renderer);
2736 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2737 application.GetScene().Add(actor);
2740 * Here we use a templatized function to perform several checks on each enumeration property.
2741 * @see CheckEnumerationProperty for details of the checks performed.
2744 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2745 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2746 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2747 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2748 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2749 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2750 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2751 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2752 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2753 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2754 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2755 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2756 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2757 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2758 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2759 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2761 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2762 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2764 application.SendNotification();
2765 application.Render();
2766 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2769 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2771 application.SendNotification();
2772 application.Render();
2773 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2779 Renderer RendererTestFixture(TestApplication& application)
2781 Geometry geometry = CreateQuadGeometry();
2782 Shader shader = CreateShader();
2783 Renderer renderer = Renderer::New(geometry, shader);
2785 Actor actor = Actor::New();
2786 actor.AddRenderer(renderer);
2787 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2788 Integration::Scene scene = application.GetScene();
2789 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2795 int UtcDaliRendererSetDepthTestMode(void)
2797 TestApplication application;
2798 tet_infoline("Test setting the DepthTestMode");
2800 Renderer renderer = RendererTestFixture(application);
2801 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2802 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2803 glEnableDisableStack.Enable(true);
2804 glEnableDisableStack.EnableLogging(true);
2806 glEnableDisableStack.Reset();
2807 application.SendNotification();
2808 application.Render();
2810 // Check depth-test is enabled by default.
2811 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2812 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2814 // 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.
2815 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2816 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2818 glEnableDisableStack.Reset();
2819 application.SendNotification();
2820 application.Render();
2822 // Check the depth buffer was disabled.
2823 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2825 // Turn on automatic mode depth-testing.
2826 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2827 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2829 glEnableDisableStack.Reset();
2830 application.SendNotification();
2831 application.Render();
2833 // Check depth-test is now enabled.
2834 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2835 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2837 // Change the layer behavior to LAYER_UI.
2838 // Note this will also disable depth testing for the layer by default, we test this first.
2839 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2841 glEnableDisableStack.Reset();
2842 application.SendNotification();
2843 application.Render();
2845 // Check depth-test is disabled.
2846 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2848 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2849 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2851 glEnableDisableStack.Reset();
2852 application.SendNotification();
2853 application.Render();
2855 // Check depth-test is *still* disabled.
2856 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2861 int UtcDaliRendererSetDepthWriteMode(void)
2863 TestApplication application;
2864 tet_infoline("Test setting the DepthWriteMode");
2866 Renderer renderer = RendererTestFixture(application);
2867 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2869 application.SendNotification();
2870 application.Render();
2872 // Check the default depth-write status first.
2873 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2875 // Turn off depth-writing.
2876 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2878 application.SendNotification();
2879 application.Render();
2881 // Check depth-write is now disabled.
2882 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2884 // Test the AUTO mode for depth-writing.
2885 // As our renderer is opaque, depth-testing should be enabled.
2886 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2888 application.SendNotification();
2889 application.Render();
2891 // Check depth-write is now enabled.
2892 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2894 // Now make the renderer be treated as translucent by enabling blending.
2895 // The AUTO depth-write mode should turn depth-write off in this scenario.
2896 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2898 application.SendNotification();
2899 application.Render();
2901 // Check depth-write is now disabled.
2902 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2907 int UtcDaliRendererBlendModeUseActorOpacity(void)
2909 TestApplication application;
2910 tet_infoline("Test setting the UseActorOpacity");
2912 Geometry geometry = CreateQuadGeometry();
2913 Shader shader = CreateShader();
2914 Renderer renderer = Renderer::New(geometry, shader);
2916 Actor actor = Actor::New();
2917 actor.AddRenderer(renderer);
2918 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2919 Integration::Scene scene = application.GetScene();
2920 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2923 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2924 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::USE_ACTOR_OPACITY);
2925 actor.AddRenderer(renderer);
2926 application.GetScene().Add(actor);
2928 application.SendNotification();
2929 application.Render();
2931 // Check the default depth-write status first.
2932 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2934 // Turn off depth-writing.
2935 actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.5));
2937 application.SendNotification();
2938 application.Render();
2940 // Check depth-write is now disabled.
2941 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2943 // Turn on depth-writing.
2944 actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 1));
2946 application.SendNotification();
2947 application.Render();
2949 // Check depth-write is now enabled.
2950 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2952 // Turn off depth-writing.
2953 actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.0));
2955 application.SendNotification();
2956 application.Render();
2958 // if actor alpha is 0, SetDepthWriteEnable is not called so GetLastDepthMask returns default value true;
2959 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2964 int UtcDaliRendererCheckStencilDefaults(void)
2966 TestApplication application;
2967 tet_infoline("Test the stencil defaults");
2969 Renderer renderer = RendererTestFixture(application);
2970 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2971 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2972 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2973 glEnableDisableStack.Enable(true);
2974 glEnableDisableStack.EnableLogging(true);
2975 glStencilFunctionStack.Enable(true);
2976 glStencilFunctionStack.EnableLogging(true);
2978 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2980 // Check the defaults:
2981 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2982 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2983 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2984 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2985 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2986 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);
2987 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);
2992 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2994 TestApplication application;
2995 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2997 Renderer renderer = RendererTestFixture(application);
2998 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2999 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3000 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3001 glEnableDisableStack.Enable(true);
3002 glEnableDisableStack.EnableLogging(true);
3003 glStencilFunctionStack.Enable(true);
3004 glStencilFunctionStack.EnableLogging(true);
3006 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
3007 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
3008 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
3009 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3011 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
3012 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
3014 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3015 std::string methodString("StencilFunc");
3016 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3018 // Test the other RenderModes that will not enable the stencil buffer.
3019 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
3020 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3021 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3023 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
3024 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3025 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3027 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
3028 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3029 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3031 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
3032 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
3034 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
3035 // First set a mode to turn off the stencil buffer, so the enable is required.
3036 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
3037 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3038 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
3039 // Set a different stencil function as the last one is cached.
3040 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
3041 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3043 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
3044 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
3049 // Helper function for the SetRenderModeToUseColorBuffer test.
3050 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
3052 // Set the RenderMode property to a value that should not allow color buffer writes.
3053 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
3054 application.SendNotification();
3055 application.Render();
3057 // Check if ColorMask has been called, and that the values are correct.
3058 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3059 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
3061 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
3062 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
3063 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
3064 // @todo Only check alpha if framebuffer supports it.
3065 //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
3068 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
3070 TestApplication application;
3071 tet_infoline("Test setting the RenderMode to use the color buffer");
3073 Renderer renderer = RendererTestFixture(application);
3075 // Set the RenderMode property to a value that should not allow color buffer writes.
3076 // Then check if ColorMask has been called, and that the values are correct.
3077 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
3078 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
3079 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
3080 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
3081 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
3086 int UtcDaliRendererSetStencilFunction(void)
3088 TestApplication application;
3089 tet_infoline("Test setting the StencilFunction");
3091 Renderer renderer = RendererTestFixture(application);
3092 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3093 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3094 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3095 glEnableDisableStack.Enable(true);
3096 glEnableDisableStack.EnableLogging(true);
3097 glStencilFunctionStack.Enable(true);
3098 glStencilFunctionStack.EnableLogging(true);
3100 // RenderMode must use the stencil for StencilFunction to operate.
3101 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3102 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3105 * Lookup table for testing StencilFunction.
3106 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
3108 const int StencilFunctionLookupTable[] = {
3117 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
3120 * Loop through all types of StencilFunction, checking:
3121 * - The value is cached (set in event thread side)
3122 * - Causes "glStencilFunc" to be called
3123 * - Checks the correct parameters to "glStencilFunc" were used
3125 std::string nonChangingParameters = "0, 255";
3126 std::string methodString("StencilFunc");
3127 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
3129 // Set the property.
3130 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
3132 // Check GetProperty returns the same value.
3133 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
3135 // Reset the trace debug.
3136 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3138 // Check the function is called and the parameters are correct.
3139 std::stringstream parameterStream;
3140 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
3142 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3145 // Change the Function Reference only and check the behavior is correct:
3146 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
3147 int testValueReference = 170;
3148 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
3150 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3152 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3154 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3156 std::stringstream parameterStream;
3157 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
3159 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3161 // Change the Function Mask only and check the behavior is correct:
3162 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
3163 int testValueMask = 85;
3164 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
3166 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3168 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3170 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3172 // Clear the stringstream.
3173 parameterStream.str(std::string());
3174 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
3176 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3181 int UtcDaliRendererSetStencilOperation(void)
3183 TestApplication application;
3184 tet_infoline("Test setting the StencilOperation");
3186 Renderer renderer = RendererTestFixture(application);
3187 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3188 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3189 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3190 glEnableDisableStack.Enable(true);
3191 glEnableDisableStack.EnableLogging(true);
3192 glStencilFunctionStack.Enable(true);
3193 glStencilFunctionStack.EnableLogging(true);
3195 // RenderMode must use the stencil for StencilOperation to operate.
3196 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3199 * Lookup table for testing StencilOperation.
3200 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3202 const int StencilOperationLookupTable[] = {
3211 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3213 // Set all 3 StencilOperation properties to a default.
3214 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3215 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3216 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3218 // Set our expected parameter list to the equivalent result.
3219 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3221 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3224 * Loop through all types of StencilOperation, checking:
3225 * - The value is cached (set in event thread side)
3226 * - Causes "glStencilFunc" to be called
3227 * - Checks the correct parameters to "glStencilFunc" were used
3228 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3230 std::string methodString("StencilOp");
3232 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3234 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3236 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3238 // Set the property (outer loop causes all 3 different properties to be set separately).
3239 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3240 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3241 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3243 // Check GetProperty returns the same value.
3244 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3245 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3246 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3248 // Reset the trace debug.
3249 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3251 // Check the function is called and the parameters are correct.
3252 // Set the expected parameter value at its correct index (only)
3253 parameters[0u] = StencilOperationLookupTable[i];
3254 parameters[1u] = StencilOperationLookupTable[j];
3255 parameters[2u] = StencilOperationLookupTable[k];
3257 // Build the parameter list.
3258 std::stringstream parameterStream;
3259 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3261 parameterStream << parameters[parameterBuild];
3262 // Comma-separate the parameters.
3263 if(parameterBuild < 2)
3265 parameterStream << ", ";
3269 // Check the function was called and the parameters were correct.
3270 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3278 int UtcDaliRendererSetStencilMask(void)
3280 TestApplication application;
3281 tet_infoline("Test setting the StencilMask");
3283 Renderer renderer = RendererTestFixture(application);
3284 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3285 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3286 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3287 glEnableDisableStack.Enable(true);
3288 glEnableDisableStack.EnableLogging(true);
3289 glStencilFunctionStack.Enable(true);
3290 glStencilFunctionStack.EnableLogging(true);
3292 // RenderMode must use the stencil for StencilMask to operate.
3293 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3295 // Set the StencilMask property to a value.
3296 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3298 // Check GetProperty returns the same value.
3299 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3301 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3303 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3305 std::string methodString("StencilMask");
3306 std::string parameterString = "0";
3308 // Check the function was called and the parameters were correct.
3309 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3311 // Set the StencilMask property to another value to ensure it has changed.
3312 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3314 // Check GetProperty returns the same value.
3315 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3317 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3319 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3321 parameterString = "255";
3323 // Check the function was called and the parameters were correct.
3324 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3329 int UtcDaliRendererWrongNumberOfTextures(void)
3331 TestApplication application;
3332 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3334 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3335 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3336 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3337 TextureSet textureSet = CreateTextureSet();
3338 textureSet.SetTexture(0, texture);
3339 textureSet.SetTexture(1, texture);
3340 textureSet.SetTexture(2, texture);
3341 textureSet.SetTexture(3, texture);
3342 Shader shader = Shader::New("VertexSource", "FragmentSource");
3343 Geometry geometry = CreateQuadGeometry();
3344 Renderer renderer = Renderer::New(geometry, shader);
3345 renderer.SetTextures(textureSet);
3347 Actor actor = Actor::New();
3348 actor.AddRenderer(renderer);
3349 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3350 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3351 application.GetScene().Add(actor);
3353 TestGlAbstraction& gl = application.GetGlAbstraction();
3354 TraceCallStack& drawTrace = gl.GetDrawTrace();
3356 drawTrace.Enable(true);
3357 drawTrace.EnableLogging(true);
3359 application.SendNotification();
3360 application.Render(0);
3362 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3363 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3365 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3366 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3367 textureSet = CreateTextureSet();
3368 renderer.SetTextures(textureSet);
3369 textureSet.SetTexture(0, texture);
3371 application.SendNotification();
3372 application.Render(0);
3374 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3375 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3380 int UtcDaliRendererOpacity(void)
3382 TestApplication application;
3384 tet_infoline("Test OPACITY property");
3386 Geometry geometry = CreateQuadGeometry();
3387 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3388 Renderer renderer = Renderer::New(geometry, shader);
3390 Actor actor = Actor::New();
3391 actor.AddRenderer(renderer);
3392 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3393 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3394 application.GetScene().Add(actor);
3396 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3398 DALI_TEST_CHECK(value.Get(opacity));
3399 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3401 application.SendNotification();
3402 application.Render();
3404 Vector4 actualValue;
3405 Vector4 actualActorColor;
3406 TestGlAbstraction& gl = application.GetGlAbstraction();
3407 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3408 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3409 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3410 DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3412 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3414 application.SendNotification();
3415 application.Render();
3417 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3418 DALI_TEST_CHECK(value.Get(opacity));
3419 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3421 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3422 DALI_TEST_CHECK(value.Get(opacity));
3423 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3425 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3426 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3428 // Note : Renderer opacity doesn't apply to uActorColor.
3429 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3430 DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3435 int UtcDaliRendererOpacityAnimation(void)
3437 TestApplication application;
3439 tet_infoline("Test OPACITY property animation");
3441 Geometry geometry = CreateQuadGeometry();
3442 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3443 Renderer renderer = Renderer::New(geometry, shader);
3445 Actor actor = Actor::New();
3446 actor.AddRenderer(renderer);
3447 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3448 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3449 application.GetScene().Add(actor);
3451 application.SendNotification();
3452 application.Render(0);
3454 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3456 DALI_TEST_CHECK(value.Get(opacity));
3457 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3459 Animation animation = Animation::New(1.0f);
3460 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3463 application.SendNotification();
3464 application.Render(1000);
3466 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3467 DALI_TEST_CHECK(value.Get(opacity));
3468 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3470 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3472 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3474 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3477 application.SendNotification();
3478 application.Render(1000);
3480 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3481 DALI_TEST_CHECK(value.Get(opacity));
3482 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3483 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3488 int UtcDaliRendererInvalidProperty(void)
3490 TestApplication application;
3492 tet_infoline("Test invalid property");
3494 Geometry geometry = CreateQuadGeometry();
3495 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3496 Renderer renderer = Renderer::New(geometry, shader);
3498 Actor actor = Actor::New();
3499 actor.AddRenderer(renderer);
3500 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3501 application.GetScene().Add(actor);
3503 application.SendNotification();
3504 application.Render(0);
3506 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3507 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3509 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3510 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3515 int UtcDaliRendererRenderingBehavior(void)
3517 TestApplication application;
3519 tet_infoline("Test RENDERING_BEHAVIOR property");
3521 Geometry geometry = CreateQuadGeometry();
3522 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3523 Renderer renderer = Renderer::New(geometry, shader);
3525 Actor actor = Actor::New();
3526 actor.AddRenderer(renderer);
3527 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3528 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3529 application.GetScene().Add(actor);
3531 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3532 int renderingBehavior;
3533 DALI_TEST_CHECK(value.Get(renderingBehavior));
3534 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3536 application.SendNotification();
3537 application.Render();
3539 uint32_t updateStatus = application.GetUpdateStatus();
3541 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3543 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3544 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3545 drawTrace.Enable(true);
3548 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3550 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3551 DALI_TEST_CHECK(value.Get(renderingBehavior));
3552 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3554 // Render and check the update status
3555 application.SendNotification();
3556 application.Render();
3558 updateStatus = application.GetUpdateStatus();
3560 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3562 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3563 DALI_TEST_CHECK(value.Get(renderingBehavior));
3564 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3566 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3570 // Render again and check the update status
3571 application.SendNotification();
3572 application.Render();
3574 updateStatus = application.GetUpdateStatus();
3576 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3578 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3581 // Render again and check the update status
3582 Animation animation = Animation::New(1.0f);
3583 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3588 application.SendNotification();
3589 application.Render(0);
3591 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3595 application.SendNotification();
3596 application.Render(100);
3598 updateStatus = application.GetUpdateStatus();
3600 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3602 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3605 // Change rendering behavior
3606 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3608 // Render and check the update status
3609 application.SendNotification();
3610 application.Render();
3612 updateStatus = application.GetUpdateStatus();
3614 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3619 int UtcDaliRendererRegenerateUniformMap(void)
3621 TestApplication application;
3623 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3625 Geometry geometry = CreateQuadGeometry();
3626 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3627 Renderer renderer = Renderer::New(geometry, shader);
3629 Actor actor = Actor::New();
3630 actor.AddRenderer(renderer);
3631 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3632 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3633 application.GetScene().Add(actor);
3635 application.SendNotification();
3636 application.Render();
3638 actor.RemoveRenderer(renderer);
3639 shader = Shader::New("vertexSrc", "fragmentSrc");
3640 shader.RegisterProperty("opacity", 0.5f);
3641 renderer.SetShader(shader);
3643 Stage::GetCurrent().KeepRendering(1.0f);
3645 // Update for several frames
3646 application.SendNotification();
3647 application.Render();
3648 application.SendNotification();
3649 application.Render();
3650 application.SendNotification();
3651 application.Render();
3652 application.SendNotification();
3653 application.Render();
3656 actor.AddRenderer(renderer);
3657 application.SendNotification();
3658 application.Render();
3660 // Nothing to test here, the test must not crash
3661 auto updateStatus = application.GetUpdateStatus();
3662 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3667 int UtcDaliRendererRenderAfterAddShader(void)
3669 TestApplication application;
3670 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3672 tet_infoline("Test regenerating uniform map when shader changed");
3674 Geometry geometry = CreateQuadGeometry();
3675 Shader shader1 = Shader::New("vertexSrc1", "fragmentSrc1");
3676 Shader shader2 = Shader::New("vertexSrc2", "fragmentSrc2");
3677 Renderer renderer = Renderer::New(geometry, shader1);
3679 // Register each shader1 and shader2 only had
3680 shader1.RegisterProperty("uUniform1", Color::CRIMSON);
3681 shader2.RegisterProperty("uShader2Only", Color::AQUA_MARINE);
3683 Actor actor = Actor::New();
3684 actor.AddRenderer(renderer);
3685 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3686 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3687 application.GetScene().Add(actor);
3689 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3690 int renderingBehavior;
3691 DALI_TEST_CHECK(value.Get(renderingBehavior));
3692 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3694 application.SendNotification();
3695 application.Render(0);
3697 // Check uUniform1 rendered and uUniform2 not rendered before
3698 Vector4 actualValue(Vector4::ZERO);
3699 DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uUniform1", actualValue));
3700 DALI_TEST_EQUALS(actualValue, Color::CRIMSON, TEST_LOCATION);
3702 uint32_t updateStatus = application.GetUpdateStatus();
3704 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3706 // Update for several frames
3707 application.SendNotification();
3708 application.Render();
3709 application.SendNotification();
3710 application.Render();
3711 application.SendNotification();
3712 application.Render();
3713 application.SendNotification();
3714 application.Render();
3715 application.SendNotification();
3716 application.Render();
3718 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3719 drawTrace.Enable(true);
3722 std::vector<UniformData> customUniforms{{"uShader2Only", Property::VECTOR4}};
3724 application.GetGraphicsController().AddCustomUniforms(customUniforms);
3727 renderer.SetShader(shader2);
3729 // Render and check the update status
3730 application.SendNotification();
3731 application.Render(0);
3733 updateStatus = application.GetUpdateStatus();
3735 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3737 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3739 // Check uUniform2 rendered now
3740 DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uShader2Only", actualValue));
3741 DALI_TEST_EQUALS(actualValue, Color::AQUA_MARINE, TEST_LOCATION);
3746 int UtcDaliRendererAddDrawCommands(void)
3748 TestApplication application;
3750 tet_infoline("Test adding draw commands to the renderer");
3752 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3753 glAbstraction.EnableEnableDisableCallTrace(true);
3755 Geometry geometry = CreateQuadGeometry();
3756 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3757 Renderer renderer = Renderer::New(geometry, shader);
3759 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3760 Actor actor = Actor::New();
3761 actor.AddRenderer(renderer);
3762 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3763 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3764 application.GetScene().Add(actor);
3766 // Expect delivering a single draw call
3767 auto& drawTrace = glAbstraction.GetDrawTrace();
3769 drawTrace.Enable(true);
3770 application.SendNotification();
3771 application.Render();
3773 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3775 tet_infoline("\n\nTesting extension draw commands\n");
3776 auto drawCommand1 = DevelRenderer::DrawCommand{};
3777 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3778 drawCommand1.firstIndex = 0;
3779 drawCommand1.elementCount = 2;
3780 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3782 auto drawCommand2 = DevelRenderer::DrawCommand{};
3783 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3784 drawCommand2.firstIndex = 2;
3785 drawCommand2.elementCount = 2;
3786 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3788 auto drawCommand3 = DevelRenderer::DrawCommand{};
3789 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3790 drawCommand3.firstIndex = 2;
3791 drawCommand3.elementCount = 2;
3792 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3794 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3795 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3796 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3799 drawTrace.Enable(true);
3800 application.SendNotification();
3801 application.Render();
3803 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3806 int UtcDaliRendererSetGeometryNegative(void)
3808 TestApplication application;
3809 Dali::Renderer instance;
3812 Dali::Geometry arg1;
3813 instance.SetGeometry(arg1);
3814 DALI_TEST_CHECK(false); // Should not get here
3818 DALI_TEST_CHECK(true); // We expect an assert
3823 int UtcDaliRendererSetTexturesNegative(void)
3825 TestApplication application;
3826 Dali::Renderer instance;
3829 Dali::TextureSet arg1;
3830 instance.SetTextures(arg1);
3831 DALI_TEST_CHECK(false); // Should not get here
3835 DALI_TEST_CHECK(true); // We expect an assert
3840 int UtcDaliRendererSetShaderNegative(void)
3842 TestApplication application;
3843 Dali::Renderer instance;
3847 instance.SetShader(arg1);
3848 DALI_TEST_CHECK(false); // Should not get here
3852 DALI_TEST_CHECK(true); // We expect an assert
3857 int UtcDaliRendererGetGeometryNegative(void)
3859 TestApplication application;
3860 Dali::Renderer instance;
3863 instance.GetGeometry();
3864 DALI_TEST_CHECK(false); // Should not get here
3868 DALI_TEST_CHECK(true); // We expect an assert
3873 int UtcDaliRendererGetTexturesNegative(void)
3875 TestApplication application;
3876 Dali::Renderer instance;
3879 instance.GetTextures();
3880 DALI_TEST_CHECK(false); // Should not get here
3884 DALI_TEST_CHECK(true); // We expect an assert
3889 int UtcDaliRendererGetShaderNegative(void)
3891 TestApplication application;
3892 Dali::Renderer instance;
3895 instance.GetShader();
3896 DALI_TEST_CHECK(false); // Should not get here
3900 DALI_TEST_CHECK(true); // We expect an assert
3905 int UtcDaliRendererCheckTextureBindingP(void)
3907 TestApplication application;
3909 tet_infoline("Test adding draw commands to the renderer");
3911 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3912 glAbstraction.EnableEnableDisableCallTrace(true);
3914 Geometry geometry = CreateQuadGeometry();
3915 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3916 Renderer renderer = Renderer::New(geometry, shader);
3918 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3919 Actor actor = Actor::New();
3920 actor.AddRenderer(renderer);
3921 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3922 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3923 application.GetScene().Add(actor);
3925 TestGraphicsController& graphics = application.GetGraphicsController();
3926 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3927 cmdBufCallstack.Enable(true);
3929 application.SendNotification();
3930 application.Render();
3932 DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3934 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3935 TextureSet textureSet0 = CreateTextureSet(image0);
3936 renderer.SetTextures(textureSet0);
3938 application.SendNotification();
3939 application.Render();
3941 DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3945 int UtcDaliRendererPreparePipeline(void)
3947 TestApplication application;
3949 tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3951 Property::Map vf = CreateModelVertexFormat();
3952 Geometry modelGeometry = CreateModelGeometry(vf);
3953 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3954 Renderer renderer = Renderer::New(modelGeometry, shader);
3955 Actor actor = Actor::New();
3957 // Change the order up to get a fair test
3958 Property::Map modelVF;
3959 modelVF["aBoneIndex[0]"] = Property::INTEGER;
3960 modelVF["aBoneIndex[1]"] = Property::INTEGER;
3961 modelVF["aBoneIndex[2]"] = Property::INTEGER;
3962 modelVF["aBoneIndex[3]"] = Property::INTEGER;
3963 modelVF["aBoneWeights[0]"] = Property::FLOAT;
3964 modelVF["aBoneWeights[1]"] = Property::FLOAT;
3965 modelVF["aBoneWeights[2]"] = Property::FLOAT;
3966 modelVF["aBoneWeights[3]"] = Property::FLOAT;
3967 modelVF["aPosition"] = Property::VECTOR3;
3968 modelVF["aNormal"] = Property::VECTOR3;
3969 modelVF["aTexCoord1"] = Property::VECTOR3;
3970 modelVF["aTexCoord2"] = Property::VECTOR3;
3972 Property::Array vfs;
3973 vfs.PushBack(modelVF);
3974 TestGraphicsController& graphics = application.GetGraphicsController();
3975 graphics.SetVertexFormats(vfs);
3977 actor.AddRenderer(renderer);
3978 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3979 actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3980 application.GetScene().Add(actor);
3982 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3983 TraceCallStack& graphicsCallstack = graphics.mCallStack;
3984 cmdBufCallstack.Enable(true);
3985 graphicsCallstack.Enable(true);
3987 application.SendNotification();
3988 application.Render();
3990 DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3991 std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3992 DALI_TEST_CHECK(submissions.size() > 0);
3994 TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3996 auto result = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3997 auto pipeline = result[0]->data.bindPipeline.pipeline;
4001 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
4002 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
4005 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
4006 Graphics::VertexInputFormat::FVECTOR3,
4013 int UtcDaliRendererPreparePipelineMissingAttrs(void)
4015 TestApplication application;
4017 tet_infoline("Test that rendering an actor tries to bind the attributes locs from the reflection, but fails");
4018 Debug::Filter::SetGlobalLogLevel(Debug::Verbose);
4020 Property::Map modelVF;
4021 modelVF["aPosition"] = Property::VECTOR3;
4022 modelVF["aNormal"] = Property::VECTOR3;
4023 Property::Array vfs;
4024 vfs.PushBack(modelVF);
4026 TestGraphicsController& graphics = application.GetGraphicsController();
4027 graphics.SetAutoAttrCreation(false);
4028 graphics.SetVertexFormats(vfs);
4030 Property::Map vf = CreateModelVertexFormat();
4031 Geometry modelGeometry = CreateModelGeometry(vf);
4032 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
4033 Renderer renderer = Renderer::New(modelGeometry, shader);
4034 Actor actor = Actor::New();
4036 actor.AddRenderer(renderer);
4037 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4038 actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
4039 application.GetScene().Add(actor);
4041 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
4042 TraceCallStack& graphicsCallstack = graphics.mCallStack;
4043 cmdBufCallstack.Enable(true);
4044 graphicsCallstack.Enable(true);
4046 application.SendNotification();
4047 application.Render();
4049 DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
4050 std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
4051 DALI_TEST_CHECK(submissions.size() > 0);
4053 TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
4055 auto result = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
4056 auto pipeline = result[0]->data.bindPipeline.pipeline;
4060 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 2, TEST_LOCATION);
4066 int UtcDaliRendererUniformArrayOfStruct(void)
4068 TestApplication application;
4069 tet_infoline("Test that uniforms that are elements of arrays of structs can be accessed");
4071 std::vector<UniformData> customUniforms{{"arrayof[10].color", Property::VECTOR4},
4072 {"arrayof[10].position", Property::VECTOR2},
4073 {"arrayof[10].normal", Property::VECTOR3}};
4075 application.GetGraphicsController().AddCustomUniforms(customUniforms);
4077 Geometry geometry = CreateQuadGeometry();
4078 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
4079 Renderer renderer = Renderer::New(geometry, shader);
4080 Actor actor = Actor::New();
4081 actor.AddRenderer(renderer);
4082 actor[Actor::Property::SIZE] = Vector2(120, 120);
4083 application.GetScene().Add(actor);
4085 // Define some properties to match the custom uniforms.
4086 // Ensure they can be written & read back from the abstraction.
4088 struct UniformIndexPair
4090 Property::Index index;
4092 UniformIndexPair(Property::Index index, std::string name)
4098 std::vector<UniformIndexPair> uniformIndices;
4100 std::ostringstream oss;
4101 for(int i = 0; i < 10; ++i)
4103 Property::Index index;
4104 oss << "arrayof[" << i << "].color";
4105 Vector4 color = Color::WHITE;
4106 color.r = 25.5f * i;
4107 index = renderer.RegisterProperty(oss.str(), color);
4108 uniformIndices.emplace_back(index, oss.str());
4112 oss << "arrayof[" << i << "].position";
4113 Vector2 pos(i, 10 + i * 5);
4114 index = renderer.RegisterProperty(oss.str(), pos);
4115 uniformIndices.emplace_back(index, oss.str());
4119 oss << "arrayof[" << i << "].normal";
4120 Vector3 normal(i, i * 10, i * 100);
4121 index = renderer.RegisterProperty(oss.str(), normal);
4122 uniformIndices.emplace_back(index, oss.str());
4126 auto& gl = application.GetGlAbstraction();
4127 TraceCallStack& callStack = gl.GetSetUniformTrace();
4128 gl.EnableSetUniformCallTrace(true);
4130 application.SendNotification();
4131 application.Render();
4133 // Check that the uniforms match.
4134 TraceCallStack::NamedParams params;
4135 for(auto& uniformInfo : uniformIndices)
4137 Property::Value value = renderer.GetProperty(uniformInfo.index);
4138 switch(value.GetType())
4140 case Property::VECTOR2:
4142 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4144 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniformInfo.name.c_str(), setValue));
4145 DALI_TEST_EQUALS(value.Get<Vector2>(), setValue, 0.001f, TEST_LOCATION);
4148 case Property::VECTOR3:
4150 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4152 DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniformInfo.name.c_str(), setValue));
4153 DALI_TEST_EQUALS(value.Get<Vector3>(), setValue, 0.001f, TEST_LOCATION);
4156 case Property::VECTOR4:
4158 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4160 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniformInfo.name.c_str(), setValue));
4161 DALI_TEST_EQUALS(value.Get<Vector4>(), setValue, 0.001f, TEST_LOCATION);
4169 // There is a hash in the property name's uniform map: check this in debugger
4170 // There is a hash in the reflection. Check this in the debugger.
4172 // Check that the reflection contains individual locs for each array entry's struct element
4173 // and that it hashes the whole string
4175 // Ensure that the property name's hash is also for the whole string.
4180 int utcDaliRendererPartialUpdateChangeUniform(void)
4182 TestApplication application(
4183 TestApplication::DEFAULT_SURFACE_WIDTH,
4184 TestApplication::DEFAULT_SURFACE_HEIGHT,
4185 TestApplication::DEFAULT_HORIZONTAL_DPI,
4186 TestApplication::DEFAULT_VERTICAL_DPI,
4190 tet_infoline("Check the damaged rect with changing uniform");
4192 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4194 std::vector<Rect<int>> damagedRects;
4195 Rect<int> clippingRect;
4196 application.SendNotification();
4197 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4199 // First render pass, nothing to render, adaptor would just do swap buffer.
4200 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4201 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4203 Shader shader = Shader::New("VertexSource", "FragmentSource");
4204 Geometry geometry = CreateQuadGeometry();
4205 Renderer renderer = Renderer::New(geometry, shader);
4207 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", Color::WHITE);
4209 Actor actor = Actor::New();
4210 actor.AddRenderer(renderer);
4211 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4212 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4213 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4214 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4215 Stage::GetCurrent().Add(actor);
4217 application.SendNotification();
4219 // 1. Actor added, damaged rect is added size of actor
4220 damagedRects.clear();
4221 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4222 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4225 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4226 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4227 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4228 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4229 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4230 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4231 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4233 damagedRects.clear();
4234 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4235 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4237 // Ensure the damaged rect is empty
4238 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4240 // 2. Change the uniform value
4241 renderer.SetProperty(colorIndex, Color::RED);
4242 application.SendNotification();
4244 damagedRects.clear();
4245 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4246 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4249 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4250 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4251 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4252 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4253 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4254 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4255 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4257 damagedRects.clear();
4258 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4259 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4261 // 3. Change the uniform value and another property together
4262 actor.SetProperty(Actor::Property::COLOR, Color::YELLOW);
4263 renderer.SetProperty(colorIndex, Color::BLUE);
4264 application.SendNotification();
4266 damagedRects.clear();
4267 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4268 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4271 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4272 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4273 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4274 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4275 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4276 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4277 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4279 damagedRects.clear();
4280 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4281 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4283 // 4. Change the uniform value only
4284 renderer.SetProperty(colorIndex, Color::RED); // Set the previous value (#2)
4285 application.SendNotification();
4287 damagedRects.clear();
4288 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4289 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4292 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4293 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4294 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4295 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4296 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4297 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4298 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4303 int utcDaliRendererPartialUpdateAddRemoveRenderer(void)
4305 TestApplication application(
4306 TestApplication::DEFAULT_SURFACE_WIDTH,
4307 TestApplication::DEFAULT_SURFACE_HEIGHT,
4308 TestApplication::DEFAULT_HORIZONTAL_DPI,
4309 TestApplication::DEFAULT_VERTICAL_DPI,
4313 tet_infoline("Check the damaged rect with adding / removing renderer");
4315 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4317 Shader shader = Shader::New("VertexSource", "FragmentSource");
4318 Geometry geometry = CreateQuadGeometry();
4319 Renderer renderer = Renderer::New(geometry, shader);
4321 Actor actor = Actor::New();
4322 actor.AddRenderer(renderer);
4323 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4324 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4325 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4326 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4327 Stage::GetCurrent().Add(actor);
4329 application.SendNotification();
4331 std::vector<Rect<int>> damagedRects;
4332 Rect<int> clippingRect;
4334 // 1. Actor added, damaged rect is added size of actor
4335 damagedRects.clear();
4336 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4337 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4340 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4341 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4342 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4343 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4344 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4345 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4346 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4348 // 2. Remove renderer
4349 actor.RemoveRenderer(renderer);
4350 application.SendNotification();
4352 damagedRects.clear();
4353 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4355 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4356 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4358 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4360 // 3. Change a property value of the Renderer
4361 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
4362 application.SendNotification();
4364 damagedRects.clear();
4365 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4367 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4369 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4371 // 4. Add renderer again
4372 actor.AddRenderer(renderer);
4373 application.SendNotification();
4375 damagedRects.clear();
4376 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4378 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4379 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4381 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4383 // 5. Remove renderer agin
4384 actor.RemoveRenderer(renderer);
4385 application.SendNotification();
4387 damagedRects.clear();
4388 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4390 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4391 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4393 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4398 int utcDaliRendererPartialUpdateRenderingBehavior(void)
4400 TestApplication application(
4401 TestApplication::DEFAULT_SURFACE_WIDTH,
4402 TestApplication::DEFAULT_SURFACE_HEIGHT,
4403 TestApplication::DEFAULT_HORIZONTAL_DPI,
4404 TestApplication::DEFAULT_VERTICAL_DPI,
4408 tet_infoline("Check the damaged rect with changing rendering behavior");
4410 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4412 Shader shader = Shader::New("VertexSource", "FragmentSource");
4413 Geometry geometry = CreateQuadGeometry();
4414 Renderer renderer = Renderer::New(geometry, shader);
4416 Actor actor = Actor::New();
4417 actor.AddRenderer(renderer);
4418 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4419 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4420 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4421 actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4422 Stage::GetCurrent().Add(actor);
4424 application.SendNotification();
4426 std::vector<Rect<int>> damagedRects;
4427 Rect<int> clippingRect;
4429 // Actor added, damaged rect is added size of actor
4430 damagedRects.clear();
4431 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4432 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4435 clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4436 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4437 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4438 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4439 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4440 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4441 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4443 damagedRects.clear();
4444 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4445 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4447 // Ensure the damaged rect is empty
4448 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4450 // Change rendering behavior to CONTINUOUSLY
4451 renderer[DevelRenderer::Property::RENDERING_BEHAVIOR] = DevelRenderer::Rendering::CONTINUOUSLY;
4453 application.SendNotification();
4455 damagedRects.clear();
4456 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4457 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4459 // The damaged rect should not be empty
4460 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4461 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4463 damagedRects.clear();
4464 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4465 application.RenderWithPartialUpdate(damagedRects, clippingRect);
4467 // The damaged rect should not be empty again!
4468 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4469 DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4474 int utcDaliRendererDoNotSkipRenderIfTextureSetChanged(void)
4476 TestApplication application;
4477 tet_infoline("Check to not skip rendering in case of the TextureSet Changed");
4479 TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
4480 drawTrace.Enable(true);
4483 Actor actor = CreateRenderableActor();
4484 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4485 actor.SetProperty(Actor::Property::SIZE, Vector3(80.0f, 80.0f, 0.0f));
4486 application.GetScene().Add(actor);
4488 // Make any animation to skip rendering.
4489 // Delay duration must be bigger than 0.0f
4490 Animation animation = Animation::New(2.0f);
4491 animation.AnimateTo(Property(actor, Actor::Property::POSITION_X), 1.0f, TimePeriod(1.0f, 1.0f));
4494 DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4496 Renderer renderer = actor.GetRendererAt(0u);
4498 Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
4499 TextureSet textureSet = CreateTextureSet(image);
4501 // Render at least 2 frames
4502 application.SendNotification();
4503 application.Render();
4504 application.SendNotification();
4505 application.Render();
4509 application.SendNotification();
4510 application.Render();
4513 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
4515 // Change TextureSet
4516 renderer.SetTextures(textureSet);
4518 application.SendNotification();
4519 application.Render(16u);
4521 // Should not Skip rendering!
4522 DALI_TEST_GREATER(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
4527 int UtcDaliRendererSetInstanceCount(void)
4529 TestApplication application;
4531 tet_infoline("Test setting the instance count results in instanced draw");
4533 Property::Map vertexFormat{{"aPosition", Property::VECTOR2}, {"aTexCoord", Property::VECTOR2}};
4534 Property::Map instanceFormat{{"aTranslation", Property::VECTOR2}, {"aSize", Property::VECTOR2}};
4536 const float halfQuadSize = .5f;
4537 struct TexturedQuadVertex
4542 TexturedQuadVertex texturedQuadVertexData[4] = {
4543 {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
4544 {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
4545 {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
4546 {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
4548 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
4549 vertexBuffer.SetData(texturedQuadVertexData, 4);
4551 VertexBuffer instanceBuffer = VertexBuffer::New(instanceFormat);
4552 instanceBuffer.SetDivisor(1);
4556 Vector2 aTranslation;
4559 std::vector<Instance> instanceData = {{Vector2{111.f, 222.f}, Vector2{32, 32}}, {Vector2{-112.f, 342.f}, Vector2{32, 32}}, {Vector2{124.f, 294.f}, Vector2{32, 32}}, {Vector2{459.f, -392.f}, Vector2{32, 32}}};
4561 Dali::Geometry geometry = Dali::Geometry::New();
4562 geometry.AddVertexBuffer(vertexBuffer);
4563 geometry.AddVertexBuffer(instanceBuffer);
4564 geometry.SetType(Geometry::TRIANGLE_STRIP);
4566 Shader shader = CreateShader();
4568 Actor actor = Actor::New();
4569 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4570 application.GetScene().Add(actor);
4572 Renderer renderer = Renderer::New(geometry, shader);
4573 actor.AddRenderer(renderer);
4575 auto& graphicsController = application.GetGraphicsController();
4576 graphicsController.mCallStack.EnableLogging(true);
4577 graphicsController.mCommandBufferCallStack.EnableLogging(true);
4579 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
4580 auto& drawTrace = glAbstraction.GetDrawTrace();
4581 drawTrace.Enable(true);
4582 drawTrace.EnableLogging(true);
4584 application.SendNotification();
4585 application.Render();
4587 tet_infoline("Without instance buffer loaded, should not draw");
4588 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4589 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4591 instanceBuffer.SetData(&instanceData[0], 4);
4592 application.SendNotification();
4593 application.Render();
4595 tet_infoline("With no instance count set, should not draw instanced.");
4596 DALI_TEST_CHECK(drawTrace.FindMethod("DrawArrays"));
4597 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4599 renderer[DevelRenderer::Property::INSTANCE_COUNT] = 4;
4601 Property::Value v = renderer["instanceCount"];
4602 DALI_TEST_EQUALS(v, Property::Value(4), TEST_LOCATION);
4605 application.SendNotification();
4606 application.Render();
4608 tet_infoline("With instance count set to 4, should draw 4 instances.");
4609 TraceCallStack::NamedParams params;
4610 params["instanceCount"] << 4;
4611 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4612 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArraysInstanced", params));
4614 renderer[DevelRenderer::Property::INSTANCE_COUNT] = 1;
4616 application.SendNotification();
4617 application.Render();
4619 tet_infoline("With instance count set to 1, should draw 1 instance.");
4620 TraceCallStack::NamedParams params2;
4621 params["instanceCount"] << 1;
4622 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4623 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArraysInstanced", params2));
4625 renderer[DevelRenderer::Property::INSTANCE_COUNT] = 0;
4627 application.SendNotification();
4628 application.Render();
4630 tet_infoline("With instance count set to 0, should revert to DrawArrays.");
4631 DALI_TEST_CHECK(drawTrace.FindMethod("DrawArrays"));
4632 DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4637 int UtcDaliRendererVertexRange(void)
4639 TestApplication application;
4641 tet_infoline("Test setting the instance count results in instanced draw");
4643 Property::Map vertexFormat{{"aPosition", Property::VECTOR2}, {"aTexCoord", Property::VECTOR2}};
4644 Property::Map instanceFormat{{"aTranslation", Property::VECTOR2}, {"aSize", Property::VECTOR2}};
4646 const float halfQuadSize = .5f;
4647 struct TexturedQuadVertex
4652 TexturedQuadVertex texturedQuadVertexData[4] = {
4653 {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
4654 {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
4655 {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
4656 {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
4658 const int VERTEX_SET_COUNT(10);
4659 std::vector<TexturedQuadVertex> vertexData;
4660 vertexData.resize(VERTEX_SET_COUNT * 4);
4661 for(int i = 0; i < VERTEX_SET_COUNT; ++i)
4663 for(int j = 0; j < 4; ++j)
4665 vertexData.push_back({texturedQuadVertexData[j].aPosition * (20.0f * i), texturedQuadVertexData[j].aTexCoord});
4669 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
4670 vertexBuffer.SetData(&vertexData[0], VERTEX_SET_COUNT * 4);
4672 Dali::Geometry geometry = Dali::Geometry::New();
4673 geometry.AddVertexBuffer(vertexBuffer);
4674 geometry.SetType(Geometry::TRIANGLE_STRIP);
4676 Shader shader = CreateShader();
4678 Actor actor = Actor::New();
4679 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4680 application.GetScene().Add(actor);
4682 for(int i = 0; i < VERTEX_SET_COUNT; ++i)
4684 Renderer renderer = Renderer::New(geometry, shader);
4685 renderer[DevelRenderer::Property::VERTEX_RANGE_FIRST] = i * 4;
4686 renderer[DevelRenderer::Property::VERTEX_RANGE_COUNT] = 4;
4687 actor.AddRenderer(renderer);
4690 for(uint32_t i = 0; i < actor.GetRendererCount(); ++i)
4692 auto renderer = actor.GetRendererAt(i);
4693 DALI_TEST_EQUALS(renderer.GetProperty<int>(DevelRenderer::Property::VERTEX_RANGE_FIRST), i * 4, TEST_LOCATION);
4694 DALI_TEST_EQUALS(renderer.GetProperty<int>(DevelRenderer::Property::VERTEX_RANGE_COUNT), 4, TEST_LOCATION);
4697 auto& graphicsController = application.GetGraphicsController();
4698 graphicsController.mCallStack.EnableLogging(true);
4699 graphicsController.mCommandBufferCallStack.EnableLogging(true);
4701 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
4702 auto& drawTrace = glAbstraction.GetDrawTrace();
4703 drawTrace.Enable(true);
4704 drawTrace.EnableLogging(true);
4706 application.SendNotification();
4707 application.Render();
4709 TraceCallStack::NamedParams namedParams;
4710 namedParams["first"] << 0;
4711 namedParams["count"] << 4;
4712 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4714 namedParams["first"].str("");
4715 namedParams["first"].clear();
4716 namedParams["first"] << 4;
4717 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4719 namedParams["first"].str("");
4720 namedParams["first"].clear();
4721 namedParams["first"] << 8;
4722 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4724 namedParams["first"].str("");
4725 namedParams["first"].clear();
4726 namedParams["first"] << 12;
4727 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4729 namedParams["first"].str("");
4730 namedParams["first"].clear();
4731 namedParams["first"] << 16;
4732 DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4734 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 10, TEST_LOCATION);
4738 TestGraphicsBuffer* FindUniformBuffer(int bufferIndex, TestGraphicsController& graphics)
4741 for(auto bufferPtr : graphics.mAllocatedBuffers)
4743 if(((bufferPtr->mCreateInfo.usage & (0 | Graphics::BufferUsage::UNIFORM_BUFFER)) > 0) &&
4744 !(bufferPtr->mCpuOnly))
4746 if(counter == bufferIndex)
4756 void CreateRendererProperties(Renderer renderer, const Matrix& m, const Matrix& n)
4758 for(int i = 0; i < 300; ++i)
4760 std::ostringstream property;
4761 property << "uBone[" << i << "]";
4763 renderer.RegisterProperty(property.str(), m);
4765 renderer.RegisterProperty(property.str(), n);
4767 renderer.RegisterProperty("uNumberOfBlendShapes", 55.0f);
4768 float weight = 0.5f;
4769 for(int i = 0; i < 128; ++i)
4771 std::ostringstream property;
4772 property << "uBlendShapeWeight[" << i << "]";
4773 renderer.RegisterProperty(property.str(), weight);
4778 renderer["uBlendShapeWeight[0]"] = w1;
4779 renderer["uBlendShapeWeight[55]"] = w2;
4780 renderer["uBlendShapeWeight[127]"] = w3;
4783 int UtcDaliRendererUniformBlocks01(void)
4785 setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4786 TestApplication application;
4788 tet_infoline("Test that uniforms in blocks are written to a gpu buffer");
4789 auto& graphics = application.GetGraphicsController();
4790 auto& gl = application.GetGlAbstraction();
4791 gl.mBufferTrace.EnableLogging(true);
4793 gl.SetUniformBufferOffsetAlignment(1024); // Arbitrarily big to easily see it work in debug
4795 const int MAX_BONE_COUNT{300};
4796 const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4798 graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4800 const int MAX_MORPH_COUNT{128};
4801 const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4802 graphics.AddCustomUniformBlock(
4803 TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4805 Actor actor = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4806 Shader shader = CreateShader(); // Don't care about src content
4807 Geometry geometry = CreateQuadGeometry();
4808 Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4812 n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4814 CreateRendererProperties(renderer, m, n);
4816 TraceCallStack& graphicsTrace = graphics.mCallStack;
4817 TraceCallStack& cmdTrace = graphics.mCommandBufferCallStack;
4818 graphicsTrace.EnableLogging(true);
4819 cmdTrace.EnableLogging(true);
4821 application.SendNotification();
4822 application.Render();
4824 // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4825 DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4827 tet_infoline("Test that uBone[299] is written correctly");
4830 for(auto bufferPtr : graphics.mAllocatedBuffers)
4832 if(((bufferPtr->mCreateInfo.usage & (0 | Graphics::BufferUsage::UNIFORM_BUFFER)) > 0) &&
4833 !(bufferPtr->mCpuOnly))
4835 // We have a GPU uniform buffer. Probably the right one.
4836 // The custom uniform block above should point us to the right spot...
4837 DALI_TEST_CHECK(bufferPtr->memory.size() >= skinningBlockSize);
4839 Matrix* mPtr = reinterpret_cast<Dali::Matrix*>(&bufferPtr->memory[0] + sizeof(Dali::Matrix) * 299);
4840 DALI_TEST_EQUALS(*mPtr, n, 0.0001, TEST_LOCATION);
4844 DALI_TEST_CHECK(found);
4849 int UtcDaliRendererUniformBlocks02(void)
4851 setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4852 TestApplication application;
4854 tet_infoline("Test that repeated update/render cycles write into alternative buffers");
4855 auto& graphics = application.GetGraphicsController();
4856 auto& gl = application.GetGlAbstraction();
4857 gl.mBufferTrace.EnableLogging(true);
4859 const uint32_t UNIFORM_BLOCK_ALIGNMENT(512);
4860 gl.SetUniformBufferOffsetAlignment(UNIFORM_BLOCK_ALIGNMENT);
4862 const int MAX_BONE_COUNT{300};
4863 const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4865 graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4867 const int MAX_MORPH_COUNT{128};
4868 const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4869 graphics.AddCustomUniformBlock(
4870 TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4872 Actor actor = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4873 Shader shader = CreateShader(); // Don't care about src content
4874 Geometry geometry = CreateQuadGeometry();
4875 Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4879 n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4881 CreateRendererProperties(renderer, m, n);
4885 renderer["uBlendShapeWeight[0]"] = w1;
4886 renderer["uBlendShapeWeight[55]"] = w2;
4887 renderer["uBlendShapeWeight[127]"] = w3;
4889 TraceCallStack& graphicsTrace = graphics.mCallStack;
4890 TraceCallStack& cmdTrace = graphics.mCommandBufferCallStack;
4891 graphicsTrace.EnableLogging(true);
4892 cmdTrace.EnableLogging(true);
4894 application.SendNotification();
4895 application.Render();
4897 // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4898 DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4900 const uint32_t MORPH_BLOCK_OFFSET = (skinningBlockSize % UNIFORM_BLOCK_ALIGNMENT == 0) ? skinningBlockSize : ((skinningBlockSize / UNIFORM_BLOCK_ALIGNMENT) + 1) * UNIFORM_BLOCK_ALIGNMENT;
4902 for(int i = 0; i < 50; ++i)
4904 tet_infoline("\nTest that uBone[299] is written correctly");
4905 TestGraphicsBuffer* bufferPtr = FindUniformBuffer(i % 2, graphics);
4906 DALI_TEST_CHECK(graphics.mAllocatedBuffers.size() == (i == 0 ? 4 : 5));
4907 DALI_TEST_CHECK(bufferPtr != nullptr);
4908 Matrix* mPtr = reinterpret_cast<Dali::Matrix*>(&bufferPtr->memory[0] + sizeof(Dali::Matrix) * 299);
4909 DALI_TEST_EQUALS(*mPtr, n, 0.0001, TEST_LOCATION);
4911 float* wPtr1 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 1);
4912 float* wPtr2 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 56);
4913 float* wPtr3 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 128);
4915 tet_printf("Test that uBlendShapeWeight[0] is written correctly as %4.2f\n", w1);
4916 tet_printf("Test that uBlendShapeWeight[55] is written correctly as %4.2f\n", w2);
4917 tet_printf("Test that uBlendShapeWeight[127] is written correctly as %4.2f\n", w3);
4919 DALI_TEST_EQUALS(*wPtr1, w1, 0.0001f, TEST_LOCATION);
4920 DALI_TEST_EQUALS(*wPtr2, w2, 0.0001f, TEST_LOCATION);
4921 DALI_TEST_EQUALS(*wPtr3, w3, 0.0001f, TEST_LOCATION);
4923 n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(i * 0.3f), Vector3::YAXIS), Vector3(200.0f + i * 10.0f, -i, 20.0f));
4924 renderer["uBone[299]"] = n;
4929 renderer["uBlendShapeWeight[0]"] = w1;
4930 renderer["uBlendShapeWeight[55]"] = w2;
4931 renderer["uBlendShapeWeight[127]"] = w3;
4933 application.SendNotification();
4934 application.Render();
4940 int AlignSize(int size, int align)
4942 return (size % align == 0) ? size : ((size / align) + 1) * align;
4945 int UtcDaliRendererUniformBlocks03(void)
4947 setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4948 TestApplication application;
4950 tet_infoline("Test that adding actors grows the uniform buffer");
4951 auto& graphics = application.GetGraphicsController();
4952 auto& gl = application.GetGlAbstraction();
4953 gl.mBufferTrace.EnableLogging(true);
4955 const uint32_t UNIFORM_BLOCK_ALIGNMENT(512);
4956 gl.SetUniformBufferOffsetAlignment(UNIFORM_BLOCK_ALIGNMENT);
4958 const int MAX_BONE_COUNT{300};
4959 const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4961 graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4963 const int MAX_MORPH_COUNT{128};
4964 const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4965 graphics.AddCustomUniformBlock(
4966 TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4968 Actor actor = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4969 Shader shader = CreateShader(); // Don't care about src content
4970 Geometry geometry = CreateQuadGeometry();
4971 Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4975 n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4977 CreateRendererProperties(renderer, m, n);
4979 TraceCallStack& graphicsTrace = graphics.mCallStack;
4980 TraceCallStack& cmdTrace = graphics.mCommandBufferCallStack;
4981 graphicsTrace.EnableLogging(true);
4982 cmdTrace.EnableLogging(true);
4984 application.SendNotification();
4985 application.Render();
4987 // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4988 DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4990 unsigned int overallSize = 0;
4992 for(int i = 0; i < 10; ++i)
4994 overallSize += AlignSize(skinningBlockSize, UNIFORM_BLOCK_ALIGNMENT) + AlignSize(morphBlockSize, UNIFORM_BLOCK_ALIGNMENT);
4996 DALI_TEST_CHECK(graphics.mAllocatedBuffers.size() == (i == 0 ? 4 : 5));
4998 TestGraphicsBuffer* bufferPtr = graphics.mAllocatedBuffers.back();
4999 tet_printf("\nTest that latest buffer is big enough(%d)>%d\n", bufferPtr->memory.size(), overallSize);
5001 DALI_TEST_CHECK(bufferPtr->memory.size() >= overallSize);
5003 Actor actor = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
5004 actor.AddRenderer(renderer);
5005 application.GetScene().Add(actor);
5007 application.SendNotification();
5008 application.Render();
5014 int UtcDaliRendererUniformBlocksUnregisterScene01(void)
5016 TestApplication application;
5018 tet_infoline("Test that uniform buffers are unregistered after a scene is destroyed\n");
5020 auto& graphics = application.GetGraphicsController();
5021 auto& gl = application.GetGlAbstraction();
5022 graphics.mCallStack.EnableLogging(true);
5023 graphics.mCommandBufferCallStack.EnableLogging(true);
5024 gl.mBufferTrace.EnableLogging(true);
5025 gl.mBufferTrace.Enable(true);
5027 Actor dummyActor = CreateRenderableActor(CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 45, 45));
5028 application.GetScene().Add(dummyActor);
5029 application.SendNotification();
5030 application.Render();
5032 Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
5033 DALI_TEST_CHECK(scene);
5034 application.AddScene(scene);
5036 Actor actor = CreateActor(scene.GetRootLayer(), 0, TEST_LOCATION);
5037 Shader shader = CreateShader(); // Don't really care...
5038 Geometry geometry = CreateQuadGeometry();
5039 Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
5041 const int MAX_BONE_COUNT{300};
5042 const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
5044 graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
5047 for(int i = 0; i < MAX_BONE_COUNT; ++i)
5049 std::ostringstream property;
5050 property << "uBone[" << i << "]";
5051 renderer.RegisterProperty(property.str(), m);
5053 tet_infoline("--Expect new scene's buffers to be created here");
5054 application.SendNotification();
5055 application.Render();
5057 scene.RemoveSceneObject(); // Scene's scene graph lifecycle is NOT managed by scene handle
5061 gl.mBufferTrace.Reset();
5063 tet_infoline("--Expect UnregisterScene to happen during this render cycle");
5064 dummyActor[Actor::Property::SIZE] = Vector3(100, 100, 0);
5065 application.SendNotification();
5066 application.Render();
5068 TraceCallStack::NamedParams namedParams;
5069 namedParams["id"] << 6;
5070 DALI_TEST_CHECK(gl.mBufferTrace.FindMethodAndParams("DeleteBuffers", namedParams));
5075 int UtcDaliRendererUniformNameCrop(void)
5077 TestApplication application;
5078 tet_infoline("Tests against reflection cropping one character too many form array uniform name.\n");
5080 auto& graphics = application.GetGraphicsController();
5082 auto uniforms = std::vector<UniformData>{
5083 {"uSomeColor", Dali::Property::Type::FLOAT},
5084 {"uSomeColors[10]", Dali::Property::Type::FLOAT}};
5085 graphics.AddCustomUniforms(uniforms);
5087 auto& gl = application.GetGlAbstraction();
5088 graphics.mCallStack.EnableLogging(true);
5089 graphics.mCommandBufferCallStack.EnableLogging(true);
5090 gl.mBufferTrace.EnableLogging(true);
5091 gl.mBufferTrace.Enable(true);
5093 gl.mSetUniformTrace.EnableLogging(true);
5094 gl.mSetUniformTrace.Enable(true);
5096 Geometry geometry = CreateQuadGeometry();
5097 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
5098 Renderer renderer = Renderer::New(geometry, shader);
5099 Actor actor = Actor::New();
5100 actor.AddRenderer(renderer);
5101 actor[Actor::Property::SIZE] = Vector2(120, 120);
5102 application.GetScene().Add(actor);
5104 std::ostringstream oss;
5105 struct UniformIndexPair
5107 Property::Index index;
5109 UniformIndexPair(Property::Index index, std::string name)
5111 name(std::move(name))
5115 std::vector<UniformIndexPair> uniformIndices;
5116 for(int i = 0; i < 10; ++i)
5118 Property::Index index;
5119 oss << "uArray[" << i + 1 << "]";
5120 auto value = float(i);
5121 index = renderer.RegisterProperty(oss.str(), value);
5122 uniformIndices.emplace_back(index, oss.str());
5127 // Cause overwrite, index 10 and uToOverflow should share same memory
5128 [[maybe_unused]] auto badArrayIndex = renderer.RegisterProperty("uSomeColor", 100.0f);
5129 [[maybe_unused]] auto badArrayIndex2 = renderer.RegisterProperty("uSomeColors[0]", 200.0f);
5131 application.GetScene().Add(actor);
5132 application.SendNotification();
5133 application.Render(0);
5136 gl.GetUniformValue("uSomeColor", value);
5138 // Test against the bug when name is one character short and array may be mistaken for
5139 // an individual uniform of the same name minut 1 character.
5140 DALI_TEST_EQUALS(value, 100.0f, std::numeric_limits<float>::epsilon(), TEST_LOCATION);
5144 int UtcDaliRendererUniformArrayOverflow(void)
5146 TestApplication application;
5147 tet_infoline("Overflow test whether uColor uniform would be overriden by array with out-of-bound index.\n");
5149 auto& graphics = application.GetGraphicsController();
5150 auto uniforms = std::vector<UniformData>{{"uArray[10]", Dali::Property::Type::FLOAT}};
5152 graphics.AddCustomUniforms(uniforms);
5154 auto& gl = application.GetGlAbstraction();
5155 graphics.mCallStack.EnableLogging(true);
5156 graphics.mCommandBufferCallStack.EnableLogging(true);
5157 gl.mBufferTrace.EnableLogging(true);
5158 gl.mBufferTrace.Enable(true);
5160 gl.mSetUniformTrace.EnableLogging(true);
5161 gl.mSetUniformTrace.Enable(true);
5163 Geometry geometry = CreateQuadGeometry();
5164 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
5165 Renderer renderer = Renderer::New(geometry, shader);
5166 Actor actor = Actor::New();
5167 actor.AddRenderer(renderer);
5168 actor[Actor::Property::SIZE] = Vector2(120, 120);
5169 application.GetScene().Add(actor);
5171 std::ostringstream oss;
5172 struct UniformIndexPair
5174 Property::Index index;
5176 UniformIndexPair(Property::Index index, std::string name)
5178 name(std::move(name))
5182 std::vector<UniformIndexPair> uniformIndices;
5183 for(int i = 0; i < 10; ++i)
5185 Property::Index index;
5186 oss << "uArray[" << i << "]";
5187 auto value = float(i);
5188 index = renderer.RegisterProperty(oss.str(), value);
5189 uniformIndices.emplace_back(index, oss.str());
5194 // Cause overwrite, index 10 and uToOverflow should share same memory
5195 [[maybe_unused]] auto badArrayIndex = renderer.RegisterProperty("uArray[10]", 0.0f);
5197 application.GetScene().Add(actor);
5198 application.SendNotification();
5199 application.Render(0);
5201 Vector4 uniformColor = Vector4::ZERO;
5202 gl.GetUniformValue("uColor", uniformColor);
5203 tet_printf("uColor value %f, %f, %f, %f\n",
5209 // the r component of uColor uniform must not be changed.
5210 // if r is 0.0f then test fails as the array stomped on the uniform's memory.
5211 DALI_TEST_EQUALS((uniformColor.r != 0.0f), true, TEST_LOCATION);