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>
20 #include <dali/devel-api/rendering/renderer.h>
24 #include <mesh-builder.h>
28 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
34 void propertyBuffer_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void propertyBuffer_test_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliPropertyBufferNew01(void)
46 TestApplication application;
48 Property::Map texturedQuadVertexFormat;
49 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
50 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
52 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
54 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
58 int UtcDaliPropertyBufferNew02(void)
60 TestApplication application;
61 PropertyBuffer propertyBuffer;
62 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
66 int UtcDaliPropertyBufferDownCast01(void)
68 TestApplication application;
70 Property::Map texturedQuadVertexFormat;
71 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
72 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
74 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
76 BaseHandle handle(propertyBuffer);
77 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
78 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
82 int UtcDaliPropertyBufferDownCast02(void)
84 TestApplication application;
86 Handle handle = Handle::New(); // Create a custom object
87 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
88 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
92 int UtcDaliPropertyBufferCopyConstructor(void)
94 TestApplication application;
96 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
98 PropertyBuffer propertyBufferCopy(propertyBuffer);
100 DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
101 DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 4u, TEST_LOCATION );
106 int UtcDaliPropertyBufferAssignmentOperator(void)
108 TestApplication application;
110 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
112 PropertyBuffer propertyBuffer2;
113 DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
115 propertyBuffer2 = propertyBuffer;
116 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
117 DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 4u, TEST_LOCATION );
122 int UtcDaliPropertyBufferConstraint01(void)
124 TestApplication application;
126 tet_infoline("Test that a non-uniform propertyBuffer property can be constrained");
128 Shader shader = Shader::New("VertexSource", "FragmentSource");
129 Material material = Material::New( shader );
130 material.SetProperty(Material::Property::COLOR, Color::WHITE);
132 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
133 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
134 Renderer renderer = Renderer::New( geometry, material );
136 Actor actor = Actor::New();
137 actor.AddRenderer(renderer);
138 actor.SetSize(400, 400);
139 Stage::GetCurrent().Add(actor);
141 Vector4 initialColor = Color::WHITE;
142 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
144 application.SendNotification();
145 application.Render(0);
146 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
149 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
151 application.SendNotification();
152 application.Render(0);
154 // Expect no blue component in either buffer - yellow
155 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
156 application.Render(0);
157 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
159 propertyBuffer.RemoveConstraints();
160 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
161 application.SendNotification();
162 application.Render(0);
163 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
168 int UtcDaliPropertyBufferConstraint02(void)
170 TestApplication application;
172 tet_infoline("Test that a uniform map propertyBuffer property can be constrained");
174 Shader shader = Shader::New( "VertexSource", "FragmentSource" );
175 Material material = Material::New( shader );
176 material.SetProperty(Material::Property::COLOR, Color::WHITE);
178 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
179 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
180 Renderer renderer = Renderer::New( geometry, material );
182 Actor actor = Actor::New();
183 actor.AddRenderer(renderer);
184 actor.SetSize(400, 400);
185 Stage::GetCurrent().Add(actor);
186 application.SendNotification();
187 application.Render(0);
189 Vector4 initialColor = Color::WHITE;
190 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
192 TestGlAbstraction& gl = application.GetGlAbstraction();
194 application.SendNotification();
195 application.Render(0);
197 Vector4 actualValue(Vector4::ZERO);
198 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
199 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
202 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
204 application.SendNotification();
205 application.Render(0);
207 // Expect no blue component in either buffer - yellow
208 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
209 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
211 application.Render(0);
212 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
213 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
215 propertyBuffer.RemoveConstraints();
216 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
217 application.SendNotification();
218 application.Render(0);
220 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
221 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
228 int UtcDaliPropertyBufferAnimatedProperty01(void)
230 TestApplication application;
232 tet_infoline("Test that a non-uniform propertyBuffer property can be animated");
234 Shader shader = Shader::New("VertexSource", "FragmentSource");
235 Material material = Material::New( shader );
236 material.SetProperty(Material::Property::COLOR, Color::WHITE);
238 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
239 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
240 Renderer renderer = Renderer::New( geometry, material );
242 Actor actor = Actor::New();
243 actor.AddRenderer(renderer);
244 actor.SetSize(400, 400);
245 Stage::GetCurrent().Add(actor);
247 Vector4 initialColor = Color::WHITE;
248 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
250 application.SendNotification();
251 application.Render(0);
252 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
254 Animation animation = Animation::New(1.0f);
255 KeyFrames keyFrames = KeyFrames::New();
256 keyFrames.Add(0.0f, initialColor);
257 keyFrames.Add(1.0f, Color::TRANSPARENT);
258 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
261 application.SendNotification();
262 application.Render(500);
264 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
266 application.Render(500);
268 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
273 int UtcDaliPropertyBufferAnimatedProperty02(void)
275 TestApplication application;
277 tet_infoline("Test that a uniform map propertyBuffer property can be animated");
279 Shader shader = Shader::New("VertexSource", "FragmentSource");
280 Material material = Material::New( shader );
281 material.SetProperty(Material::Property::COLOR, Color::WHITE);
283 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
284 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
285 Renderer renderer = Renderer::New( geometry, material );
287 Actor actor = Actor::New();
288 actor.AddRenderer(renderer);
289 actor.SetSize(400, 400);
290 Stage::GetCurrent().Add(actor);
291 application.SendNotification();
292 application.Render(0);
294 Vector4 initialColor = Color::WHITE;
295 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
297 TestGlAbstraction& gl = application.GetGlAbstraction();
299 application.SendNotification();
300 application.Render(0);
302 Vector4 actualValue(Vector4::ZERO);
303 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
304 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
306 Animation animation = Animation::New(1.0f);
307 KeyFrames keyFrames = KeyFrames::New();
308 keyFrames.Add(0.0f, initialColor);
309 keyFrames.Add(1.0f, Color::TRANSPARENT);
310 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
313 application.SendNotification();
314 application.Render(500);
316 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
317 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
319 application.Render(500);
320 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
321 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
326 int UtcDaliPropertyBufferSetData01(void)
328 TestApplication application;
330 Property::Map texturedQuadVertexFormat;
331 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
332 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
334 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
335 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
337 const float halfQuadSize = .5f;
338 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
339 TexturedQuadVertex texturedQuadVertexData[4] = {
340 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
341 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
342 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
343 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
345 propertyBuffer.SetData( texturedQuadVertexData );
347 Geometry geometry = Geometry::New();
348 geometry.AddVertexBuffer( propertyBuffer );
350 Material material = CreateMaterial(1.f);
351 Renderer renderer = Renderer::New(geometry, material);
352 Actor actor = Actor::New();
353 actor.SetSize(Vector3::ONE * 100.f);
354 actor.AddRenderer(renderer);
355 Stage::GetCurrent().Add(actor);
357 application.SendNotification();
358 application.Render(0);
359 application.Render();
360 application.SendNotification();
362 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
363 application.GetGlAbstraction().GetBufferDataCalls();
365 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
367 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
372 int UtcDaliPropertyBufferSetData02(void)
374 TestApplication application;
376 Property::Map texturedQuadVertexFormat;
377 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
378 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
380 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
381 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
383 const float halfQuadSize = .5f;
384 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
385 TexturedQuadVertex texturedQuadVertexData[4] = {
386 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
387 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
388 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
389 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
391 propertyBuffer.SetData( texturedQuadVertexData );
393 Geometry geometry = Geometry::New();
394 geometry.AddVertexBuffer( propertyBuffer );
396 Material material = CreateMaterial(1.f);
397 Renderer renderer = Renderer::New(geometry, material);
398 Actor actor = Actor::New();
399 actor.SetSize(Vector3::ONE * 100.f);
400 actor.AddRenderer(renderer);
401 Stage::GetCurrent().Add(actor);
403 application.SendNotification();
404 application.Render(0);
405 application.Render();
406 application.SendNotification();
409 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
410 application.GetGlAbstraction().GetBufferDataCalls();
412 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
414 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
417 // Re-upload the data on the propertyBuffer
418 propertyBuffer.SetData( texturedQuadVertexData );
420 application.SendNotification();
421 application.Render(0);
422 application.Render();
423 application.SendNotification();
426 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
427 application.GetGlAbstraction().GetBufferSubDataCalls();
429 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
431 if ( bufferSubDataCalls.size() )
433 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
440 int UtcDaliPropertyBufferSetGetSize01(void)
442 TestApplication application;
444 Property::Map texturedQuadVertexFormat;
445 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
446 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
448 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4u );
449 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
451 size_t size = propertyBuffer.GetSize();
452 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
454 propertyBuffer.SetSize( 10u );
455 size = propertyBuffer.GetSize();
456 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );
461 //Todo: also test that the SetSize function is equivalent to setting the property SIZE
462 int UtcDaliPropertyBufferSetGetSize02(void)
464 TestApplication application;
466 Property::Map texturedQuadVertexFormat;
467 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
468 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
470 unsigned int size = 5u;
471 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, size );
472 DALI_TEST_EQUALS( propertyBuffer.GetProperty<unsigned int>(PropertyBuffer::Property::SIZE), size, TEST_LOCATION );
473 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
476 propertyBuffer.SetSize( size );
477 DALI_TEST_EQUALS( propertyBuffer.GetProperty<unsigned int>(PropertyBuffer::Property::SIZE), size, TEST_LOCATION );
478 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
481 propertyBuffer.SetProperty(PropertyBuffer::Property::SIZE, size );
482 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );