2 * Copyright (c) 2022 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>
32 #include "test-graphics-command-buffer.h"
36 namespace // unnamed namespace
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
41 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
44 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
47 * @brief Get GL stencil test enumeration value as a string.
48 * @return The string representation of the value of GL_STENCIL_TEST
50 std::string GetStencilTestString(void)
52 std::stringstream stream;
53 stream << std::hex << GL_STENCIL_TEST;
58 * @brief Get GL depth test enumeration value as a string.
59 * @return The string representation of the value of GL_DEPTH_TEST
61 std::string GetDepthTestString(void)
63 std::stringstream stream;
64 stream << std::hex << GL_DEPTH_TEST;
68 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
70 glEnableDisableStack.Reset();
71 glStencilFunctionStack.Reset();
72 application.SendNotification();
76 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
81 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
83 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
84 TextureSet textureSet0 = CreateTextureSet(image0);
85 Renderer renderer0 = Renderer::New(geometry, shader);
86 renderer0.SetTextures(textureSet0);
87 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
88 actor.AddRenderer(renderer0);
92 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
94 Actor actor = Actor::New();
95 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
96 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
97 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
98 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
100 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
101 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
106 } // unnamed namespace
108 void renderer_test_startup(void)
110 test_return_value = TET_UNDEF;
113 void renderer_test_cleanup(void)
115 test_return_value = TET_PASS;
118 int UtcDaliRendererNew01(void)
120 TestApplication application;
122 Geometry geometry = CreateQuadGeometry();
123 Shader shader = CreateShader();
124 Renderer renderer = Renderer::New(geometry, shader);
126 DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
130 int UtcDaliRendererNew02(void)
132 TestApplication application;
134 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
138 int UtcDaliRendererCopyConstructor(void)
140 TestApplication application;
142 Geometry geometry = CreateQuadGeometry();
143 Shader shader = CreateShader();
144 Renderer renderer = Renderer::New(geometry, shader);
146 Renderer rendererCopy(renderer);
147 DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
152 int UtcDaliRendererAssignmentOperator(void)
154 TestApplication application;
156 Geometry geometry = CreateQuadGeometry();
157 Shader shader = CreateShader();
158 Renderer renderer = Renderer::New(geometry, shader);
161 DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
163 renderer2 = renderer;
164 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
168 int UtcDaliRendererMoveConstructor(void)
170 TestApplication application;
172 Geometry geometry = CreateQuadGeometry();
173 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
174 Renderer renderer = Renderer::New(geometry, shader);
175 DALI_TEST_CHECK(renderer);
176 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
177 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
179 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
180 application.SendNotification();
181 application.Render();
182 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
184 Renderer move = std::move(renderer);
185 DALI_TEST_CHECK(move);
186 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
188 DALI_TEST_CHECK(!renderer);
193 int UtcDaliRendererMoveAssignment(void)
195 TestApplication application;
197 Geometry geometry = CreateQuadGeometry();
198 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
199 Renderer renderer = Renderer::New(geometry, shader);
200 DALI_TEST_CHECK(renderer);
201 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
202 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
204 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
205 application.SendNotification();
206 application.Render();
207 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
210 move = std::move(renderer);
211 DALI_TEST_CHECK(move);
212 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
213 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
214 DALI_TEST_CHECK(!renderer);
219 int UtcDaliRendererDownCast01(void)
221 TestApplication application;
223 Geometry geometry = CreateQuadGeometry();
224 Shader shader = CreateShader();
225 Renderer renderer = Renderer::New(geometry, shader);
227 BaseHandle handle(renderer);
228 Renderer renderer2 = Renderer::DownCast(handle);
229 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
233 int UtcDaliRendererDownCast02(void)
235 TestApplication application;
237 Handle handle = Handle::New(); // Create a custom object
238 Renderer renderer = Renderer::DownCast(handle);
239 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
243 // using a template to auto deduce the parameter types
244 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
245 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
247 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
248 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
249 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
250 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
251 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
252 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
255 int UtcDaliRendererDefaultProperties(void)
257 TestApplication application;
258 /* from renderer-impl.cpp
259 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
260 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
261 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
262 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
263 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
264 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
265 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
266 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
267 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
268 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
269 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
270 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
271 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
272 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
273 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
274 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
275 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
276 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
277 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
278 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
279 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
280 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
281 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
282 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
283 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
284 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
285 DALI_PROPERTY( "blendEquation", INTEGER, true, false, false, Dali::DevelRenderer::Property::BLEND_EQUATION )
288 Geometry geometry = CreateQuadGeometry();
289 Shader shader = CreateShader();
290 Renderer renderer = Renderer::New(geometry, shader);
291 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27, TEST_LOCATION);
293 TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
294 TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
295 TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
296 TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
297 TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
298 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
299 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
300 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
301 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
302 TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
303 TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
304 TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
305 TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
306 TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
307 TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
308 TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
309 TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
310 TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
311 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
312 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
313 TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
314 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
315 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
316 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
317 TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
318 TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
319 TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
324 int UtcDaliRendererSetGetGeometry(void)
326 TestApplication application;
327 tet_infoline("Test SetGeometry, GetGeometry");
329 Geometry geometry1 = CreateQuadGeometry();
330 Geometry geometry2 = CreateQuadGeometry();
332 Shader shader = CreateShader();
333 Renderer renderer = Renderer::New(geometry1, shader);
334 Actor actor = Actor::New();
335 actor.AddRenderer(renderer);
336 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
337 application.GetScene().Add(actor);
339 application.SendNotification();
340 application.Render(0);
341 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
343 // Set geometry2 to the renderer
344 renderer.SetGeometry(geometry2);
346 application.SendNotification();
347 application.Render(0);
348 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
353 int UtcDaliRendererSetGetShader(void)
355 TestApplication application;
356 tet_infoline("Test SetShader, GetShader");
358 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
359 glAbstraction.EnableCullFaceCallTrace(true);
361 Shader shader1 = CreateShader();
362 shader1.RegisterProperty("uFadeColor", Color::RED);
364 Shader shader2 = CreateShader();
365 shader2.RegisterProperty("uFadeColor", Color::GREEN);
367 Geometry geometry = CreateQuadGeometry();
368 Renderer renderer = Renderer::New(geometry, shader1);
369 Actor actor = Actor::New();
370 actor.AddRenderer(renderer);
371 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
372 application.GetScene().Add(actor);
374 TestGlAbstraction& gl = application.GetGlAbstraction();
375 application.SendNotification();
376 application.Render(0);
378 // Expect that the first shaders's fade color property is accessed
379 Vector4 actualValue(Vector4::ZERO);
380 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
381 DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
383 DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
385 // set the second shader to the renderer
386 renderer.SetShader(shader2);
388 application.SendNotification();
389 application.Render(0);
391 // Expect that the second shader's fade color property is accessed
392 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
393 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
395 DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
400 int UtcDaliRendererSetGetDepthIndex(void)
402 TestApplication application;
404 tet_infoline("Test SetDepthIndex, GetDepthIndex");
406 Shader shader = CreateShader();
407 Geometry geometry = CreateQuadGeometry();
408 Renderer renderer = Renderer::New(geometry, shader);
409 Actor actor = Actor::New();
410 actor.AddRenderer(renderer);
411 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
412 application.GetScene().Add(actor);
414 application.SendNotification();
415 application.Render(0);
416 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
418 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
420 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
421 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
423 application.SendNotification();
424 application.Render(0);
425 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
427 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
429 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
430 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
432 application.SendNotification();
433 application.Render(0);
434 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
439 int UtcDaliRendererSetGetFaceCullingMode(void)
441 TestApplication application;
443 tet_infoline("Test SetFaceCullingMode(cullingMode)");
444 Geometry geometry = CreateQuadGeometry();
445 Shader shader = CreateShader();
446 Renderer renderer = Renderer::New(geometry, shader);
448 Actor actor = Actor::New();
449 actor.AddRenderer(renderer);
450 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
451 application.GetScene().Add(actor);
453 // By default, none of the faces should be culled
454 unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
455 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
457 TestGlAbstraction& gl = application.GetGlAbstraction();
458 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
459 gl.EnableCullFaceCallTrace(true);
462 cullFaceStack.Reset();
463 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
464 application.SendNotification();
465 application.Render();
467 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
469 std::ostringstream cullModeString;
470 cullModeString << std::hex << GL_FRONT_AND_BACK;
472 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
473 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
474 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
478 cullFaceStack.Reset();
479 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
480 application.SendNotification();
481 application.Render();
483 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
485 std::ostringstream cullModeString;
486 cullModeString << std::hex << GL_BACK;
488 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
489 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
490 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
494 cullFaceStack.Reset();
495 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
496 application.SendNotification();
497 application.Render();
499 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
501 std::ostringstream cullModeString;
502 cullModeString << std::hex << GL_FRONT;
504 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
505 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
506 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
510 cullFaceStack.Reset();
511 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
512 application.SendNotification();
513 application.Render();
515 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
516 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
517 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
523 int UtcDaliRendererBlendOptions01(void)
525 TestApplication application;
527 tet_infoline("Test BLEND_FACTOR properties ");
529 Geometry geometry = CreateQuadGeometry();
530 Shader shader = CreateShader();
531 Renderer renderer = Renderer::New(geometry, shader);
533 Actor actor = Actor::New();
534 // set a transparent actor color so that blending is enabled
535 actor.SetProperty(Actor::Property::OPACITY, 0.5f);
536 actor.AddRenderer(renderer);
537 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
538 application.GetScene().Add(actor);
540 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
541 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
542 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
543 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
545 // Test that Set was successful:
546 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
547 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
548 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
549 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
551 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
552 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
553 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
554 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
556 application.SendNotification();
557 application.Render();
559 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
561 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
562 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
563 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
564 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
569 int UtcDaliRendererBlendOptions02(void)
571 TestApplication application;
573 tet_infoline("Test BLEND_FACTOR properties ");
575 Geometry geometry = CreateQuadGeometry();
576 Shader shader = CreateShader();
577 Renderer renderer = Renderer::New(geometry, shader);
579 Actor actor = Actor::New();
580 actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
581 actor.AddRenderer(renderer);
582 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
583 application.GetScene().Add(actor);
585 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
586 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
587 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
588 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
590 // Test that Set was successful:
592 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
593 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
594 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
595 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
597 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
598 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
599 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
600 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
603 application.SendNotification();
604 application.Render();
606 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
607 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
608 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
609 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
610 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
615 int UtcDaliRendererBlendOptions03(void)
617 TestApplication application;
619 tet_infoline("Test GetBlendEquation() defaults ");
621 Geometry geometry = CreateQuadGeometry();
622 Shader shader = CreateShader();
623 Renderer renderer = Renderer::New(geometry, shader);
625 Actor actor = Actor::New();
626 actor.AddRenderer(renderer);
627 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
628 application.GetScene().Add(actor);
630 // Test the defaults as documented in blending.h
631 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
632 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
634 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
635 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
640 int UtcDaliRendererBlendOptions04(void)
642 TestApplication application;
644 tet_infoline("Test SetBlendEquation() ");
646 Geometry geometry = CreateQuadGeometry();
647 Shader shader = CreateShader();
648 Renderer renderer = Renderer::New(geometry, shader);
650 Actor actor = Actor::New();
651 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
652 actor.AddRenderer(renderer);
653 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
654 application.GetScene().Add(actor);
656 // Test the single blending equation setting
658 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
659 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
660 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
663 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
664 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
666 // Test that Set was successful
668 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
669 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
670 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
671 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
674 // Render & check GL commands
675 application.SendNotification();
676 application.Render();
678 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
679 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
680 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
685 int UtcDaliRendererBlendOptions05(void)
687 TestApplication application;
689 tet_infoline("Test SetAdvancedBlendEquation ");
691 Geometry geometry = CreateQuadGeometry();
692 Shader shader = CreateShader();
693 Renderer renderer = Renderer::New(geometry, shader);
695 Actor actor = Actor::New();
696 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
698 actor.AddRenderer(renderer);
699 actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
700 application.GetScene().Add(actor);
701 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
702 glAbstraction.EnableEnableDisableCallTrace(true);
704 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
706 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX);
707 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
708 DALI_TEST_EQUALS((int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION);
711 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
713 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
714 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
715 int equation = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
717 DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION);
718 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), true, TEST_LOCATION);
720 application.SendNotification();
721 application.Render();
724 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
725 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY))
727 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD);
728 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
729 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN);
730 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY);
731 int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_RGB);
732 int equationAlpha = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_ALPHA);
734 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION);
735 DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION);
736 DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), false, TEST_LOCATION);
738 application.SendNotification();
739 application.Render();
742 tet_infoline("Error Checking\n");
743 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY) &&
744 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
745 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::OVERLAY) &&
746 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DARKEN) &&
747 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LIGHTEN) &&
748 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_DODGE) &&
749 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_BURN) &&
750 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HARD_LIGHT) &&
751 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SOFT_LIGHT) &&
752 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DIFFERENCE) &&
753 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::EXCLUSION) &&
754 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HUE) &&
755 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SATURATION) &&
756 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR) &&
757 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LUMINOSITY))
759 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
760 DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
761 application.SendNotification();
762 application.Render();
763 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_MULTIPLY, TEST_LOCATION);
765 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
766 DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
767 application.SendNotification();
768 application.Render();
769 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SCREEN, TEST_LOCATION);
771 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
772 DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
773 application.SendNotification();
774 application.Render();
775 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_OVERLAY, TEST_LOCATION);
777 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
778 DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
779 application.SendNotification();
780 application.Render();
781 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DARKEN, TEST_LOCATION);
783 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
784 DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
785 application.SendNotification();
786 application.Render();
787 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_LIGHTEN, TEST_LOCATION);
789 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
790 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
791 application.SendNotification();
792 application.Render();
793 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORDODGE, TEST_LOCATION);
795 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
796 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
797 application.SendNotification();
798 application.Render();
799 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORBURN, TEST_LOCATION);
801 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
802 DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
803 application.SendNotification();
804 application.Render();
805 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HARDLIGHT, TEST_LOCATION);
807 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
808 DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
809 application.SendNotification();
810 application.Render();
811 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SOFTLIGHT, TEST_LOCATION);
813 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
814 DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
815 application.SendNotification();
816 application.Render();
817 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DIFFERENCE, TEST_LOCATION);
819 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
820 DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
821 application.SendNotification();
822 application.Render();
823 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_EXCLUSION, TEST_LOCATION);
825 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
826 DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
827 application.SendNotification();
828 application.Render();
829 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_HUE, TEST_LOCATION);
831 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
832 DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
833 application.SendNotification();
834 application.Render();
835 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_SATURATION, TEST_LOCATION);
837 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
838 DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
839 application.SendNotification();
840 application.Render();
841 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_COLOR, TEST_LOCATION);
843 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
844 DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
845 application.SendNotification();
846 application.Render();
847 DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_LUMINOSITY, TEST_LOCATION);
853 int UtcDaliRendererSetBlendMode01(void)
855 TestApplication application;
857 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
859 Geometry geometry = CreateQuadGeometry();
860 Shader shader = CreateShader();
861 Renderer renderer = Renderer::New(geometry, shader);
863 Actor actor = Actor::New();
864 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
865 actor.AddRenderer(renderer);
866 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
867 application.GetScene().Add(actor);
869 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
871 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
872 glAbstraction.EnableEnableDisableCallTrace(true);
874 application.SendNotification();
875 application.Render();
877 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
878 TraceCallStack::NamedParams params;
879 params["cap"] << std::hex << GL_BLEND;
880 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
885 int UtcDaliRendererSetBlendMode01b(void)
887 TestApplication application;
889 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
891 Geometry geometry = CreateQuadGeometry();
892 Shader shader = CreateShader();
893 Renderer renderer = Renderer::New(geometry, shader);
895 Actor actor = Actor::New();
896 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
897 actor.AddRenderer(renderer);
898 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
899 application.GetScene().Add(actor);
901 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
903 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
904 glAbstraction.EnableEnableDisableCallTrace(true);
905 glAbstraction.EnableDrawCallTrace(true);
907 application.SendNotification();
908 application.Render();
910 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
911 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
913 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
918 int UtcDaliRendererSetBlendMode02(void)
920 TestApplication application;
922 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
924 Geometry geometry = CreateQuadGeometry();
925 Shader shader = CreateShader();
926 Renderer renderer = Renderer::New(geometry, shader);
928 Actor actor = Actor::New();
929 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
930 actor.AddRenderer(renderer);
931 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
932 application.GetScene().Add(actor);
934 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
936 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
937 glAbstraction.EnableEnableDisableCallTrace(true);
939 application.SendNotification();
940 application.Render();
942 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
943 TraceCallStack::NamedParams params;
944 params["cap"] << std::hex << GL_BLEND;
945 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
950 int UtcDaliRendererSetBlendMode03(void)
952 TestApplication application;
954 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
956 Geometry geometry = CreateQuadGeometry();
957 Shader shader = CreateShader();
958 Renderer renderer = Renderer::New(geometry, shader);
960 Actor actor = Actor::New();
961 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
962 actor.AddRenderer(renderer);
963 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
964 application.GetScene().Add(actor);
966 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
968 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
969 glAbstraction.EnableEnableDisableCallTrace(true);
971 application.SendNotification();
972 application.Render();
974 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
975 TraceCallStack::NamedParams params;
976 params["cap"] << std::hex << GL_BLEND;
977 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
982 int UtcDaliRendererSetBlendMode04(void)
984 TestApplication application;
986 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
988 Geometry geometry = CreateQuadGeometry();
989 Shader shader = CreateShader();
990 Renderer renderer = Renderer::New(geometry, shader);
992 Actor actor = Actor::New();
993 actor.AddRenderer(renderer);
994 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
995 application.GetScene().Add(actor);
997 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
999 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1000 glAbstraction.EnableEnableDisableCallTrace(true);
1002 application.SendNotification();
1003 application.Render();
1005 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1006 TraceCallStack::NamedParams params;
1007 params["cap"] << std::hex << GL_BLEND;
1008 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1009 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1014 int UtcDaliRendererSetBlendMode04b(void)
1016 TestApplication application;
1018 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
1020 Geometry geometry = CreateQuadGeometry();
1021 Shader shader = CreateShader();
1022 Renderer renderer = Renderer::New(geometry, shader);
1024 Actor actor = Actor::New();
1025 actor.AddRenderer(renderer);
1026 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1027 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1028 application.GetScene().Add(actor);
1030 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1032 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1033 glAbstraction.EnableEnableDisableCallTrace(true);
1035 application.SendNotification();
1036 application.Render();
1038 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1039 TraceCallStack::NamedParams params;
1040 params["cap"] << std::hex << GL_BLEND;
1041 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1046 int UtcDaliRendererSetBlendMode04c(void)
1048 TestApplication application;
1050 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1052 Geometry geometry = CreateQuadGeometry();
1053 Shader shader = CreateShader();
1054 Renderer renderer = Renderer::New(geometry, shader);
1056 Actor actor = Actor::New();
1057 actor.AddRenderer(renderer);
1058 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1059 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1060 application.GetScene().Add(actor);
1062 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1064 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1065 glAbstraction.EnableEnableDisableCallTrace(true);
1067 application.SendNotification();
1068 application.Render();
1070 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1071 TraceCallStack::NamedParams params;
1072 params["cap"] << std::hex << GL_BLEND;
1073 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1074 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1079 int UtcDaliRendererSetBlendMode05(void)
1081 TestApplication application;
1083 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1085 Geometry geometry = CreateQuadGeometry();
1086 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1088 Shader shader = CreateShader();
1089 TextureSet textureSet = CreateTextureSet(image);
1090 Renderer renderer = Renderer::New(geometry, shader);
1091 renderer.SetTextures(textureSet);
1093 Actor actor = Actor::New();
1094 actor.AddRenderer(renderer);
1095 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1096 application.GetScene().Add(actor);
1098 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1100 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1101 glAbstraction.EnableEnableDisableCallTrace(true);
1103 application.SendNotification();
1104 application.Render();
1106 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1107 TraceCallStack::NamedParams params;
1108 params["cap"] << std::hex << GL_BLEND;
1109 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1114 int UtcDaliRendererSetBlendMode06(void)
1116 TestApplication application;
1117 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");
1119 Geometry geometry = CreateQuadGeometry();
1120 Shader shader = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1122 Renderer renderer = Renderer::New(geometry, shader);
1124 Actor actor = Actor::New();
1125 actor.AddRenderer(renderer);
1126 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1127 application.GetScene().Add(actor);
1129 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1131 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1132 glAbstraction.EnableEnableDisableCallTrace(true);
1134 application.SendNotification();
1135 application.Render();
1137 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1138 TraceCallStack::NamedParams params;
1139 params["cap"] << std::hex << GL_BLEND;
1140 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1145 int UtcDaliRendererSetBlendMode07(void)
1147 TestApplication application;
1148 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");
1150 Geometry geometry = CreateQuadGeometry();
1151 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1153 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1154 TextureSet textureSet = CreateTextureSet(image);
1155 Renderer renderer = Renderer::New(geometry, shader);
1156 renderer.SetTextures(textureSet);
1158 Actor actor = Actor::New();
1159 actor.AddRenderer(renderer);
1160 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1161 application.GetScene().Add(actor);
1163 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1165 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1166 glAbstraction.EnableEnableDisableCallTrace(true);
1168 application.SendNotification();
1169 application.Render();
1171 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1172 TraceCallStack::NamedParams params;
1173 params["cap"] << std::hex << GL_BLEND;
1174 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1179 int UtcDaliRendererSetBlendMode08(void)
1181 TestApplication application;
1183 tet_infoline("Test setting the blend mode to auto 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::AUTO);
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 UtcDaliRendererSetBlendMode08b(void)
1218 TestApplication application;
1220 tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1222 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1224 Geometry geometry = CreateQuadGeometry();
1225 Shader shader = CreateShader();
1226 Renderer renderer = Renderer::New(geometry, shader);
1228 Actor actor = Actor::New();
1229 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1230 actor.AddRenderer(renderer);
1231 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1232 application.GetScene().Add(actor);
1234 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1235 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1236 renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1238 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1239 glAbstraction.EnableEnableDisableCallTrace(true);
1241 application.SendNotification();
1242 application.Render();
1244 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1245 TraceCallStack::NamedParams params;
1246 params["cap"] << std::hex << GL_BLEND;
1247 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1253 int UtcDaliRendererSetBlendMode09(void)
1255 TestApplication application;
1257 tet_infoline("Test setting the blend mode to on_without_cull with an opaque color renders with blending enabled");
1259 Geometry geometry = CreateQuadGeometry();
1260 Shader shader = CreateShader();
1261 Renderer renderer = Renderer::New(geometry, shader);
1263 Actor actor = Actor::New();
1264 actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1265 actor.AddRenderer(renderer);
1266 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1267 application.GetScene().Add(actor);
1269 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1271 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1272 glAbstraction.EnableEnableDisableCallTrace(true);
1274 application.SendNotification();
1275 application.Render();
1277 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1278 TraceCallStack::NamedParams params;
1279 params["cap"] << std::hex << GL_BLEND;
1280 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1285 int UtcDaliRendererSetBlendMode09b(void)
1287 TestApplication application;
1289 tet_infoline("Test setting the blend mode to on_without_cull with an transparent color renders with blending enabled");
1291 Geometry geometry = CreateQuadGeometry();
1292 Shader shader = CreateShader();
1293 Renderer renderer = Renderer::New(geometry, shader);
1295 Actor actor = Actor::New();
1296 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
1297 actor.AddRenderer(renderer);
1298 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1299 application.GetScene().Add(actor);
1301 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1303 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1304 glAbstraction.EnableEnableDisableCallTrace(true);
1305 glAbstraction.EnableDrawCallTrace(true);
1307 application.SendNotification();
1308 application.Render();
1310 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1311 DALI_TEST_CHECK(glEnableStack.FindMethod("Enable"));
1313 DALI_TEST_CHECK(glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
1318 int UtcDaliRendererGetBlendMode(void)
1320 TestApplication application;
1322 tet_infoline("Test GetBlendMode()");
1324 Geometry geometry = CreateQuadGeometry();
1325 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1326 Renderer renderer = Renderer::New(geometry, shader);
1329 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1330 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1333 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1334 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1335 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1338 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1339 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1340 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1343 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1344 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1345 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON_WITHOUT_CULL, TEST_LOCATION);
1350 int UtcDaliRendererSetBlendColor(void)
1352 TestApplication application;
1354 tet_infoline("Test SetBlendColor(color)");
1356 Geometry geometry = CreateQuadGeometry();
1357 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1358 TextureSet textureSet = TextureSet::New();
1359 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1360 textureSet.SetTexture(0u, image);
1361 Renderer renderer = Renderer::New(geometry, shader);
1362 renderer.SetTextures(textureSet);
1364 Actor actor = Actor::New();
1365 actor.AddRenderer(renderer);
1366 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1367 application.GetScene().Add(actor);
1369 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1371 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1373 application.SendNotification();
1374 application.Render();
1376 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1377 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1378 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1380 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1382 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1383 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1385 application.SendNotification();
1386 application.Render();
1388 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1389 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1391 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1392 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1393 application.SendNotification();
1394 application.Render();
1395 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1400 int UtcDaliRendererGetBlendColor(void)
1402 TestApplication application;
1404 tet_infoline("Test GetBlendColor()");
1406 Geometry geometry = CreateQuadGeometry();
1407 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1408 Renderer renderer = Renderer::New(geometry, shader);
1410 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1412 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1413 application.SendNotification();
1414 application.Render();
1415 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1417 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1418 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1419 application.SendNotification();
1420 application.Render();
1421 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1426 int UtcDaliRendererPreMultipledAlpha(void)
1428 TestApplication application;
1430 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1432 Geometry geometry = CreateQuadGeometry();
1433 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1434 Renderer renderer = Renderer::New(geometry, shader);
1436 Actor actor = Actor::New();
1437 actor.AddRenderer(renderer);
1438 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1439 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1440 application.GetScene().Add(actor);
1442 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1443 bool preMultipliedAlpha;
1444 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1445 DALI_TEST_CHECK(!preMultipliedAlpha);
1447 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1448 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1449 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1450 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1452 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1453 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1454 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1455 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1457 application.SendNotification();
1458 application.Render();
1460 Vector4 actualValue(Vector4::ZERO);
1461 Vector4 actualActorColor(Vector4::ZERO);
1462 TestGlAbstraction& gl = application.GetGlAbstraction();
1463 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1464 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1465 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1466 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1468 // Enable pre-multiplied alpha
1469 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1471 application.SendNotification();
1472 application.Render();
1474 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1475 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1476 DALI_TEST_CHECK(preMultipliedAlpha);
1478 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1479 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1480 DALI_TEST_CHECK(preMultipliedAlpha);
1482 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1483 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1484 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1485 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1487 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1488 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1489 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1490 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1492 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1493 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1494 // Note : uActorColor doesn't premultiplied.
1495 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1496 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1498 // Disable pre-multiplied alpha again
1499 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1501 application.SendNotification();
1502 application.Render();
1504 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1505 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1506 DALI_TEST_CHECK(!preMultipliedAlpha);
1508 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1509 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1510 DALI_TEST_CHECK(!preMultipliedAlpha);
1512 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1513 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1514 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1515 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1517 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1518 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1519 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1520 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1522 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1523 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1524 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1525 DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1530 int UtcDaliRendererConstraint01(void)
1532 TestApplication application;
1534 tet_infoline("Test that a non-uniform renderer property can be constrained");
1536 Shader shader = Shader::New("VertexSource", "FragmentSource");
1537 Geometry geometry = CreateQuadGeometry();
1538 Renderer renderer = Renderer::New(geometry, shader);
1540 Actor actor = Actor::New();
1541 actor.AddRenderer(renderer);
1542 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1543 application.GetScene().Add(actor);
1545 Vector4 initialColor = Color::WHITE;
1546 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1548 application.SendNotification();
1549 application.Render(0);
1550 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1553 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1555 application.SendNotification();
1556 application.Render(0);
1558 // Expect no blue component in either buffer - yellow
1559 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1560 application.Render(0);
1561 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1563 renderer.RemoveConstraints();
1564 renderer.SetProperty(colorIndex, Color::WHITE);
1565 application.SendNotification();
1566 application.Render(0);
1567 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1572 int UtcDaliRendererConstraint02(void)
1574 TestApplication application;
1576 tet_infoline("Test that a uniform map renderer property can be constrained");
1578 Shader shader = Shader::New("VertexSource", "FragmentSource");
1579 Geometry geometry = CreateQuadGeometry();
1580 Renderer renderer = Renderer::New(geometry, shader);
1582 Actor actor = Actor::New();
1583 actor.AddRenderer(renderer);
1584 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1585 application.GetScene().Add(actor);
1586 application.SendNotification();
1587 application.Render(0);
1589 Vector4 initialColor = Color::WHITE;
1590 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1592 TestGlAbstraction& gl = application.GetGlAbstraction();
1594 application.SendNotification();
1595 application.Render(0);
1597 Vector4 actualValue(Vector4::ZERO);
1598 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1599 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1602 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1604 application.SendNotification();
1605 application.Render(0);
1607 // Expect no blue component in either buffer - yellow
1608 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1609 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1611 application.Render(0);
1612 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1613 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1615 renderer.RemoveConstraints();
1616 renderer.SetProperty(colorIndex, Color::WHITE);
1617 application.SendNotification();
1618 application.Render(0);
1620 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1621 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1626 int UtcDaliRendererAnimatedProperty01(void)
1628 TestApplication application;
1630 tet_infoline("Test that a non-uniform renderer property can be animated");
1632 Shader shader = Shader::New("VertexSource", "FragmentSource");
1633 Geometry geometry = CreateQuadGeometry();
1634 Renderer renderer = Renderer::New(geometry, shader);
1636 Actor actor = Actor::New();
1637 actor.AddRenderer(renderer);
1638 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1639 application.GetScene().Add(actor);
1641 Vector4 initialColor = Color::WHITE;
1642 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1644 application.SendNotification();
1645 application.Render(0);
1646 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1648 Animation animation = Animation::New(1.0f);
1649 KeyFrames keyFrames = KeyFrames::New();
1650 keyFrames.Add(0.0f, initialColor);
1651 keyFrames.Add(1.0f, Color::TRANSPARENT);
1652 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1655 application.SendNotification();
1656 application.Render(500);
1658 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1660 application.Render(500);
1662 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1667 int UtcDaliRendererAnimatedProperty02(void)
1669 TestApplication application;
1671 tet_infoline("Test that a uniform map renderer property can be animated");
1673 Shader shader = Shader::New("VertexSource", "FragmentSource");
1674 Geometry geometry = CreateQuadGeometry();
1675 Renderer renderer = Renderer::New(geometry, shader);
1677 Actor actor = Actor::New();
1678 actor.AddRenderer(renderer);
1679 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1680 application.GetScene().Add(actor);
1681 application.SendNotification();
1682 application.Render(0);
1684 Vector4 initialColor = Color::WHITE;
1685 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1687 TestGlAbstraction& gl = application.GetGlAbstraction();
1689 application.SendNotification();
1690 application.Render(0);
1692 Vector4 actualValue(Vector4::ZERO);
1693 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1694 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1696 Animation animation = Animation::New(1.0f);
1697 KeyFrames keyFrames = KeyFrames::New();
1698 keyFrames.Add(0.0f, initialColor);
1699 keyFrames.Add(1.0f, Color::TRANSPARENT);
1700 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1703 application.SendNotification();
1704 application.Render(500);
1706 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1707 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1709 application.Render(500);
1710 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1711 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1716 int UtcDaliRendererUniformMapPrecendence01(void)
1718 TestApplication application;
1720 tet_infoline("Test the uniform map precedence is applied properly");
1722 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1724 Shader shader = Shader::New("VertexSource", "FragmentSource");
1725 TextureSet textureSet = CreateTextureSet(image);
1727 Geometry geometry = CreateQuadGeometry();
1728 Renderer renderer = Renderer::New(geometry, shader);
1729 renderer.SetTextures(textureSet);
1731 Actor actor = Actor::New();
1732 actor.AddRenderer(renderer);
1733 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1734 application.GetScene().Add(actor);
1735 application.SendNotification();
1736 application.Render(0);
1738 renderer.RegisterProperty("uFadeColor", Color::RED);
1739 actor.RegisterProperty("uFadeColor", Color::GREEN);
1740 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1742 TestGlAbstraction& gl = application.GetGlAbstraction();
1744 application.SendNotification();
1745 application.Render(0);
1747 // Expect that the actor's fade color property is accessed
1748 Vector4 actualValue(Vector4::ZERO);
1749 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1750 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1752 // Animate shader's fade color property. Should be no change to uniform
1753 Animation animation = Animation::New(1.0f);
1754 KeyFrames keyFrames = KeyFrames::New();
1755 keyFrames.Add(0.0f, Color::WHITE);
1756 keyFrames.Add(1.0f, Color::TRANSPARENT);
1757 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1760 application.SendNotification();
1761 application.Render(500);
1763 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1764 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1766 application.Render(500);
1767 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1768 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1773 int UtcDaliRendererUniformMapPrecendence02(void)
1775 TestApplication application;
1777 tet_infoline("Test the uniform map precedence is applied properly");
1779 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1781 Shader shader = Shader::New("VertexSource", "FragmentSource");
1782 TextureSet textureSet = CreateTextureSet(image);
1784 Geometry geometry = CreateQuadGeometry();
1785 Renderer renderer = Renderer::New(geometry, shader);
1786 renderer.SetTextures(textureSet);
1788 Actor actor = Actor::New();
1789 actor.AddRenderer(renderer);
1790 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1791 application.GetScene().Add(actor);
1792 application.SendNotification();
1793 application.Render(0);
1795 // Don't add property / uniform map to renderer
1796 actor.RegisterProperty("uFadeColor", Color::GREEN);
1797 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1799 TestGlAbstraction& gl = application.GetGlAbstraction();
1801 application.SendNotification();
1802 application.Render(0);
1804 // Expect that the actor's fade color property is accessed
1805 Vector4 actualValue(Vector4::ZERO);
1806 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1807 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1809 // Animate texture set's fade color property. Should be no change to uniform
1810 Animation animation = Animation::New(1.0f);
1811 KeyFrames keyFrames = KeyFrames::New();
1812 keyFrames.Add(0.0f, Color::WHITE);
1813 keyFrames.Add(1.0f, Color::TRANSPARENT);
1814 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1817 application.SendNotification();
1818 application.Render(500);
1820 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1821 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1823 application.Render(500);
1824 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1825 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1830 int UtcDaliRendererUniformMapPrecendence03(void)
1832 TestApplication application;
1834 tet_infoline("Test the uniform map precedence is applied properly");
1836 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1838 Shader shader = Shader::New("VertexSource", "FragmentSource");
1839 TextureSet textureSet = CreateTextureSet(image);
1841 Geometry geometry = CreateQuadGeometry();
1842 Renderer renderer = Renderer::New(geometry, shader);
1843 renderer.SetTextures(textureSet);
1845 Actor actor = Actor::New();
1846 actor.AddRenderer(renderer);
1847 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1848 application.GetScene().Add(actor);
1849 application.SendNotification();
1850 application.Render(0);
1852 // Don't add property / uniform map to renderer or actor
1853 shader.RegisterProperty("uFadeColor", Color::BLACK);
1855 TestGlAbstraction& gl = application.GetGlAbstraction();
1857 application.SendNotification();
1858 application.Render(0);
1860 // Expect that the shader's fade color property is accessed
1861 Vector4 actualValue(Vector4::ZERO);
1862 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1863 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1868 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1870 TestApplication application;
1872 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1874 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1876 Shader shader = Shader::New("VertexSource", "FragmentSource");
1877 TextureSet textureSet = CreateTextureSet(image);
1879 Geometry geometry = CreateQuadGeometry();
1880 Renderer renderer = Renderer::New(geometry, shader);
1881 renderer.SetTextures(textureSet);
1883 Actor actor = Actor::New();
1884 actor.AddRenderer(renderer);
1885 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1886 application.GetScene().Add(actor);
1887 application.SendNotification();
1888 application.Render(0);
1890 renderer.RegisterProperty("uUniform1", Color::RED);
1891 actor.RegisterProperty("uUniform2", Color::GREEN);
1892 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1894 TestGlAbstraction& gl = application.GetGlAbstraction();
1896 application.SendNotification();
1897 application.Render(0);
1899 // Expect that each of the object's uniforms are set
1900 Vector4 uniform1Value(Vector4::ZERO);
1901 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1902 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1904 Vector4 uniform2Value(Vector4::ZERO);
1905 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1906 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1908 Vector4 uniform3Value(Vector4::ZERO);
1909 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1910 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1915 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1917 TestApplication application;
1919 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1921 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1923 Shader shader = Shader::New("VertexSource", "FragmentSource");
1924 TextureSet textureSet = CreateTextureSet(image);
1926 Geometry geometry = CreateQuadGeometry();
1927 Renderer renderer = Renderer::New(geometry, shader);
1928 renderer.SetTextures(textureSet);
1930 Actor actor = Actor::New();
1931 actor.AddRenderer(renderer);
1932 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1933 application.GetScene().Add(actor);
1934 application.SendNotification();
1935 application.Render(0);
1937 Property::Value value1(Color::RED);
1938 renderer.RegisterProperty("uFadeColor", value1);
1940 Property::Value value2(1.0f);
1941 actor.RegisterProperty("uFadeProgress", value2);
1943 Property::Value value3(Matrix3::IDENTITY);
1944 shader.RegisterProperty("uANormalMatrix", value3);
1946 TestGlAbstraction& gl = application.GetGlAbstraction();
1948 application.SendNotification();
1949 application.Render(0);
1951 // Expect that each of the object's uniforms are set
1952 Vector4 uniform1Value(Vector4::ZERO);
1953 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1954 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1956 float uniform2Value(0.0f);
1957 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1958 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1960 Matrix3 uniform3Value;
1961 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1962 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1967 int UtcDaliRendererRenderOrder2DLayer(void)
1969 TestApplication application;
1970 tet_infoline("Test the rendering order in a 2D layer is correct");
1972 Shader shader = Shader::New("VertexSource", "FragmentSource");
1973 Geometry geometry = CreateQuadGeometry();
1975 Actor root = application.GetScene().GetRootLayer();
1977 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1978 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1980 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1981 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1983 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1984 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1986 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1987 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1989 application.SendNotification();
1990 application.Render(0);
1993 * Create the following hierarchy:
2006 * Expected rendering order : actor2 - actor1 - actor0 - actor3
2011 application.SendNotification();
2012 application.Render(0);
2014 TestGlAbstraction& gl = application.GetGlAbstraction();
2015 gl.GetTextureTrace().Reset();
2016 gl.EnableTextureCallTrace(true);
2017 application.SendNotification();
2018 application.Render(0);
2020 int textureBindIndex[4];
2021 for(unsigned int i(0); i < 4; ++i)
2023 std::stringstream params;
2024 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2025 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2028 //Check that actor1 has been rendered after actor2
2029 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
2031 //Check that actor0 has been rendered after actor1
2032 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2034 //Check that actor3 has been rendered after actor0
2035 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2040 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
2042 TestApplication application;
2043 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
2046 * Creates the following hierarchy:
2048 * actor0------------------------>actor1
2052 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
2054 * renderer0 has depth index 2
2055 * renderer1 has depth index 0
2056 * renderer2 has depth index 1
2058 * renderer3 has depth index 1
2059 * renderer4 has depth index 0
2060 * renderer5 has depth index -1
2062 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
2065 Shader shader = Shader::New("VertexSource", "FragmentSource");
2066 Geometry geometry = CreateQuadGeometry();
2068 Actor root = application.GetScene().GetRootLayer();
2070 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2071 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
2072 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2073 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2074 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
2075 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2076 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
2077 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
2079 application.SendNotification();
2080 application.Render(0);
2082 TestGlAbstraction& gl = application.GetGlAbstraction();
2083 gl.GetTextureTrace().Reset();
2084 gl.EnableTextureCallTrace(true);
2085 application.SendNotification();
2086 application.Render(0);
2088 int textureBindIndex[6];
2089 for(unsigned int i(0); i < 6; ++i)
2091 std::stringstream params;
2092 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2093 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2096 //Check that renderer3 has been rendered after renderer4
2097 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
2099 //Check that renderer0 has been rendered after renderer2
2100 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
2102 //Check that renderer5 has been rendered after renderer2
2103 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
2105 //Check that renderer0 has been rendered after renderer2
2106 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
2108 //Check that renderer2 has been rendered after renderer1
2109 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
2114 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2116 TestApplication application;
2117 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2120 * Creates the following hierarchy:
2128 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
2132 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
2133 * DI:2 DI:0 | DI:0 DI:1 DI:2
2138 * actor0 has sibling order 1
2139 * actor1 has sibling order 0
2140 * actor2 has sibling order 0
2142 * renderer0 has depth index 2
2143 * renderer1 has depth index 0
2145 * renderer2 has depth index 0
2146 * renderer3 has depth index 1
2147 * renderer4 has depth index 2
2149 * renderer5 has depth index -1
2151 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2154 Shader shader = Shader::New("VertexSource", "FragmentSource");
2155 Geometry geometry = CreateQuadGeometry();
2156 Actor root = application.GetScene().GetRootLayer();
2157 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
2158 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2159 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
2161 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2162 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2163 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2164 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2165 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2166 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2168 application.SendNotification();
2169 application.Render();
2171 TestGlAbstraction& gl = application.GetGlAbstraction();
2172 gl.GetTextureTrace().Reset();
2173 gl.EnableTextureCallTrace(true);
2174 application.SendNotification();
2175 application.Render(0);
2177 int textureBindIndex[6];
2178 for(unsigned int i(0); i < 6; ++i)
2180 std::stringstream params;
2181 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2182 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2185 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2186 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2187 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2188 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2189 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2190 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2192 // Change sibling order of actor1
2193 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2194 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2196 gl.GetTextureTrace().Reset();
2197 application.SendNotification();
2198 application.Render(0);
2200 for(unsigned int i(0); i < 6; ++i)
2202 std::stringstream params;
2203 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2204 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2207 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2208 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2209 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2210 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2211 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2212 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2217 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2219 TestApplication application;
2220 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2222 Shader shader = Shader::New("VertexSource", "FragmentSource");
2223 Geometry geometry = CreateQuadGeometry();
2224 Actor root = application.GetScene().GetRootLayer();
2227 * Create the following hierarchy:
2234 * (Overlay) (Regular actor)
2244 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2247 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2248 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2249 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2251 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2252 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2253 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2255 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
2256 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2258 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2259 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2260 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2262 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
2263 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2265 application.SendNotification();
2266 application.Render(0);
2273 TestGlAbstraction& gl = application.GetGlAbstraction();
2274 gl.GetTextureTrace().Reset();
2275 gl.EnableTextureCallTrace(true);
2276 application.SendNotification();
2277 application.Render(0);
2279 int textureBindIndex[5];
2280 for(unsigned int i(0); i < 5; ++i)
2282 std::stringstream params;
2283 params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2284 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2287 //Check that actor4 has been rendered after actor2
2288 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2290 //Check that actor1 has been rendered after actor4
2291 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2293 //Check that actor0 has been rendered after actor1
2294 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2296 //Check that actor3 has been rendered after actor0
2297 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2302 int UtcDaliRendererSetIndexRange(void)
2306 "attribute vec2 aPosition;\n"
2309 " gl_Position = aPosition;\n"
2314 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2317 TestApplication application;
2318 tet_infoline("Test setting the range of indices to draw");
2320 TestGlAbstraction& gl = application.GetGlAbstraction();
2321 gl.EnableDrawCallTrace(true);
2323 Actor actor = Actor::New();
2324 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2327 Geometry geometry = Geometry::New();
2328 geometry.SetType(Geometry::LINE_LOOP);
2330 // --------------------------------------------------------------------------
2332 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2342 9, // offset = 5, count = 10
2348 1}; // offset = 15, count = 6 // line strip
2350 // --------------------------------------------------------------------------
2359 {Vector2(0.0f, 1.00f)},
2360 {Vector2(0.0f, -1.00f)},
2361 {Vector2(-0.95f, 0.31f)},
2362 {Vector2(0.59f, 0.81f)},
2363 {Vector2(-0.59f, -0.81f)},
2364 {Vector2(-0.95f, -0.31f)},
2365 {Vector2(0.59f, -0.81f)},
2366 {Vector2(0.95f, -0.31f)},
2367 {Vector2(0.95f, 0.31f)},
2368 {Vector2(-0.59f, 0.81f)},
2370 Property::Map vertexFormat;
2371 vertexFormat["aPosition"] = Property::VECTOR2;
2372 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2373 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2375 // --------------------------------------------------------------------------
2376 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2377 geometry.AddVertexBuffer(vertexBuffer);
2380 Shader shader = Shader::New(vertexShader, fragmentShader);
2381 Renderer renderer = Renderer::New(geometry, shader);
2382 actor.AddRenderer(renderer);
2384 Integration::Scene scene = application.GetScene();
2389 // LINE_LOOP, first 0, count 5
2391 renderer.SetIndexRange(0, 5);
2392 application.SendNotification();
2393 application.Render();
2395 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2397 DALI_TEST_CHECK(value.Get(convertedValue));
2398 DALI_TEST_CHECK(convertedValue == 0);
2400 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2401 DALI_TEST_CHECK(value.Get(convertedValue));
2402 DALI_TEST_CHECK(convertedValue == 0);
2404 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2405 DALI_TEST_CHECK(value.Get(convertedValue));
2406 DALI_TEST_CHECK(convertedValue == 5);
2408 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2409 DALI_TEST_CHECK(value.Get(convertedValue));
2410 DALI_TEST_CHECK(convertedValue == 5);
2412 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2413 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2414 DALI_TEST_CHECK(result);
2417 // LINE_LOOP, first 5, count 10
2419 renderer.SetIndexRange(5, 10);
2420 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2421 application.SendNotification();
2422 application.Render();
2423 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2424 DALI_TEST_CHECK(result);
2427 // LINE_STRIP, first 15, count 6
2429 renderer.SetIndexRange(15, 6);
2430 geometry.SetType(Geometry::LINE_STRIP);
2431 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2432 application.SendNotification();
2433 application.Render();
2434 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2435 DALI_TEST_CHECK(result);
2438 // Index out of bounds
2440 renderer.SetIndexRange(15, 30);
2441 geometry.SetType(Geometry::LINE_STRIP);
2442 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2443 application.SendNotification();
2444 application.Render();
2445 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2446 DALI_TEST_CHECK(result);
2449 // drawing whole buffer starting from 15 ( last valid primitive )
2451 renderer.SetIndexRange(15, 0);
2452 geometry.SetType(Geometry::LINE_STRIP);
2453 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2454 application.SendNotification();
2455 application.Render();
2456 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2457 DALI_TEST_CHECK(result);
2463 int UtcDaliRendererSetDepthFunction(void)
2465 TestApplication application;
2467 tet_infoline("Test setting the depth function");
2469 Geometry geometry = CreateQuadGeometry();
2470 Shader shader = CreateShader();
2471 Renderer renderer = Renderer::New(geometry, shader);
2473 Actor actor = Actor::New();
2474 actor.AddRenderer(renderer);
2475 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2476 Integration::Scene scene = application.GetScene();
2477 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2480 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2481 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2482 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2484 glEnableDisableStack.Enable(true);
2485 glDepthFunctionStack.Enable(true);
2486 glEnableDisableStack.EnableLogging(true);
2487 glDepthFunctionStack.EnableLogging(true);
2489 std::ostringstream depthTestStr;
2490 depthTestStr << std::hex << GL_DEPTH_TEST;
2494 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2496 glEnableDisableStack.Reset();
2497 glDepthFunctionStack.Reset();
2498 application.SendNotification();
2499 application.Render();
2501 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2502 std::ostringstream depthFunctionStr;
2503 depthFunctionStr << std::hex << GL_NEVER;
2504 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2509 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2511 glDepthFunctionStack.Reset();
2512 application.SendNotification();
2513 application.Render();
2515 std::ostringstream depthFunctionStr;
2516 depthFunctionStr << std::hex << GL_ALWAYS;
2517 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2522 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2524 glDepthFunctionStack.Reset();
2525 application.SendNotification();
2526 application.Render();
2528 std::ostringstream depthFunctionStr;
2529 depthFunctionStr << std::hex << GL_LESS;
2530 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2535 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2537 glDepthFunctionStack.Reset();
2538 application.SendNotification();
2539 application.Render();
2541 std::ostringstream depthFunctionStr;
2542 depthFunctionStr << std::hex << GL_GREATER;
2543 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2548 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2550 glDepthFunctionStack.Reset();
2551 application.SendNotification();
2552 application.Render();
2554 std::ostringstream depthFunctionStr;
2555 depthFunctionStr << std::hex << GL_EQUAL;
2556 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2561 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2563 glDepthFunctionStack.Reset();
2564 application.SendNotification();
2565 application.Render();
2567 std::ostringstream depthFunctionStr;
2568 depthFunctionStr << std::hex << GL_NOTEQUAL;
2569 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2574 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2576 glDepthFunctionStack.Reset();
2577 application.SendNotification();
2578 application.Render();
2580 std::ostringstream depthFunctionStr;
2581 depthFunctionStr << std::hex << GL_LEQUAL;
2582 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2587 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2589 glDepthFunctionStack.Reset();
2590 application.SendNotification();
2591 application.Render();
2593 std::ostringstream depthFunctionStr;
2594 depthFunctionStr << std::hex << GL_GEQUAL;
2595 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2602 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2603 * The checks performed are as follows:
2604 * - Check the initial/default value.
2605 * - Set a different value via enum.
2606 * - Check it was set.
2607 * - Set a different value via string.
2608 * - Check it was set.
2610 template<typename T>
2611 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2613 application.SendNotification();
2614 application.Render();
2616 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2617 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2618 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2619 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2620 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2622 application.SendNotification();
2623 application.Render();
2625 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2626 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2628 renderer.SetProperty(propertyIndex, secondCheckString);
2629 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2630 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2632 application.SendNotification();
2633 application.Render();
2635 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2636 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2639 int UtcDaliRendererEnumProperties(void)
2641 TestApplication application;
2642 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2644 Geometry geometry = CreateQuadGeometry();
2645 Shader shader = CreateShader();
2646 Renderer renderer = Renderer::New(geometry, shader);
2648 Actor actor = Actor::New();
2649 actor.AddRenderer(renderer);
2650 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2651 application.GetScene().Add(actor);
2654 * Here we use a templatized function to perform several checks on each enumeration property.
2655 * @see CheckEnumerationProperty for details of the checks performed.
2658 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2659 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2660 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2661 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2662 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2663 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2664 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2665 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2666 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2667 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2668 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2669 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2670 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2671 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2672 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2673 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2675 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2676 Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2678 application.SendNotification();
2679 application.Render();
2680 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2683 if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2685 application.SendNotification();
2686 application.Render();
2687 CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2693 Renderer RendererTestFixture(TestApplication& application)
2695 Geometry geometry = CreateQuadGeometry();
2696 Shader shader = CreateShader();
2697 Renderer renderer = Renderer::New(geometry, shader);
2699 Actor actor = Actor::New();
2700 actor.AddRenderer(renderer);
2701 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2702 Integration::Scene scene = application.GetScene();
2703 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2709 int UtcDaliRendererSetDepthTestMode(void)
2711 TestApplication application;
2712 tet_infoline("Test setting the DepthTestMode");
2714 Renderer renderer = RendererTestFixture(application);
2715 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2716 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2717 glEnableDisableStack.Enable(true);
2718 glEnableDisableStack.EnableLogging(true);
2720 glEnableDisableStack.Reset();
2721 application.SendNotification();
2722 application.Render();
2724 // Check depth-test is enabled by default.
2725 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2726 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2728 // 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.
2729 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2730 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2732 glEnableDisableStack.Reset();
2733 application.SendNotification();
2734 application.Render();
2736 // Check the depth buffer was disabled.
2737 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2739 // Turn on automatic mode depth-testing.
2740 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2741 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2743 glEnableDisableStack.Reset();
2744 application.SendNotification();
2745 application.Render();
2747 // Check depth-test is now enabled.
2748 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2749 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2751 // Change the layer behavior to LAYER_UI.
2752 // Note this will also disable depth testing for the layer by default, we test this first.
2753 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2755 glEnableDisableStack.Reset();
2756 application.SendNotification();
2757 application.Render();
2759 // Check depth-test is disabled.
2760 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2762 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2763 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2765 glEnableDisableStack.Reset();
2766 application.SendNotification();
2767 application.Render();
2769 // Check depth-test is *still* disabled.
2770 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2775 int UtcDaliRendererSetDepthWriteMode(void)
2777 TestApplication application;
2778 tet_infoline("Test setting the DepthWriteMode");
2780 Renderer renderer = RendererTestFixture(application);
2781 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2783 application.SendNotification();
2784 application.Render();
2786 // Check the default depth-write status first.
2787 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2789 // Turn off depth-writing.
2790 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2792 application.SendNotification();
2793 application.Render();
2795 // Check depth-write is now disabled.
2796 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2798 // Test the AUTO mode for depth-writing.
2799 // As our renderer is opaque, depth-testing should be enabled.
2800 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2802 application.SendNotification();
2803 application.Render();
2805 // Check depth-write is now enabled.
2806 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2808 // Now make the renderer be treated as translucent by enabling blending.
2809 // The AUTO depth-write mode should turn depth-write off in this scenario.
2810 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2812 application.SendNotification();
2813 application.Render();
2815 // Check depth-write is now disabled.
2816 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2821 int UtcDaliRendererCheckStencilDefaults(void)
2823 TestApplication application;
2824 tet_infoline("Test the stencil defaults");
2826 Renderer renderer = RendererTestFixture(application);
2827 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2828 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2829 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2830 glEnableDisableStack.Enable(true);
2831 glEnableDisableStack.EnableLogging(true);
2832 glStencilFunctionStack.Enable(true);
2833 glStencilFunctionStack.EnableLogging(true);
2835 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2837 // Check the defaults:
2838 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2839 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2840 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2841 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2842 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2843 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);
2844 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);
2849 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2851 TestApplication application;
2852 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2854 Renderer renderer = RendererTestFixture(application);
2855 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2856 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2857 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2858 glEnableDisableStack.Enable(true);
2859 glEnableDisableStack.EnableLogging(true);
2860 glStencilFunctionStack.Enable(true);
2861 glStencilFunctionStack.EnableLogging(true);
2863 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2864 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2865 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2866 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2868 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2869 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2871 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2872 std::string methodString("StencilFunc");
2873 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2875 // Test the other RenderModes that will not enable the stencil buffer.
2876 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2877 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2878 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2880 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2881 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2882 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2884 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2885 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2886 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2888 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2889 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2891 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2892 // First set a mode to turn off the stencil buffer, so the enable is required.
2893 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2894 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2895 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2896 // Set a different stencil function as the last one is cached.
2897 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2898 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2900 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2901 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2906 // Helper function for the SetRenderModeToUseColorBuffer test.
2907 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2909 // Set the RenderMode property to a value that should not allow color buffer writes.
2910 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2911 application.SendNotification();
2912 application.Render();
2914 // Check if ColorMask has been called, and that the values are correct.
2915 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2916 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2918 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2919 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2920 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2921 // @todo Only check alpha if framebuffer supports it.
2922 //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2925 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2927 TestApplication application;
2928 tet_infoline("Test setting the RenderMode to use the color buffer");
2930 Renderer renderer = RendererTestFixture(application);
2932 // Set the RenderMode property to a value that should not allow color buffer writes.
2933 // Then check if ColorMask has been called, and that the values are correct.
2934 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2935 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2936 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2937 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2938 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2943 int UtcDaliRendererSetStencilFunction(void)
2945 TestApplication application;
2946 tet_infoline("Test setting the StencilFunction");
2948 Renderer renderer = RendererTestFixture(application);
2949 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2950 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2951 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2952 glEnableDisableStack.Enable(true);
2953 glEnableDisableStack.EnableLogging(true);
2954 glStencilFunctionStack.Enable(true);
2955 glStencilFunctionStack.EnableLogging(true);
2957 // RenderMode must use the stencil for StencilFunction to operate.
2958 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2959 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2962 * Lookup table for testing StencilFunction.
2963 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2965 const int StencilFunctionLookupTable[] = {
2974 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2977 * Loop through all types of StencilFunction, checking:
2978 * - The value is cached (set in event thread side)
2979 * - Causes "glStencilFunc" to be called
2980 * - Checks the correct parameters to "glStencilFunc" were used
2982 std::string nonChangingParameters = "0, 255";
2983 std::string methodString("StencilFunc");
2984 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2986 // Set the property.
2987 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2989 // Check GetProperty returns the same value.
2990 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2992 // Reset the trace debug.
2993 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2995 // Check the function is called and the parameters are correct.
2996 std::stringstream parameterStream;
2997 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2999 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3002 // Change the Function Reference only and check the behavior is correct:
3003 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
3004 int testValueReference = 170;
3005 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
3007 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3009 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3011 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3013 std::stringstream parameterStream;
3014 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
3016 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3018 // Change the Function Mask only and check the behavior is correct:
3019 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
3020 int testValueMask = 85;
3021 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
3023 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3025 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3027 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3029 // Clear the stringstream.
3030 parameterStream.str(std::string());
3031 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
3033 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3038 int UtcDaliRendererSetStencilOperation(void)
3040 TestApplication application;
3041 tet_infoline("Test setting the StencilOperation");
3043 Renderer renderer = RendererTestFixture(application);
3044 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3045 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3046 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3047 glEnableDisableStack.Enable(true);
3048 glEnableDisableStack.EnableLogging(true);
3049 glStencilFunctionStack.Enable(true);
3050 glStencilFunctionStack.EnableLogging(true);
3052 // RenderMode must use the stencil for StencilOperation to operate.
3053 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3056 * Lookup table for testing StencilOperation.
3057 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3059 const int StencilOperationLookupTable[] = {
3068 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3070 // Set all 3 StencilOperation properties to a default.
3071 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3072 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3073 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3075 // Set our expected parameter list to the equivalent result.
3076 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3078 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3081 * Loop through all types of StencilOperation, checking:
3082 * - The value is cached (set in event thread side)
3083 * - Causes "glStencilFunc" to be called
3084 * - Checks the correct parameters to "glStencilFunc" were used
3085 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3087 std::string methodString("StencilOp");
3089 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3091 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3093 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3095 // Set the property (outer loop causes all 3 different properties to be set separately).
3096 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3097 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3098 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3100 // Check GetProperty returns the same value.
3101 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3102 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3103 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3105 // Reset the trace debug.
3106 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3108 // Check the function is called and the parameters are correct.
3109 // Set the expected parameter value at its correct index (only)
3110 parameters[0u] = StencilOperationLookupTable[i];
3111 parameters[1u] = StencilOperationLookupTable[j];
3112 parameters[2u] = StencilOperationLookupTable[k];
3114 // Build the parameter list.
3115 std::stringstream parameterStream;
3116 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3118 parameterStream << parameters[parameterBuild];
3119 // Comma-separate the parameters.
3120 if(parameterBuild < 2)
3122 parameterStream << ", ";
3126 // Check the function was called and the parameters were correct.
3127 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3135 int UtcDaliRendererSetStencilMask(void)
3137 TestApplication application;
3138 tet_infoline("Test setting the StencilMask");
3140 Renderer renderer = RendererTestFixture(application);
3141 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3142 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
3143 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3144 glEnableDisableStack.Enable(true);
3145 glEnableDisableStack.EnableLogging(true);
3146 glStencilFunctionStack.Enable(true);
3147 glStencilFunctionStack.EnableLogging(true);
3149 // RenderMode must use the stencil for StencilMask to operate.
3150 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3152 // Set the StencilMask property to a value.
3153 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3155 // Check GetProperty returns the same value.
3156 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3158 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3160 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3162 std::string methodString("StencilMask");
3163 std::string parameterString = "0";
3165 // Check the function was called and the parameters were correct.
3166 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3168 // Set the StencilMask property to another value to ensure it has changed.
3169 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3171 // Check GetProperty returns the same value.
3172 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3174 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3176 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3178 parameterString = "255";
3180 // Check the function was called and the parameters were correct.
3181 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3186 int UtcDaliRendererWrongNumberOfTextures(void)
3188 TestApplication application;
3189 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3191 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3192 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3193 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3194 TextureSet textureSet = CreateTextureSet();
3195 textureSet.SetTexture(0, texture);
3196 textureSet.SetTexture(1, texture);
3197 textureSet.SetTexture(2, texture);
3198 textureSet.SetTexture(3, texture);
3199 Shader shader = Shader::New("VertexSource", "FragmentSource");
3200 Geometry geometry = CreateQuadGeometry();
3201 Renderer renderer = Renderer::New(geometry, shader);
3202 renderer.SetTextures(textureSet);
3204 Actor actor = Actor::New();
3205 actor.AddRenderer(renderer);
3206 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3207 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3208 application.GetScene().Add(actor);
3210 TestGlAbstraction& gl = application.GetGlAbstraction();
3211 TraceCallStack& drawTrace = gl.GetDrawTrace();
3213 drawTrace.Enable(true);
3214 drawTrace.EnableLogging(true);
3216 application.SendNotification();
3217 application.Render(0);
3219 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3220 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3222 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3223 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3224 textureSet = CreateTextureSet();
3225 renderer.SetTextures(textureSet);
3226 textureSet.SetTexture(0, texture);
3228 application.SendNotification();
3229 application.Render(0);
3231 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3232 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3237 int UtcDaliRendererOpacity(void)
3239 TestApplication application;
3241 tet_infoline("Test OPACITY property");
3243 Geometry geometry = CreateQuadGeometry();
3244 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3245 Renderer renderer = Renderer::New(geometry, shader);
3247 Actor actor = Actor::New();
3248 actor.AddRenderer(renderer);
3249 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3250 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3251 application.GetScene().Add(actor);
3253 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3255 DALI_TEST_CHECK(value.Get(opacity));
3256 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3258 application.SendNotification();
3259 application.Render();
3261 Vector4 actualValue;
3262 Vector4 actualActorColor;
3263 TestGlAbstraction& gl = application.GetGlAbstraction();
3264 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3265 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3266 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3267 DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3269 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3271 application.SendNotification();
3272 application.Render();
3274 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3275 DALI_TEST_CHECK(value.Get(opacity));
3276 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3278 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3279 DALI_TEST_CHECK(value.Get(opacity));
3280 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3282 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3283 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3285 // Note : Renderer opacity doesn't apply to uActorColor.
3286 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3287 DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3292 int UtcDaliRendererOpacityAnimation(void)
3294 TestApplication application;
3296 tet_infoline("Test OPACITY property animation");
3298 Geometry geometry = CreateQuadGeometry();
3299 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3300 Renderer renderer = Renderer::New(geometry, shader);
3302 Actor actor = Actor::New();
3303 actor.AddRenderer(renderer);
3304 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3305 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3306 application.GetScene().Add(actor);
3308 application.SendNotification();
3309 application.Render(0);
3311 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3313 DALI_TEST_CHECK(value.Get(opacity));
3314 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3316 Animation animation = Animation::New(1.0f);
3317 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3320 application.SendNotification();
3321 application.Render(1000);
3323 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3324 DALI_TEST_CHECK(value.Get(opacity));
3325 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3327 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3329 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3331 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3334 application.SendNotification();
3335 application.Render(1000);
3337 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3338 DALI_TEST_CHECK(value.Get(opacity));
3339 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3340 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3345 int UtcDaliRendererInvalidProperty(void)
3347 TestApplication application;
3349 tet_infoline("Test invalid property");
3351 Geometry geometry = CreateQuadGeometry();
3352 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3353 Renderer renderer = Renderer::New(geometry, shader);
3355 Actor actor = Actor::New();
3356 actor.AddRenderer(renderer);
3357 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3358 application.GetScene().Add(actor);
3360 application.SendNotification();
3361 application.Render(0);
3363 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3364 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3366 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3367 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3372 int UtcDaliRendererRenderingBehavior(void)
3374 TestApplication application;
3376 tet_infoline("Test RENDERING_BEHAVIOR property");
3378 Geometry geometry = CreateQuadGeometry();
3379 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3380 Renderer renderer = Renderer::New(geometry, shader);
3382 Actor actor = Actor::New();
3383 actor.AddRenderer(renderer);
3384 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3385 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3386 application.GetScene().Add(actor);
3388 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3389 int renderingBehavior;
3390 DALI_TEST_CHECK(value.Get(renderingBehavior));
3391 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3393 application.SendNotification();
3394 application.Render();
3396 uint32_t updateStatus = application.GetUpdateStatus();
3398 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3400 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3401 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3402 drawTrace.Enable(true);
3405 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3407 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3408 DALI_TEST_CHECK(value.Get(renderingBehavior));
3409 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3411 // Render and check the update status
3412 application.SendNotification();
3413 application.Render();
3415 updateStatus = application.GetUpdateStatus();
3417 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3419 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3420 DALI_TEST_CHECK(value.Get(renderingBehavior));
3421 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3423 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3427 // Render again and check the update status
3428 application.SendNotification();
3429 application.Render();
3431 updateStatus = application.GetUpdateStatus();
3433 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3435 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3438 // Render again and check the update status
3439 Animation animation = Animation::New(1.0f);
3440 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3445 application.SendNotification();
3446 application.Render(0);
3448 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3452 application.SendNotification();
3453 application.Render(100);
3455 updateStatus = application.GetUpdateStatus();
3457 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3459 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3462 // Change rendering behavior
3463 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3465 // Render and check the update status
3466 application.SendNotification();
3467 application.Render();
3469 updateStatus = application.GetUpdateStatus();
3471 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3476 int UtcDaliRendererRegenerateUniformMap(void)
3478 TestApplication application;
3480 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3482 Geometry geometry = CreateQuadGeometry();
3483 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3484 Renderer renderer = Renderer::New(geometry, shader);
3486 Actor actor = Actor::New();
3487 actor.AddRenderer(renderer);
3488 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3489 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3490 application.GetScene().Add(actor);
3492 application.SendNotification();
3493 application.Render();
3495 actor.RemoveRenderer(renderer);
3496 shader = Shader::New("vertexSrc", "fragmentSrc");
3497 shader.RegisterProperty("opacity", 0.5f);
3498 renderer.SetShader(shader);
3500 Stage::GetCurrent().KeepRendering(1.0f);
3502 // Update for several frames
3503 application.SendNotification();
3504 application.Render();
3505 application.SendNotification();
3506 application.Render();
3507 application.SendNotification();
3508 application.Render();
3509 application.SendNotification();
3510 application.Render();
3513 actor.AddRenderer(renderer);
3514 application.SendNotification();
3515 application.Render();
3517 // Nothing to test here, the test must not crash
3518 auto updateStatus = application.GetUpdateStatus();
3519 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3524 int UtcDaliRendererRenderAfterAddShader(void)
3526 TestApplication application;
3527 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3529 tet_infoline("Test regenerating uniform map when shader changed");
3531 Geometry geometry = CreateQuadGeometry();
3532 Shader shader1 = Shader::New("vertexSrc1", "fragmentSrc1");
3533 Shader shader2 = Shader::New("vertexSrc2", "fragmentSrc2");
3534 Renderer renderer = Renderer::New(geometry, shader1);
3536 // Register each shader1 and shader2 only had
3537 shader1.RegisterProperty("uUniform1", Color::CRIMSON);
3538 shader2.RegisterProperty("uShader2Only", Color::AQUA_MARINE);
3540 Actor actor = Actor::New();
3541 actor.AddRenderer(renderer);
3542 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3543 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3544 application.GetScene().Add(actor);
3546 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3547 int renderingBehavior;
3548 DALI_TEST_CHECK(value.Get(renderingBehavior));
3549 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3551 application.SendNotification();
3552 application.Render(0);
3554 // Check uUniform1 rendered and uUniform2 not rendered before
3555 Vector4 actualValue(Vector4::ZERO);
3556 DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uUniform1", actualValue));
3557 DALI_TEST_EQUALS(actualValue, Color::CRIMSON, TEST_LOCATION);
3559 uint32_t updateStatus = application.GetUpdateStatus();
3561 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3563 // Update for several frames
3564 application.SendNotification();
3565 application.Render();
3566 application.SendNotification();
3567 application.Render();
3568 application.SendNotification();
3569 application.Render();
3570 application.SendNotification();
3571 application.Render();
3572 application.SendNotification();
3573 application.Render();
3575 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3576 drawTrace.Enable(true);
3579 std::vector<UniformData> customUniforms{{"uShader2Only", Property::VECTOR4}};
3581 application.GetGraphicsController().AddCustomUniforms(customUniforms);
3584 renderer.SetShader(shader2);
3586 // Render and check the update status
3587 application.SendNotification();
3588 application.Render(0);
3590 updateStatus = application.GetUpdateStatus();
3592 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3594 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3596 // Check uUniform2 rendered now
3597 DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uShader2Only", actualValue));
3598 DALI_TEST_EQUALS(actualValue, Color::AQUA_MARINE, TEST_LOCATION);
3603 int UtcDaliRendererAddDrawCommands(void)
3605 TestApplication application;
3607 tet_infoline("Test adding draw commands to the renderer");
3609 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3610 glAbstraction.EnableEnableDisableCallTrace(true);
3612 Geometry geometry = CreateQuadGeometry();
3613 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3614 Renderer renderer = Renderer::New(geometry, shader);
3616 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3617 Actor actor = Actor::New();
3618 actor.AddRenderer(renderer);
3619 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3620 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3621 application.GetScene().Add(actor);
3623 // Expect delivering a single draw call
3624 auto& drawTrace = glAbstraction.GetDrawTrace();
3626 drawTrace.Enable(true);
3627 application.SendNotification();
3628 application.Render();
3630 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3632 tet_infoline("\n\nTesting extension draw commands\n");
3633 auto drawCommand1 = DevelRenderer::DrawCommand{};
3634 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3635 drawCommand1.firstIndex = 0;
3636 drawCommand1.elementCount = 2;
3637 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3639 auto drawCommand2 = DevelRenderer::DrawCommand{};
3640 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3641 drawCommand2.firstIndex = 2;
3642 drawCommand2.elementCount = 2;
3643 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3645 auto drawCommand3 = DevelRenderer::DrawCommand{};
3646 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3647 drawCommand3.firstIndex = 2;
3648 drawCommand3.elementCount = 2;
3649 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3651 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3652 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3653 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3656 drawTrace.Enable(true);
3657 application.SendNotification();
3658 application.Render();
3660 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3663 int UtcDaliRendererSetGeometryNegative(void)
3665 TestApplication application;
3666 Dali::Renderer instance;
3669 Dali::Geometry arg1;
3670 instance.SetGeometry(arg1);
3671 DALI_TEST_CHECK(false); // Should not get here
3675 DALI_TEST_CHECK(true); // We expect an assert
3680 int UtcDaliRendererSetTexturesNegative(void)
3682 TestApplication application;
3683 Dali::Renderer instance;
3686 Dali::TextureSet arg1;
3687 instance.SetTextures(arg1);
3688 DALI_TEST_CHECK(false); // Should not get here
3692 DALI_TEST_CHECK(true); // We expect an assert
3697 int UtcDaliRendererSetShaderNegative(void)
3699 TestApplication application;
3700 Dali::Renderer instance;
3704 instance.SetShader(arg1);
3705 DALI_TEST_CHECK(false); // Should not get here
3709 DALI_TEST_CHECK(true); // We expect an assert
3714 int UtcDaliRendererGetGeometryNegative(void)
3716 TestApplication application;
3717 Dali::Renderer instance;
3720 instance.GetGeometry();
3721 DALI_TEST_CHECK(false); // Should not get here
3725 DALI_TEST_CHECK(true); // We expect an assert
3730 int UtcDaliRendererGetTexturesNegative(void)
3732 TestApplication application;
3733 Dali::Renderer instance;
3736 instance.GetTextures();
3737 DALI_TEST_CHECK(false); // Should not get here
3741 DALI_TEST_CHECK(true); // We expect an assert
3746 int UtcDaliRendererGetShaderNegative(void)
3748 TestApplication application;
3749 Dali::Renderer instance;
3752 instance.GetShader();
3753 DALI_TEST_CHECK(false); // Should not get here
3757 DALI_TEST_CHECK(true); // We expect an assert
3762 int UtcDaliRendererCheckTextureBindingP(void)
3764 TestApplication application;
3766 tet_infoline("Test adding draw commands to the renderer");
3768 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3769 glAbstraction.EnableEnableDisableCallTrace(true);
3771 Geometry geometry = CreateQuadGeometry();
3772 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3773 Renderer renderer = Renderer::New(geometry, shader);
3775 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3776 Actor actor = Actor::New();
3777 actor.AddRenderer(renderer);
3778 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3779 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3780 application.GetScene().Add(actor);
3782 TestGraphicsController& graphics = application.GetGraphicsController();
3783 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3784 cmdBufCallstack.Enable(true);
3786 application.SendNotification();
3787 application.Render();
3789 DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3791 Texture image0 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3792 TextureSet textureSet0 = CreateTextureSet(image0);
3793 renderer.SetTextures(textureSet0);
3795 application.SendNotification();
3796 application.Render();
3798 DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3802 int UtcDaliRendererPreparePipeline(void)
3804 TestApplication application;
3806 tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3808 Property::Map vf = CreateModelVertexFormat();
3809 Geometry modelGeometry = CreateModelGeometry(vf);
3810 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3811 Renderer renderer = Renderer::New(modelGeometry, shader);
3812 Actor actor = Actor::New();
3814 // Change the order up to get a fair test
3815 Property::Map modelVF;
3816 modelVF["aBoneIndex[0]"] = Property::INTEGER;
3817 modelVF["aBoneIndex[1]"] = Property::INTEGER;
3818 modelVF["aBoneIndex[2]"] = Property::INTEGER;
3819 modelVF["aBoneIndex[3]"] = Property::INTEGER;
3820 modelVF["aBoneWeights[0]"] = Property::FLOAT;
3821 modelVF["aBoneWeights[1]"] = Property::FLOAT;
3822 modelVF["aBoneWeights[2]"] = Property::FLOAT;
3823 modelVF["aBoneWeights[3]"] = Property::FLOAT;
3824 modelVF["aPosition"] = Property::VECTOR3;
3825 modelVF["aNormal"] = Property::VECTOR3;
3826 modelVF["aTexCoord1"] = Property::VECTOR3;
3827 modelVF["aTexCoord2"] = Property::VECTOR3;
3829 Property::Array vfs;
3830 vfs.PushBack(modelVF);
3831 TestGraphicsController& graphics = application.GetGraphicsController();
3832 graphics.SetVertexFormats(vfs);
3834 actor.AddRenderer(renderer);
3835 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3836 actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3837 application.GetScene().Add(actor);
3839 TraceCallStack& cmdBufCallstack = graphics.mCommandBufferCallStack;
3840 TraceCallStack& graphicsCallstack = graphics.mCallStack;
3841 cmdBufCallstack.Enable(true);
3842 graphicsCallstack.Enable(true);
3844 application.SendNotification();
3845 application.Render();
3847 DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3848 std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3849 DALI_TEST_CHECK(submissions.size() > 0);
3851 TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3853 auto result = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3854 auto pipeline = result[0]->data.bindPipeline.pipeline;
3858 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
3859 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
3862 DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
3863 Graphics::VertexInputFormat::FVECTOR3,
3870 int UtcDaliRendererUniformArrayOfStruct(void)
3872 TestApplication application;
3873 tet_infoline("Test that uniforms that are elements of arrays of structs can be accessed");
3875 std::vector<UniformData> customUniforms{{"arrayof[10].color", Property::VECTOR4},
3876 {"arrayof[10].position", Property::VECTOR2},
3877 {"arrayof[10].normal", Property::VECTOR3}};
3879 application.GetGraphicsController().AddCustomUniforms(customUniforms);
3881 Geometry geometry = CreateQuadGeometry();
3882 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3883 Renderer renderer = Renderer::New(geometry, shader);
3884 Actor actor = Actor::New();
3885 actor.AddRenderer(renderer);
3886 actor[Actor::Property::SIZE] = Vector2(120, 120);
3887 application.GetScene().Add(actor);
3889 // Define some properties to match the custom uniforms.
3890 // Ensure they can be written & read back from the abstraction.
3892 struct UniformIndexPair
3894 Property::Index index;
3896 UniformIndexPair(Property::Index index, std::string name)
3902 std::vector<UniformIndexPair> uniformIndices;
3904 std::ostringstream oss;
3905 for(int i = 0; i < 10; ++i)
3907 Property::Index index;
3908 oss << "arrayof[" << i << "].color";
3909 Vector4 color = Color::WHITE;
3910 color.r = 25.5f * i;
3911 index = renderer.RegisterProperty(oss.str(), color);
3912 uniformIndices.emplace_back(index, oss.str());
3916 oss << "arrayof[" << i << "].position";
3917 Vector2 pos(i, 10 + i * 5);
3918 index = renderer.RegisterProperty(oss.str(), pos);
3919 uniformIndices.emplace_back(index, oss.str());
3923 oss << "arrayof[" << i << "].normal";
3924 Vector3 normal(i, i * 10, i * 100);
3925 index = renderer.RegisterProperty(oss.str(), normal);
3926 uniformIndices.emplace_back(index, oss.str());
3930 auto& gl = application.GetGlAbstraction();
3931 TraceCallStack& callStack = gl.GetSetUniformTrace();
3932 gl.EnableSetUniformCallTrace(true);
3934 application.SendNotification();
3935 application.Render();
3937 // Check that the uniforms match.
3938 TraceCallStack::NamedParams params;
3939 for(auto& uniformInfo : uniformIndices)
3941 Property::Value value = renderer.GetProperty(uniformInfo.index);
3942 switch(value.GetType())
3944 case Property::VECTOR2:
3946 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3948 DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniformInfo.name.c_str(), setValue));
3949 DALI_TEST_EQUALS(value.Get<Vector2>(), setValue, 0.001f, TEST_LOCATION);
3952 case Property::VECTOR3:
3954 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3956 DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniformInfo.name.c_str(), setValue));
3957 DALI_TEST_EQUALS(value.Get<Vector3>(), setValue, 0.001f, TEST_LOCATION);
3960 case Property::VECTOR4:
3962 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3964 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniformInfo.name.c_str(), setValue));
3965 DALI_TEST_EQUALS(value.Get<Vector4>(), setValue, 0.001f, TEST_LOCATION);
3973 // There is a hash in the property name's uniform map: check this in debugger
3974 // There is a hash in the reflection. Check this in the debugger.
3976 // Check that the reflection contains individual locs for each array entry's struct element
3977 // and that it hashes the whole string
3979 // Ensure that the property name's hash is also for the whole string.