2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
25 void material_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void material_test_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliMaterialNew01(void)
37 TestApplication application;
39 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
40 Material material = Material::New(shader);
42 DALI_TEST_EQUALS( (bool)material, true, TEST_LOCATION );
46 int UtcDaliMaterialNew02(void)
48 TestApplication application;
50 DALI_TEST_EQUALS( (bool)material, false, TEST_LOCATION );
54 int UtcDaliMaterialDownCast01(void)
56 TestApplication application;
57 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
58 Material material = Material::New(shader);
60 BaseHandle handle(material);
61 Material material2 = Material::DownCast(handle);
62 DALI_TEST_EQUALS( (bool)material2, true, TEST_LOCATION );
66 int UtcDaliMaterialDownCast02(void)
68 TestApplication application;
70 Handle handle = Handle::New(); // Create a custom object
71 Material material = Material::DownCast(handle);
72 DALI_TEST_EQUALS( (bool)material, false, TEST_LOCATION );
78 int UtcDaliMaterialBlendingOptions01(void)
80 TestApplication application;
82 tet_infoline("Test SetBlendFunc(src, dest) ");
84 Geometry geometry = CreateQuadGeometry();
85 Material material = CreateMaterial(0.5f);
86 Renderer renderer = Renderer::New( geometry, material );
88 Actor actor = Actor::New();
89 actor.AddRenderer(renderer);
90 actor.SetSize(400, 400);
91 Stage::GetCurrent().Add(actor);
93 material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
95 // Test that Set was successful:
97 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
98 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
99 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
100 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
101 material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
103 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
104 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
105 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
106 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
109 application.SendNotification();
110 application.Render();
112 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
114 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
115 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
116 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
117 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
122 int UtcDaliMaterialBlendingOptions02(void)
124 TestApplication application;
126 tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
128 Geometry geometry = CreateQuadGeometry();
129 Material material = CreateMaterial(0.5f);
130 Renderer renderer = Renderer::New( geometry, material );
132 Actor actor = Actor::New();
133 actor.AddRenderer(renderer);
134 actor.SetSize(400, 400);
135 Stage::GetCurrent().Add(actor);
137 material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
138 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
140 // Test that Set was successful:
142 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
143 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
144 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
145 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
146 material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
148 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
149 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
150 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
151 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
154 application.SendNotification();
155 application.Render();
157 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
158 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
159 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
160 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
161 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
168 int UtcDaliMaterialBlendingOptions03(void)
170 TestApplication application;
172 tet_infoline("Test GetBlendEquation() defaults ");
174 Geometry geometry = CreateQuadGeometry();
175 Material material = CreateMaterial(0.5f);
176 Renderer renderer = Renderer::New( geometry, material );
178 Actor actor = Actor::New();
179 actor.AddRenderer(renderer);
180 actor.SetSize(400, 400);
181 Stage::GetCurrent().Add(actor);
183 // Test the defaults as documented int blending.h
185 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
186 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
187 material.GetBlendEquation( equationRgb, equationAlpha );
188 DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
189 DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
196 int UtcDaliMaterialBlendingOptions04(void)
198 TestApplication application;
200 tet_infoline("Test SetBlendEquation() ");
202 Geometry geometry = CreateQuadGeometry();
203 Material material = CreateMaterial(0.5f);
204 Renderer renderer = Renderer::New( geometry, material );
206 Actor actor = Actor::New();
207 actor.AddRenderer(renderer);
208 actor.SetSize(400, 400);
209 Stage::GetCurrent().Add(actor);
211 // Test the single blending equation setting
213 material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
214 BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
215 material.GetBlendEquation( equationRgba, equationRgba );
216 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
219 material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
221 // Test that Set was successful
223 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
224 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
225 material.GetBlendEquation( equationRgb, equationAlpha );
226 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
227 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
230 // Render & check GL commands
231 application.SendNotification();
232 application.Render();
234 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
235 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
236 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
241 int UtcDaliMaterialSetBlendMode01(void)
243 TestApplication application;
245 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
247 Geometry geometry = CreateQuadGeometry();
248 Material material = CreateMaterial(1.0f);
249 Renderer renderer = Renderer::New( geometry, material );
251 Actor actor = Actor::New();
252 actor.AddRenderer(renderer);
253 actor.SetSize(400, 400);
254 Stage::GetCurrent().Add(actor);
256 material.SetBlendMode(BlendingMode::ON);
258 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
259 glAbstraction.EnableCullFaceCallTrace(true);
261 application.SendNotification();
262 application.Render();
264 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
265 std::ostringstream blendStr;
266 blendStr << GL_BLEND;
267 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
273 int UtcDaliMaterialSetBlendMode02(void)
275 TestApplication application;
277 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
279 Geometry geometry = CreateQuadGeometry();
280 Material material = CreateMaterial(0.5f);
281 Renderer renderer = Renderer::New( geometry, material );
283 Actor actor = Actor::New();
284 actor.AddRenderer(renderer);
285 actor.SetSize(400, 400);
286 Stage::GetCurrent().Add(actor);
288 material.SetBlendMode(BlendingMode::OFF);
290 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
291 glAbstraction.EnableCullFaceCallTrace(true);
293 application.SendNotification();
294 application.Render();
296 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
297 std::ostringstream blendStr;
298 blendStr << GL_BLEND;
299 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
304 int UtcDaliMaterialSetBlendMode03(void)
306 TestApplication application;
308 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
310 Geometry geometry = CreateQuadGeometry();
311 Material material = CreateMaterial(0.5f);
312 Renderer renderer = Renderer::New( geometry, material );
314 Actor actor = Actor::New();
315 actor.AddRenderer(renderer);
316 actor.SetSize(400, 400);
317 Stage::GetCurrent().Add(actor);
319 material.SetBlendMode(BlendingMode::AUTO);
321 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
322 glAbstraction.EnableCullFaceCallTrace(true);
324 application.SendNotification();
325 application.Render();
327 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
328 std::ostringstream blendStr;
329 blendStr << GL_BLEND;
330 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
335 int UtcDaliMaterialSetBlendMode04(void)
337 TestApplication application;
339 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
341 Geometry geometry = CreateQuadGeometry();
342 Material material = CreateMaterial(1.0f);
343 Renderer renderer = Renderer::New( geometry, material );
345 Actor actor = Actor::New();
346 actor.AddRenderer(renderer);
347 actor.SetSize(400, 400);
348 Stage::GetCurrent().Add(actor);
350 material.SetBlendMode(BlendingMode::AUTO);
352 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
353 glAbstraction.EnableCullFaceCallTrace(true);
355 application.SendNotification();
356 application.Render();
358 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
359 std::ostringstream blendStr;
360 blendStr << GL_BLEND;
361 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
366 int UtcDaliMaterialSetBlendMode05(void)
368 TestApplication application;
370 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
372 Geometry geometry = CreateQuadGeometry();
373 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
374 Material material = CreateMaterial(1.0f, image);
375 Renderer renderer = Renderer::New( geometry, material );
377 Actor actor = Actor::New();
378 actor.AddRenderer(renderer);
379 actor.SetSize(400, 400);
380 Stage::GetCurrent().Add(actor);
382 material.SetBlendMode(BlendingMode::AUTO);
384 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
385 glAbstraction.EnableCullFaceCallTrace(true);
387 application.SendNotification();
388 application.Render();
390 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
391 std::ostringstream blendStr;
392 blendStr << GL_BLEND;
393 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );