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>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
33 void propertyBuffer_test_startup(void)
35 test_return_value = TET_UNDEF;
38 void propertyBuffer_test_cleanup(void)
40 test_return_value = TET_PASS;
43 int UtcDaliPropertyBufferNew01(void)
45 TestApplication application;
47 Property::Map texturedQuadVertexFormat;
48 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
49 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
51 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
53 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
57 int UtcDaliPropertyBufferNew02(void)
59 TestApplication application;
60 PropertyBuffer propertyBuffer;
61 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
65 int UtcDaliPropertyBufferDownCast01(void)
67 TestApplication application;
69 Property::Map texturedQuadVertexFormat;
70 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
71 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
73 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
75 BaseHandle handle(propertyBuffer);
76 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
77 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
81 int UtcDaliPropertyBufferDownCast02(void)
83 TestApplication application;
85 Handle handle = Handle::New(); // Create a custom object
86 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
87 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
92 int UtcDaliPropertyBufferConstraint01(void)
94 TestApplication application;
96 tet_infoline("Test that a non-uniform propertyBuffer property can be constrained");
98 Shader shader = Shader::New("VertexSource", "FragmentSource");
99 Material material = Material::New( shader );
100 material.SetProperty(Material::Property::COLOR, Color::WHITE);
102 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
103 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
104 Renderer renderer = Renderer::New( geometry, material );
106 Actor actor = Actor::New();
107 actor.AddRenderer(renderer);
108 actor.SetSize(400, 400);
109 Stage::GetCurrent().Add(actor);
111 Vector4 initialColor = Color::WHITE;
112 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
114 application.SendNotification();
115 application.Render(0);
116 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
119 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
121 application.SendNotification();
122 application.Render(0);
124 // Expect no blue component in either buffer - yellow
125 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
126 application.Render(0);
127 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
129 propertyBuffer.RemoveConstraints();
130 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
131 application.SendNotification();
132 application.Render(0);
133 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
138 int UtcDaliPropertyBufferConstraint02(void)
140 TestApplication application;
142 tet_infoline("Test that a uniform map propertyBuffer property can be constrained");
144 Shader shader = Shader::New( "VertexSource", "FragmentSource" );
145 Material material = Material::New( shader );
146 material.SetProperty(Material::Property::COLOR, Color::WHITE);
148 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
149 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
150 Renderer renderer = Renderer::New( geometry, material );
152 Actor actor = Actor::New();
153 actor.AddRenderer(renderer);
154 actor.SetSize(400, 400);
155 Stage::GetCurrent().Add(actor);
156 application.SendNotification();
157 application.Render(0);
159 Vector4 initialColor = Color::WHITE;
160 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
161 propertyBuffer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
163 TestGlAbstraction& gl = application.GetGlAbstraction();
165 application.SendNotification();
166 application.Render(0);
168 Vector4 actualValue(Vector4::ZERO);
169 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
170 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
173 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
175 application.SendNotification();
176 application.Render(0);
178 // Expect no blue component in either buffer - yellow
179 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
180 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
182 application.Render(0);
183 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
184 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
186 propertyBuffer.RemoveConstraints();
187 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
188 application.SendNotification();
189 application.Render(0);
191 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
192 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
199 int UtcDaliPropertyBufferAnimatedProperty01(void)
201 TestApplication application;
203 tet_infoline("Test that a non-uniform propertyBuffer property can be animated");
205 Shader shader = Shader::New("VertexSource", "FragmentSource");
206 Material material = Material::New( shader );
207 material.SetProperty(Material::Property::COLOR, Color::WHITE);
209 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
210 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
211 Renderer renderer = Renderer::New( geometry, material );
213 Actor actor = Actor::New();
214 actor.AddRenderer(renderer);
215 actor.SetSize(400, 400);
216 Stage::GetCurrent().Add(actor);
218 Vector4 initialColor = Color::WHITE;
219 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
221 application.SendNotification();
222 application.Render(0);
223 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
225 Animation animation = Animation::New(1.0f);
226 KeyFrames keyFrames = KeyFrames::New();
227 keyFrames.Add(0.0f, initialColor);
228 keyFrames.Add(1.0f, Color::TRANSPARENT);
229 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
232 application.SendNotification();
233 application.Render(500);
235 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
237 application.Render(500);
239 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
244 int UtcDaliPropertyBufferAnimatedProperty02(void)
246 TestApplication application;
248 tet_infoline("Test that a uniform map propertyBuffer property can be animated");
250 Shader shader = Shader::New("VertexSource", "FragmentSource");
251 Material material = Material::New( shader );
252 material.SetProperty(Material::Property::COLOR, Color::WHITE);
254 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
255 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
256 Renderer renderer = Renderer::New( geometry, material );
258 Actor actor = Actor::New();
259 actor.AddRenderer(renderer);
260 actor.SetSize(400, 400);
261 Stage::GetCurrent().Add(actor);
262 application.SendNotification();
263 application.Render(0);
265 Vector4 initialColor = Color::WHITE;
266 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
267 propertyBuffer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
269 TestGlAbstraction& gl = application.GetGlAbstraction();
271 application.SendNotification();
272 application.Render(0);
274 Vector4 actualValue(Vector4::ZERO);
275 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
276 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
278 Animation animation = Animation::New(1.0f);
279 KeyFrames keyFrames = KeyFrames::New();
280 keyFrames.Add(0.0f, initialColor);
281 keyFrames.Add(1.0f, Color::TRANSPARENT);
282 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
285 application.SendNotification();
286 application.Render(500);
288 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
289 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
291 application.Render(500);
292 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
293 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
298 int UtcDaliPropertyBufferSetData01(void)
300 TestApplication application;
302 Property::Map texturedQuadVertexFormat;
303 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
304 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
306 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
307 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
309 const float halfQuadSize = .5f;
310 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
311 TexturedQuadVertex texturedQuadVertexData[4] = {
312 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
313 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
314 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
315 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
317 propertyBuffer.SetData( texturedQuadVertexData );
319 Geometry geometry = Geometry::New();
320 geometry.AddVertexBuffer( propertyBuffer );
322 Material material = CreateMaterial(1.f);
323 Renderer renderer = Renderer::New(geometry, material);
324 Actor actor = Actor::New();
325 actor.SetSize(Vector3::ONE * 100.f);
326 actor.AddRenderer(renderer);
327 Stage::GetCurrent().Add(actor);
329 application.SendNotification();
330 application.Render(0);
331 application.Render();
332 application.SendNotification();
334 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
335 application.GetGlAbstraction().GetBufferDataCalls();
337 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
339 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
344 int UtcDaliPropertyBufferSetData02(void)
346 TestApplication application;
348 Property::Map texturedQuadVertexFormat;
349 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
350 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
352 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
353 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
355 const float halfQuadSize = .5f;
356 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
357 TexturedQuadVertex texturedQuadVertexData[4] = {
358 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
359 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
360 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
361 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
363 propertyBuffer.SetData( texturedQuadVertexData );
365 Geometry geometry = Geometry::New();
366 geometry.AddVertexBuffer( propertyBuffer );
368 Material material = CreateMaterial(1.f);
369 Renderer renderer = Renderer::New(geometry, material);
370 Actor actor = Actor::New();
371 actor.SetSize(Vector3::ONE * 100.f);
372 actor.AddRenderer(renderer);
373 Stage::GetCurrent().Add(actor);
375 application.SendNotification();
376 application.Render(0);
377 application.Render();
378 application.SendNotification();
381 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
382 application.GetGlAbstraction().GetBufferDataCalls();
384 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
386 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
389 // Re-upload the data on the propertyBuffer
390 propertyBuffer.SetData( texturedQuadVertexData );
392 application.SendNotification();
393 application.Render(0);
394 application.Render();
395 application.SendNotification();
398 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
399 application.GetGlAbstraction().GetBufferSubDataCalls();
401 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
403 if ( bufferSubDataCalls.size() )
405 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
412 int UtcDaliPropertyBufferSetSize01(void)
414 TestApplication application;
416 Property::Map texturedQuadVertexFormat;
417 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
418 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
420 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4u );
421 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
423 size_t size = propertyBuffer.GetSize();
424 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
426 propertyBuffer.SetSize( 10u );
427 size = propertyBuffer.GetSize();
428 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );