Remove uniform mappings.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Geometry.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 void geometry_test_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void geometry_test_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 namespace
36 {
37
38 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
39 {
40   current.b = 0.0f;
41 }
42
43 }
44
45
46 int UtcDaliGeometryNew01(void)
47 {
48   TestApplication application;
49
50   Geometry geometry = Geometry::New();
51
52   DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
53   END_TEST;
54 }
55
56 int UtcDaliGeometryNew02(void)
57 {
58   TestApplication application;
59   Geometry geometry;
60   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
61   END_TEST;
62 }
63
64 int UtcDaliGeometryDownCast01(void)
65 {
66   TestApplication application;
67
68   Geometry geometry = Geometry::New();
69
70   BaseHandle handle(geometry);
71   Geometry geometry2 = Geometry::DownCast(handle);
72   DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
73   END_TEST;
74 }
75
76 int UtcDaliGeometryDownCast02(void)
77 {
78   TestApplication application;
79
80   Handle handle = Handle::New(); // Create a custom object
81   Geometry geometry = Geometry::DownCast(handle);
82   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
83   END_TEST;
84 }
85
86
87 int UtcDaliGeometryConstraint01(void)
88 {
89   TestApplication application;
90
91   tet_infoline("Test that a non-uniform geometry property can be constrained");
92
93   Shader shader = Shader::New("VertexSource", "FragmentSource");
94   Material material = Material::New( shader );
95   material.SetProperty(Material::Property::COLOR, Color::WHITE);
96
97   Geometry geometry = CreateQuadGeometry();
98   Renderer renderer = Renderer::New( geometry, material );
99
100   Actor actor = Actor::New();
101   actor.AddRenderer(renderer);
102   actor.SetSize(400, 400);
103   Stage::GetCurrent().Add(actor);
104
105   Vector4 initialColor = Color::WHITE;
106   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
107
108   application.SendNotification();
109   application.Render(0);
110   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
111
112   // Apply constraint
113   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
114   constraint.Apply();
115   application.SendNotification();
116   application.Render(0);
117
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 );
122
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 );
128
129   END_TEST;
130 }
131
132 int UtcDaliGeometryConstraint02(void)
133 {
134   TestApplication application;
135
136   tet_infoline("Test that a uniform map geometry property can be constrained");
137
138   Shader shader = Shader::New("VertexSource", "FragmentSource");
139   Material material = Material::New( shader );
140   material.SetProperty(Material::Property::COLOR, Color::WHITE);
141
142   Geometry geometry = CreateQuadGeometry();
143   Renderer renderer = Renderer::New( geometry, material );
144
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);
151
152   Vector4 initialColor = Color::WHITE;
153   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
154
155   TestGlAbstraction& gl = application.GetGlAbstraction();
156
157   application.SendNotification();
158   application.Render(0);
159
160   Vector4 actualValue(Vector4::ZERO);
161   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
162   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
163
164   // Apply constraint
165   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
166   constraint.Apply();
167   application.SendNotification();
168   application.Render(0);
169
170    // Expect no blue component in either buffer - yellow
171   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
172   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
173
174   application.Render(0);
175   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
176   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
177
178   geometry.RemoveConstraints();
179   geometry.SetProperty(colorIndex, Color::WHITE );
180   application.SendNotification();
181   application.Render(0);
182
183   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
184   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
185
186   END_TEST;
187 }
188
189
190
191 int UtcDaliGeometryAnimatedProperty01(void)
192 {
193   TestApplication application;
194
195   tet_infoline("Test that a non-uniform geometry property can be animated");
196
197   Shader shader = Shader::New("VertexSource", "FragmentSource");
198   Material material = Material::New( shader );
199   material.SetProperty(Material::Property::COLOR, Color::WHITE);
200
201   Geometry geometry = CreateQuadGeometry();
202   Renderer renderer = Renderer::New( geometry, material );
203
204   Actor actor = Actor::New();
205   actor.AddRenderer(renderer);
206   actor.SetSize(400, 400);
207   Stage::GetCurrent().Add(actor);
208
209   Vector4 initialColor = Color::WHITE;
210   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
211
212   application.SendNotification();
213   application.Render(0);
214   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
215
216   Animation  animation = Animation::New(1.0f);
217   KeyFrames keyFrames = KeyFrames::New();
218   keyFrames.Add(0.0f, initialColor);
219   keyFrames.Add(1.0f, Color::TRANSPARENT);
220   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
221   animation.Play();
222
223   application.SendNotification();
224   application.Render(500);
225
226   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
227
228   application.Render(500);
229
230   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
231
232   END_TEST;
233 }
234
235 int UtcDaliGeometryAnimatedProperty02(void)
236 {
237   TestApplication application;
238
239   tet_infoline("Test that a uniform map geometry property can be animated");
240
241   Shader shader = Shader::New("VertexSource", "FragmentSource");
242   Material material = Material::New( shader );
243   material.SetProperty(Material::Property::COLOR, Color::WHITE);
244
245   Geometry geometry = CreateQuadGeometry();
246   Renderer renderer = Renderer::New( geometry, material );
247
248   Actor actor = Actor::New();
249   actor.AddRenderer(renderer);
250   actor.SetSize(400, 400);
251   Stage::GetCurrent().Add(actor);
252   application.SendNotification();
253   application.Render(0);
254
255   Vector4 initialColor = Color::WHITE;
256   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
257
258   TestGlAbstraction& gl = application.GetGlAbstraction();
259
260   application.SendNotification();
261   application.Render(0);
262
263   Vector4 actualValue(Vector4::ZERO);
264   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
265   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
266
267   Animation  animation = Animation::New(1.0f);
268   KeyFrames keyFrames = KeyFrames::New();
269   keyFrames.Add(0.0f, initialColor);
270   keyFrames.Add(1.0f, Color::TRANSPARENT);
271   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
272   animation.Play();
273
274   application.SendNotification();
275   application.Render(500);
276
277   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
278   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
279
280   application.Render(500);
281   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
282   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
283
284   END_TEST;
285 }