2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/common/capabilities.h>
21 #include <dali/devel-api/common/stage.h>
22 #include <dali/devel-api/rendering/renderer-devel.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/dali-core.h>
29 #include <dali-test-suite-utils.h>
30 #include <mesh-builder.h>
31 #include <test-trace-call-stack.h>
35 namespace // unnamed namespace
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
46 * @brief Get GL stencil test enumeration value as a string.
47 * @return The string representation of the value of GL_STENCIL_TEST
49 std::string GetStencilTestString(void)
51 std::stringstream stream;
52 stream << GL_STENCIL_TEST;
57 * @brief Get GL depth test enumeration value as a string.
58 * @return The string representation of the value of GL_DEPTH_TEST
60 std::string GetDepthTestString(void)
62 std::stringstream stream;
63 stream << GL_DEPTH_TEST;
67 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
69 glEnableDisableStack.Reset();
70 glStencilFunctionStack.Reset();
71 application.SendNotification();
75 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
80 Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
82 Texture texture = Texture::New(type, format, width, height);
84 int bufferSize = width * height * Pixel::GetBytesPerPixel(format);
85 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
86 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
87 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
91 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
93 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
94 TextureSet textureSet0 = CreateTextureSet(image0);
95 Renderer renderer0 = Renderer::New(geometry, shader);
96 renderer0.SetTextures(textureSet0);
97 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
98 actor.AddRenderer(renderer0);
102 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
104 Actor actor = Actor::New();
105 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
106 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
107 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
108 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
110 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
111 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
116 } // unnamed namespace
118 void renderer_test_startup(void)
120 test_return_value = TET_UNDEF;
123 void renderer_test_cleanup(void)
125 test_return_value = TET_PASS;
128 int UtcDaliRendererNew01(void)
130 TestApplication application;
132 Geometry geometry = CreateQuadGeometry();
133 Shader shader = CreateShader();
134 Renderer renderer = Renderer::New(geometry, shader);
136 DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
140 int UtcDaliRendererNew02(void)
142 TestApplication application;
144 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
148 int UtcDaliRendererCopyConstructor(void)
150 TestApplication application;
152 Geometry geometry = CreateQuadGeometry();
153 Shader shader = CreateShader();
154 Renderer renderer = Renderer::New(geometry, shader);
156 Renderer rendererCopy(renderer);
157 DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
162 int UtcDaliRendererAssignmentOperator(void)
164 TestApplication application;
166 Geometry geometry = CreateQuadGeometry();
167 Shader shader = CreateShader();
168 Renderer renderer = Renderer::New(geometry, shader);
171 DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
173 renderer2 = renderer;
174 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
178 int UtcDaliRendererMoveConstructor(void)
180 TestApplication application;
182 Geometry geometry = CreateQuadGeometry();
183 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
184 Renderer renderer = Renderer::New(geometry, shader);
185 DALI_TEST_CHECK(renderer);
186 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
189 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
190 application.SendNotification();
191 application.Render();
192 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
194 Renderer move = std::move(renderer);
195 DALI_TEST_CHECK(move);
196 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
197 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
198 DALI_TEST_CHECK(!renderer);
203 int UtcDaliRendererMoveAssignment(void)
205 TestApplication application;
207 Geometry geometry = CreateQuadGeometry();
208 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
209 Renderer renderer = Renderer::New(geometry, shader);
210 DALI_TEST_CHECK(renderer);
211 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
212 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
214 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
215 application.SendNotification();
216 application.Render();
217 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
220 move = std::move(renderer);
221 DALI_TEST_CHECK(move);
222 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
223 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
224 DALI_TEST_CHECK(!renderer);
229 int UtcDaliRendererDownCast01(void)
231 TestApplication application;
233 Geometry geometry = CreateQuadGeometry();
234 Shader shader = CreateShader();
235 Renderer renderer = Renderer::New(geometry, shader);
237 BaseHandle handle(renderer);
238 Renderer renderer2 = Renderer::DownCast(handle);
239 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
243 int UtcDaliRendererDownCast02(void)
245 TestApplication application;
247 Handle handle = Handle::New(); // Create a custom object
248 Renderer renderer = Renderer::DownCast(handle);
249 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
253 // using a template to auto deduce the parameter types
254 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
255 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
257 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
258 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
259 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
260 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
261 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
262 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
265 int UtcDaliRendererDefaultProperties(void)
267 TestApplication application;
268 /* from renderer-impl.cpp
269 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
270 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
271 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
272 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
273 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
274 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
275 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
276 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
277 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
278 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
279 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
280 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
281 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
282 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
283 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
284 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
285 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
286 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
287 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
288 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
289 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
290 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
291 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
292 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
293 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
294 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
295 DALI_PROPERTY( "blendEquation", INTEGER, true, false, false, Dali::DevelRenderer::Property::BLEND_EQUATION )
298 Geometry geometry = CreateQuadGeometry();
299 Shader shader = CreateShader();
300 Renderer renderer = Renderer::New(geometry, shader);
301 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27, TEST_LOCATION);
303 TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
304 TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
305 TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
306 TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
307 TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
308 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
309 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
310 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
311 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
312 TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
313 TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
314 TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
315 TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
316 TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
317 TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
318 TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
319 TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
320 TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
321 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
322 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
323 TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
324 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
325 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
326 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
327 TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
328 TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
329 TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
334 int UtcDaliRendererSetGetGeometry(void)
336 TestApplication application;
337 tet_infoline("Test SetGeometry, GetGeometry");
339 Geometry geometry1 = CreateQuadGeometry();
340 Geometry geometry2 = CreateQuadGeometry();
342 Shader shader = CreateShader();
343 Renderer renderer = Renderer::New(geometry1, shader);
344 Actor actor = Actor::New();
345 actor.AddRenderer(renderer);
346 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
347 application.GetScene().Add(actor);
349 application.SendNotification();
350 application.Render(0);
351 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
353 // Set geometry2 to the renderer
354 renderer.SetGeometry(geometry2);
356 application.SendNotification();
357 application.Render(0);
358 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
363 int UtcDaliRendererSetGetShader(void)
365 TestApplication application;
366 tet_infoline("Test SetShader, GetShader");
368 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
369 glAbstraction.EnableCullFaceCallTrace(true);
371 Shader shader1 = CreateShader();
372 shader1.RegisterProperty("uFadeColor", Color::RED);
374 Shader shader2 = CreateShader();
375 shader2.RegisterProperty("uFadeColor", Color::GREEN);
377 Geometry geometry = CreateQuadGeometry();
378 Renderer renderer = Renderer::New(geometry, shader1);
379 Actor actor = Actor::New();
380 actor.AddRenderer(renderer);
381 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
382 application.GetScene().Add(actor);
384 TestGlAbstraction& gl = application.GetGlAbstraction();
385 application.SendNotification();
386 application.Render(0);
388 // Expect that the first shaders's fade color property is accessed
389 Vector4 actualValue(Vector4::ZERO);
390 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
391 DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
393 DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
395 // set the second shader to the renderer
396 renderer.SetShader(shader2);
398 application.SendNotification();
399 application.Render(0);
401 // Expect that the second shader's fade color property is accessed
402 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
403 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
405 DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
410 int UtcDaliRendererSetGetDepthIndex(void)
412 TestApplication application;
414 tet_infoline("Test SetDepthIndex, GetDepthIndex");
416 Shader shader = CreateShader();
417 Geometry geometry = CreateQuadGeometry();
418 Renderer renderer = Renderer::New(geometry, shader);
419 Actor actor = Actor::New();
420 actor.AddRenderer(renderer);
421 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
422 application.GetScene().Add(actor);
424 application.SendNotification();
425 application.Render(0);
426 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
428 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
430 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
431 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
433 application.SendNotification();
434 application.Render(0);
435 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
437 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
439 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
440 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
442 application.SendNotification();
443 application.Render(0);
444 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
449 int UtcDaliRendererSetGetFaceCullingMode(void)
451 TestApplication application;
453 tet_infoline("Test SetFaceCullingMode(cullingMode)");
454 Geometry geometry = CreateQuadGeometry();
455 Shader shader = CreateShader();
456 Renderer renderer = Renderer::New(geometry, shader);
458 Actor actor = Actor::New();
459 actor.AddRenderer(renderer);
460 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
461 application.GetScene().Add(actor);
463 // By default, none of the faces should be culled
464 unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
465 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
467 TestGlAbstraction& gl = application.GetGlAbstraction();
468 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
469 gl.EnableCullFaceCallTrace(true);
472 cullFaceStack.Reset();
473 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
474 application.SendNotification();
475 application.Render();
477 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
479 std::ostringstream cullModeString;
480 cullModeString << GL_FRONT_AND_BACK;
482 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
483 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
484 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
488 cullFaceStack.Reset();
489 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
490 application.SendNotification();
491 application.Render();
493 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
495 std::ostringstream cullModeString;
496 cullModeString << GL_BACK;
498 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
499 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
500 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
504 cullFaceStack.Reset();
505 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
506 application.SendNotification();
507 application.Render();
509 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
511 std::ostringstream cullModeString;
512 cullModeString << GL_FRONT;
514 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
515 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
516 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
520 cullFaceStack.Reset();
521 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
522 application.SendNotification();
523 application.Render();
525 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
526 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
527 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
533 int UtcDaliRendererBlendOptions01(void)
535 TestApplication application;
537 tet_infoline("Test BLEND_FACTOR properties ");
539 Geometry geometry = CreateQuadGeometry();
540 Shader shader = CreateShader();
541 Renderer renderer = Renderer::New(geometry, shader);
543 Actor actor = Actor::New();
544 // set a transparent actor color so that blending is enabled
545 actor.SetProperty(Actor::Property::OPACITY, 0.5f);
546 actor.AddRenderer(renderer);
547 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
548 application.GetScene().Add(actor);
550 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
551 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
552 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
553 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
555 // Test that Set was successful:
556 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
557 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
558 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
559 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
561 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
562 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
563 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
564 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
566 application.SendNotification();
567 application.Render();
569 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
571 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
572 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
573 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
574 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
579 int UtcDaliRendererBlendOptions02(void)
581 TestApplication application;
583 tet_infoline("Test BLEND_FACTOR properties ");
585 Geometry geometry = CreateQuadGeometry();
586 Shader shader = CreateShader();
587 Renderer renderer = Renderer::New(geometry, shader);
589 Actor actor = Actor::New();
590 actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
591 actor.AddRenderer(renderer);
592 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
593 application.GetScene().Add(actor);
595 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
596 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
597 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
598 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
600 // Test that Set was successful:
602 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
603 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
604 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
605 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
607 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
608 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
609 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
610 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
613 application.SendNotification();
614 application.Render();
616 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
617 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
618 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
619 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
620 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
625 int UtcDaliRendererBlendOptions03(void)
627 TestApplication application;
629 tet_infoline("Test GetBlendEquation() defaults ");
631 Geometry geometry = CreateQuadGeometry();
632 Shader shader = CreateShader();
633 Renderer renderer = Renderer::New(geometry, shader);
635 Actor actor = Actor::New();
636 actor.AddRenderer(renderer);
637 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
638 application.GetScene().Add(actor);
640 // Test the defaults as documented in blending.h
641 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
642 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
644 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
645 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
650 int UtcDaliRendererBlendOptions04(void)
652 TestApplication application;
654 tet_infoline("Test SetBlendEquation() ");
656 Geometry geometry = CreateQuadGeometry();
657 Shader shader = CreateShader();
658 Renderer renderer = Renderer::New(geometry, shader);
660 Actor actor = Actor::New();
661 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
662 actor.AddRenderer(renderer);
663 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
664 application.GetScene().Add(actor);
666 // Test the single blending equation setting
668 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
669 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
670 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
673 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
674 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
676 // Test that Set was successful
678 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
679 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
680 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
681 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
684 // Render & check GL commands
685 application.SendNotification();
686 application.Render();
688 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
689 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
690 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
695 int UtcDaliRendererBlendOptions05(void)
697 TestApplication application;
699 tet_infoline("Test SetAdvancedBlendEquation ");
701 Geometry geometry = CreateQuadGeometry();
702 Shader shader = CreateShader();
703 Renderer renderer = Renderer::New(geometry, shader);
705 Actor actor = Actor::New();
706 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
708 actor.AddRenderer(renderer);
709 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
710 application.GetScene().Add(actor);
712 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
714 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX);
715 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
716 DALI_TEST_EQUALS((int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION);
719 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
721 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
722 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
723 int equation = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
725 DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION);
726 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), true, TEST_LOCATION);
728 application.SendNotification();
729 application.Render();
732 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
733 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY))
735 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD);
736 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
737 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN);
738 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY);
739 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_RGB);
740 int equationAlpha = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_ALPHA);
742 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION);
743 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION);
744 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), false, TEST_LOCATION);
746 application.SendNotification();
747 application.Render();
750 tet_infoline("Error Checking\n");
751 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY) &&
752 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
753 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::OVERLAY) &&
754 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DARKEN) &&
755 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LIGHTEN) &&
756 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_DODGE) &&
757 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_BURN) &&
758 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HARD_LIGHT) &&
759 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SOFT_LIGHT) &&
760 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DIFFERENCE) &&
761 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::EXCLUSION) &&
762 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HUE) &&
763 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SATURATION) &&
764 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR) &&
765 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LUMINOSITY))
767 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
768 DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), 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);
773 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
774 DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
776 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
777 DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
779 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
780 DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
782 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
783 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
785 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
786 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
788 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
789 DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
791 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
792 DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
794 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
795 DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
797 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
798 DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
800 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
801 DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
803 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
804 DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
806 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
807 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
809 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
810 DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
816 int UtcDaliRendererSetBlendMode01(void)
818 TestApplication application;
820 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
822 Geometry geometry = CreateQuadGeometry();
823 Shader shader = CreateShader();
824 Renderer renderer = Renderer::New(geometry, shader);
826 Actor actor = Actor::New();
827 actor.SetProperty(Actor::Property::OPACITY, 0.98f);
828 actor.AddRenderer(renderer);
829 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
830 application.GetScene().Add(actor);
832 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
834 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
835 glAbstraction.EnableEnableDisableCallTrace(true);
837 application.SendNotification();
838 application.Render();
840 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
841 std::ostringstream blendStr;
842 blendStr << GL_BLEND;
843 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
848 int UtcDaliRendererSetBlendMode01b(void)
850 TestApplication application;
852 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
854 Geometry geometry = CreateQuadGeometry();
855 Shader shader = CreateShader();
856 Renderer renderer = Renderer::New(geometry, shader);
858 Actor actor = Actor::New();
859 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
860 actor.AddRenderer(renderer);
861 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
862 application.GetScene().Add(actor);
864 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
866 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
867 glAbstraction.EnableEnableDisableCallTrace(true);
868 glAbstraction.EnableDrawCallTrace(true);
870 application.SendNotification();
871 application.Render();
873 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
874 std::ostringstream blendStr;
875 blendStr << GL_BLEND;
876 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
878 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
883 int UtcDaliRendererSetBlendMode02(void)
885 TestApplication application;
887 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
889 Geometry geometry = CreateQuadGeometry();
890 Shader shader = CreateShader();
891 Renderer renderer = Renderer::New(geometry, shader);
893 Actor actor = Actor::New();
894 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
895 actor.AddRenderer(renderer);
896 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
897 application.GetScene().Add(actor);
899 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
901 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
902 glAbstraction.EnableEnableDisableCallTrace(true);
904 application.SendNotification();
905 application.Render();
907 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
908 std::ostringstream blendStr;
909 blendStr << GL_BLEND;
910 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
915 int UtcDaliRendererSetBlendMode03(void)
917 TestApplication application;
919 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
921 Geometry geometry = CreateQuadGeometry();
922 Shader shader = CreateShader();
923 Renderer renderer = Renderer::New(geometry, shader);
925 Actor actor = Actor::New();
926 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
927 actor.AddRenderer(renderer);
928 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
929 application.GetScene().Add(actor);
931 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
933 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
934 glAbstraction.EnableEnableDisableCallTrace(true);
936 application.SendNotification();
937 application.Render();
939 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
940 std::ostringstream blendStr;
941 blendStr << GL_BLEND;
942 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
947 int UtcDaliRendererSetBlendMode04(void)
949 TestApplication application;
951 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
953 Geometry geometry = CreateQuadGeometry();
954 Shader shader = CreateShader();
955 Renderer renderer = Renderer::New(geometry, shader);
957 Actor actor = Actor::New();
958 actor.AddRenderer(renderer);
959 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
960 application.GetScene().Add(actor);
962 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
964 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
965 glAbstraction.EnableEnableDisableCallTrace(true);
967 application.SendNotification();
968 application.Render();
970 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
971 std::ostringstream blendStr;
972 blendStr << GL_BLEND;
973 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
978 int UtcDaliRendererSetBlendMode04b(void)
980 TestApplication application;
982 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
984 Geometry geometry = CreateQuadGeometry();
985 Shader shader = CreateShader();
986 Renderer renderer = Renderer::New(geometry, shader);
988 Actor actor = Actor::New();
989 actor.AddRenderer(renderer);
990 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
991 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
992 application.GetScene().Add(actor);
994 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
996 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
997 glAbstraction.EnableEnableDisableCallTrace(true);
999 application.SendNotification();
1000 application.Render();
1002 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1003 std::ostringstream blendStr;
1004 blendStr << GL_BLEND;
1005 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1010 int UtcDaliRendererSetBlendMode04c(void)
1012 TestApplication application;
1014 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1016 Geometry geometry = CreateQuadGeometry();
1017 Shader shader = CreateShader();
1018 Renderer renderer = Renderer::New(geometry, shader);
1020 Actor actor = Actor::New();
1021 actor.AddRenderer(renderer);
1022 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1023 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1024 application.GetScene().Add(actor);
1026 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1028 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1029 glAbstraction.EnableEnableDisableCallTrace(true);
1031 application.SendNotification();
1032 application.Render();
1034 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1035 std::ostringstream blendStr;
1036 blendStr << GL_BLEND;
1037 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1042 int UtcDaliRendererSetBlendMode05(void)
1044 TestApplication application;
1046 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1048 Geometry geometry = CreateQuadGeometry();
1049 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1051 Shader shader = CreateShader();
1052 TextureSet textureSet = CreateTextureSet(image);
1053 Renderer renderer = Renderer::New(geometry, shader);
1054 renderer.SetTextures(textureSet);
1056 Actor actor = Actor::New();
1057 actor.AddRenderer(renderer);
1058 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1059 application.GetScene().Add(actor);
1061 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1063 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1064 glAbstraction.EnableEnableDisableCallTrace(true);
1066 application.SendNotification();
1067 application.Render();
1069 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1070 std::ostringstream blendStr;
1071 blendStr << GL_BLEND;
1072 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1077 int UtcDaliRendererSetBlendMode06(void)
1079 TestApplication application;
1080 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");
1082 Geometry geometry = CreateQuadGeometry();
1083 Shader shader = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1085 Renderer renderer = Renderer::New(geometry, shader);
1087 Actor actor = Actor::New();
1088 actor.AddRenderer(renderer);
1089 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1090 application.GetScene().Add(actor);
1092 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1094 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1095 glAbstraction.EnableEnableDisableCallTrace(true);
1097 application.SendNotification();
1098 application.Render();
1100 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1101 std::ostringstream blendStr;
1102 blendStr << GL_BLEND;
1103 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1108 int UtcDaliRendererSetBlendMode07(void)
1110 TestApplication application;
1111 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");
1113 Geometry geometry = CreateQuadGeometry();
1114 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1116 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1117 TextureSet textureSet = CreateTextureSet(image);
1118 Renderer renderer = Renderer::New(geometry, shader);
1119 renderer.SetTextures(textureSet);
1121 Actor actor = Actor::New();
1122 actor.AddRenderer(renderer);
1123 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1124 application.GetScene().Add(actor);
1126 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1128 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1129 glAbstraction.EnableEnableDisableCallTrace(true);
1131 application.SendNotification();
1132 application.Render();
1134 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1135 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", "GL_BLEND"));
1140 int UtcDaliRendererSetBlendMode08(void)
1142 TestApplication application;
1144 tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1146 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1148 Geometry geometry = CreateQuadGeometry();
1149 Shader shader = CreateShader();
1150 Renderer renderer = Renderer::New(geometry, shader);
1152 Actor actor = Actor::New();
1153 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1154 actor.AddRenderer(renderer);
1155 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1156 application.GetScene().Add(actor);
1158 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1159 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1160 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1162 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1163 glAbstraction.EnableEnableDisableCallTrace(true);
1165 application.SendNotification();
1166 application.Render();
1168 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1169 std::ostringstream blendStr;
1170 blendStr << GL_BLEND;
1171 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1177 int UtcDaliRendererSetBlendMode08b(void)
1179 TestApplication application;
1181 tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1183 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1185 Geometry geometry = CreateQuadGeometry();
1186 Shader shader = CreateShader();
1187 Renderer renderer = Renderer::New(geometry, shader);
1189 Actor actor = Actor::New();
1190 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1191 actor.AddRenderer(renderer);
1192 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1193 application.GetScene().Add(actor);
1195 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1196 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1197 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1199 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1200 glAbstraction.EnableEnableDisableCallTrace(true);
1202 application.SendNotification();
1203 application.Render();
1205 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1206 std::ostringstream blendStr;
1207 blendStr << GL_BLEND;
1208 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1214 int UtcDaliRendererGetBlendMode(void)
1216 TestApplication application;
1218 tet_infoline("Test GetBlendMode()");
1220 Geometry geometry = CreateQuadGeometry();
1221 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1222 Renderer renderer = Renderer::New(geometry, shader);
1225 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1226 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1229 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1230 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1231 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1234 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1235 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1236 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1241 int UtcDaliRendererSetBlendColor(void)
1243 TestApplication application;
1245 tet_infoline("Test SetBlendColor(color)");
1247 Geometry geometry = CreateQuadGeometry();
1248 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1249 TextureSet textureSet = TextureSet::New();
1250 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1251 textureSet.SetTexture(0u, image);
1252 Renderer renderer = Renderer::New(geometry, shader);
1253 renderer.SetTextures(textureSet);
1255 Actor actor = Actor::New();
1256 actor.AddRenderer(renderer);
1257 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1258 application.GetScene().Add(actor);
1260 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1262 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1264 application.SendNotification();
1265 application.Render();
1267 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1268 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1269 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1271 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1273 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1274 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1276 application.SendNotification();
1277 application.Render();
1279 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1280 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1282 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1283 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1284 application.SendNotification();
1285 application.Render();
1286 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1291 int UtcDaliRendererGetBlendColor(void)
1293 TestApplication application;
1295 tet_infoline("Test GetBlendColor()");
1297 Geometry geometry = CreateQuadGeometry();
1298 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1299 Renderer renderer = Renderer::New(geometry, shader);
1301 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1303 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1304 application.SendNotification();
1305 application.Render();
1306 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1308 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1309 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1310 application.SendNotification();
1311 application.Render();
1312 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1317 int UtcDaliRendererPreMultipledAlpha(void)
1319 TestApplication application;
1321 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1323 Geometry geometry = CreateQuadGeometry();
1324 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1325 Renderer renderer = Renderer::New(geometry, shader);
1327 Actor actor = Actor::New();
1328 actor.AddRenderer(renderer);
1329 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1330 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1331 application.GetScene().Add(actor);
1333 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1334 bool preMultipliedAlpha;
1335 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1336 DALI_TEST_CHECK(!preMultipliedAlpha);
1338 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1339 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1340 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1341 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1343 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1344 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1345 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1346 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1348 application.SendNotification();
1349 application.Render();
1351 Vector4 actualValue(Vector4::ZERO);
1352 TestGlAbstraction& gl = application.GetGlAbstraction();
1353 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1354 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1356 // Enable pre-multiplied alpha
1357 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1359 application.SendNotification();
1360 application.Render();
1362 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1363 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1364 DALI_TEST_CHECK(preMultipliedAlpha);
1366 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1367 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1368 DALI_TEST_CHECK(preMultipliedAlpha);
1370 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1371 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1372 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1373 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1375 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1376 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1377 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1378 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1380 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1381 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1383 // Disable pre-multiplied alpha again
1384 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1386 application.SendNotification();
1387 application.Render();
1389 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1390 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1391 DALI_TEST_CHECK(!preMultipliedAlpha);
1393 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1394 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1395 DALI_TEST_CHECK(!preMultipliedAlpha);
1397 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1398 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1399 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1400 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1402 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1403 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1404 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1405 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1407 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1408 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1413 int UtcDaliRendererConstraint01(void)
1415 TestApplication application;
1417 tet_infoline("Test that a non-uniform renderer property can be constrained");
1419 Shader shader = Shader::New("VertexSource", "FragmentSource");
1420 Geometry geometry = CreateQuadGeometry();
1421 Renderer renderer = Renderer::New(geometry, shader);
1423 Actor actor = Actor::New();
1424 actor.AddRenderer(renderer);
1425 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1426 application.GetScene().Add(actor);
1428 Vector4 initialColor = Color::WHITE;
1429 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1431 application.SendNotification();
1432 application.Render(0);
1433 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1436 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1438 application.SendNotification();
1439 application.Render(0);
1441 // Expect no blue component in either buffer - yellow
1442 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1443 application.Render(0);
1444 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1446 renderer.RemoveConstraints();
1447 renderer.SetProperty(colorIndex, Color::WHITE);
1448 application.SendNotification();
1449 application.Render(0);
1450 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1455 int UtcDaliRendererConstraint02(void)
1457 TestApplication application;
1459 tet_infoline("Test that a uniform map renderer property can be constrained");
1461 Shader shader = Shader::New("VertexSource", "FragmentSource");
1462 Geometry geometry = CreateQuadGeometry();
1463 Renderer renderer = Renderer::New(geometry, shader);
1465 Actor actor = Actor::New();
1466 actor.AddRenderer(renderer);
1467 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1468 application.GetScene().Add(actor);
1469 application.SendNotification();
1470 application.Render(0);
1472 Vector4 initialColor = Color::WHITE;
1473 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1475 TestGlAbstraction& gl = application.GetGlAbstraction();
1477 application.SendNotification();
1478 application.Render(0);
1480 Vector4 actualValue(Vector4::ZERO);
1481 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1482 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1485 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1487 application.SendNotification();
1488 application.Render(0);
1490 // Expect no blue component in either buffer - yellow
1491 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1492 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1494 application.Render(0);
1495 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1496 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1498 renderer.RemoveConstraints();
1499 renderer.SetProperty(colorIndex, Color::WHITE);
1500 application.SendNotification();
1501 application.Render(0);
1503 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1504 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1509 int UtcDaliRendererAnimatedProperty01(void)
1511 TestApplication application;
1513 tet_infoline("Test that a non-uniform renderer property can be animated");
1515 Shader shader = Shader::New("VertexSource", "FragmentSource");
1516 Geometry geometry = CreateQuadGeometry();
1517 Renderer renderer = Renderer::New(geometry, shader);
1519 Actor actor = Actor::New();
1520 actor.AddRenderer(renderer);
1521 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1522 application.GetScene().Add(actor);
1524 Vector4 initialColor = Color::WHITE;
1525 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1527 application.SendNotification();
1528 application.Render(0);
1529 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1531 Animation animation = Animation::New(1.0f);
1532 KeyFrames keyFrames = KeyFrames::New();
1533 keyFrames.Add(0.0f, initialColor);
1534 keyFrames.Add(1.0f, Color::TRANSPARENT);
1535 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1538 application.SendNotification();
1539 application.Render(500);
1541 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1543 application.Render(500);
1545 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1550 int UtcDaliRendererAnimatedProperty02(void)
1552 TestApplication application;
1554 tet_infoline("Test that a uniform map renderer property can be animated");
1556 Shader shader = Shader::New("VertexSource", "FragmentSource");
1557 Geometry geometry = CreateQuadGeometry();
1558 Renderer renderer = Renderer::New(geometry, shader);
1560 Actor actor = Actor::New();
1561 actor.AddRenderer(renderer);
1562 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1563 application.GetScene().Add(actor);
1564 application.SendNotification();
1565 application.Render(0);
1567 Vector4 initialColor = Color::WHITE;
1568 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1570 TestGlAbstraction& gl = application.GetGlAbstraction();
1572 application.SendNotification();
1573 application.Render(0);
1575 Vector4 actualValue(Vector4::ZERO);
1576 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1577 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1579 Animation animation = Animation::New(1.0f);
1580 KeyFrames keyFrames = KeyFrames::New();
1581 keyFrames.Add(0.0f, initialColor);
1582 keyFrames.Add(1.0f, Color::TRANSPARENT);
1583 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1586 application.SendNotification();
1587 application.Render(500);
1589 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1590 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1592 application.Render(500);
1593 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1594 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1599 int UtcDaliRendererUniformMapPrecendence01(void)
1601 TestApplication application;
1603 tet_infoline("Test the uniform map precedence is applied properly");
1605 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1607 Shader shader = Shader::New("VertexSource", "FragmentSource");
1608 TextureSet textureSet = CreateTextureSet(image);
1610 Geometry geometry = CreateQuadGeometry();
1611 Renderer renderer = Renderer::New(geometry, shader);
1612 renderer.SetTextures(textureSet);
1614 Actor actor = Actor::New();
1615 actor.AddRenderer(renderer);
1616 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1617 application.GetScene().Add(actor);
1618 application.SendNotification();
1619 application.Render(0);
1621 renderer.RegisterProperty("uFadeColor", Color::RED);
1622 actor.RegisterProperty("uFadeColor", Color::GREEN);
1623 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1625 TestGlAbstraction& gl = application.GetGlAbstraction();
1627 application.SendNotification();
1628 application.Render(0);
1630 // Expect that the actor's fade color property is accessed
1631 Vector4 actualValue(Vector4::ZERO);
1632 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1633 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1635 // Animate shader's fade color property. Should be no change to uniform
1636 Animation animation = Animation::New(1.0f);
1637 KeyFrames keyFrames = KeyFrames::New();
1638 keyFrames.Add(0.0f, Color::WHITE);
1639 keyFrames.Add(1.0f, Color::TRANSPARENT);
1640 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1643 application.SendNotification();
1644 application.Render(500);
1646 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1647 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1649 application.Render(500);
1650 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1651 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1656 int UtcDaliRendererUniformMapPrecendence02(void)
1658 TestApplication application;
1660 tet_infoline("Test the uniform map precedence is applied properly");
1662 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1664 Shader shader = Shader::New("VertexSource", "FragmentSource");
1665 TextureSet textureSet = CreateTextureSet(image);
1667 Geometry geometry = CreateQuadGeometry();
1668 Renderer renderer = Renderer::New(geometry, shader);
1669 renderer.SetTextures(textureSet);
1671 Actor actor = Actor::New();
1672 actor.AddRenderer(renderer);
1673 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1674 application.GetScene().Add(actor);
1675 application.SendNotification();
1676 application.Render(0);
1678 // Don't add property / uniform map to renderer
1679 actor.RegisterProperty("uFadeColor", Color::GREEN);
1680 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1682 TestGlAbstraction& gl = application.GetGlAbstraction();
1684 application.SendNotification();
1685 application.Render(0);
1687 // Expect that the actor's fade color property is accessed
1688 Vector4 actualValue(Vector4::ZERO);
1689 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1690 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1692 // Animate texture set's fade color property. Should be no change to uniform
1693 Animation animation = Animation::New(1.0f);
1694 KeyFrames keyFrames = KeyFrames::New();
1695 keyFrames.Add(0.0f, Color::WHITE);
1696 keyFrames.Add(1.0f, Color::TRANSPARENT);
1697 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1700 application.SendNotification();
1701 application.Render(500);
1703 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1704 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1706 application.Render(500);
1707 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1708 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1713 int UtcDaliRendererUniformMapPrecendence03(void)
1715 TestApplication application;
1717 tet_infoline("Test the uniform map precedence is applied properly");
1719 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1721 Shader shader = Shader::New("VertexSource", "FragmentSource");
1722 TextureSet textureSet = CreateTextureSet(image);
1724 Geometry geometry = CreateQuadGeometry();
1725 Renderer renderer = Renderer::New(geometry, shader);
1726 renderer.SetTextures(textureSet);
1728 Actor actor = Actor::New();
1729 actor.AddRenderer(renderer);
1730 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1731 application.GetScene().Add(actor);
1732 application.SendNotification();
1733 application.Render(0);
1735 // Don't add property / uniform map to renderer or actor
1736 shader.RegisterProperty("uFadeColor", Color::BLACK);
1738 TestGlAbstraction& gl = application.GetGlAbstraction();
1740 application.SendNotification();
1741 application.Render(0);
1743 // Expect that the shader's fade color property is accessed
1744 Vector4 actualValue(Vector4::ZERO);
1745 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1746 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1751 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1753 TestApplication application;
1755 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1757 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1759 Shader shader = Shader::New("VertexSource", "FragmentSource");
1760 TextureSet textureSet = CreateTextureSet(image);
1762 Geometry geometry = CreateQuadGeometry();
1763 Renderer renderer = Renderer::New(geometry, shader);
1764 renderer.SetTextures(textureSet);
1766 Actor actor = Actor::New();
1767 actor.AddRenderer(renderer);
1768 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1769 application.GetScene().Add(actor);
1770 application.SendNotification();
1771 application.Render(0);
1773 renderer.RegisterProperty("uUniform1", Color::RED);
1774 actor.RegisterProperty("uUniform2", Color::GREEN);
1775 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1777 TestGlAbstraction& gl = application.GetGlAbstraction();
1779 application.SendNotification();
1780 application.Render(0);
1782 // Expect that each of the object's uniforms are set
1783 Vector4 uniform1Value(Vector4::ZERO);
1784 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1785 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1787 Vector4 uniform2Value(Vector4::ZERO);
1788 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1789 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1791 Vector4 uniform3Value(Vector4::ZERO);
1792 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1793 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1798 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1800 TestApplication application;
1802 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1804 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1806 Shader shader = Shader::New("VertexSource", "FragmentSource");
1807 TextureSet textureSet = CreateTextureSet(image);
1809 Geometry geometry = CreateQuadGeometry();
1810 Renderer renderer = Renderer::New(geometry, shader);
1811 renderer.SetTextures(textureSet);
1813 Actor actor = Actor::New();
1814 actor.AddRenderer(renderer);
1815 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1816 application.GetScene().Add(actor);
1817 application.SendNotification();
1818 application.Render(0);
1820 Property::Value value1(Color::RED);
1821 renderer.RegisterProperty("uFadeColor", value1);
1823 Property::Value value2(1.0f);
1824 actor.RegisterProperty("uFadeProgress", value2);
1826 Property::Value value3(Matrix3::IDENTITY);
1827 shader.RegisterProperty("uANormalMatrix", value3);
1829 TestGlAbstraction& gl = application.GetGlAbstraction();
1831 application.SendNotification();
1832 application.Render(0);
1834 // Expect that each of the object's uniforms are set
1835 Vector4 uniform1Value(Vector4::ZERO);
1836 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1837 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1839 float uniform2Value(0.0f);
1840 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1841 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1843 Matrix3 uniform3Value;
1844 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1845 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1850 int UtcDaliRendererRenderOrder2DLayer(void)
1852 TestApplication application;
1853 tet_infoline("Test the rendering order in a 2D layer is correct");
1855 Shader shader = Shader::New("VertexSource", "FragmentSource");
1856 Geometry geometry = CreateQuadGeometry();
1858 Actor root = application.GetScene().GetRootLayer();
1860 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1861 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1863 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1864 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1866 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1867 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1869 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1870 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1872 application.SendNotification();
1873 application.Render(0);
1876 * Create the following hierarchy:
1889 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1894 application.SendNotification();
1895 application.Render(0);
1897 TestGlAbstraction& gl = application.GetGlAbstraction();
1898 gl.GetTextureTrace().Reset();
1899 gl.EnableTextureCallTrace(true);
1900 application.SendNotification();
1901 application.Render(0);
1903 int textureBindIndex[4];
1904 for(unsigned int i(0); i < 4; ++i)
1906 std::stringstream params;
1907 params << GL_TEXTURE_2D << ", " << i + 1;
1908 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1911 //Check that actor1 has been rendered after actor2
1912 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1914 //Check that actor0 has been rendered after actor1
1915 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1917 //Check that actor3 has been rendered after actor0
1918 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1923 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1925 TestApplication application;
1926 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1929 * Creates the following hierarchy:
1931 * actor0------------------------>actor1
1935 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1937 * renderer0 has depth index 2
1938 * renderer1 has depth index 0
1939 * renderer2 has depth index 1
1941 * renderer3 has depth index 1
1942 * renderer4 has depth index 0
1943 * renderer5 has depth index -1
1945 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1948 Shader shader = Shader::New("VertexSource", "FragmentSource");
1949 Geometry geometry = CreateQuadGeometry();
1951 Actor root = application.GetScene().GetRootLayer();
1953 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1954 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
1955 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1956 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1957 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1958 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1959 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1960 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1962 application.SendNotification();
1963 application.Render(0);
1965 TestGlAbstraction& gl = application.GetGlAbstraction();
1966 gl.GetTextureTrace().Reset();
1967 gl.EnableTextureCallTrace(true);
1968 application.SendNotification();
1969 application.Render(0);
1971 int textureBindIndex[6];
1972 for(unsigned int i(0); i < 6; ++i)
1974 std::stringstream params;
1975 params << GL_TEXTURE_2D << ", " << i + 1;
1976 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1979 //Check that renderer3 has been rendered after renderer4
1980 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1982 //Check that renderer0 has been rendered after renderer2
1983 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1985 //Check that renderer5 has been rendered after renderer2
1986 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1988 //Check that renderer0 has been rendered after renderer2
1989 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1991 //Check that renderer2 has been rendered after renderer1
1992 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1997 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1999 TestApplication application;
2000 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2003 * Creates the following hierarchy:
2011 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
2015 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
2016 * DI:2 DI:0 | DI:0 DI:1 DI:2
2021 * actor0 has sibling order 1
2022 * actor1 has sibling order 0
2023 * actor2 has sibling order 0
2025 * renderer0 has depth index 2
2026 * renderer1 has depth index 0
2028 * renderer2 has depth index 0
2029 * renderer3 has depth index 1
2030 * renderer4 has depth index 2
2032 * renderer5 has depth index -1
2034 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2037 Shader shader = Shader::New("VertexSource", "FragmentSource");
2038 Geometry geometry = CreateQuadGeometry();
2039 Actor root = application.GetScene().GetRootLayer();
2040 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
2041 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2042 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
2044 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2045 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2046 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2047 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2048 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2049 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2051 application.SendNotification();
2052 application.Render();
2054 TestGlAbstraction& gl = application.GetGlAbstraction();
2055 gl.GetTextureTrace().Reset();
2056 gl.EnableTextureCallTrace(true);
2057 application.SendNotification();
2058 application.Render(0);
2060 int textureBindIndex[6];
2061 for(unsigned int i(0); i < 6; ++i)
2063 std::stringstream params;
2064 params << GL_TEXTURE_2D << ", " << i + 1;
2065 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2068 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2069 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2070 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2071 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2072 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2073 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2075 // Change sibling order of actor1
2076 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2077 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2079 gl.GetTextureTrace().Reset();
2080 application.SendNotification();
2081 application.Render(0);
2083 for(unsigned int i(0); i < 6; ++i)
2085 std::stringstream params;
2086 params << GL_TEXTURE_2D << ", " << i + 1;
2087 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2090 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2091 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2092 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2093 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2094 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2095 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2100 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2102 TestApplication application;
2103 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2105 Shader shader = Shader::New("VertexSource", "FragmentSource");
2106 Geometry geometry = CreateQuadGeometry();
2107 Actor root = application.GetScene().GetRootLayer();
2110 * Create the following hierarchy:
2117 * (Overlay) (Regular actor)
2127 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2130 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2131 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2132 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2134 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2135 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2136 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2138 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2139 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2141 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2142 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2143 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2145 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2146 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2148 application.SendNotification();
2149 application.Render(0);
2156 TestGlAbstraction& gl = application.GetGlAbstraction();
2157 gl.GetTextureTrace().Reset();
2158 gl.EnableTextureCallTrace(true);
2159 application.SendNotification();
2160 application.Render(0);
2162 int textureBindIndex[5];
2163 for(unsigned int i(0); i < 5; ++i)
2165 std::stringstream params;
2166 params << GL_TEXTURE_2D << ", " << i + 1;
2167 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2170 //Check that actor4 has been rendered after actor2
2171 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2173 //Check that actor1 has been rendered after actor4
2174 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2176 //Check that actor0 has been rendered after actor1
2177 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2179 //Check that actor3 has been rendered after actor0
2180 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2185 int UtcDaliRendererSetIndexRange(void)
2189 "attribute vec2 aPosition;\n"
2192 " gl_Position = aPosition;\n"
2197 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2200 TestApplication application;
2201 tet_infoline("Test setting the range of indices to draw");
2203 TestGlAbstraction& gl = application.GetGlAbstraction();
2204 gl.EnableDrawCallTrace(true);
2206 Actor actor = Actor::New();
2207 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2210 Geometry geometry = Geometry::New();
2211 geometry.SetType(Geometry::LINE_LOOP);
2213 // --------------------------------------------------------------------------
2215 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2225 9, // offset = 5, count = 10
2231 1}; // offset = 15, count = 6 // line strip
2233 // --------------------------------------------------------------------------
2242 {Vector2(0.0f, 1.00f)},
2243 {Vector2(0.0f, -1.00f)},
2244 {Vector2(-0.95f, 0.31f)},
2245 {Vector2(0.59f, 0.81f)},
2246 {Vector2(-0.59f, -0.81f)},
2247 {Vector2(-0.95f, -0.31f)},
2248 {Vector2(0.59f, -0.81f)},
2249 {Vector2(0.95f, -0.31f)},
2250 {Vector2(0.95f, 0.31f)},
2251 {Vector2(-0.59f, 0.81f)},
2253 Property::Map vertexFormat;
2254 vertexFormat["aPosition"] = Property::VECTOR2;
2255 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2256 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2258 // --------------------------------------------------------------------------
2259 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2260 geometry.AddVertexBuffer(vertexBuffer);
2263 Shader shader = Shader::New(vertexShader, fragmentShader);
2264 Renderer renderer = Renderer::New(geometry, shader);
2265 actor.AddRenderer(renderer);
2267 Integration::Scene scene = application.GetScene();
2272 // LINE_LOOP, first 0, count 5
2274 renderer.SetIndexRange(0, 5);
2275 application.SendNotification();
2276 application.Render();
2278 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2280 DALI_TEST_CHECK(value.Get(convertedValue));
2281 DALI_TEST_CHECK(convertedValue == 0);
2283 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2284 DALI_TEST_CHECK(value.Get(convertedValue));
2285 DALI_TEST_CHECK(convertedValue == 0);
2287 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2288 DALI_TEST_CHECK(value.Get(convertedValue));
2289 DALI_TEST_CHECK(convertedValue == 5);
2291 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2292 DALI_TEST_CHECK(value.Get(convertedValue));
2293 DALI_TEST_CHECK(convertedValue == 5);
2295 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2296 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2297 DALI_TEST_CHECK(result);
2300 // LINE_LOOP, first 5, count 10
2302 renderer.SetIndexRange(5, 10);
2303 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2304 application.SendNotification();
2305 application.Render();
2306 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2307 DALI_TEST_CHECK(result);
2310 // LINE_STRIP, first 15, count 6
2312 renderer.SetIndexRange(15, 6);
2313 geometry.SetType(Geometry::LINE_STRIP);
2314 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2315 application.SendNotification();
2316 application.Render();
2317 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2318 DALI_TEST_CHECK(result);
2321 // Index out of bounds
2323 renderer.SetIndexRange(15, 30);
2324 geometry.SetType(Geometry::LINE_STRIP);
2325 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2326 application.SendNotification();
2327 application.Render();
2328 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2329 DALI_TEST_CHECK(result);
2332 // drawing whole buffer starting from 15 ( last valid primitive )
2334 renderer.SetIndexRange(15, 0);
2335 geometry.SetType(Geometry::LINE_STRIP);
2336 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2337 application.SendNotification();
2338 application.Render();
2339 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2340 DALI_TEST_CHECK(result);
2346 int UtcDaliRendererSetDepthFunction(void)
2348 TestApplication application;
2350 tet_infoline("Test setting the depth function");
2352 Geometry geometry = CreateQuadGeometry();
2353 Shader shader = CreateShader();
2354 Renderer renderer = Renderer::New(geometry, shader);
2356 Actor actor = Actor::New();
2357 actor.AddRenderer(renderer);
2358 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2359 Integration::Scene scene = application.GetScene();
2360 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2363 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2364 glAbstraction.EnableEnableDisableCallTrace(true);
2365 glAbstraction.EnableDepthFunctionCallTrace(true);
2367 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2368 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2370 std::ostringstream depthTestStr;
2371 depthTestStr << GL_DEPTH_TEST;
2375 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2377 glEnableDisableStack.Reset();
2378 glDepthFunctionStack.Reset();
2379 application.SendNotification();
2380 application.Render();
2382 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2383 std::ostringstream depthFunctionStr;
2384 depthFunctionStr << GL_NEVER;
2385 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2390 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2392 glDepthFunctionStack.Reset();
2393 application.SendNotification();
2394 application.Render();
2396 std::ostringstream depthFunctionStr;
2397 depthFunctionStr << GL_ALWAYS;
2398 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2403 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2405 glDepthFunctionStack.Reset();
2406 application.SendNotification();
2407 application.Render();
2409 std::ostringstream depthFunctionStr;
2410 depthFunctionStr << GL_LESS;
2411 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2416 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2418 glDepthFunctionStack.Reset();
2419 application.SendNotification();
2420 application.Render();
2422 std::ostringstream depthFunctionStr;
2423 depthFunctionStr << GL_GREATER;
2424 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2429 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2431 glDepthFunctionStack.Reset();
2432 application.SendNotification();
2433 application.Render();
2435 std::ostringstream depthFunctionStr;
2436 depthFunctionStr << GL_EQUAL;
2437 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2442 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2444 glDepthFunctionStack.Reset();
2445 application.SendNotification();
2446 application.Render();
2448 std::ostringstream depthFunctionStr;
2449 depthFunctionStr << GL_NOTEQUAL;
2450 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2455 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2457 glDepthFunctionStack.Reset();
2458 application.SendNotification();
2459 application.Render();
2461 std::ostringstream depthFunctionStr;
2462 depthFunctionStr << GL_LEQUAL;
2463 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2468 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2470 glDepthFunctionStack.Reset();
2471 application.SendNotification();
2472 application.Render();
2474 std::ostringstream depthFunctionStr;
2475 depthFunctionStr << GL_GEQUAL;
2476 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2483 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2484 * The checks performed are as follows:
2485 * - Check the initial/default value.
2486 * - Set a different value via enum.
2487 * - Check it was set.
2488 * - Set a different value via string.
2489 * - Check it was set.
2491 template<typename T>
2492 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2494 application.SendNotification();
2495 application.Render();
2497 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2498 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2499 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2500 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2501 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2503 application.SendNotification();
2504 application.Render();
2506 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2507 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2509 renderer.SetProperty(propertyIndex, secondCheckString);
2510 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2511 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2513 application.SendNotification();
2514 application.Render();
2516 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2517 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2520 int UtcDaliRendererEnumProperties(void)
2522 TestApplication application;
2523 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2525 Geometry geometry = CreateQuadGeometry();
2526 Shader shader = CreateShader();
2527 Renderer renderer = Renderer::New(geometry, shader);
2529 Actor actor = Actor::New();
2530 actor.AddRenderer(renderer);
2531 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2532 application.GetScene().Add(actor);
2535 * Here we use a templatized function to perform several checks on each enumeration property.
2536 * @see CheckEnumerationProperty for details of the checks performed.
2539 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2540 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2541 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2542 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2543 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2544 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2545 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2546 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2547 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2548 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2549 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2550 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2551 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2552 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2553 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2554 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2556 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2557 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2559 application.SendNotification();
2560 application.Render();
2561 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2564 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2566 application.SendNotification();
2567 application.Render();
2568 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2574 Renderer RendererTestFixture(TestApplication& application)
2576 Geometry geometry = CreateQuadGeometry();
2577 Shader shader = CreateShader();
2578 Renderer renderer = Renderer::New(geometry, shader);
2580 Actor actor = Actor::New();
2581 actor.AddRenderer(renderer);
2582 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2583 Integration::Scene scene = application.GetScene();
2584 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2590 int UtcDaliRendererSetDepthTestMode(void)
2592 TestApplication application;
2593 tet_infoline("Test setting the DepthTestMode");
2595 Renderer renderer = RendererTestFixture(application);
2596 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2597 glAbstraction.EnableEnableDisableCallTrace(true);
2598 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2600 glEnableDisableStack.Reset();
2601 application.SendNotification();
2602 application.Render();
2604 // Check depth-test is enabled by default.
2605 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2606 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2608 // 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.
2609 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2610 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2612 glEnableDisableStack.Reset();
2613 application.SendNotification();
2614 application.Render();
2616 // Check the depth buffer was disabled.
2617 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2619 // Turn on automatic mode depth-testing.
2620 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2621 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2623 glEnableDisableStack.Reset();
2624 application.SendNotification();
2625 application.Render();
2627 // Check depth-test is now enabled.
2628 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2629 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2631 // Change the layer behavior to LAYER_UI.
2632 // Note this will also disable depth testing for the layer by default, we test this first.
2633 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2635 glEnableDisableStack.Reset();
2636 application.SendNotification();
2637 application.Render();
2639 // Check depth-test is disabled.
2640 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2642 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2643 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2645 glEnableDisableStack.Reset();
2646 application.SendNotification();
2647 application.Render();
2649 // Check depth-test is *still* disabled.
2650 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2655 int UtcDaliRendererSetDepthWriteMode(void)
2657 TestApplication application;
2658 tet_infoline("Test setting the DepthWriteMode");
2660 Renderer renderer = RendererTestFixture(application);
2661 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2663 application.SendNotification();
2664 application.Render();
2666 // Check the default depth-write status first.
2667 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2669 // Turn off depth-writing.
2670 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2672 application.SendNotification();
2673 application.Render();
2675 // Check depth-write is now disabled.
2676 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2678 // Test the AUTO mode for depth-writing.
2679 // As our renderer is opaque, depth-testing should be enabled.
2680 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2682 application.SendNotification();
2683 application.Render();
2685 // Check depth-write is now enabled.
2686 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2688 // Now make the renderer be treated as translucent by enabling blending.
2689 // The AUTO depth-write mode should turn depth-write off in this scenario.
2690 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2692 application.SendNotification();
2693 application.Render();
2695 // Check depth-write is now disabled.
2696 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2701 int UtcDaliRendererCheckStencilDefaults(void)
2703 TestApplication application;
2704 tet_infoline("Test the stencil defaults");
2706 Renderer renderer = RendererTestFixture(application);
2707 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2708 glAbstraction.EnableEnableDisableCallTrace(true);
2709 glAbstraction.EnableStencilFunctionCallTrace(true);
2710 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2711 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2713 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2715 // Check the defaults:
2716 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2717 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2718 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2719 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2720 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2721 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);
2722 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);
2727 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2729 TestApplication application;
2730 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2732 Renderer renderer = RendererTestFixture(application);
2733 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2734 glAbstraction.EnableEnableDisableCallTrace(true);
2735 glAbstraction.EnableStencilFunctionCallTrace(true);
2736 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2737 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2739 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2740 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2741 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2742 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2744 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2745 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2747 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2748 std::string methodString("StencilFunc");
2749 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2751 // Test the other RenderModes that will not enable the stencil buffer.
2752 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2753 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2754 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2756 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2757 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2758 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2760 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2761 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2762 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2764 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2765 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2767 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2768 // First set a mode to turn off the stencil buffer, so the enable is required.
2769 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2770 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2771 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2772 // Set a different stencil function as the last one is cached.
2773 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2774 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2776 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2777 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2782 // Helper function for the SetRenderModeToUseColorBuffer test.
2783 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2785 // Set the RenderMode property to a value that should not allow color buffer writes.
2786 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2787 application.SendNotification();
2788 application.Render();
2790 // Check if ColorMask has been called, and that the values are correct.
2791 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2792 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2794 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2795 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2796 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2797 DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2800 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2802 TestApplication application;
2803 tet_infoline("Test setting the RenderMode to use the color buffer");
2805 Renderer renderer = RendererTestFixture(application);
2807 // Set the RenderMode property to a value that should not allow color buffer writes.
2808 // Then check if ColorMask has been called, and that the values are correct.
2809 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2810 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2811 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2812 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2813 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2818 int UtcDaliRendererSetStencilFunction(void)
2820 TestApplication application;
2821 tet_infoline("Test setting the StencilFunction");
2823 Renderer renderer = RendererTestFixture(application);
2824 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2825 glAbstraction.EnableEnableDisableCallTrace(true);
2826 glAbstraction.EnableStencilFunctionCallTrace(true);
2827 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2828 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2830 // RenderMode must use the stencil for StencilFunction to operate.
2831 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2832 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2835 * Lookup table for testing StencilFunction.
2836 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2838 const int StencilFunctionLookupTable[] = {
2847 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2850 * Loop through all types of StencilFunction, checking:
2851 * - The value is cached (set in event thread side)
2852 * - Causes "glStencilFunc" to be called
2853 * - Checks the correct parameters to "glStencilFunc" were used
2855 std::string nonChangingParameters = "0, 255";
2856 std::string methodString("StencilFunc");
2857 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2859 // Set the property.
2860 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2862 // Check GetProperty returns the same value.
2863 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2865 // Reset the trace debug.
2866 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2868 // Check the function is called and the parameters are correct.
2869 std::stringstream parameterStream;
2870 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2872 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2875 // Change the Function Reference only and check the behavior is correct:
2876 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2877 int testValueReference = 170;
2878 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2880 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2882 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2884 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2886 std::stringstream parameterStream;
2887 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2889 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2891 // Change the Function Mask only and check the behavior is correct:
2892 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2893 int testValueMask = 85;
2894 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2896 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2898 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2900 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2902 // Clear the stringstream.
2903 parameterStream.str(std::string());
2904 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2906 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2911 int UtcDaliRendererSetStencilOperation(void)
2913 TestApplication application;
2914 tet_infoline("Test setting the StencilOperation");
2916 Renderer renderer = RendererTestFixture(application);
2917 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2918 glAbstraction.EnableEnableDisableCallTrace(true);
2919 glAbstraction.EnableStencilFunctionCallTrace(true);
2920 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2921 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2923 // RenderMode must use the stencil for StencilOperation to operate.
2924 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2927 * Lookup table for testing StencilOperation.
2928 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2930 const int StencilOperationLookupTable[] = {
2939 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2941 // Set all 3 StencilOperation properties to a default.
2942 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2943 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2944 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2946 // Set our expected parameter list to the equivalent result.
2947 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2949 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2952 * Loop through all types of StencilOperation, checking:
2953 * - The value is cached (set in event thread side)
2954 * - Causes "glStencilFunc" to be called
2955 * - Checks the correct parameters to "glStencilFunc" were used
2956 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2958 std::string methodString("StencilOp");
2960 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2962 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2964 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2966 // Set the property (outer loop causes all 3 different properties to be set separately).
2967 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2968 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2969 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2971 // Check GetProperty returns the same value.
2972 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2973 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2974 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2976 // Reset the trace debug.
2977 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2979 // Check the function is called and the parameters are correct.
2980 // Set the expected parameter value at its correct index (only)
2981 parameters[0u] = StencilOperationLookupTable[i];
2982 parameters[1u] = StencilOperationLookupTable[j];
2983 parameters[2u] = StencilOperationLookupTable[k];
2985 // Build the parameter list.
2986 std::stringstream parameterStream;
2987 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
2989 parameterStream << parameters[parameterBuild];
2990 // Comma-separate the parameters.
2991 if(parameterBuild < 2)
2993 parameterStream << ", ";
2997 // Check the function was called and the parameters were correct.
2998 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3006 int UtcDaliRendererSetStencilMask(void)
3008 TestApplication application;
3009 tet_infoline("Test setting the StencilMask");
3011 Renderer renderer = RendererTestFixture(application);
3012 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3013 glAbstraction.EnableEnableDisableCallTrace(true);
3014 glAbstraction.EnableStencilFunctionCallTrace(true);
3015 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3016 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3018 // RenderMode must use the stencil for StencilMask to operate.
3019 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3021 // Set the StencilMask property to a value.
3022 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3024 // Check GetProperty returns the same value.
3025 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3027 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3029 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3031 std::string methodString("StencilMask");
3032 std::string parameterString = "0";
3034 // Check the function was called and the parameters were correct.
3035 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3037 // Set the StencilMask property to another value to ensure it has changed.
3038 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3040 // Check GetProperty returns the same value.
3041 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3043 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3045 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3047 parameterString = "255";
3049 // Check the function was called and the parameters were correct.
3050 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3055 int UtcDaliRendererWrongNumberOfTextures(void)
3057 TestApplication application;
3058 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3060 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3061 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3062 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3063 TextureSet textureSet = CreateTextureSet();
3064 textureSet.SetTexture(0, texture);
3065 textureSet.SetTexture(1, texture);
3066 textureSet.SetTexture(2, texture);
3067 textureSet.SetTexture(3, texture);
3068 Shader shader = Shader::New("VertexSource", "FragmentSource");
3069 Geometry geometry = CreateQuadGeometry();
3070 Renderer renderer = Renderer::New(geometry, shader);
3071 renderer.SetTextures(textureSet);
3073 Actor actor = Actor::New();
3074 actor.AddRenderer(renderer);
3075 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3076 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3077 application.GetScene().Add(actor);
3079 TestGlAbstraction& gl = application.GetGlAbstraction();
3080 TraceCallStack& drawTrace = gl.GetDrawTrace();
3082 drawTrace.Enable(true);
3084 application.SendNotification();
3085 application.Render(0);
3087 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3088 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3090 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3091 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3092 textureSet = CreateTextureSet();
3093 renderer.SetTextures(textureSet);
3094 textureSet.SetTexture(0, texture);
3096 application.SendNotification();
3097 application.Render(0);
3099 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3100 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3105 int UtcDaliRendererOpacity(void)
3107 TestApplication application;
3109 tet_infoline("Test OPACITY property");
3111 Geometry geometry = CreateQuadGeometry();
3112 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3113 Renderer renderer = Renderer::New(geometry, shader);
3115 Actor actor = Actor::New();
3116 actor.AddRenderer(renderer);
3117 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3118 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3119 application.GetScene().Add(actor);
3121 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3123 DALI_TEST_CHECK(value.Get(opacity));
3124 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3126 application.SendNotification();
3127 application.Render();
3129 Vector4 actualValue;
3130 TestGlAbstraction& gl = application.GetGlAbstraction();
3131 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3132 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3134 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3136 application.SendNotification();
3137 application.Render();
3139 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3140 DALI_TEST_CHECK(value.Get(opacity));
3141 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3143 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3144 DALI_TEST_CHECK(value.Get(opacity));
3145 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3147 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3148 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3153 int UtcDaliRendererOpacityAnimation(void)
3155 TestApplication application;
3157 tet_infoline("Test OPACITY property animation");
3159 Geometry geometry = CreateQuadGeometry();
3160 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3161 Renderer renderer = Renderer::New(geometry, shader);
3163 Actor actor = Actor::New();
3164 actor.AddRenderer(renderer);
3165 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3166 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3167 application.GetScene().Add(actor);
3169 application.SendNotification();
3170 application.Render(0);
3172 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3174 DALI_TEST_CHECK(value.Get(opacity));
3175 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3177 Animation animation = Animation::New(1.0f);
3178 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3181 application.SendNotification();
3182 application.Render(1000);
3184 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3185 DALI_TEST_CHECK(value.Get(opacity));
3186 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3188 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3190 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3192 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3195 application.SendNotification();
3196 application.Render(1000);
3198 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3199 DALI_TEST_CHECK(value.Get(opacity));
3200 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3201 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3206 int UtcDaliRendererInvalidProperty(void)
3208 TestApplication application;
3210 tet_infoline("Test invalid property");
3212 Geometry geometry = CreateQuadGeometry();
3213 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3214 Renderer renderer = Renderer::New(geometry, shader);
3216 Actor actor = Actor::New();
3217 actor.AddRenderer(renderer);
3218 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3219 application.GetScene().Add(actor);
3221 application.SendNotification();
3222 application.Render(0);
3224 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3225 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3227 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3228 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3233 int UtcDaliRendererRenderingBehavior(void)
3235 TestApplication application;
3237 tet_infoline("Test RENDERING_BEHAVIOR property");
3239 Geometry geometry = CreateQuadGeometry();
3240 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3241 Renderer renderer = Renderer::New(geometry, shader);
3243 Actor actor = Actor::New();
3244 actor.AddRenderer(renderer);
3245 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3246 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3247 application.GetScene().Add(actor);
3249 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3250 int renderingBehavior;
3251 DALI_TEST_CHECK(value.Get(renderingBehavior));
3252 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3254 application.SendNotification();
3255 application.Render();
3257 uint32_t updateStatus = application.GetUpdateStatus();
3259 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3261 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3262 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3263 drawTrace.Enable(true);
3266 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3268 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3269 DALI_TEST_CHECK(value.Get(renderingBehavior));
3270 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3272 // Render and check the update status
3273 application.SendNotification();
3274 application.Render();
3276 updateStatus = application.GetUpdateStatus();
3278 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3280 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3281 DALI_TEST_CHECK(value.Get(renderingBehavior));
3282 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3284 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3288 // Render again and check the update status
3289 application.SendNotification();
3290 application.Render();
3292 updateStatus = application.GetUpdateStatus();
3294 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3296 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3299 // Render again and check the update status
3300 Animation animation = Animation::New(1.0f);
3301 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3306 application.SendNotification();
3307 application.Render(0);
3309 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3313 application.SendNotification();
3314 application.Render(100);
3316 updateStatus = application.GetUpdateStatus();
3318 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3320 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3323 // Change rendering behavior
3324 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3326 // Render and check the update status
3327 application.SendNotification();
3328 application.Render();
3330 updateStatus = application.GetUpdateStatus();
3332 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3337 int UtcDaliRendererRegenerateUniformMap(void)
3339 TestApplication application;
3341 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3343 Geometry geometry = CreateQuadGeometry();
3344 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3345 Renderer renderer = Renderer::New(geometry, shader);
3347 Actor actor = Actor::New();
3348 actor.AddRenderer(renderer);
3349 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3350 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3351 application.GetScene().Add(actor);
3353 application.SendNotification();
3354 application.Render();
3356 actor.RemoveRenderer(renderer);
3357 shader = Shader::New("vertexSrc", "fragmentSrc");
3358 shader.RegisterProperty("opacity", 0.5f);
3359 renderer.SetShader(shader);
3361 Stage::GetCurrent().KeepRendering(1.0f);
3363 // Update for several frames
3364 application.SendNotification();
3365 application.Render();
3366 application.SendNotification();
3367 application.Render();
3368 application.SendNotification();
3369 application.Render();
3370 application.SendNotification();
3371 application.Render();
3374 actor.AddRenderer(renderer);
3375 application.SendNotification();
3376 application.Render();
3378 // Nothing to test here, the test must not crash
3379 auto updateStatus = application.GetUpdateStatus();
3380 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3385 int UtcDaliRendererAddDrawCommands(void)
3387 TestApplication application;
3389 tet_infoline("Test adding draw commands to the renderer");
3391 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3392 glAbstraction.EnableEnableDisableCallTrace(true);
3394 Geometry geometry = CreateQuadGeometry();
3395 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3396 Renderer renderer = Renderer::New(geometry, shader);
3398 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3399 Actor actor = Actor::New();
3400 actor.AddRenderer(renderer);
3401 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3402 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3403 application.GetScene().Add(actor);
3405 // Expect delivering a single draw call
3406 auto& drawTrace = glAbstraction.GetDrawTrace();
3408 drawTrace.Enable(true);
3409 application.SendNotification();
3410 application.Render();
3412 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3414 auto drawCommand1 = DevelRenderer::DrawCommand{};
3415 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3416 drawCommand1.firstIndex = 0;
3417 drawCommand1.elementCount = 2;
3418 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3420 auto drawCommand2 = DevelRenderer::DrawCommand{};
3421 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3422 drawCommand2.firstIndex = 2;
3423 drawCommand2.elementCount = 2;
3424 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3426 auto drawCommand3 = DevelRenderer::DrawCommand{};
3427 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3428 drawCommand3.firstIndex = 2;
3429 drawCommand3.elementCount = 2;
3430 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3432 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3433 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3434 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3437 drawTrace.Enable(true);
3438 application.SendNotification();
3439 application.Render();
3441 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3445 int UtcDaliRendererSetGeometryNegative(void)
3447 TestApplication application;
3448 Dali::Renderer instance;
3451 Dali::Geometry arg1;
3452 instance.SetGeometry(arg1);
3453 DALI_TEST_CHECK(false); // Should not get here
3457 DALI_TEST_CHECK(true); // We expect an assert
3462 int UtcDaliRendererSetTexturesNegative(void)
3464 TestApplication application;
3465 Dali::Renderer instance;
3468 Dali::TextureSet arg1;
3469 instance.SetTextures(arg1);
3470 DALI_TEST_CHECK(false); // Should not get here
3474 DALI_TEST_CHECK(true); // We expect an assert
3479 int UtcDaliRendererSetShaderNegative(void)
3481 TestApplication application;
3482 Dali::Renderer instance;
3486 instance.SetShader(arg1);
3487 DALI_TEST_CHECK(false); // Should not get here
3491 DALI_TEST_CHECK(true); // We expect an assert
3496 int UtcDaliRendererGetGeometryNegative(void)
3498 TestApplication application;
3499 Dali::Renderer instance;
3502 instance.GetGeometry();
3503 DALI_TEST_CHECK(false); // Should not get here
3507 DALI_TEST_CHECK(true); // We expect an assert
3512 int UtcDaliRendererGetTexturesNegative(void)
3514 TestApplication application;
3515 Dali::Renderer instance;
3518 instance.GetTextures();
3519 DALI_TEST_CHECK(false); // Should not get here
3523 DALI_TEST_CHECK(true); // We expect an assert
3528 int UtcDaliRendererGetShaderNegative(void)
3530 TestApplication application;
3531 Dali::Renderer instance;
3534 instance.GetShader();
3535 DALI_TEST_CHECK(false); // Should not get here
3539 DALI_TEST_CHECK(true); // We expect an assert
3544 int UtcDaliRendererCheckTextureBindingP(void)
3546 TestApplication application;
3548 tet_infoline("Test adding draw commands to the renderer");
3550 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3551 glAbstraction.EnableEnableDisableCallTrace(true);
3553 Geometry geometry = CreateQuadGeometry();
3554 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3555 Renderer renderer = Renderer::New(geometry, shader);
3557 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3558 Actor actor = Actor::New();
3559 actor.AddRenderer(renderer);
3560 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3561 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3562 application.GetScene().Add(actor);
3564 TestGraphicsController& graphics = application.GetGraphicsController();
3565 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3566 cmdBufCallstack.Enable(true);
3568 application.SendNotification();
3569 application.Render();
3571 DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3573 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3574 TextureSet textureSet0 = CreateTextureSet(image0);
3575 renderer.SetTextures(textureSet0);
3577 application.SendNotification();
3578 application.Render();
3580 DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));