2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/common/stage.h>
21 #include <dali/devel-api/rendering/renderer-devel.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
29 #include <dali-test-suite-utils.h>
30 #include <mesh-builder.h>
31 #include <test-trace-call-stack.h>
35 namespace // unnamed namespace
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
46 * @brief Get GL stencil test enumeration value as a string.
47 * @return The string representation of the value of GL_STENCIL_TEST
49 std::string GetStencilTestString(void)
51 std::stringstream stream;
52 stream << GL_STENCIL_TEST;
57 * @brief Get GL depth test enumeration value as a string.
58 * @return The string representation of the value of GL_DEPTH_TEST
60 std::string GetDepthTestString(void)
62 std::stringstream stream;
63 stream << GL_DEPTH_TEST;
67 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
69 glEnableDisableStack.Reset();
70 glStencilFunctionStack.Reset();
71 application.SendNotification();
75 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
80 } // unnamed namespace
82 void renderer_test_startup(void)
84 test_return_value = TET_UNDEF;
87 void renderer_test_cleanup(void)
89 test_return_value = TET_PASS;
92 int UtcDaliRendererNew01(void)
94 TestApplication application;
96 Geometry geometry = CreateQuadGeometry();
97 Shader shader = CreateShader();
98 Renderer renderer = Renderer::New(geometry, shader);
100 DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
104 int UtcDaliRendererNew02(void)
106 TestApplication application;
108 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
112 int UtcDaliRendererCopyConstructor(void)
114 TestApplication application;
116 Geometry geometry = CreateQuadGeometry();
117 Shader shader = CreateShader();
118 Renderer renderer = Renderer::New(geometry, shader);
120 Renderer rendererCopy(renderer);
121 DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
126 int UtcDaliRendererAssignmentOperator(void)
128 TestApplication application;
130 Geometry geometry = CreateQuadGeometry();
131 Shader shader = CreateShader();
132 Renderer renderer = Renderer::New(geometry, shader);
135 DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
137 renderer2 = renderer;
138 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
142 int UtcDaliRendererMoveConstructor(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
148 Renderer renderer = Renderer::New(geometry, shader);
149 DALI_TEST_CHECK(renderer);
150 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
151 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
153 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
154 application.SendNotification();
155 application.Render();
156 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
158 Renderer move = std::move(renderer);
159 DALI_TEST_CHECK(move);
160 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
161 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
162 DALI_TEST_CHECK(!renderer);
167 int UtcDaliRendererMoveAssignment(void)
169 TestApplication application;
171 Geometry geometry = CreateQuadGeometry();
172 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
173 Renderer renderer = Renderer::New(geometry, shader);
174 DALI_TEST_CHECK(renderer);
175 DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
176 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
178 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
179 application.SendNotification();
180 application.Render();
181 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
184 move = std::move(renderer);
185 DALI_TEST_CHECK(move);
186 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
187 DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
188 DALI_TEST_CHECK(!renderer);
193 int UtcDaliRendererDownCast01(void)
195 TestApplication application;
197 Geometry geometry = CreateQuadGeometry();
198 Shader shader = CreateShader();
199 Renderer renderer = Renderer::New(geometry, shader);
201 BaseHandle handle(renderer);
202 Renderer renderer2 = Renderer::DownCast(handle);
203 DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
207 int UtcDaliRendererDownCast02(void)
209 TestApplication application;
211 Handle handle = Handle::New(); // Create a custom object
212 Renderer renderer = Renderer::DownCast(handle);
213 DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
217 // using a template to auto deduce the parameter types
218 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
219 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
221 DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
222 DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
223 DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
224 DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
225 DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
226 DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
229 int UtcDaliRendererDefaultProperties(void)
231 TestApplication application;
232 /* from renderer-impl.cpp
233 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
234 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
235 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
236 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
237 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
238 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
239 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
240 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
241 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
242 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
243 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
244 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
245 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
246 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
247 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
248 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
249 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
250 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
251 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
252 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
253 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
254 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
255 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
256 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
257 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
258 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
261 Geometry geometry = CreateQuadGeometry();
262 Shader shader = CreateShader();
263 Renderer renderer = Renderer::New(geometry, shader);
264 DALI_TEST_EQUALS(renderer.GetPropertyCount(), 26, TEST_LOCATION);
266 TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
267 TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
268 TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
269 TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
270 TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
271 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
272 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
273 TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
274 TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
275 TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
276 TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
277 TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
278 TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
279 TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
280 TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
281 TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
282 TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
283 TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
284 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
285 TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
286 TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
287 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
288 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
289 TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
290 TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
291 TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
296 int UtcDaliRendererSetGetGeometry(void)
298 TestApplication application;
299 tet_infoline("Test SetGeometry, GetGeometry");
301 Geometry geometry1 = CreateQuadGeometry();
302 Geometry geometry2 = CreateQuadGeometry();
304 Shader shader = CreateShader();
305 Renderer renderer = Renderer::New(geometry1, shader);
306 Actor actor = Actor::New();
307 actor.AddRenderer(renderer);
308 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
309 application.GetScene().Add(actor);
311 application.SendNotification();
312 application.Render(0);
313 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
315 // Set geometry2 to the renderer
316 renderer.SetGeometry(geometry2);
318 application.SendNotification();
319 application.Render(0);
320 DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
325 int UtcDaliRendererSetGetShader(void)
327 TestApplication application;
328 tet_infoline("Test SetShader, GetShader");
330 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
331 glAbstraction.EnableCullFaceCallTrace(true);
333 Shader shader1 = CreateShader();
334 shader1.RegisterProperty("uFadeColor", Color::RED);
336 Shader shader2 = CreateShader();
337 shader2.RegisterProperty("uFadeColor", Color::GREEN);
339 Geometry geometry = CreateQuadGeometry();
340 Renderer renderer = Renderer::New(geometry, shader1);
341 Actor actor = Actor::New();
342 actor.AddRenderer(renderer);
343 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
344 application.GetScene().Add(actor);
346 TestGlAbstraction& gl = application.GetGlAbstraction();
347 application.SendNotification();
348 application.Render(0);
350 // Expect that the first shaders's fade color property is accessed
351 Vector4 actualValue(Vector4::ZERO);
352 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
353 DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
355 DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
357 // set the second shader to the renderer
358 renderer.SetShader(shader2);
360 application.SendNotification();
361 application.Render(0);
363 // Expect that the second shader's fade color property is accessed
364 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
365 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
367 DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
372 int UtcDaliRendererSetGetDepthIndex(void)
374 TestApplication application;
376 tet_infoline("Test SetDepthIndex, GetDepthIndex");
378 Shader shader = CreateShader();
379 Geometry geometry = CreateQuadGeometry();
380 Renderer renderer = Renderer::New(geometry, shader);
381 Actor actor = Actor::New();
382 actor.AddRenderer(renderer);
383 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
384 application.GetScene().Add(actor);
386 application.SendNotification();
387 application.Render(0);
388 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
390 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
392 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
393 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
395 application.SendNotification();
396 application.Render(0);
397 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
399 renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
401 DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
402 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
404 application.SendNotification();
405 application.Render(0);
406 DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
411 int UtcDaliRendererSetGetFaceCullingMode(void)
413 TestApplication application;
415 tet_infoline("Test SetFaceCullingMode(cullingMode)");
416 Geometry geometry = CreateQuadGeometry();
417 Shader shader = CreateShader();
418 Renderer renderer = Renderer::New(geometry, shader);
420 Actor actor = Actor::New();
421 actor.AddRenderer(renderer);
422 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
423 application.GetScene().Add(actor);
425 // By default, none of the faces should be culled
426 unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
427 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
429 TestGlAbstraction& gl = application.GetGlAbstraction();
430 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
431 gl.EnableCullFaceCallTrace(true);
434 cullFaceStack.Reset();
435 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
436 application.SendNotification();
437 application.Render();
439 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
441 std::ostringstream cullModeString;
442 cullModeString << GL_FRONT_AND_BACK;
444 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
445 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
446 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
450 cullFaceStack.Reset();
451 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
452 application.SendNotification();
453 application.Render();
455 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
457 std::ostringstream cullModeString;
458 cullModeString << GL_BACK;
460 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
461 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
462 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
466 cullFaceStack.Reset();
467 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
468 application.SendNotification();
469 application.Render();
471 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
473 std::ostringstream cullModeString;
474 cullModeString << GL_FRONT;
476 DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
477 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
478 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
482 cullFaceStack.Reset();
483 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
484 application.SendNotification();
485 application.Render();
487 DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
488 cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
489 DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
495 int UtcDaliRendererBlendOptions01(void)
497 TestApplication application;
499 tet_infoline("Test BLEND_FACTOR properties ");
501 Geometry geometry = CreateQuadGeometry();
502 Shader shader = CreateShader();
503 Renderer renderer = Renderer::New(geometry, shader);
505 Actor actor = Actor::New();
506 // set a transparent actor color so that blending is enabled
507 actor.SetProperty(Actor::Property::OPACITY, 0.5f);
508 actor.AddRenderer(renderer);
509 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
510 application.GetScene().Add(actor);
512 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
513 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
514 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
515 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
517 // Test that Set was successful:
518 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
519 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
520 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
521 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
523 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
524 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
525 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
526 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
528 application.SendNotification();
529 application.Render();
531 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
533 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
534 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
535 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
536 DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
541 int UtcDaliRendererBlendOptions02(void)
543 TestApplication application;
545 tet_infoline("Test BLEND_FACTOR properties ");
547 Geometry geometry = CreateQuadGeometry();
548 Shader shader = CreateShader();
549 Renderer renderer = Renderer::New(geometry, shader);
551 Actor actor = Actor::New();
552 actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
553 actor.AddRenderer(renderer);
554 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
555 application.GetScene().Add(actor);
557 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
558 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
559 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
560 renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
562 // Test that Set was successful:
564 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
565 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
566 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
567 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
569 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
570 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
571 DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
572 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
575 application.SendNotification();
576 application.Render();
578 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
579 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
580 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
581 DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
582 DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
587 int UtcDaliRendererBlendOptions03(void)
589 TestApplication application;
591 tet_infoline("Test GetBlendEquation() defaults ");
593 Geometry geometry = CreateQuadGeometry();
594 Shader shader = CreateShader();
595 Renderer renderer = Renderer::New(geometry, shader);
597 Actor actor = Actor::New();
598 actor.AddRenderer(renderer);
599 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
600 application.GetScene().Add(actor);
602 // Test the defaults as documented in blending.h
603 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
604 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
606 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
607 DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
612 int UtcDaliRendererBlendOptions04(void)
614 TestApplication application;
616 tet_infoline("Test SetBlendEquation() ");
618 Geometry geometry = CreateQuadGeometry();
619 Shader shader = CreateShader();
620 Renderer renderer = Renderer::New(geometry, shader);
622 Actor actor = Actor::New();
623 actor.SetProperty(Actor::Property::OPACITY, 0.1f);
624 actor.AddRenderer(renderer);
625 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
626 application.GetScene().Add(actor);
628 // Test the single blending equation setting
630 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
631 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
632 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
635 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
636 renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
638 // Test that Set was successful
640 int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
641 int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
642 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
643 DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
646 // Render & check GL commands
647 application.SendNotification();
648 application.Render();
650 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
651 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
652 DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
657 int UtcDaliRendererSetBlendMode01(void)
659 TestApplication application;
661 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
663 Geometry geometry = CreateQuadGeometry();
664 Shader shader = CreateShader();
665 Renderer renderer = Renderer::New(geometry, shader);
667 Actor actor = Actor::New();
668 actor.SetProperty(Actor::Property::OPACITY, 0.98f);
669 actor.AddRenderer(renderer);
670 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
671 application.GetScene().Add(actor);
673 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
675 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
676 glAbstraction.EnableEnableDisableCallTrace(true);
678 application.SendNotification();
679 application.Render();
681 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
682 std::ostringstream blendStr;
683 blendStr << GL_BLEND;
684 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
689 int UtcDaliRendererSetBlendMode01b(void)
691 TestApplication application;
693 tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
695 Geometry geometry = CreateQuadGeometry();
696 Shader shader = CreateShader();
697 Renderer renderer = Renderer::New(geometry, shader);
699 Actor actor = Actor::New();
700 actor.SetProperty(Actor::Property::OPACITY, 0.0f);
701 actor.AddRenderer(renderer);
702 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
703 application.GetScene().Add(actor);
705 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
707 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
708 glAbstraction.EnableEnableDisableCallTrace(true);
709 glAbstraction.EnableDrawCallTrace(true);
711 application.SendNotification();
712 application.Render();
714 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
715 std::ostringstream blendStr;
716 blendStr << GL_BLEND;
717 DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
719 DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
724 int UtcDaliRendererSetBlendMode02(void)
726 TestApplication application;
728 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
730 Geometry geometry = CreateQuadGeometry();
731 Shader shader = CreateShader();
732 Renderer renderer = Renderer::New(geometry, shader);
734 Actor actor = Actor::New();
735 actor.SetProperty(Actor::Property::OPACITY, 0.15f);
736 actor.AddRenderer(renderer);
737 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
738 application.GetScene().Add(actor);
740 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
742 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
743 glAbstraction.EnableEnableDisableCallTrace(true);
745 application.SendNotification();
746 application.Render();
748 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
749 std::ostringstream blendStr;
750 blendStr << GL_BLEND;
751 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
756 int UtcDaliRendererSetBlendMode03(void)
758 TestApplication application;
760 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
762 Geometry geometry = CreateQuadGeometry();
763 Shader shader = CreateShader();
764 Renderer renderer = Renderer::New(geometry, shader);
766 Actor actor = Actor::New();
767 actor.SetProperty(Actor::Property::OPACITY, 0.75f);
768 actor.AddRenderer(renderer);
769 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
770 application.GetScene().Add(actor);
772 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
774 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
775 glAbstraction.EnableEnableDisableCallTrace(true);
777 application.SendNotification();
778 application.Render();
780 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
781 std::ostringstream blendStr;
782 blendStr << GL_BLEND;
783 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
788 int UtcDaliRendererSetBlendMode04(void)
790 TestApplication application;
792 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
794 Geometry geometry = CreateQuadGeometry();
795 Shader shader = CreateShader();
796 Renderer renderer = Renderer::New(geometry, shader);
798 Actor actor = Actor::New();
799 actor.AddRenderer(renderer);
800 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
801 application.GetScene().Add(actor);
803 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
805 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
806 glAbstraction.EnableEnableDisableCallTrace(true);
808 application.SendNotification();
809 application.Render();
811 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
812 std::ostringstream blendStr;
813 blendStr << GL_BLEND;
814 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
819 int UtcDaliRendererSetBlendMode04b(void)
821 TestApplication application;
823 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
825 Geometry geometry = CreateQuadGeometry();
826 Shader shader = CreateShader();
827 Renderer renderer = Renderer::New(geometry, shader);
829 Actor actor = Actor::New();
830 actor.AddRenderer(renderer);
831 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
832 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
833 application.GetScene().Add(actor);
835 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
837 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
838 glAbstraction.EnableEnableDisableCallTrace(true);
840 application.SendNotification();
841 application.Render();
843 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
844 std::ostringstream blendStr;
845 blendStr << GL_BLEND;
846 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
851 int UtcDaliRendererSetBlendMode04c(void)
853 TestApplication application;
855 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
857 Geometry geometry = CreateQuadGeometry();
858 Shader shader = CreateShader();
859 Renderer renderer = Renderer::New(geometry, shader);
861 Actor actor = Actor::New();
862 actor.AddRenderer(renderer);
863 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
864 actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
865 application.GetScene().Add(actor);
867 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
869 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
870 glAbstraction.EnableEnableDisableCallTrace(true);
872 application.SendNotification();
873 application.Render();
875 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
876 std::ostringstream blendStr;
877 blendStr << GL_BLEND;
878 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
883 int UtcDaliRendererSetBlendMode05(void)
885 TestApplication application;
887 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
889 Geometry geometry = CreateQuadGeometry();
890 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
892 Shader shader = CreateShader();
893 TextureSet textureSet = CreateTextureSet(image);
894 Renderer renderer = Renderer::New(geometry, shader);
895 renderer.SetTextures(textureSet);
897 Actor actor = Actor::New();
898 actor.AddRenderer(renderer);
899 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
900 application.GetScene().Add(actor);
902 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
904 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
905 glAbstraction.EnableEnableDisableCallTrace(true);
907 application.SendNotification();
908 application.Render();
910 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
911 std::ostringstream blendStr;
912 blendStr << GL_BLEND;
913 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
918 int UtcDaliRendererSetBlendMode06(void)
920 TestApplication application;
921 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");
923 Geometry geometry = CreateQuadGeometry();
924 Shader shader = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
926 Renderer renderer = Renderer::New(geometry, shader);
928 Actor actor = Actor::New();
929 actor.AddRenderer(renderer);
930 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
931 application.GetScene().Add(actor);
933 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
935 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
936 glAbstraction.EnableEnableDisableCallTrace(true);
938 application.SendNotification();
939 application.Render();
941 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
942 std::ostringstream blendStr;
943 blendStr << GL_BLEND;
944 DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
949 int UtcDaliRendererSetBlendMode07(void)
951 TestApplication application;
952 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");
954 Geometry geometry = CreateQuadGeometry();
955 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
957 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
958 TextureSet textureSet = CreateTextureSet(image);
959 Renderer renderer = Renderer::New(geometry, shader);
960 renderer.SetTextures(textureSet);
962 Actor actor = Actor::New();
963 actor.AddRenderer(renderer);
964 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
965 application.GetScene().Add(actor);
967 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
969 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
970 glAbstraction.EnableEnableDisableCallTrace(true);
972 application.SendNotification();
973 application.Render();
975 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
976 DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", "GL_BLEND"));
981 int UtcDaliRendererGetBlendMode(void)
983 TestApplication application;
985 tet_infoline("Test GetBlendMode()");
987 Geometry geometry = CreateQuadGeometry();
988 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
989 Renderer renderer = Renderer::New(geometry, shader);
992 unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
993 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
996 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
997 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
998 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1001 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1002 mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1003 DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1008 int UtcDaliRendererSetBlendColor(void)
1010 TestApplication application;
1012 tet_infoline("Test SetBlendColor(color)");
1014 Geometry geometry = CreateQuadGeometry();
1015 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1016 TextureSet textureSet = TextureSet::New();
1017 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1018 textureSet.SetTexture(0u, image);
1019 Renderer renderer = Renderer::New(geometry, shader);
1020 renderer.SetTextures(textureSet);
1022 Actor actor = Actor::New();
1023 actor.AddRenderer(renderer);
1024 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1025 application.GetScene().Add(actor);
1027 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1029 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1031 application.SendNotification();
1032 application.Render();
1034 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1035 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1036 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1038 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1040 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1041 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1043 application.SendNotification();
1044 application.Render();
1046 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1047 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1049 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1050 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1051 application.SendNotification();
1052 application.Render();
1053 DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1058 int UtcDaliRendererGetBlendColor(void)
1060 TestApplication application;
1062 tet_infoline("Test GetBlendColor()");
1064 Geometry geometry = CreateQuadGeometry();
1065 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1066 Renderer renderer = Renderer::New(geometry, shader);
1068 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1070 renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1071 application.SendNotification();
1072 application.Render();
1073 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1075 Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1076 renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1077 application.SendNotification();
1078 application.Render();
1079 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1084 int UtcDaliRendererPreMultipledAlpha(void)
1086 TestApplication application;
1088 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1090 Geometry geometry = CreateQuadGeometry();
1091 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1092 Renderer renderer = Renderer::New(geometry, shader);
1094 Actor actor = Actor::New();
1095 actor.AddRenderer(renderer);
1096 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1097 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1098 application.GetScene().Add(actor);
1100 Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1101 bool preMultipliedAlpha;
1102 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1103 DALI_TEST_CHECK(!preMultipliedAlpha);
1105 int srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1106 int destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1107 int srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1108 int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1110 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1111 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1112 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1113 DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1115 application.SendNotification();
1116 application.Render();
1118 Vector4 actualValue(Vector4::ZERO);
1119 TestGlAbstraction& gl = application.GetGlAbstraction();
1120 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1121 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1123 // Enable pre-multiplied alpha
1124 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1126 application.SendNotification();
1127 application.Render();
1129 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1130 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1131 DALI_TEST_CHECK(preMultipliedAlpha);
1133 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1134 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1135 DALI_TEST_CHECK(preMultipliedAlpha);
1137 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1138 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1139 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1140 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1142 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1143 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1144 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1145 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1147 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1148 DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1150 // Disable pre-multiplied alpha again
1151 renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1153 application.SendNotification();
1154 application.Render();
1156 value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1157 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1158 DALI_TEST_CHECK(!preMultipliedAlpha);
1160 value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1161 DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1162 DALI_TEST_CHECK(!preMultipliedAlpha);
1164 srcFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1165 destFactorRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1166 srcFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1167 destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1169 DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1170 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1171 DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1172 DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1174 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1175 DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1180 int UtcDaliRendererConstraint01(void)
1182 TestApplication application;
1184 tet_infoline("Test that a non-uniform renderer property can be constrained");
1186 Shader shader = Shader::New("VertexSource", "FragmentSource");
1187 Geometry geometry = CreateQuadGeometry();
1188 Renderer renderer = Renderer::New(geometry, shader);
1190 Actor actor = Actor::New();
1191 actor.AddRenderer(renderer);
1192 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1193 application.GetScene().Add(actor);
1195 Vector4 initialColor = Color::WHITE;
1196 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1198 application.SendNotification();
1199 application.Render(0);
1200 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1203 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1205 application.SendNotification();
1206 application.Render(0);
1208 // Expect no blue component in either buffer - yellow
1209 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1210 application.Render(0);
1211 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1213 renderer.RemoveConstraints();
1214 renderer.SetProperty(colorIndex, Color::WHITE);
1215 application.SendNotification();
1216 application.Render(0);
1217 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1222 int UtcDaliRendererConstraint02(void)
1224 TestApplication application;
1226 tet_infoline("Test that a uniform map renderer property can be constrained");
1228 Shader shader = Shader::New("VertexSource", "FragmentSource");
1229 Geometry geometry = CreateQuadGeometry();
1230 Renderer renderer = Renderer::New(geometry, shader);
1232 Actor actor = Actor::New();
1233 actor.AddRenderer(renderer);
1234 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1235 application.GetScene().Add(actor);
1236 application.SendNotification();
1237 application.Render(0);
1239 Vector4 initialColor = Color::WHITE;
1240 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1242 TestGlAbstraction& gl = application.GetGlAbstraction();
1244 application.SendNotification();
1245 application.Render(0);
1247 Vector4 actualValue(Vector4::ZERO);
1248 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1249 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1252 Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1254 application.SendNotification();
1255 application.Render(0);
1257 // Expect no blue component in either buffer - yellow
1258 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1259 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1261 application.Render(0);
1262 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1263 DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1265 renderer.RemoveConstraints();
1266 renderer.SetProperty(colorIndex, Color::WHITE);
1267 application.SendNotification();
1268 application.Render(0);
1270 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1271 DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1276 int UtcDaliRendererAnimatedProperty01(void)
1278 TestApplication application;
1280 tet_infoline("Test that a non-uniform renderer property can be animated");
1282 Shader shader = Shader::New("VertexSource", "FragmentSource");
1283 Geometry geometry = CreateQuadGeometry();
1284 Renderer renderer = Renderer::New(geometry, shader);
1286 Actor actor = Actor::New();
1287 actor.AddRenderer(renderer);
1288 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1289 application.GetScene().Add(actor);
1291 Vector4 initialColor = Color::WHITE;
1292 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1294 application.SendNotification();
1295 application.Render(0);
1296 DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1298 Animation animation = Animation::New(1.0f);
1299 KeyFrames keyFrames = KeyFrames::New();
1300 keyFrames.Add(0.0f, initialColor);
1301 keyFrames.Add(1.0f, Color::TRANSPARENT);
1302 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1305 application.SendNotification();
1306 application.Render(500);
1308 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1310 application.Render(500);
1312 DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1317 int UtcDaliRendererAnimatedProperty02(void)
1319 TestApplication application;
1321 tet_infoline("Test that a uniform map renderer property can be animated");
1323 Shader shader = Shader::New("VertexSource", "FragmentSource");
1324 Geometry geometry = CreateQuadGeometry();
1325 Renderer renderer = Renderer::New(geometry, shader);
1327 Actor actor = Actor::New();
1328 actor.AddRenderer(renderer);
1329 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1330 application.GetScene().Add(actor);
1331 application.SendNotification();
1332 application.Render(0);
1334 Vector4 initialColor = Color::WHITE;
1335 Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", initialColor);
1337 TestGlAbstraction& gl = application.GetGlAbstraction();
1339 application.SendNotification();
1340 application.Render(0);
1342 Vector4 actualValue(Vector4::ZERO);
1343 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1344 DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1346 Animation animation = Animation::New(1.0f);
1347 KeyFrames keyFrames = KeyFrames::New();
1348 keyFrames.Add(0.0f, initialColor);
1349 keyFrames.Add(1.0f, Color::TRANSPARENT);
1350 animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1353 application.SendNotification();
1354 application.Render(500);
1356 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1357 DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1359 application.Render(500);
1360 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1361 DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1366 int UtcDaliRendererUniformMapPrecendence01(void)
1368 TestApplication application;
1370 tet_infoline("Test the uniform map precedence is applied properly");
1372 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1374 Shader shader = Shader::New("VertexSource", "FragmentSource");
1375 TextureSet textureSet = CreateTextureSet(image);
1377 Geometry geometry = CreateQuadGeometry();
1378 Renderer renderer = Renderer::New(geometry, shader);
1379 renderer.SetTextures(textureSet);
1381 Actor actor = Actor::New();
1382 actor.AddRenderer(renderer);
1383 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1384 application.GetScene().Add(actor);
1385 application.SendNotification();
1386 application.Render(0);
1388 renderer.RegisterProperty("uFadeColor", Color::RED);
1389 actor.RegisterProperty("uFadeColor", Color::GREEN);
1390 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1392 TestGlAbstraction& gl = application.GetGlAbstraction();
1394 application.SendNotification();
1395 application.Render(0);
1397 // Expect that the actor's fade color property is accessed
1398 Vector4 actualValue(Vector4::ZERO);
1399 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1400 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1402 // Animate shader's fade color property. Should be no change to uniform
1403 Animation animation = Animation::New(1.0f);
1404 KeyFrames keyFrames = KeyFrames::New();
1405 keyFrames.Add(0.0f, Color::WHITE);
1406 keyFrames.Add(1.0f, Color::TRANSPARENT);
1407 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1410 application.SendNotification();
1411 application.Render(500);
1413 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1414 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1416 application.Render(500);
1417 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1418 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1423 int UtcDaliRendererUniformMapPrecendence02(void)
1425 TestApplication application;
1427 tet_infoline("Test the uniform map precedence is applied properly");
1429 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1431 Shader shader = Shader::New("VertexSource", "FragmentSource");
1432 TextureSet textureSet = CreateTextureSet(image);
1434 Geometry geometry = CreateQuadGeometry();
1435 Renderer renderer = Renderer::New(geometry, shader);
1436 renderer.SetTextures(textureSet);
1438 Actor actor = Actor::New();
1439 actor.AddRenderer(renderer);
1440 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1441 application.GetScene().Add(actor);
1442 application.SendNotification();
1443 application.Render(0);
1445 // Don't add property / uniform map to renderer
1446 actor.RegisterProperty("uFadeColor", Color::GREEN);
1447 Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1449 TestGlAbstraction& gl = application.GetGlAbstraction();
1451 application.SendNotification();
1452 application.Render(0);
1454 // Expect that the actor's fade color property is accessed
1455 Vector4 actualValue(Vector4::ZERO);
1456 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1457 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1459 // Animate texture set's fade color property. Should be no change to uniform
1460 Animation animation = Animation::New(1.0f);
1461 KeyFrames keyFrames = KeyFrames::New();
1462 keyFrames.Add(0.0f, Color::WHITE);
1463 keyFrames.Add(1.0f, Color::TRANSPARENT);
1464 animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1467 application.SendNotification();
1468 application.Render(500);
1470 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1471 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1473 application.Render(500);
1474 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1475 DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1480 int UtcDaliRendererUniformMapPrecendence03(void)
1482 TestApplication application;
1484 tet_infoline("Test the uniform map precedence is applied properly");
1486 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1488 Shader shader = Shader::New("VertexSource", "FragmentSource");
1489 TextureSet textureSet = CreateTextureSet(image);
1491 Geometry geometry = CreateQuadGeometry();
1492 Renderer renderer = Renderer::New(geometry, shader);
1493 renderer.SetTextures(textureSet);
1495 Actor actor = Actor::New();
1496 actor.AddRenderer(renderer);
1497 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1498 application.GetScene().Add(actor);
1499 application.SendNotification();
1500 application.Render(0);
1502 // Don't add property / uniform map to renderer or actor
1503 shader.RegisterProperty("uFadeColor", Color::BLACK);
1505 TestGlAbstraction& gl = application.GetGlAbstraction();
1507 application.SendNotification();
1508 application.Render(0);
1510 // Expect that the shader's fade color property is accessed
1511 Vector4 actualValue(Vector4::ZERO);
1512 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1513 DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1518 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1520 TestApplication application;
1522 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1524 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1526 Shader shader = Shader::New("VertexSource", "FragmentSource");
1527 TextureSet textureSet = CreateTextureSet(image);
1529 Geometry geometry = CreateQuadGeometry();
1530 Renderer renderer = Renderer::New(geometry, shader);
1531 renderer.SetTextures(textureSet);
1533 Actor actor = Actor::New();
1534 actor.AddRenderer(renderer);
1535 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1536 application.GetScene().Add(actor);
1537 application.SendNotification();
1538 application.Render(0);
1540 renderer.RegisterProperty("uUniform1", Color::RED);
1541 actor.RegisterProperty("uUniform2", Color::GREEN);
1542 shader.RegisterProperty("uUniform3", Color::MAGENTA);
1544 TestGlAbstraction& gl = application.GetGlAbstraction();
1546 application.SendNotification();
1547 application.Render(0);
1549 // Expect that each of the object's uniforms are set
1550 Vector4 uniform1Value(Vector4::ZERO);
1551 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1552 DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1554 Vector4 uniform2Value(Vector4::ZERO);
1555 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1556 DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1558 Vector4 uniform3Value(Vector4::ZERO);
1559 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1560 DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1565 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1567 TestApplication application;
1569 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1571 Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1573 Shader shader = Shader::New("VertexSource", "FragmentSource");
1574 TextureSet textureSet = CreateTextureSet(image);
1576 Geometry geometry = CreateQuadGeometry();
1577 Renderer renderer = Renderer::New(geometry, shader);
1578 renderer.SetTextures(textureSet);
1580 Actor actor = Actor::New();
1581 actor.AddRenderer(renderer);
1582 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1583 application.GetScene().Add(actor);
1584 application.SendNotification();
1585 application.Render(0);
1587 Property::Value value1(Color::RED);
1588 renderer.RegisterProperty("uFadeColor", value1);
1590 Property::Value value2(1.0f);
1591 actor.RegisterProperty("uFadeProgress", value2);
1593 Property::Value value3(Matrix3::IDENTITY);
1594 shader.RegisterProperty("uANormalMatrix", value3);
1596 TestGlAbstraction& gl = application.GetGlAbstraction();
1598 application.SendNotification();
1599 application.Render(0);
1601 // Expect that each of the object's uniforms are set
1602 Vector4 uniform1Value(Vector4::ZERO);
1603 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1604 DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1606 float uniform2Value(0.0f);
1607 DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1608 DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1610 Matrix3 uniform3Value;
1611 DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1612 DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1617 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
1619 Texture image0 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
1620 TextureSet textureSet0 = CreateTextureSet(image0);
1621 Renderer renderer0 = Renderer::New(geometry, shader);
1622 renderer0.SetTextures(textureSet0);
1623 renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
1624 actor.AddRenderer(renderer0);
1628 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
1630 Actor actor = Actor::New();
1631 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1632 actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
1633 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1634 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1636 actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
1637 DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
1642 int UtcDaliRendererRenderOrder2DLayer(void)
1644 TestApplication application;
1645 tet_infoline("Test the rendering order in a 2D layer is correct");
1647 Shader shader = Shader::New("VertexSource", "FragmentSource");
1648 Geometry geometry = CreateQuadGeometry();
1650 Actor root = application.GetScene().GetRootLayer();
1652 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1653 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1655 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1656 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1658 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1659 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1661 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1662 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1664 application.SendNotification();
1665 application.Render(0);
1668 * Create the following hierarchy:
1681 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1686 application.SendNotification();
1687 application.Render(0);
1689 TestGlAbstraction& gl = application.GetGlAbstraction();
1690 gl.EnableTextureCallTrace(true);
1691 application.SendNotification();
1692 application.Render(0);
1694 int textureBindIndex[4];
1695 for(unsigned int i(0); i < 4; ++i)
1697 std::stringstream params;
1698 params << GL_TEXTURE_2D << ", " << i + 1;
1699 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1702 //Check that actor1 has been rendered after actor2
1703 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1705 //Check that actor0 has been rendered after actor1
1706 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1708 //Check that actor3 has been rendered after actor0
1709 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1714 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1716 TestApplication application;
1717 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1720 * Creates the following hierarchy:
1722 * actor0------------------------>actor1
1726 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1728 * renderer0 has depth index 2
1729 * renderer1 has depth index 0
1730 * renderer2 has depth index 1
1732 * renderer3 has depth index 1
1733 * renderer4 has depth index 0
1734 * renderer5 has depth index -1
1736 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1739 Shader shader = Shader::New("VertexSource", "FragmentSource");
1740 Geometry geometry = CreateQuadGeometry();
1742 Actor root = application.GetScene().GetRootLayer();
1744 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1745 Actor actor1 = CreateActor(actor0, 0, TEST_LOCATION);
1746 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1747 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1748 Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1749 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1750 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1751 Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1753 application.SendNotification();
1754 application.Render(0);
1756 TestGlAbstraction& gl = application.GetGlAbstraction();
1757 gl.EnableTextureCallTrace(true);
1758 application.SendNotification();
1759 application.Render(0);
1761 int textureBindIndex[6];
1762 for(unsigned int i(0); i < 6; ++i)
1764 std::stringstream params;
1765 params << GL_TEXTURE_2D << ", " << i + 1;
1766 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1769 //Check that renderer3 has been rendered after renderer4
1770 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1772 //Check that renderer0 has been rendered after renderer2
1773 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1775 //Check that renderer5 has been rendered after renderer2
1776 DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1778 //Check that renderer0 has been rendered after renderer2
1779 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1781 //Check that renderer2 has been rendered after renderer1
1782 DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1787 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1789 TestApplication application;
1790 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1793 * Creates the following hierarchy:
1801 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1805 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1806 * DI:2 DI:0 | DI:0 DI:1 DI:2
1811 * actor0 has sibling order 1
1812 * actor1 has sibling order 0
1813 * actor2 has sibling order 0
1815 * renderer0 has depth index 2
1816 * renderer1 has depth index 0
1818 * renderer2 has depth index 0
1819 * renderer3 has depth index 1
1820 * renderer4 has depth index 2
1822 * renderer5 has depth index -1
1824 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1827 Shader shader = Shader::New("VertexSource", "FragmentSource");
1828 Geometry geometry = CreateQuadGeometry();
1829 Actor root = application.GetScene().GetRootLayer();
1830 Actor actor0 = CreateActor(root, 1, TEST_LOCATION);
1831 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1832 Actor actor2 = CreateActor(actor0, 0, TEST_LOCATION);
1834 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1835 Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1836 Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
1837 Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1838 Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
1839 Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
1841 application.SendNotification();
1842 application.Render();
1844 TestGlAbstraction& gl = application.GetGlAbstraction();
1845 gl.EnableTextureCallTrace(true);
1846 application.SendNotification();
1847 application.Render(0);
1849 int textureBindIndex[6];
1850 for(unsigned int i(0); i < 6; ++i)
1852 std::stringstream params;
1853 params << GL_TEXTURE_2D << ", " << i + 1;
1854 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1857 DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
1858 DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
1859 DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
1860 DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
1861 DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
1862 DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
1864 // Change sibling order of actor1
1865 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1866 actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
1868 gl.GetTextureTrace().Reset();
1869 application.SendNotification();
1870 application.Render(0);
1872 for(unsigned int i(0); i < 6; ++i)
1874 std::stringstream params;
1875 params << GL_TEXTURE_2D << ", " << i + 1;
1876 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1879 DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
1880 DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
1881 DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
1882 DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
1883 DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
1884 DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
1889 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1891 TestApplication application;
1892 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1894 Shader shader = Shader::New("VertexSource", "FragmentSource");
1895 Geometry geometry = CreateQuadGeometry();
1896 Actor root = application.GetScene().GetRootLayer();
1899 * Create the following hierarchy:
1906 * (Overlay) (Regular actor)
1916 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1919 Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
1920 actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
1921 Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1923 Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
1924 actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
1925 Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1927 Actor actor2 = CreateActor(root, 0, TEST_LOCATION);
1928 Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1930 Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
1931 actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
1932 Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1934 Actor actor4 = CreateActor(root, 0, TEST_LOCATION);
1935 Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
1937 application.SendNotification();
1938 application.Render(0);
1945 TestGlAbstraction& gl = application.GetGlAbstraction();
1946 gl.EnableTextureCallTrace(true);
1947 application.SendNotification();
1948 application.Render(0);
1950 int textureBindIndex[5];
1951 for(unsigned int i(0); i < 5; ++i)
1953 std::stringstream params;
1954 params << GL_TEXTURE_2D << ", " << i + 1;
1955 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1958 //Check that actor4 has been rendered after actor2
1959 DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
1961 //Check that actor1 has been rendered after actor4
1962 DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
1964 //Check that actor0 has been rendered after actor1
1965 DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1967 //Check that actor3 has been rendered after actor0
1968 DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1973 int UtcDaliRendererSetIndexRange(void)
1977 "attribute vec2 aPosition;\n"
1980 " gl_Position = aPosition;\n"
1985 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1988 TestApplication application;
1989 tet_infoline("Test setting the range of indices to draw");
1991 TestGlAbstraction& gl = application.GetGlAbstraction();
1992 gl.EnableDrawCallTrace(true);
1994 Actor actor = Actor::New();
1995 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1998 Geometry geometry = Geometry::New();
1999 geometry.SetType(Geometry::LINE_LOOP);
2001 // --------------------------------------------------------------------------
2003 unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2013 9, // offset = 5, count = 10
2019 1}; // offset = 15, count = 6 // line strip
2021 // --------------------------------------------------------------------------
2030 {Vector2(0.0f, 1.00f)},
2031 {Vector2(0.0f, -1.00f)},
2032 {Vector2(-0.95f, 0.31f)},
2033 {Vector2(0.59f, 0.81f)},
2034 {Vector2(-0.59f, -0.81f)},
2035 {Vector2(-0.95f, -0.31f)},
2036 {Vector2(0.59f, -0.81f)},
2037 {Vector2(0.95f, -0.31f)},
2038 {Vector2(0.95f, 0.31f)},
2039 {Vector2(-0.59f, 0.81f)},
2041 Property::Map vertexFormat;
2042 vertexFormat["aPosition"] = Property::VECTOR2;
2043 VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2044 vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2046 // --------------------------------------------------------------------------
2047 geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2048 geometry.AddVertexBuffer(vertexBuffer);
2051 Shader shader = Shader::New(vertexShader, fragmentShader);
2052 Renderer renderer = Renderer::New(geometry, shader);
2053 actor.AddRenderer(renderer);
2055 Integration::Scene scene = application.GetScene();
2060 // LINE_LOOP, first 0, count 5
2062 renderer.SetIndexRange(0, 5);
2063 application.SendNotification();
2064 application.Render();
2066 Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2068 DALI_TEST_CHECK(value.Get(convertedValue));
2069 DALI_TEST_CHECK(convertedValue == 0);
2071 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2072 DALI_TEST_CHECK(value.Get(convertedValue));
2073 DALI_TEST_CHECK(convertedValue == 0);
2075 value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2076 DALI_TEST_CHECK(value.Get(convertedValue));
2077 DALI_TEST_CHECK(convertedValue == 5);
2079 value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2080 DALI_TEST_CHECK(value.Get(convertedValue));
2081 DALI_TEST_CHECK(convertedValue == 5);
2083 sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2084 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2085 DALI_TEST_CHECK(result);
2088 // LINE_LOOP, first 5, count 10
2090 renderer.SetIndexRange(5, 10);
2091 sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2092 application.SendNotification();
2093 application.Render();
2094 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2095 DALI_TEST_CHECK(result);
2098 // LINE_STRIP, first 15, count 6
2100 renderer.SetIndexRange(15, 6);
2101 geometry.SetType(Geometry::LINE_STRIP);
2102 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2103 application.SendNotification();
2104 application.Render();
2105 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2106 DALI_TEST_CHECK(result);
2109 // Index out of bounds
2111 renderer.SetIndexRange(15, 30);
2112 geometry.SetType(Geometry::LINE_STRIP);
2113 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2114 application.SendNotification();
2115 application.Render();
2116 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2117 DALI_TEST_CHECK(result);
2120 // drawing whole buffer starting from 15 ( last valid primitive )
2122 renderer.SetIndexRange(15, 0);
2123 geometry.SetType(Geometry::LINE_STRIP);
2124 sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2125 application.SendNotification();
2126 application.Render();
2127 bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2128 DALI_TEST_CHECK(result);
2134 int UtcDaliRendererSetDepthFunction(void)
2136 TestApplication application;
2138 tet_infoline("Test setting the depth function");
2140 Geometry geometry = CreateQuadGeometry();
2141 Shader shader = CreateShader();
2142 Renderer renderer = Renderer::New(geometry, shader);
2144 Actor actor = Actor::New();
2145 actor.AddRenderer(renderer);
2146 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2147 Integration::Scene scene = application.GetScene();
2148 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2151 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2152 glAbstraction.EnableEnableDisableCallTrace(true);
2153 glAbstraction.EnableDepthFunctionCallTrace(true);
2155 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2156 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2158 std::ostringstream depthTestStr;
2159 depthTestStr << GL_DEPTH_TEST;
2163 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2165 glEnableDisableStack.Reset();
2166 glDepthFunctionStack.Reset();
2167 application.SendNotification();
2168 application.Render();
2170 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2171 std::ostringstream depthFunctionStr;
2172 depthFunctionStr << GL_NEVER;
2173 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2178 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2180 glDepthFunctionStack.Reset();
2181 application.SendNotification();
2182 application.Render();
2184 std::ostringstream depthFunctionStr;
2185 depthFunctionStr << GL_ALWAYS;
2186 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2191 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2193 glDepthFunctionStack.Reset();
2194 application.SendNotification();
2195 application.Render();
2197 std::ostringstream depthFunctionStr;
2198 depthFunctionStr << GL_LESS;
2199 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2204 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2206 glDepthFunctionStack.Reset();
2207 application.SendNotification();
2208 application.Render();
2210 std::ostringstream depthFunctionStr;
2211 depthFunctionStr << GL_GREATER;
2212 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2217 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2219 glDepthFunctionStack.Reset();
2220 application.SendNotification();
2221 application.Render();
2223 std::ostringstream depthFunctionStr;
2224 depthFunctionStr << GL_EQUAL;
2225 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2230 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2232 glDepthFunctionStack.Reset();
2233 application.SendNotification();
2234 application.Render();
2236 std::ostringstream depthFunctionStr;
2237 depthFunctionStr << GL_NOTEQUAL;
2238 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2243 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2245 glDepthFunctionStack.Reset();
2246 application.SendNotification();
2247 application.Render();
2249 std::ostringstream depthFunctionStr;
2250 depthFunctionStr << GL_LEQUAL;
2251 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2256 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2258 glDepthFunctionStack.Reset();
2259 application.SendNotification();
2260 application.Render();
2262 std::ostringstream depthFunctionStr;
2263 depthFunctionStr << GL_GEQUAL;
2264 DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2271 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2272 * The checks performed are as follows:
2273 * - Check the initial/default value.
2274 * - Set a different value via enum.
2275 * - Check it was set.
2276 * - Set a different value via string.
2277 * - Check it was set.
2279 template<typename T>
2280 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2282 application.SendNotification();
2283 application.Render();
2285 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2286 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2287 renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2288 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2289 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2291 application.SendNotification();
2292 application.Render();
2294 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2295 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2297 renderer.SetProperty(propertyIndex, secondCheckString);
2298 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2299 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2301 application.SendNotification();
2302 application.Render();
2304 DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2305 DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2308 int UtcDaliRendererEnumProperties(void)
2310 TestApplication application;
2311 tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2313 Geometry geometry = CreateQuadGeometry();
2314 Shader shader = CreateShader();
2315 Renderer renderer = Renderer::New(geometry, shader);
2317 Actor actor = Actor::New();
2318 actor.AddRenderer(renderer);
2319 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2320 application.GetScene().Add(actor);
2323 * Here we use a templatized function to perform several checks on each enumeration property.
2324 * @see CheckEnumerationProperty for details of the checks performed.
2327 CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2328 CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2329 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2330 CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2331 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2332 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2333 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2334 CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2335 CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2336 CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2337 CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2338 CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2339 CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2340 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2341 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2342 CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2347 Renderer RendererTestFixture(TestApplication& application)
2349 Geometry geometry = CreateQuadGeometry();
2350 Shader shader = CreateShader();
2351 Renderer renderer = Renderer::New(geometry, shader);
2353 Actor actor = Actor::New();
2354 actor.AddRenderer(renderer);
2355 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2356 Integration::Scene scene = application.GetScene();
2357 scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2363 int UtcDaliRendererSetDepthTestMode(void)
2365 TestApplication application;
2366 tet_infoline("Test setting the DepthTestMode");
2368 Renderer renderer = RendererTestFixture(application);
2369 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2370 glAbstraction.EnableEnableDisableCallTrace(true);
2371 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2373 glEnableDisableStack.Reset();
2374 application.SendNotification();
2375 application.Render();
2377 // Check depth-test is enabled by default.
2378 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2379 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2381 // 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.
2382 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2383 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2385 glEnableDisableStack.Reset();
2386 application.SendNotification();
2387 application.Render();
2389 // Check the depth buffer was disabled.
2390 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2392 // Turn on automatic mode depth-testing.
2393 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2394 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2396 glEnableDisableStack.Reset();
2397 application.SendNotification();
2398 application.Render();
2400 // Check depth-test is now enabled.
2401 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2402 DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2404 // Change the layer behavior to LAYER_UI.
2405 // Note this will also disable depth testing for the layer by default, we test this first.
2406 application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2408 glEnableDisableStack.Reset();
2409 application.SendNotification();
2410 application.Render();
2412 // Check depth-test is disabled.
2413 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2415 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2416 application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2418 glEnableDisableStack.Reset();
2419 application.SendNotification();
2420 application.Render();
2422 // Check depth-test is *still* disabled.
2423 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2428 int UtcDaliRendererSetDepthWriteMode(void)
2430 TestApplication application;
2431 tet_infoline("Test setting the DepthWriteMode");
2433 Renderer renderer = RendererTestFixture(application);
2434 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2436 application.SendNotification();
2437 application.Render();
2439 // Check the default depth-write status first.
2440 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2442 // Turn off depth-writing.
2443 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2445 application.SendNotification();
2446 application.Render();
2448 // Check depth-write is now disabled.
2449 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2451 // Test the AUTO mode for depth-writing.
2452 // As our renderer is opaque, depth-testing should be enabled.
2453 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2455 application.SendNotification();
2456 application.Render();
2458 // Check depth-write is now enabled.
2459 DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2461 // Now make the renderer be treated as translucent by enabling blending.
2462 // The AUTO depth-write mode should turn depth-write off in this scenario.
2463 renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2465 application.SendNotification();
2466 application.Render();
2468 // Check depth-write is now disabled.
2469 DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2474 int UtcDaliRendererCheckStencilDefaults(void)
2476 TestApplication application;
2477 tet_infoline("Test the stencil defaults");
2479 Renderer renderer = RendererTestFixture(application);
2480 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2481 glAbstraction.EnableEnableDisableCallTrace(true);
2482 glAbstraction.EnableStencilFunctionCallTrace(true);
2483 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2484 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2486 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2488 // Check the defaults:
2489 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2490 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2491 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2492 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2493 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2494 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);
2495 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);
2500 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2502 TestApplication application;
2503 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2505 Renderer renderer = RendererTestFixture(application);
2506 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2507 glAbstraction.EnableEnableDisableCallTrace(true);
2508 glAbstraction.EnableStencilFunctionCallTrace(true);
2509 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2510 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2512 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2513 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2514 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2515 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2517 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2518 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2520 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2521 std::string methodString("StencilFunc");
2522 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2524 // Test the other RenderModes that will not enable the stencil buffer.
2525 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2526 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2527 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2529 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2530 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2531 DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2533 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2534 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2535 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2537 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2538 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2540 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2541 // First set a mode to turn off the stencil buffer, so the enable is required.
2542 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2543 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2544 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2545 // Set a different stencil function as the last one is cached.
2546 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2547 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2549 DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2550 DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2555 // Helper function for the SetRenderModeToUseColorBuffer test.
2556 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2558 // Set the RenderMode property to a value that should not allow color buffer writes.
2559 renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2560 application.SendNotification();
2561 application.Render();
2563 // Check if ColorMask has been called, and that the values are correct.
2564 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2565 const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2567 DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2568 DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2569 DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2570 DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2573 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2575 TestApplication application;
2576 tet_infoline("Test setting the RenderMode to use the color buffer");
2578 Renderer renderer = RendererTestFixture(application);
2580 // Set the RenderMode property to a value that should not allow color buffer writes.
2581 // Then check if ColorMask has been called, and that the values are correct.
2582 CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2583 CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2584 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2585 CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2586 CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2591 int UtcDaliRendererSetStencilFunction(void)
2593 TestApplication application;
2594 tet_infoline("Test setting the StencilFunction");
2596 Renderer renderer = RendererTestFixture(application);
2597 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2598 glAbstraction.EnableEnableDisableCallTrace(true);
2599 glAbstraction.EnableStencilFunctionCallTrace(true);
2600 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2601 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2603 // RenderMode must use the stencil for StencilFunction to operate.
2604 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2605 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2608 * Lookup table for testing StencilFunction.
2609 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2611 const int StencilFunctionLookupTable[] = {
2620 const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2623 * Loop through all types of StencilFunction, checking:
2624 * - The value is cached (set in event thread side)
2625 * - Causes "glStencilFunc" to be called
2626 * - Checks the correct parameters to "glStencilFunc" were used
2628 std::string nonChangingParameters = "0, 255";
2629 std::string methodString("StencilFunc");
2630 for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2632 // Set the property.
2633 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2635 // Check GetProperty returns the same value.
2636 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2638 // Reset the trace debug.
2639 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2641 // Check the function is called and the parameters are correct.
2642 std::stringstream parameterStream;
2643 parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2645 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2648 // Change the Function Reference only and check the behavior is correct:
2649 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2650 int testValueReference = 170;
2651 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2653 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2655 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2657 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2659 std::stringstream parameterStream;
2660 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2662 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2664 // Change the Function Mask only and check the behavior is correct:
2665 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2666 int testValueMask = 85;
2667 renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2669 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2671 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2673 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2675 // Clear the stringstream.
2676 parameterStream.str(std::string());
2677 parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2679 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2684 int UtcDaliRendererSetStencilOperation(void)
2686 TestApplication application;
2687 tet_infoline("Test setting the StencilOperation");
2689 Renderer renderer = RendererTestFixture(application);
2690 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2691 glAbstraction.EnableEnableDisableCallTrace(true);
2692 glAbstraction.EnableStencilFunctionCallTrace(true);
2693 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2694 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2696 // RenderMode must use the stencil for StencilOperation to operate.
2697 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2700 * Lookup table for testing StencilOperation.
2701 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2703 const int StencilOperationLookupTable[] = {
2712 const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2714 // Set all 3 StencilOperation properties to a default.
2715 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2716 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2717 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2719 // Set our expected parameter list to the equivalent result.
2720 int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2722 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2725 * Loop through all types of StencilOperation, checking:
2726 * - The value is cached (set in event thread side)
2727 * - Causes "glStencilFunc" to be called
2728 * - Checks the correct parameters to "glStencilFunc" were used
2729 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2731 std::string methodString("StencilOp");
2733 for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2735 for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2737 for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2739 // Set the property (outer loop causes all 3 different properties to be set separately).
2740 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2741 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2742 renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2744 // Check GetProperty returns the same value.
2745 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2746 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2747 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2749 // Reset the trace debug.
2750 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2752 // Check the function is called and the parameters are correct.
2753 // Set the expected parameter value at its correct index (only)
2754 parameters[0u] = StencilOperationLookupTable[i];
2755 parameters[1u] = StencilOperationLookupTable[j];
2756 parameters[2u] = StencilOperationLookupTable[k];
2758 // Build the parameter list.
2759 std::stringstream parameterStream;
2760 for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
2762 parameterStream << parameters[parameterBuild];
2763 // Comma-separate the parameters.
2764 if(parameterBuild < 2)
2766 parameterStream << ", ";
2770 // Check the function was called and the parameters were correct.
2771 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2779 int UtcDaliRendererSetStencilMask(void)
2781 TestApplication application;
2782 tet_infoline("Test setting the StencilMask");
2784 Renderer renderer = RendererTestFixture(application);
2785 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2786 glAbstraction.EnableEnableDisableCallTrace(true);
2787 glAbstraction.EnableStencilFunctionCallTrace(true);
2788 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2789 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2791 // RenderMode must use the stencil for StencilMask to operate.
2792 renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2794 // Set the StencilMask property to a value.
2795 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
2797 // Check GetProperty returns the same value.
2798 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2800 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2802 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2804 std::string methodString("StencilMask");
2805 std::string parameterString = "0";
2807 // Check the function was called and the parameters were correct.
2808 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2810 // Set the StencilMask property to another value to ensure it has changed.
2811 renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
2813 // Check GetProperty returns the same value.
2814 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2816 ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2818 DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2820 parameterString = "255";
2822 // Check the function was called and the parameters were correct.
2823 DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2828 int UtcDaliRendererWrongNumberOfTextures(void)
2830 TestApplication application;
2831 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2833 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2834 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2835 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
2836 TextureSet textureSet = CreateTextureSet();
2837 textureSet.SetTexture(0, texture);
2838 textureSet.SetTexture(1, texture);
2839 textureSet.SetTexture(2, texture);
2840 textureSet.SetTexture(3, texture);
2841 Shader shader = Shader::New("VertexSource", "FragmentSource");
2842 Geometry geometry = CreateQuadGeometry();
2843 Renderer renderer = Renderer::New(geometry, shader);
2844 renderer.SetTextures(textureSet);
2846 Actor actor = Actor::New();
2847 actor.AddRenderer(renderer);
2848 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
2849 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2850 application.GetScene().Add(actor);
2852 TestGlAbstraction& gl = application.GetGlAbstraction();
2853 TraceCallStack& drawTrace = gl.GetDrawTrace();
2855 drawTrace.Enable(true);
2857 application.SendNotification();
2858 application.Render(0);
2860 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2861 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
2863 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2864 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2865 textureSet = CreateTextureSet();
2866 renderer.SetTextures(textureSet);
2867 textureSet.SetTexture(0, texture);
2869 application.SendNotification();
2870 application.Render(0);
2872 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2873 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
2878 int UtcDaliRendererOpacity(void)
2880 TestApplication application;
2882 tet_infoline("Test OPACITY property");
2884 Geometry geometry = CreateQuadGeometry();
2885 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
2886 Renderer renderer = Renderer::New(geometry, shader);
2888 Actor actor = Actor::New();
2889 actor.AddRenderer(renderer);
2890 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2891 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
2892 application.GetScene().Add(actor);
2894 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
2896 DALI_TEST_CHECK(value.Get(opacity));
2897 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2899 application.SendNotification();
2900 application.Render();
2902 Vector4 actualValue;
2903 TestGlAbstraction& gl = application.GetGlAbstraction();
2904 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
2905 DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2907 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
2909 application.SendNotification();
2910 application.Render();
2912 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
2913 DALI_TEST_CHECK(value.Get(opacity));
2914 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2916 value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
2917 DALI_TEST_CHECK(value.Get(opacity));
2918 DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2920 DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
2921 DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2926 int UtcDaliRendererOpacityAnimation(void)
2928 TestApplication application;
2930 tet_infoline("Test OPACITY property animation");
2932 Geometry geometry = CreateQuadGeometry();
2933 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
2934 Renderer renderer = Renderer::New(geometry, shader);
2936 Actor actor = Actor::New();
2937 actor.AddRenderer(renderer);
2938 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2939 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
2940 application.GetScene().Add(actor);
2942 application.SendNotification();
2943 application.Render(0);
2945 Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
2947 DALI_TEST_CHECK(value.Get(opacity));
2948 DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2950 Animation animation = Animation::New(1.0f);
2951 animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
2954 application.SendNotification();
2955 application.Render(1000);
2957 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
2958 DALI_TEST_CHECK(value.Get(opacity));
2959 DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2961 // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
2963 renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
2965 animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
2968 application.SendNotification();
2969 application.Render(1000);
2971 value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
2972 DALI_TEST_CHECK(value.Get(opacity));
2973 DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2974 DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
2979 int UtcDaliRendererInvalidProperty(void)
2981 TestApplication application;
2983 tet_infoline("Test invalid property");
2985 Geometry geometry = CreateQuadGeometry();
2986 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
2987 Renderer renderer = Renderer::New(geometry, shader);
2989 Actor actor = Actor::New();
2990 actor.AddRenderer(renderer);
2991 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2992 application.GetScene().Add(actor);
2994 application.SendNotification();
2995 application.Render(0);
2997 Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
2998 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3000 value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3001 DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3006 int UtcDaliRendererRenderingBehavior(void)
3008 TestApplication application;
3010 tet_infoline("Test RENDERING_BEHAVIOR property");
3012 Geometry geometry = CreateQuadGeometry();
3013 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3014 Renderer renderer = Renderer::New(geometry, shader);
3016 Actor actor = Actor::New();
3017 actor.AddRenderer(renderer);
3018 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3019 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3020 application.GetScene().Add(actor);
3022 Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3023 int renderingBehavior;
3024 DALI_TEST_CHECK(value.Get(renderingBehavior));
3025 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3027 application.SendNotification();
3028 application.Render();
3030 uint32_t updateStatus = application.GetUpdateStatus();
3032 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3034 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3036 value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3037 DALI_TEST_CHECK(value.Get(renderingBehavior));
3038 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3040 // Render and check the update status
3041 application.SendNotification();
3042 application.Render();
3044 updateStatus = application.GetUpdateStatus();
3046 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3048 value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3049 DALI_TEST_CHECK(value.Get(renderingBehavior));
3050 DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3052 // Render again and check the update status
3053 application.SendNotification();
3054 application.Render();
3056 updateStatus = application.GetUpdateStatus();
3058 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3060 // Change rendering behavior
3061 renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3063 // Render and check the update status
3064 application.SendNotification();
3065 application.Render();
3067 updateStatus = application.GetUpdateStatus();
3069 DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3074 int UtcDaliRendererRegenerateUniformMap(void)
3076 TestApplication application;
3078 tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3080 Geometry geometry = CreateQuadGeometry();
3081 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3082 Renderer renderer = Renderer::New(geometry, shader);
3084 Actor actor = Actor::New();
3085 actor.AddRenderer(renderer);
3086 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3087 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3088 application.GetScene().Add(actor);
3090 application.SendNotification();
3091 application.Render();
3093 actor.RemoveRenderer(renderer);
3094 shader = Shader::New("vertexSrc", "fragmentSrc");
3095 shader.RegisterProperty("opacity", 0.5f);
3096 renderer.SetShader(shader);
3098 Stage::GetCurrent().KeepRendering(1.0f);
3100 // Update for several frames
3101 application.SendNotification();
3102 application.Render();
3103 application.SendNotification();
3104 application.Render();
3105 application.SendNotification();
3106 application.Render();
3107 application.SendNotification();
3108 application.Render();
3111 actor.AddRenderer(renderer);
3112 application.SendNotification();
3113 application.Render();
3115 // Nothing to test here, the test must not crash
3116 auto updateStatus = application.GetUpdateStatus();
3117 DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3122 int UtcDaliRendererAddDrawCommands(void)
3124 TestApplication application;
3126 tet_infoline("Test adding draw commands to the renderer");
3128 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3129 glAbstraction.EnableEnableDisableCallTrace(true);
3131 Geometry geometry = CreateQuadGeometry();
3132 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
3133 Renderer renderer = Renderer::New(geometry, shader);
3135 renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3136 Actor actor = Actor::New();
3137 actor.AddRenderer(renderer);
3138 actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3139 actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3140 application.GetScene().Add(actor);
3142 // Expect delivering a single draw call
3143 auto& drawTrace = glAbstraction.GetDrawTrace();
3145 drawTrace.Enable(true);
3146 application.SendNotification();
3147 application.Render();
3149 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3151 auto drawCommand1 = DevelRenderer::DrawCommand{};
3152 drawCommand1.drawType = DevelRenderer::DrawType::INDEXED;
3153 drawCommand1.firstIndex = 0;
3154 drawCommand1.elementCount = 2;
3155 drawCommand1.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3157 auto drawCommand2 = DevelRenderer::DrawCommand{};
3158 drawCommand2.drawType = DevelRenderer::DrawType::INDEXED;
3159 drawCommand2.firstIndex = 2;
3160 drawCommand2.elementCount = 2;
3161 drawCommand2.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3163 auto drawCommand3 = DevelRenderer::DrawCommand{};
3164 drawCommand3.drawType = DevelRenderer::DrawType::ARRAY;
3165 drawCommand3.firstIndex = 2;
3166 drawCommand3.elementCount = 2;
3167 drawCommand3.queue = DevelRenderer::RENDER_QUEUE_OPAQUE;
3169 DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3170 DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3171 DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3174 drawTrace.Enable(true);
3175 application.SendNotification();
3176 application.Render();
3178 DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3182 int UtcDaliRendererSetGeometryNegative(void)
3184 TestApplication application;
3185 Dali::Renderer instance;
3188 Dali::Geometry arg1;
3189 instance.SetGeometry(arg1);
3190 DALI_TEST_CHECK(false); // Should not get here
3194 DALI_TEST_CHECK(true); // We expect an assert
3199 int UtcDaliRendererSetTexturesNegative(void)
3201 TestApplication application;
3202 Dali::Renderer instance;
3205 Dali::TextureSet arg1;
3206 instance.SetTextures(arg1);
3207 DALI_TEST_CHECK(false); // Should not get here
3211 DALI_TEST_CHECK(true); // We expect an assert
3216 int UtcDaliRendererSetShaderNegative(void)
3218 TestApplication application;
3219 Dali::Renderer instance;
3223 instance.SetShader(arg1);
3224 DALI_TEST_CHECK(false); // Should not get here
3228 DALI_TEST_CHECK(true); // We expect an assert
3233 int UtcDaliRendererGetGeometryNegative(void)
3235 TestApplication application;
3236 Dali::Renderer instance;
3239 instance.GetGeometry();
3240 DALI_TEST_CHECK(false); // Should not get here
3244 DALI_TEST_CHECK(true); // We expect an assert
3249 int UtcDaliRendererGetTexturesNegative(void)
3251 TestApplication application;
3252 Dali::Renderer instance;
3255 instance.GetTextures();
3256 DALI_TEST_CHECK(false); // Should not get here
3260 DALI_TEST_CHECK(true); // We expect an assert
3265 int UtcDaliRendererGetShaderNegative(void)
3267 TestApplication application;
3268 Dali::Renderer instance;
3271 instance.GetShader();
3272 DALI_TEST_CHECK(false); // Should not get here
3276 DALI_TEST_CHECK(true); // We expect an assert