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 << std::hex << 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 << std::hex << 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 << std::hex << 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 << std::hex << 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 << std::hex << 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 TraceCallStack::NamedParams params;
842 params["cap"] << std::hex << GL_BLEND;
843 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
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 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
876 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
881 int UtcDaliRendererSetBlendMode02(void)
883 TestApplication application;
885 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
887 Geometry geometry = CreateQuadGeometry();
888 Shader shader = CreateShader();
889 Renderer renderer = Renderer::New(geometry, shader);
891 Actor actor = Actor::New();
892 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
893 actor.AddRenderer(renderer);
894 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
895 application.GetScene().Add(actor);
897 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
899 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
900 glAbstraction.EnableEnableDisableCallTrace(true);
902 application.SendNotification();
903 application.Render();
905 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
906 TraceCallStack::NamedParams params;
907 params["cap"] << std::hex << GL_BLEND;
908 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
913 int UtcDaliRendererSetBlendMode03(void)
915 TestApplication application;
917 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
919 Geometry geometry = CreateQuadGeometry();
920 Shader shader = CreateShader();
921 Renderer renderer = Renderer::New(geometry, shader);
923 Actor actor = Actor::New();
924 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
925 actor.AddRenderer(renderer);
926 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
927 application.GetScene().Add(actor);
929 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
931 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
932 glAbstraction.EnableEnableDisableCallTrace(true);
934 application.SendNotification();
935 application.Render();
937 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
938 TraceCallStack::NamedParams params;
939 params["cap"] << std::hex << GL_BLEND;
940 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
945 int UtcDaliRendererSetBlendMode04(void)
947 TestApplication application;
949 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
951 Geometry geometry = CreateQuadGeometry();
952 Shader shader = CreateShader();
953 Renderer renderer = Renderer::New(geometry, shader);
955 Actor actor = Actor::New();
956 actor.AddRenderer(renderer);
957 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
958 application.GetScene().Add(actor);
960 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
962 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
963 glAbstraction.EnableEnableDisableCallTrace(true);
965 application.SendNotification();
966 application.Render();
968 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
969 TraceCallStack::NamedParams params;
970 params["cap"] << std::hex << GL_BLEND;
971 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
972 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
977 int UtcDaliRendererSetBlendMode04b(void)
979 TestApplication application;
981 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
983 Geometry geometry = CreateQuadGeometry();
984 Shader shader = CreateShader();
985 Renderer renderer = Renderer::New(geometry, shader);
987 Actor actor = Actor::New();
988 actor.AddRenderer(renderer);
989 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
990 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
991 application.GetScene().Add(actor);
993 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
995 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
996 glAbstraction.EnableEnableDisableCallTrace(true);
998 application.SendNotification();
999 application.Render();
1001 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1002 TraceCallStack::NamedParams params;
1003 params["cap"] << std::hex << GL_BLEND;
1004 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1009 int UtcDaliRendererSetBlendMode04c(void)
1011 TestApplication application;
1013 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1015 Geometry geometry = CreateQuadGeometry();
1016 Shader shader = CreateShader();
1017 Renderer renderer = Renderer::New(geometry, shader);
1019 Actor actor = Actor::New();
1020 actor.AddRenderer(renderer);
1021 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1022 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1023 application.GetScene().Add(actor);
1025 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1027 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1028 glAbstraction.EnableEnableDisableCallTrace(true);
1030 application.SendNotification();
1031 application.Render();
1033 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1034 TraceCallStack::NamedParams params;
1035 params["cap"] << std::hex << GL_BLEND;
1036 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1037 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
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 TraceCallStack::NamedParams params;
1071 params["cap"] << std::hex << GL_BLEND;
1072 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
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 TraceCallStack::NamedParams params;
1102 params["cap"] << std::hex << GL_BLEND;
1103 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
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 TraceCallStack::NamedParams params;
1136 params["cap"] << std::hex << GL_BLEND;
1137 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1142 int UtcDaliRendererSetBlendMode08(void)
1144 TestApplication application;
1146 tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1148 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1150 Geometry geometry = CreateQuadGeometry();
1151 Shader shader = CreateShader();
1152 Renderer renderer = Renderer::New(geometry, shader);
1154 Actor actor = Actor::New();
1155 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1156 actor.AddRenderer(renderer);
1157 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1158 application.GetScene().Add(actor);
1160 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1161 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1162 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1164 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1165 glAbstraction.EnableEnableDisableCallTrace(true);
1167 application.SendNotification();
1168 application.Render();
1170 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1171 TraceCallStack::NamedParams params;
1172 params["cap"] << std::hex << GL_BLEND;
1173 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1179 int UtcDaliRendererSetBlendMode08b(void)
1181 TestApplication application;
1183 tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1185 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1187 Geometry geometry = CreateQuadGeometry();
1188 Shader shader = CreateShader();
1189 Renderer renderer = Renderer::New(geometry, shader);
1191 Actor actor = Actor::New();
1192 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1193 actor.AddRenderer(renderer);
1194 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1195 application.GetScene().Add(actor);
1197 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1198 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1199 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1201 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1202 glAbstraction.EnableEnableDisableCallTrace(true);
1204 application.SendNotification();
1205 application.Render();
1207 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1208 TraceCallStack::NamedParams params;
1209 params["cap"] << std::hex << GL_BLEND;
1210 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1216 int UtcDaliRendererGetBlendMode(void)
1218 TestApplication application;
1220 tet_infoline("Test GetBlendMode()");
1222 Geometry geometry = CreateQuadGeometry();
1223 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1224 Renderer renderer = Renderer::New(geometry, shader);
1227 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1228 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1231 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1232 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1233 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1236 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1237 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1238 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1243 int UtcDaliRendererSetBlendColor(void)
1245 TestApplication application;
1247 tet_infoline("Test SetBlendColor(color)");
1249 Geometry geometry = CreateQuadGeometry();
1250 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1251 TextureSet textureSet = TextureSet::New();
1252 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1253 textureSet.SetTexture(0u, image);
1254 Renderer renderer = Renderer::New(geometry, shader);
1255 renderer.SetTextures(textureSet);
1257 Actor actor = Actor::New();
1258 actor.AddRenderer(renderer);
1259 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1260 application.GetScene().Add(actor);
1262 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1264 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1266 application.SendNotification();
1267 application.Render();
1269 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1270 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1271 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1273 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1275 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1276 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1278 application.SendNotification();
1279 application.Render();
1281 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1282 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1284 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1285 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1286 application.SendNotification();
1287 application.Render();
1288 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1293 int UtcDaliRendererGetBlendColor(void)
1295 TestApplication application;
1297 tet_infoline("Test GetBlendColor()");
1299 Geometry geometry = CreateQuadGeometry();
1300 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1301 Renderer renderer = Renderer::New(geometry, shader);
1303 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1305 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1306 application.SendNotification();
1307 application.Render();
1308 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1310 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1311 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1312 application.SendNotification();
1313 application.Render();
1314 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1319 int UtcDaliRendererPreMultipledAlpha(void)
1321 TestApplication application;
1323 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1325 Geometry geometry = CreateQuadGeometry();
1326 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1327 Renderer renderer = Renderer::New(geometry, shader);
1329 Actor actor = Actor::New();
1330 actor.AddRenderer(renderer);
1331 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1332 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1333 application.GetScene().Add(actor);
1335 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1336 bool preMultipliedAlpha;
1337 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1338 DALI_TEST_CHECK(!preMultipliedAlpha);
1340 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1341 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1342 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1343 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1345 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1346 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1347 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1348 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1350 application.SendNotification();
1351 application.Render();
1353 Vector4 actualValue(Vector4::ZERO);
1354 TestGlAbstraction& gl = application.GetGlAbstraction();
1355 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1356 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1358 // Enable pre-multiplied alpha
1359 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1361 application.SendNotification();
1362 application.Render();
1364 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1365 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1366 DALI_TEST_CHECK(preMultipliedAlpha);
1368 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1369 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1370 DALI_TEST_CHECK(preMultipliedAlpha);
1372 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1373 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1374 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1375 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1377 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1378 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1379 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1380 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1382 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1383 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1385 // Disable pre-multiplied alpha again
1386 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1388 application.SendNotification();
1389 application.Render();
1391 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1392 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1393 DALI_TEST_CHECK(!preMultipliedAlpha);
1395 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1396 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1397 DALI_TEST_CHECK(!preMultipliedAlpha);
1399 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1400 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1401 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1402 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1404 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1405 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1406 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1407 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1409 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1410 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1415 int UtcDaliRendererConstraint01(void)
1417 TestApplication application;
1419 tet_infoline("Test that a non-uniform renderer property can be constrained");
1421 Shader shader = Shader::New("VertexSource", "FragmentSource");
1422 Geometry geometry = CreateQuadGeometry();
1423 Renderer renderer = Renderer::New(geometry, shader);
1425 Actor actor = Actor::New();
1426 actor.AddRenderer(renderer);
1427 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1428 application.GetScene().Add(actor);
1430 Vector4 initialColor = Color::WHITE;
1431 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1433 application.SendNotification();
1434 application.Render(0);
1435 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1438 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1440 application.SendNotification();
1441 application.Render(0);
1443 // Expect no blue component in either buffer - yellow
1444 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1445 application.Render(0);
1446 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1448 renderer.RemoveConstraints();
1449 renderer.SetProperty(colorIndex, Color::WHITE);
1450 application.SendNotification();
1451 application.Render(0);
1452 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1457 int UtcDaliRendererConstraint02(void)
1459 TestApplication application;
1461 tet_infoline("Test that a uniform map renderer property can be constrained");
1463 Shader shader = Shader::New("VertexSource", "FragmentSource");
1464 Geometry geometry = CreateQuadGeometry();
1465 Renderer renderer = Renderer::New(geometry, shader);
1467 Actor actor = Actor::New();
1468 actor.AddRenderer(renderer);
1469 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1470 application.GetScene().Add(actor);
1471 application.SendNotification();
1472 application.Render(0);
1474 Vector4 initialColor = Color::WHITE;
1475 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1477 TestGlAbstraction& gl = application.GetGlAbstraction();
1479 application.SendNotification();
1480 application.Render(0);
1482 Vector4 actualValue(Vector4::ZERO);
1483 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1484 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1487 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1489 application.SendNotification();
1490 application.Render(0);
1492 // Expect no blue component in either buffer - yellow
1493 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1494 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1496 application.Render(0);
1497 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1498 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1500 renderer.RemoveConstraints();
1501 renderer.SetProperty(colorIndex, Color::WHITE);
1502 application.SendNotification();
1503 application.Render(0);
1505 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1506 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1511 int UtcDaliRendererAnimatedProperty01(void)
1513 TestApplication application;
1515 tet_infoline("Test that a non-uniform renderer property can be animated");
1517 Shader shader = Shader::New("VertexSource", "FragmentSource");
1518 Geometry geometry = CreateQuadGeometry();
1519 Renderer renderer = Renderer::New(geometry, shader);
1521 Actor actor = Actor::New();
1522 actor.AddRenderer(renderer);
1523 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1524 application.GetScene().Add(actor);
1526 Vector4 initialColor = Color::WHITE;
1527 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1529 application.SendNotification();
1530 application.Render(0);
1531 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1533 Animation animation = Animation::New(1.0f);
1534 KeyFrames keyFrames = KeyFrames::New();
1535 keyFrames.Add(0.0f, initialColor);
1536 keyFrames.Add(1.0f, Color::TRANSPARENT);
1537 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1540 application.SendNotification();
1541 application.Render(500);
1543 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1545 application.Render(500);
1547 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1552 int UtcDaliRendererAnimatedProperty02(void)
1554 TestApplication application;
1556 tet_infoline("Test that a uniform map renderer property can be animated");
1558 Shader shader = Shader::New("VertexSource", "FragmentSource");
1559 Geometry geometry = CreateQuadGeometry();
1560 Renderer renderer = Renderer::New(geometry, shader);
1562 Actor actor = Actor::New();
1563 actor.AddRenderer(renderer);
1564 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1565 application.GetScene().Add(actor);
1566 application.SendNotification();
1567 application.Render(0);
1569 Vector4 initialColor = Color::WHITE;
1570 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1572 TestGlAbstraction& gl = application.GetGlAbstraction();
1574 application.SendNotification();
1575 application.Render(0);
1577 Vector4 actualValue(Vector4::ZERO);
1578 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1579 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1581 Animation animation = Animation::New(1.0f);
1582 KeyFrames keyFrames = KeyFrames::New();
1583 keyFrames.Add(0.0f, initialColor);
1584 keyFrames.Add(1.0f, Color::TRANSPARENT);
1585 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1588 application.SendNotification();
1589 application.Render(500);
1591 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1592 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1594 application.Render(500);
1595 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1596 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1601 int UtcDaliRendererUniformMapPrecendence01(void)
1603 TestApplication application;
1605 tet_infoline("Test the uniform map precedence is applied properly");
1607 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1609 Shader shader = Shader::New("VertexSource", "FragmentSource");
1610 TextureSet textureSet = CreateTextureSet(image);
1612 Geometry geometry = CreateQuadGeometry();
1613 Renderer renderer = Renderer::New(geometry, shader);
1614 renderer.SetTextures(textureSet);
1616 Actor actor = Actor::New();
1617 actor.AddRenderer(renderer);
1618 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1619 application.GetScene().Add(actor);
1620 application.SendNotification();
1621 application.Render(0);
1623 renderer.RegisterProperty("uFadeColor", Color::RED);
1624 actor.RegisterProperty("uFadeColor", Color::GREEN);
1625 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1627 TestGlAbstraction& gl = application.GetGlAbstraction();
1629 application.SendNotification();
1630 application.Render(0);
1632 // Expect that the actor's fade color property is accessed
1633 Vector4 actualValue(Vector4::ZERO);
1634 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1635 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1637 // Animate shader's fade color property. Should be no change to uniform
1638 Animation animation = Animation::New(1.0f);
1639 KeyFrames keyFrames = KeyFrames::New();
1640 keyFrames.Add(0.0f, Color::WHITE);
1641 keyFrames.Add(1.0f, Color::TRANSPARENT);
1642 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1645 application.SendNotification();
1646 application.Render(500);
1648 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1649 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1651 application.Render(500);
1652 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1653 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1658 int UtcDaliRendererUniformMapPrecendence02(void)
1660 TestApplication application;
1662 tet_infoline("Test the uniform map precedence is applied properly");
1664 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1666 Shader shader = Shader::New("VertexSource", "FragmentSource");
1667 TextureSet textureSet = CreateTextureSet(image);
1669 Geometry geometry = CreateQuadGeometry();
1670 Renderer renderer = Renderer::New(geometry, shader);
1671 renderer.SetTextures(textureSet);
1673 Actor actor = Actor::New();
1674 actor.AddRenderer(renderer);
1675 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1676 application.GetScene().Add(actor);
1677 application.SendNotification();
1678 application.Render(0);
1680 // Don't add property / uniform map to renderer
1681 actor.RegisterProperty("uFadeColor", Color::GREEN);
1682 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1684 TestGlAbstraction& gl = application.GetGlAbstraction();
1686 application.SendNotification();
1687 application.Render(0);
1689 // Expect that the actor's fade color property is accessed
1690 Vector4 actualValue(Vector4::ZERO);
1691 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1692 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1694 // Animate texture set's fade color property. Should be no change to uniform
1695 Animation animation = Animation::New(1.0f);
1696 KeyFrames keyFrames = KeyFrames::New();
1697 keyFrames.Add(0.0f, Color::WHITE);
1698 keyFrames.Add(1.0f, Color::TRANSPARENT);
1699 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1702 application.SendNotification();
1703 application.Render(500);
1705 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1706 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1708 application.Render(500);
1709 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1710 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1715 int UtcDaliRendererUniformMapPrecendence03(void)
1717 TestApplication application;
1719 tet_infoline("Test the uniform map precedence is applied properly");
1721 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1723 Shader shader = Shader::New("VertexSource", "FragmentSource");
1724 TextureSet textureSet = CreateTextureSet(image);
1726 Geometry geometry = CreateQuadGeometry();
1727 Renderer renderer = Renderer::New(geometry, shader);
1728 renderer.SetTextures(textureSet);
1730 Actor actor = Actor::New();
1731 actor.AddRenderer(renderer);
1732 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1733 application.GetScene().Add(actor);
1734 application.SendNotification();
1735 application.Render(0);
1737 // Don't add property / uniform map to renderer or actor
1738 shader.RegisterProperty("uFadeColor", Color::BLACK);
1740 TestGlAbstraction& gl = application.GetGlAbstraction();
1742 application.SendNotification();
1743 application.Render(0);
1745 // Expect that the shader's fade color property is accessed
1746 Vector4 actualValue(Vector4::ZERO);
1747 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1748 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1753 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1755 TestApplication application;
1757 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1759 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1761 Shader shader = Shader::New("VertexSource", "FragmentSource");
1762 TextureSet textureSet = CreateTextureSet(image);
1764 Geometry geometry = CreateQuadGeometry();
1765 Renderer renderer = Renderer::New(geometry, shader);
1766 renderer.SetTextures(textureSet);
1768 Actor actor = Actor::New();
1769 actor.AddRenderer(renderer);
1770 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1771 application.GetScene().Add(actor);
1772 application.SendNotification();
1773 application.Render(0);
1775 renderer.RegisterProperty("uUniform1", Color::RED);
1776 actor.RegisterProperty("uUniform2", Color::GREEN);
1777 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1779 TestGlAbstraction& gl = application.GetGlAbstraction();
1781 application.SendNotification();
1782 application.Render(0);
1784 // Expect that each of the object's uniforms are set
1785 Vector4 uniform1Value(Vector4::ZERO);
1786 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1787 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1789 Vector4 uniform2Value(Vector4::ZERO);
1790 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1791 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1793 Vector4 uniform3Value(Vector4::ZERO);
1794 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1795 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1800 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1802 TestApplication application;
1804 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1806 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1808 Shader shader = Shader::New("VertexSource", "FragmentSource");
1809 TextureSet textureSet = CreateTextureSet(image);
1811 Geometry geometry = CreateQuadGeometry();
1812 Renderer renderer = Renderer::New(geometry, shader);
1813 renderer.SetTextures(textureSet);
1815 Actor actor = Actor::New();
1816 actor.AddRenderer(renderer);
1817 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1818 application.GetScene().Add(actor);
1819 application.SendNotification();
1820 application.Render(0);
1822 Property::Value value1(Color::RED);
1823 renderer.RegisterProperty("uFadeColor", value1);
1825 Property::Value value2(1.0f);
1826 actor.RegisterProperty("uFadeProgress", value2);
1828 Property::Value value3(Matrix3::IDENTITY);
1829 shader.RegisterProperty("uANormalMatrix", value3);
1831 TestGlAbstraction& gl = application.GetGlAbstraction();
1833 application.SendNotification();
1834 application.Render(0);
1836 // Expect that each of the object's uniforms are set
1837 Vector4 uniform1Value(Vector4::ZERO);
1838 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1839 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1841 float uniform2Value(0.0f);
1842 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1843 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1845 Matrix3 uniform3Value;
1846 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1847 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1852 int UtcDaliRendererRenderOrder2DLayer(void)
1854 TestApplication application;
1855 tet_infoline("Test the rendering order in a 2D layer is correct");
1857 Shader shader = Shader::New("VertexSource", "FragmentSource");
1858 Geometry geometry = CreateQuadGeometry();
1860 Actor root = application.GetScene().GetRootLayer();
1862 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1863 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1865 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1866 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1868 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1869 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1871 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1872 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1874 application.SendNotification();
1875 application.Render(0);
1878 * Create the following hierarchy:
1891 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1896 application.SendNotification();
1897 application.Render(0);
1899 TestGlAbstraction& gl = application.GetGlAbstraction();
1900 gl.GetTextureTrace().Reset();
1901 gl.EnableTextureCallTrace(true);
1902 application.SendNotification();
1903 application.Render(0);
1905 int textureBindIndex[4];
1906 for(unsigned int i(0); i < 4; ++i)
1908 std::stringstream params;
1909 params << GL_TEXTURE_2D << ", " << i + 1;
1910 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1913 //Check that actor1 has been rendered after actor2
1914 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1916 //Check that actor0 has been rendered after actor1
1917 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1919 //Check that actor3 has been rendered after actor0
1920 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1925 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1927 TestApplication application;
1928 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1931 * Creates the following hierarchy:
1933 * actor0------------------------>actor1
1937 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1939 * renderer0 has depth index 2
1940 * renderer1 has depth index 0
1941 * renderer2 has depth index 1
1943 * renderer3 has depth index 1
1944 * renderer4 has depth index 0
1945 * renderer5 has depth index -1
1947 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1950 Shader shader = Shader::New("VertexSource", "FragmentSource");
1951 Geometry geometry = CreateQuadGeometry();
1953 Actor root = application.GetScene().GetRootLayer();
1955 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1956 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
1957 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1958 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1959 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1960 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1961 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1962 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1964 application.SendNotification();
1965 application.Render(0);
1967 TestGlAbstraction& gl = application.GetGlAbstraction();
1968 gl.GetTextureTrace().Reset();
1969 gl.EnableTextureCallTrace(true);
1970 application.SendNotification();
1971 application.Render(0);
1973 int textureBindIndex[6];
1974 for(unsigned int i(0); i < 6; ++i)
1976 std::stringstream params;
1977 params << GL_TEXTURE_2D << ", " << i + 1;
1978 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1981 //Check that renderer3 has been rendered after renderer4
1982 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1984 //Check that renderer0 has been rendered after renderer2
1985 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1987 //Check that renderer5 has been rendered after renderer2
1988 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1990 //Check that renderer0 has been rendered after renderer2
1991 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1993 //Check that renderer2 has been rendered after renderer1
1994 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1999 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2001 TestApplication application;
2002 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2005 * Creates the following hierarchy:
2013 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
2017 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
2018 * DI:2 DI:0 | DI:0 DI:1 DI:2
2023 * actor0 has sibling order 1
2024 * actor1 has sibling order 0
2025 * actor2 has sibling order 0
2027 * renderer0 has depth index 2
2028 * renderer1 has depth index 0
2030 * renderer2 has depth index 0
2031 * renderer3 has depth index 1
2032 * renderer4 has depth index 2
2034 * renderer5 has depth index -1
2036 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2039 Shader shader = Shader::New("VertexSource", "FragmentSource");
2040 Geometry geometry = CreateQuadGeometry();
2041 Actor root = application.GetScene().GetRootLayer();
2042 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
2043 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2044 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
2046 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2047 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2048 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2049 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2050 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2051 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2053 application.SendNotification();
2054 application.Render();
2056 TestGlAbstraction& gl = application.GetGlAbstraction();
2057 gl.GetTextureTrace().Reset();
2058 gl.EnableTextureCallTrace(true);
2059 application.SendNotification();
2060 application.Render(0);
2062 int textureBindIndex[6];
2063 for(unsigned int i(0); i < 6; ++i)
2065 std::stringstream params;
2066 params << GL_TEXTURE_2D << ", " << i + 1;
2067 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2070 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2071 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2072 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2073 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2074 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2075 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2077 // Change sibling order of actor1
2078 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2079 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2081 gl.GetTextureTrace().Reset();
2082 application.SendNotification();
2083 application.Render(0);
2085 for(unsigned int i(0); i < 6; ++i)
2087 std::stringstream params;
2088 params << GL_TEXTURE_2D << ", " << i + 1;
2089 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2092 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2093 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2094 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2095 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2096 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2097 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2102 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2104 TestApplication application;
2105 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2107 Shader shader = Shader::New("VertexSource", "FragmentSource");
2108 Geometry geometry = CreateQuadGeometry();
2109 Actor root = application.GetScene().GetRootLayer();
2112 * Create the following hierarchy:
2119 * (Overlay) (Regular actor)
2129 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2132 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2133 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2134 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2136 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2137 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2138 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2140 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2141 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2143 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2144 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2145 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2147 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2148 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2150 application.SendNotification();
2151 application.Render(0);
2158 TestGlAbstraction& gl = application.GetGlAbstraction();
2159 gl.GetTextureTrace().Reset();
2160 gl.EnableTextureCallTrace(true);
2161 application.SendNotification();
2162 application.Render(0);
2164 int textureBindIndex[5];
2165 for(unsigned int i(0); i < 5; ++i)
2167 std::stringstream params;
2168 params << GL_TEXTURE_2D << ", " << i + 1;
2169 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2172 //Check that actor4 has been rendered after actor2
2173 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2175 //Check that actor1 has been rendered after actor4
2176 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2178 //Check that actor0 has been rendered after actor1
2179 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2181 //Check that actor3 has been rendered after actor0
2182 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2187 int UtcDaliRendererSetIndexRange(void)
2191 "attribute vec2 aPosition;\n"
2194 " gl_Position = aPosition;\n"
2199 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2202 TestApplication application;
2203 tet_infoline("Test setting the range of indices to draw");
2205 TestGlAbstraction& gl = application.GetGlAbstraction();
2206 gl.EnableDrawCallTrace(true);
2208 Actor actor = Actor::New();
2209 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2212 Geometry geometry = Geometry::New();
2213 geometry.SetType(Geometry::LINE_LOOP);
2215 // --------------------------------------------------------------------------
2217 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2227 9, // offset = 5, count = 10
2233 1}; // offset = 15, count = 6 // line strip
2235 // --------------------------------------------------------------------------
2244 {Vector2(0.0f, 1.00f)},
2245 {Vector2(0.0f, -1.00f)},
2246 {Vector2(-0.95f, 0.31f)},
2247 {Vector2(0.59f, 0.81f)},
2248 {Vector2(-0.59f, -0.81f)},
2249 {Vector2(-0.95f, -0.31f)},
2250 {Vector2(0.59f, -0.81f)},
2251 {Vector2(0.95f, -0.31f)},
2252 {Vector2(0.95f, 0.31f)},
2253 {Vector2(-0.59f, 0.81f)},
2255 Property::Map vertexFormat;
2256 vertexFormat["aPosition"] = Property::VECTOR2;
2257 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2258 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2260 // --------------------------------------------------------------------------
2261 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2262 geometry.AddVertexBuffer(vertexBuffer);
2265 Shader shader = Shader::New(vertexShader, fragmentShader);
2266 Renderer renderer = Renderer::New(geometry, shader);
2267 actor.AddRenderer(renderer);
2269 Integration::Scene scene = application.GetScene();
2274 // LINE_LOOP, first 0, count 5
2276 renderer.SetIndexRange(0, 5);
2277 application.SendNotification();
2278 application.Render();
2280 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2282 DALI_TEST_CHECK(value.Get(convertedValue));
2283 DALI_TEST_CHECK(convertedValue == 0);
2285 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2286 DALI_TEST_CHECK(value.Get(convertedValue));
2287 DALI_TEST_CHECK(convertedValue == 0);
2289 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2290 DALI_TEST_CHECK(value.Get(convertedValue));
2291 DALI_TEST_CHECK(convertedValue == 5);
2293 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2294 DALI_TEST_CHECK(value.Get(convertedValue));
2295 DALI_TEST_CHECK(convertedValue == 5);
2297 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2298 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2299 DALI_TEST_CHECK(result);
2302 // LINE_LOOP, first 5, count 10
2304 renderer.SetIndexRange(5, 10);
2305 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2306 application.SendNotification();
2307 application.Render();
2308 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2309 DALI_TEST_CHECK(result);
2312 // LINE_STRIP, first 15, count 6
2314 renderer.SetIndexRange(15, 6);
2315 geometry.SetType(Geometry::LINE_STRIP);
2316 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2317 application.SendNotification();
2318 application.Render();
2319 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2320 DALI_TEST_CHECK(result);
2323 // Index out of bounds
2325 renderer.SetIndexRange(15, 30);
2326 geometry.SetType(Geometry::LINE_STRIP);
2327 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2328 application.SendNotification();
2329 application.Render();
2330 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2331 DALI_TEST_CHECK(result);
2334 // drawing whole buffer starting from 15 ( last valid primitive )
2336 renderer.SetIndexRange(15, 0);
2337 geometry.SetType(Geometry::LINE_STRIP);
2338 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2339 application.SendNotification();
2340 application.Render();
2341 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2342 DALI_TEST_CHECK(result);
2348 int UtcDaliRendererSetDepthFunction(void)
2350 TestApplication application;
2352 tet_infoline("Test setting the depth function");
2354 Geometry geometry = CreateQuadGeometry();
2355 Shader shader = CreateShader();
2356 Renderer renderer = Renderer::New(geometry, shader);
2358 Actor actor = Actor::New();
2359 actor.AddRenderer(renderer);
2360 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2361 Integration::Scene scene = application.GetScene();
2362 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2365 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2366 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2367 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2369 glEnableDisableStack.Enable(true);
2370 glDepthFunctionStack.Enable(true);
2371 glEnableDisableStack.EnableLogging(true);
2372 glDepthFunctionStack.EnableLogging(true);
2374 std::ostringstream depthTestStr;
2375 depthTestStr << std::hex << GL_DEPTH_TEST;
2379 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2381 glEnableDisableStack.Reset();
2382 glDepthFunctionStack.Reset();
2383 application.SendNotification();
2384 application.Render();
2386 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2387 std::ostringstream depthFunctionStr;
2388 depthFunctionStr << std::hex << GL_NEVER;
2389 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2394 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2396 glDepthFunctionStack.Reset();
2397 application.SendNotification();
2398 application.Render();
2400 std::ostringstream depthFunctionStr;
2401 depthFunctionStr << std::hex << GL_ALWAYS;
2402 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2407 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2409 glDepthFunctionStack.Reset();
2410 application.SendNotification();
2411 application.Render();
2413 std::ostringstream depthFunctionStr;
2414 depthFunctionStr << std::hex << GL_LESS;
2415 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2420 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2422 glDepthFunctionStack.Reset();
2423 application.SendNotification();
2424 application.Render();
2426 std::ostringstream depthFunctionStr;
2427 depthFunctionStr << std::hex << GL_GREATER;
2428 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2433 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2435 glDepthFunctionStack.Reset();
2436 application.SendNotification();
2437 application.Render();
2439 std::ostringstream depthFunctionStr;
2440 depthFunctionStr << std::hex << GL_EQUAL;
2441 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2446 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2448 glDepthFunctionStack.Reset();
2449 application.SendNotification();
2450 application.Render();
2452 std::ostringstream depthFunctionStr;
2453 depthFunctionStr << std::hex << GL_NOTEQUAL;
2454 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2459 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2461 glDepthFunctionStack.Reset();
2462 application.SendNotification();
2463 application.Render();
2465 std::ostringstream depthFunctionStr;
2466 depthFunctionStr << std::hex << GL_LEQUAL;
2467 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2472 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2474 glDepthFunctionStack.Reset();
2475 application.SendNotification();
2476 application.Render();
2478 std::ostringstream depthFunctionStr;
2479 depthFunctionStr << std::hex << GL_GEQUAL;
2480 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2487 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2488 * The checks performed are as follows:
2489 * - Check the initial/default value.
2490 * - Set a different value via enum.
2491 * - Check it was set.
2492 * - Set a different value via string.
2493 * - Check it was set.
2495 template<typename T>
2496 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2498 application.SendNotification();
2499 application.Render();
2501 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2502 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2503 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2504 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2505 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2507 application.SendNotification();
2508 application.Render();
2510 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2511 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2513 renderer.SetProperty(propertyIndex, secondCheckString);
2514 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2515 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2517 application.SendNotification();
2518 application.Render();
2520 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2521 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2524 int UtcDaliRendererEnumProperties(void)
2526 TestApplication application;
2527 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2529 Geometry geometry = CreateQuadGeometry();
2530 Shader shader = CreateShader();
2531 Renderer renderer = Renderer::New(geometry, shader);
2533 Actor actor = Actor::New();
2534 actor.AddRenderer(renderer);
2535 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2536 application.GetScene().Add(actor);
2539 * Here we use a templatized function to perform several checks on each enumeration property.
2540 * @see CheckEnumerationProperty for details of the checks performed.
2543 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2544 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2545 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2546 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2547 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2548 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2549 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2550 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2551 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2552 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2553 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2554 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2555 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2556 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2557 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2558 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2560 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2561 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2563 application.SendNotification();
2564 application.Render();
2565 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2568 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2570 application.SendNotification();
2571 application.Render();
2572 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2578 Renderer RendererTestFixture(TestApplication& application)
2580 Geometry geometry = CreateQuadGeometry();
2581 Shader shader = CreateShader();
2582 Renderer renderer = Renderer::New(geometry, shader);
2584 Actor actor = Actor::New();
2585 actor.AddRenderer(renderer);
2586 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2587 Integration::Scene scene = application.GetScene();
2588 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2594 int UtcDaliRendererSetDepthTestMode(void)
2596 TestApplication application;
2597 tet_infoline("Test setting the DepthTestMode");
2599 Renderer renderer = RendererTestFixture(application);
2600 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2601 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2602 glEnableDisableStack.Enable(true);
2603 glEnableDisableStack.EnableLogging(true);
2605 glEnableDisableStack.Reset();
2606 application.SendNotification();
2607 application.Render();
2609 // Check depth-test is enabled by default.
2610 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2611 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2613 // 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.
2614 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2615 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2617 glEnableDisableStack.Reset();
2618 application.SendNotification();
2619 application.Render();
2621 // Check the depth buffer was disabled.
2622 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2624 // Turn on automatic mode depth-testing.
2625 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2626 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2628 glEnableDisableStack.Reset();
2629 application.SendNotification();
2630 application.Render();
2632 // Check depth-test is now enabled.
2633 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2634 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2636 // Change the layer behavior to LAYER_UI.
2637 // Note this will also disable depth testing for the layer by default, we test this first.
2638 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2640 glEnableDisableStack.Reset();
2641 application.SendNotification();
2642 application.Render();
2644 // Check depth-test is disabled.
2645 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2647 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2648 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2650 glEnableDisableStack.Reset();
2651 application.SendNotification();
2652 application.Render();
2654 // Check depth-test is *still* disabled.
2655 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2660 int UtcDaliRendererSetDepthWriteMode(void)
2662 TestApplication application;
2663 tet_infoline("Test setting the DepthWriteMode");
2665 Renderer renderer = RendererTestFixture(application);
2666 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2668 application.SendNotification();
2669 application.Render();
2671 // Check the default depth-write status first.
2672 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2674 // Turn off depth-writing.
2675 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2677 application.SendNotification();
2678 application.Render();
2680 // Check depth-write is now disabled.
2681 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2683 // Test the AUTO mode for depth-writing.
2684 // As our renderer is opaque, depth-testing should be enabled.
2685 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2687 application.SendNotification();
2688 application.Render();
2690 // Check depth-write is now enabled.
2691 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2693 // Now make the renderer be treated as translucent by enabling blending.
2694 // The AUTO depth-write mode should turn depth-write off in this scenario.
2695 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2697 application.SendNotification();
2698 application.Render();
2700 // Check depth-write is now disabled.
2701 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2706 int UtcDaliRendererCheckStencilDefaults(void)
2708 TestApplication application;
2709 tet_infoline("Test the stencil defaults");
2711 Renderer renderer = RendererTestFixture(application);
2712 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2713 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2714 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2715 glEnableDisableStack.Enable(true);
2716 glEnableDisableStack.EnableLogging(true);
2717 glStencilFunctionStack.Enable(true);
2718 glStencilFunctionStack.EnableLogging(true);
2720 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2722 // Check the defaults:
2723 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2724 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2725 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2726 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2727 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2728 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);
2729 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);
2734 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2736 TestApplication application;
2737 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2739 Renderer renderer = RendererTestFixture(application);
2740 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2741 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2742 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2743 glEnableDisableStack.Enable(true);
2744 glEnableDisableStack.EnableLogging(true);
2745 glStencilFunctionStack.Enable(true);
2746 glStencilFunctionStack.EnableLogging(true);
2748 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2749 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2750 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2751 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2753 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2754 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2756 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2757 std::string methodString("StencilFunc");
2758 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2760 // Test the other RenderModes that will not enable the stencil buffer.
2761 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2762 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2763 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2765 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2766 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2767 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2769 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2770 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2771 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2773 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2774 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2776 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2777 // First set a mode to turn off the stencil buffer, so the enable is required.
2778 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2779 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2780 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2781 // Set a different stencil function as the last one is cached.
2782 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2783 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2785 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2786 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2791 // Helper function for the SetRenderModeToUseColorBuffer test.
2792 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2794 // Set the RenderMode property to a value that should not allow color buffer writes.
2795 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2796 application.SendNotification();
2797 application.Render();
2799 // Check if ColorMask has been called, and that the values are correct.
2800 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2801 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2803 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2804 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2805 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2806 DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2809 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2811 TestApplication application;
2812 tet_infoline("Test setting the RenderMode to use the color buffer");
2814 Renderer renderer = RendererTestFixture(application);
2816 // Set the RenderMode property to a value that should not allow color buffer writes.
2817 // Then check if ColorMask has been called, and that the values are correct.
2818 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2819 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2820 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2821 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2822 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2827 int UtcDaliRendererSetStencilFunction(void)
2829 TestApplication application;
2830 tet_infoline("Test setting the StencilFunction");
2832 Renderer renderer = RendererTestFixture(application);
2833 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2834 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2835 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2836 glEnableDisableStack.Enable(true);
2837 glEnableDisableStack.EnableLogging(true);
2838 glStencilFunctionStack.Enable(true);
2839 glStencilFunctionStack.EnableLogging(true);
2841 // RenderMode must use the stencil for StencilFunction to operate.
2842 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2843 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2846 * Lookup table for testing StencilFunction.
2847 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2849 const int StencilFunctionLookupTable[] = {
2858 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2861 * Loop through all types of StencilFunction, checking:
2862 * - The value is cached (set in event thread side)
2863 * - Causes "glStencilFunc" to be called
2864 * - Checks the correct parameters to "glStencilFunc" were used
2866 std::string nonChangingParameters = "0, 255";
2867 std::string methodString("StencilFunc");
2868 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2870 // Set the property.
2871 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2873 // Check GetProperty returns the same value.
2874 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2876 // Reset the trace debug.
2877 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2879 // Check the function is called and the parameters are correct.
2880 std::stringstream parameterStream;
2881 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2883 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2886 // Change the Function Reference only and check the behavior is correct:
2887 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2888 int testValueReference = 170;
2889 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2891 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2893 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2895 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2897 std::stringstream parameterStream;
2898 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2900 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2902 // Change the Function Mask only and check the behavior is correct:
2903 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2904 int testValueMask = 85;
2905 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2907 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2909 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2911 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2913 // Clear the stringstream.
2914 parameterStream.str(std::string());
2915 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2917 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2922 int UtcDaliRendererSetStencilOperation(void)
2924 TestApplication application;
2925 tet_infoline("Test setting the StencilOperation");
2927 Renderer renderer = RendererTestFixture(application);
2928 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2929 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2930 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2931 glEnableDisableStack.Enable(true);
2932 glEnableDisableStack.EnableLogging(true);
2933 glStencilFunctionStack.Enable(true);
2934 glStencilFunctionStack.EnableLogging(true);
2936 // RenderMode must use the stencil for StencilOperation to operate.
2937 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2940 * Lookup table for testing StencilOperation.
2941 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2943 const int StencilOperationLookupTable[] = {
2952 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2954 // Set all 3 StencilOperation properties to a default.
2955 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2956 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2957 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2959 // Set our expected parameter list to the equivalent result.
2960 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2962 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2965 * Loop through all types of StencilOperation, checking:
2966 * - The value is cached (set in event thread side)
2967 * - Causes "glStencilFunc" to be called
2968 * - Checks the correct parameters to "glStencilFunc" were used
2969 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2971 std::string methodString("StencilOp");
2973 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2975 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2977 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2979 // Set the property (outer loop causes all 3 different properties to be set separately).
2980 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2981 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2982 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2984 // Check GetProperty returns the same value.
2985 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2986 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2987 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2989 // Reset the trace debug.
2990 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2992 // Check the function is called and the parameters are correct.
2993 // Set the expected parameter value at its correct index (only)
2994 parameters[0u] = StencilOperationLookupTable[i];
2995 parameters[1u] = StencilOperationLookupTable[j];
2996 parameters[2u] = StencilOperationLookupTable[k];
2998 // Build the parameter list.
2999 std::stringstream parameterStream;
3000 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3002 parameterStream << parameters[parameterBuild];
3003 // Comma-separate the parameters.
3004 if(parameterBuild < 2)
3006 parameterStream << ", ";
3010 // Check the function was called and the parameters were correct.
3011 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3019 int UtcDaliRendererSetStencilMask(void)
3021 TestApplication application;
3022 tet_infoline("Test setting the StencilMask");
3024 Renderer renderer = RendererTestFixture(application);
3025 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3026 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3027 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3028 glEnableDisableStack.Enable(true);
3029 glEnableDisableStack.EnableLogging(true);
3030 glStencilFunctionStack.Enable(true);
3031 glStencilFunctionStack.EnableLogging(true);
3033 // RenderMode must use the stencil for StencilMask to operate.
3034 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3036 // Set the StencilMask property to a value.
3037 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3039 // Check GetProperty returns the same value.
3040 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3042 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3044 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3046 std::string methodString("StencilMask");
3047 std::string parameterString = "0";
3049 // Check the function was called and the parameters were correct.
3050 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3052 // Set the StencilMask property to another value to ensure it has changed.
3053 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3055 // Check GetProperty returns the same value.
3056 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3058 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3060 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3062 parameterString = "255";
3064 // Check the function was called and the parameters were correct.
3065 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3070 int UtcDaliRendererWrongNumberOfTextures(void)
3072 TestApplication application;
3073 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3075 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3076 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3077 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3078 TextureSet textureSet = CreateTextureSet();
3079 textureSet.SetTexture(0, texture);
3080 textureSet.SetTexture(1, texture);
3081 textureSet.SetTexture(2, texture);
3082 textureSet.SetTexture(3, texture);
3083 Shader shader = Shader::New("VertexSource", "FragmentSource");
3084 Geometry geometry = CreateQuadGeometry();
3085 Renderer renderer = Renderer::New(geometry, shader);
3086 renderer.SetTextures(textureSet);
3088 Actor actor = Actor::New();
3089 actor.AddRenderer(renderer);
3090 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3091 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3092 application.GetScene().Add(actor);
3094 TestGlAbstraction& gl = application.GetGlAbstraction();
3095 TraceCallStack& drawTrace = gl.GetDrawTrace();
3097 drawTrace.Enable(true);
3098 drawTrace.EnableLogging(true);
3100 application.SendNotification();
3101 application.Render(0);
3103 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3104 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3106 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3107 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3108 textureSet = CreateTextureSet();
3109 renderer.SetTextures(textureSet);
3110 textureSet.SetTexture(0, texture);
3112 application.SendNotification();
3113 application.Render(0);
3115 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3116 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3121 int UtcDaliRendererOpacity(void)
3123 TestApplication application;
3125 tet_infoline("Test OPACITY property");
3127 Geometry geometry = CreateQuadGeometry();
3128 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3129 Renderer renderer = Renderer::New(geometry, shader);
3131 Actor actor = Actor::New();
3132 actor.AddRenderer(renderer);
3133 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3134 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3135 application.GetScene().Add(actor);
3137 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3139 DALI_TEST_CHECK(value.Get(opacity));
3140 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3142 application.SendNotification();
3143 application.Render();
3145 Vector4 actualValue;
3146 TestGlAbstraction& gl = application.GetGlAbstraction();
3147 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3148 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3150 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3152 application.SendNotification();
3153 application.Render();
3155 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3156 DALI_TEST_CHECK(value.Get(opacity));
3157 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3159 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3160 DALI_TEST_CHECK(value.Get(opacity));
3161 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3163 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3164 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3169 int UtcDaliRendererOpacityAnimation(void)
3171 TestApplication application;
3173 tet_infoline("Test OPACITY property animation");
3175 Geometry geometry = CreateQuadGeometry();
3176 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3177 Renderer renderer = Renderer::New(geometry, shader);
3179 Actor actor = Actor::New();
3180 actor.AddRenderer(renderer);
3181 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3182 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3183 application.GetScene().Add(actor);
3185 application.SendNotification();
3186 application.Render(0);
3188 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3190 DALI_TEST_CHECK(value.Get(opacity));
3191 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3193 Animation animation = Animation::New(1.0f);
3194 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3197 application.SendNotification();
3198 application.Render(1000);
3200 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3201 DALI_TEST_CHECK(value.Get(opacity));
3202 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3204 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3206 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3208 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3211 application.SendNotification();
3212 application.Render(1000);
3214 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3215 DALI_TEST_CHECK(value.Get(opacity));
3216 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3217 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3222 int UtcDaliRendererInvalidProperty(void)
3224 TestApplication application;
3226 tet_infoline("Test invalid property");
3228 Geometry geometry = CreateQuadGeometry();
3229 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3230 Renderer renderer = Renderer::New(geometry, shader);
3232 Actor actor = Actor::New();
3233 actor.AddRenderer(renderer);
3234 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3235 application.GetScene().Add(actor);
3237 application.SendNotification();
3238 application.Render(0);
3240 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3241 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3243 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3244 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3249 int UtcDaliRendererRenderingBehavior(void)
3251 TestApplication application;
3253 tet_infoline("Test RENDERING_BEHAVIOR property");
3255 Geometry geometry = CreateQuadGeometry();
3256 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3257 Renderer renderer = Renderer::New(geometry, shader);
3259 Actor actor = Actor::New();
3260 actor.AddRenderer(renderer);
3261 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3262 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3263 application.GetScene().Add(actor);
3265 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3266 int renderingBehavior;
3267 DALI_TEST_CHECK(value.Get(renderingBehavior));
3268 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3270 application.SendNotification();
3271 application.Render();
3273 uint32_t updateStatus = application.GetUpdateStatus();
3275 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3277 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3278 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3279 drawTrace.Enable(true);
3282 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3284 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3285 DALI_TEST_CHECK(value.Get(renderingBehavior));
3286 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3288 // Render 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 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3297 DALI_TEST_CHECK(value.Get(renderingBehavior));
3298 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3300 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3304 // Render again and check the update status
3305 application.SendNotification();
3306 application.Render();
3308 updateStatus = application.GetUpdateStatus();
3310 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3312 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3315 // Render again and check the update status
3316 Animation animation = Animation::New(1.0f);
3317 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3322 application.SendNotification();
3323 application.Render(0);
3325 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3329 application.SendNotification();
3330 application.Render(100);
3332 updateStatus = application.GetUpdateStatus();
3334 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3336 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3339 // Change rendering behavior
3340 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3342 // Render and check the update status
3343 application.SendNotification();
3344 application.Render();
3346 updateStatus = application.GetUpdateStatus();
3348 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3353 int UtcDaliRendererRegenerateUniformMap(void)
3355 TestApplication application;
3357 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3359 Geometry geometry = CreateQuadGeometry();
3360 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3361 Renderer renderer = Renderer::New(geometry, shader);
3363 Actor actor = Actor::New();
3364 actor.AddRenderer(renderer);
3365 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3366 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3367 application.GetScene().Add(actor);
3369 application.SendNotification();
3370 application.Render();
3372 actor.RemoveRenderer(renderer);
3373 shader = Shader::New("vertexSrc", "fragmentSrc");
3374 shader.RegisterProperty("opacity", 0.5f);
3375 renderer.SetShader(shader);
3377 Stage::GetCurrent().KeepRendering(1.0f);
3379 // Update for several frames
3380 application.SendNotification();
3381 application.Render();
3382 application.SendNotification();
3383 application.Render();
3384 application.SendNotification();
3385 application.Render();
3386 application.SendNotification();
3387 application.Render();
3390 actor.AddRenderer(renderer);
3391 application.SendNotification();
3392 application.Render();
3394 // Nothing to test here, the test must not crash
3395 auto updateStatus = application.GetUpdateStatus();
3396 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3401 int UtcDaliRendererAddDrawCommands(void)
3403 TestApplication application;
3405 tet_infoline("Test adding draw commands to the renderer");
3407 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3408 glAbstraction.EnableEnableDisableCallTrace(true);
3410 Geometry geometry = CreateQuadGeometry();
3411 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3412 Renderer renderer = Renderer::New(geometry, shader);
3414 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3415 Actor actor = Actor::New();
3416 actor.AddRenderer(renderer);
3417 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3418 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3419 application.GetScene().Add(actor);
3421 // Expect delivering a single draw call
3422 auto& drawTrace = glAbstraction.GetDrawTrace();
3424 drawTrace.Enable(true);
3425 application.SendNotification();
3426 application.Render();
3428 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3430 tet_infoline("\n\nTesting extension draw commands\n");
3431 tet_infoline("TEMPORARILY REMOVED. MUST PUT BACK!\n");
3432 #ifdef TEMPORARY_TEST_REMOVAL
3433 auto drawCommand1 = DevelRenderer::DrawCommand{};
3434 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3435 drawCommand1.firstIndex = 0;
3436 drawCommand1.elementCount = 2;
3437 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3439 auto drawCommand2 = DevelRenderer::DrawCommand{};
3440 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3441 drawCommand2.firstIndex = 2;
3442 drawCommand2.elementCount = 2;
3443 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3445 auto drawCommand3 = DevelRenderer::DrawCommand{};
3446 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3447 drawCommand3.firstIndex = 2;
3448 drawCommand3.elementCount = 2;
3449 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3451 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3452 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3453 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3456 drawTrace.Enable(true);
3457 application.SendNotification();
3458 application.Render();
3460 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3464 int UtcDaliRendererSetGeometryNegative(void)
3466 TestApplication application;
3467 Dali::Renderer instance;
3470 Dali::Geometry arg1;
3471 instance.SetGeometry(arg1);
3472 DALI_TEST_CHECK(false); // Should not get here
3476 DALI_TEST_CHECK(true); // We expect an assert
3481 int UtcDaliRendererSetTexturesNegative(void)
3483 TestApplication application;
3484 Dali::Renderer instance;
3487 Dali::TextureSet arg1;
3488 instance.SetTextures(arg1);
3489 DALI_TEST_CHECK(false); // Should not get here
3493 DALI_TEST_CHECK(true); // We expect an assert
3498 int UtcDaliRendererSetShaderNegative(void)
3500 TestApplication application;
3501 Dali::Renderer instance;
3505 instance.SetShader(arg1);
3506 DALI_TEST_CHECK(false); // Should not get here
3510 DALI_TEST_CHECK(true); // We expect an assert
3515 int UtcDaliRendererGetGeometryNegative(void)
3517 TestApplication application;
3518 Dali::Renderer instance;
3521 instance.GetGeometry();
3522 DALI_TEST_CHECK(false); // Should not get here
3526 DALI_TEST_CHECK(true); // We expect an assert
3531 int UtcDaliRendererGetTexturesNegative(void)
3533 TestApplication application;
3534 Dali::Renderer instance;
3537 instance.GetTextures();
3538 DALI_TEST_CHECK(false); // Should not get here
3542 DALI_TEST_CHECK(true); // We expect an assert
3547 int UtcDaliRendererGetShaderNegative(void)
3549 TestApplication application;
3550 Dali::Renderer instance;
3553 instance.GetShader();
3554 DALI_TEST_CHECK(false); // Should not get here
3558 DALI_TEST_CHECK(true); // We expect an assert
3563 int UtcDaliRendererCheckTextureBindingP(void)
3565 TestApplication application;
3567 tet_infoline("Test adding draw commands to the renderer");
3569 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3570 glAbstraction.EnableEnableDisableCallTrace(true);
3572 Geometry geometry = CreateQuadGeometry();
3573 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3574 Renderer renderer = Renderer::New(geometry, shader);
3576 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3577 Actor actor = Actor::New();
3578 actor.AddRenderer(renderer);
3579 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3580 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3581 application.GetScene().Add(actor);
3583 TestGraphicsController& graphics = application.GetGraphicsController();
3584 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3585 cmdBufCallstack.Enable(true);
3587 application.SendNotification();
3588 application.Render();
3590 DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3592 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3593 TextureSet textureSet0 = CreateTextureSet(image0);
3594 renderer.SetTextures(textureSet0);
3596 application.SendNotification();
3597 application.Render();
3599 DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));