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 geometry_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void geometry_test_cleanup(void)
32 test_return_value = TET_PASS;
38 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
46 int UtcDaliGeometryNew01(void)
48 TestApplication application;
50 Geometry geometry = Geometry::New();
52 DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
56 int UtcDaliGeometryNew02(void)
58 TestApplication application;
60 DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
64 int UtcDaliGeometryDownCast01(void)
66 TestApplication application;
68 Geometry geometry = Geometry::New();
70 BaseHandle handle(geometry);
71 Geometry geometry2 = Geometry::DownCast(handle);
72 DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
76 int UtcDaliGeometryDownCast02(void)
78 TestApplication application;
80 Handle handle = Handle::New(); // Create a custom object
81 Geometry geometry = Geometry::DownCast(handle);
82 DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
87 int UtcDaliGeometryConstraint01(void)
89 TestApplication application;
91 tet_infoline("Test that a non-uniform geometry property can be constrained");
93 Shader shader = Shader::New("VertexSource", "FragmentSource");
94 Material material = Material::New( shader );
95 material.SetProperty(Material::Property::COLOR, Color::WHITE);
97 Geometry geometry = CreateQuadGeometry();
98 Renderer renderer = Renderer::New( geometry, material );
100 Actor actor = Actor::New();
101 actor.AddRenderer(renderer);
102 actor.SetSize(400, 400);
103 Stage::GetCurrent().Add(actor);
105 Vector4 initialColor = Color::WHITE;
106 Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
108 application.SendNotification();
109 application.Render(0);
110 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
113 Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
115 application.SendNotification();
116 application.Render(0);
118 // Expect no blue component in either buffer - yellow
119 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
120 application.Render(0);
121 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
123 geometry.RemoveConstraints();
124 geometry.SetProperty(colorIndex, Color::WHITE );
125 application.SendNotification();
126 application.Render(0);
127 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
132 int UtcDaliGeometryConstraint02(void)
134 TestApplication application;
136 tet_infoline("Test that a uniform map geometry property can be constrained");
138 Shader shader = Shader::New("VertexSource", "FragmentSource");
139 Material material = Material::New( shader );
140 material.SetProperty(Material::Property::COLOR, Color::WHITE);
142 Geometry geometry = CreateQuadGeometry();
143 Renderer renderer = Renderer::New( geometry, material );
145 Actor actor = Actor::New();
146 actor.AddRenderer(renderer);
147 actor.SetSize(400, 400);
148 Stage::GetCurrent().Add(actor);
149 application.SendNotification();
150 application.Render(0);
152 Vector4 initialColor = Color::WHITE;
153 Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
154 geometry.AddUniformMapping( colorIndex, std::string("uFadeColor") );
156 TestGlAbstraction& gl = application.GetGlAbstraction();
158 application.SendNotification();
159 application.Render(0);
161 Vector4 actualValue(Vector4::ZERO);
162 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
163 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
166 Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
168 application.SendNotification();
169 application.Render(0);
171 // Expect no blue component in either buffer - yellow
172 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
173 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
175 application.Render(0);
176 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
177 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
179 geometry.RemoveConstraints();
180 geometry.SetProperty(colorIndex, Color::WHITE );
181 application.SendNotification();
182 application.Render(0);
184 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
185 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
192 int UtcDaliGeometryAnimatedProperty01(void)
194 TestApplication application;
196 tet_infoline("Test that a non-uniform geometry property can be animated");
198 Shader shader = Shader::New("VertexSource", "FragmentSource");
199 Material material = Material::New( shader );
200 material.SetProperty(Material::Property::COLOR, Color::WHITE);
202 Geometry geometry = CreateQuadGeometry();
203 Renderer renderer = Renderer::New( geometry, material );
205 Actor actor = Actor::New();
206 actor.AddRenderer(renderer);
207 actor.SetSize(400, 400);
208 Stage::GetCurrent().Add(actor);
210 Vector4 initialColor = Color::WHITE;
211 Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
213 application.SendNotification();
214 application.Render(0);
215 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
217 Animation animation = Animation::New(1.0f);
218 KeyFrames keyFrames = KeyFrames::New();
219 keyFrames.Add(0.0f, initialColor);
220 keyFrames.Add(1.0f, Color::TRANSPARENT);
221 animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
224 application.SendNotification();
225 application.Render(500);
227 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
229 application.Render(500);
231 DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
236 int UtcDaliGeometryAnimatedProperty02(void)
238 TestApplication application;
240 tet_infoline("Test that a uniform map geometry property can be animated");
242 Shader shader = Shader::New("VertexSource", "FragmentSource");
243 Material material = Material::New( shader );
244 material.SetProperty(Material::Property::COLOR, Color::WHITE);
246 Geometry geometry = CreateQuadGeometry();
247 Renderer renderer = Renderer::New( geometry, material );
249 Actor actor = Actor::New();
250 actor.AddRenderer(renderer);
251 actor.SetSize(400, 400);
252 Stage::GetCurrent().Add(actor);
253 application.SendNotification();
254 application.Render(0);
256 Vector4 initialColor = Color::WHITE;
257 Property::Index colorIndex = geometry.RegisterProperty( "fade-color", initialColor );
258 geometry.AddUniformMapping( colorIndex, std::string("uFadeColor") );
260 TestGlAbstraction& gl = application.GetGlAbstraction();
262 application.SendNotification();
263 application.Render(0);
265 Vector4 actualValue(Vector4::ZERO);
266 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
267 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
269 Animation animation = Animation::New(1.0f);
270 KeyFrames keyFrames = KeyFrames::New();
271 keyFrames.Add(0.0f, initialColor);
272 keyFrames.Add(1.0f, Color::TRANSPARENT);
273 animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
276 application.SendNotification();
277 application.Render(500);
279 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
280 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
282 application.Render(500);
283 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
284 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );