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 );
91 int UtcDaliPropertyBufferCopyConstructor(void)
93 TestApplication application;
95 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
97 PropertyBuffer propertyBufferCopy(propertyBuffer);
99 DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
100 DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 4u, TEST_LOCATION );
105 int UtcDaliPropertyBufferAssignmentOperator(void)
107 TestApplication application;
109 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
111 PropertyBuffer propertyBuffer2;
112 DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
114 propertyBuffer2 = propertyBuffer;
115 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
116 DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 4u, TEST_LOCATION );
121 int UtcDaliPropertyBufferConstraint01(void)
123 TestApplication application;
125 tet_infoline("Test that a non-uniform propertyBuffer property can be constrained");
127 Shader shader = Shader::New("VertexSource", "FragmentSource");
128 Material material = Material::New( shader );
129 material.SetProperty(Material::Property::COLOR, Color::WHITE);
131 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
132 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
133 Renderer renderer = Renderer::New( geometry, material );
135 Actor actor = Actor::New();
136 actor.AddRenderer(renderer);
137 actor.SetSize(400, 400);
138 Stage::GetCurrent().Add(actor);
140 Vector4 initialColor = Color::WHITE;
141 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
143 application.SendNotification();
144 application.Render(0);
145 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
148 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
150 application.SendNotification();
151 application.Render(0);
153 // Expect no blue component in either buffer - yellow
154 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
155 application.Render(0);
156 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
158 propertyBuffer.RemoveConstraints();
159 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
160 application.SendNotification();
161 application.Render(0);
162 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
167 int UtcDaliPropertyBufferConstraint02(void)
169 TestApplication application;
171 tet_infoline("Test that a uniform map propertyBuffer property can be constrained");
173 Shader shader = Shader::New( "VertexSource", "FragmentSource" );
174 Material material = Material::New( shader );
175 material.SetProperty(Material::Property::COLOR, Color::WHITE);
177 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
178 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
179 Renderer renderer = Renderer::New( geometry, material );
181 Actor actor = Actor::New();
182 actor.AddRenderer(renderer);
183 actor.SetSize(400, 400);
184 Stage::GetCurrent().Add(actor);
185 application.SendNotification();
186 application.Render(0);
188 Vector4 initialColor = Color::WHITE;
189 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
191 TestGlAbstraction& gl = application.GetGlAbstraction();
193 application.SendNotification();
194 application.Render(0);
196 Vector4 actualValue(Vector4::ZERO);
197 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
198 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
201 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
203 application.SendNotification();
204 application.Render(0);
206 // Expect no blue component in either buffer - yellow
207 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
208 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
210 application.Render(0);
211 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
212 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
214 propertyBuffer.RemoveConstraints();
215 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
216 application.SendNotification();
217 application.Render(0);
219 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
220 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
227 int UtcDaliPropertyBufferAnimatedProperty01(void)
229 TestApplication application;
231 tet_infoline("Test that a non-uniform propertyBuffer property can be animated");
233 Shader shader = Shader::New("VertexSource", "FragmentSource");
234 Material material = Material::New( shader );
235 material.SetProperty(Material::Property::COLOR, Color::WHITE);
237 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
238 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
239 Renderer renderer = Renderer::New( geometry, material );
241 Actor actor = Actor::New();
242 actor.AddRenderer(renderer);
243 actor.SetSize(400, 400);
244 Stage::GetCurrent().Add(actor);
246 Vector4 initialColor = Color::WHITE;
247 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
249 application.SendNotification();
250 application.Render(0);
251 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
253 Animation animation = Animation::New(1.0f);
254 KeyFrames keyFrames = KeyFrames::New();
255 keyFrames.Add(0.0f, initialColor);
256 keyFrames.Add(1.0f, Color::TRANSPARENT);
257 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
260 application.SendNotification();
261 application.Render(500);
263 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
265 application.Render(500);
267 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
272 int UtcDaliPropertyBufferAnimatedProperty02(void)
274 TestApplication application;
276 tet_infoline("Test that a uniform map propertyBuffer property can be animated");
278 Shader shader = Shader::New("VertexSource", "FragmentSource");
279 Material material = Material::New( shader );
280 material.SetProperty(Material::Property::COLOR, Color::WHITE);
282 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
283 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
284 Renderer renderer = Renderer::New( geometry, material );
286 Actor actor = Actor::New();
287 actor.AddRenderer(renderer);
288 actor.SetSize(400, 400);
289 Stage::GetCurrent().Add(actor);
290 application.SendNotification();
291 application.Render(0);
293 Vector4 initialColor = Color::WHITE;
294 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
296 TestGlAbstraction& gl = application.GetGlAbstraction();
298 application.SendNotification();
299 application.Render(0);
301 Vector4 actualValue(Vector4::ZERO);
302 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
303 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
305 Animation animation = Animation::New(1.0f);
306 KeyFrames keyFrames = KeyFrames::New();
307 keyFrames.Add(0.0f, initialColor);
308 keyFrames.Add(1.0f, Color::TRANSPARENT);
309 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
312 application.SendNotification();
313 application.Render(500);
315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
316 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
318 application.Render(500);
319 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
320 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
325 int UtcDaliPropertyBufferSetData01(void)
327 TestApplication application;
329 Property::Map texturedQuadVertexFormat;
330 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
331 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
333 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
334 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
336 const float halfQuadSize = .5f;
337 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
338 TexturedQuadVertex texturedQuadVertexData[4] = {
339 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
340 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
341 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
342 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
344 propertyBuffer.SetData( texturedQuadVertexData );
346 Geometry geometry = Geometry::New();
347 geometry.AddVertexBuffer( propertyBuffer );
349 Material material = CreateMaterial(1.f);
350 Renderer renderer = Renderer::New(geometry, material);
351 Actor actor = Actor::New();
352 actor.SetSize(Vector3::ONE * 100.f);
353 actor.AddRenderer(renderer);
354 Stage::GetCurrent().Add(actor);
356 application.SendNotification();
357 application.Render(0);
358 application.Render();
359 application.SendNotification();
361 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
362 application.GetGlAbstraction().GetBufferDataCalls();
364 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
366 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
371 int UtcDaliPropertyBufferSetData02(void)
373 TestApplication application;
375 Property::Map texturedQuadVertexFormat;
376 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
377 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
379 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
380 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
382 const float halfQuadSize = .5f;
383 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
384 TexturedQuadVertex texturedQuadVertexData[4] = {
385 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
386 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
387 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
388 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
390 propertyBuffer.SetData( texturedQuadVertexData );
392 Geometry geometry = Geometry::New();
393 geometry.AddVertexBuffer( propertyBuffer );
395 Material material = CreateMaterial(1.f);
396 Renderer renderer = Renderer::New(geometry, material);
397 Actor actor = Actor::New();
398 actor.SetSize(Vector3::ONE * 100.f);
399 actor.AddRenderer(renderer);
400 Stage::GetCurrent().Add(actor);
402 application.SendNotification();
403 application.Render(0);
404 application.Render();
405 application.SendNotification();
408 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
409 application.GetGlAbstraction().GetBufferDataCalls();
411 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
413 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
416 // Re-upload the data on the propertyBuffer
417 propertyBuffer.SetData( texturedQuadVertexData );
419 application.SendNotification();
420 application.Render(0);
421 application.Render();
422 application.SendNotification();
425 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
426 application.GetGlAbstraction().GetBufferSubDataCalls();
428 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
430 if ( bufferSubDataCalls.size() )
432 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
439 int UtcDaliPropertyBufferSetGetSize01(void)
441 TestApplication application;
443 Property::Map texturedQuadVertexFormat;
444 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
445 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
447 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4u );
448 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
450 size_t size = propertyBuffer.GetSize();
451 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
453 propertyBuffer.SetSize( 10u );
454 size = propertyBuffer.GetSize();
455 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );
460 //Todo: also test that the SetSize function is equivalent to setting the property SIZE
461 int UtcDaliPropertyBufferSetGetSize02(void)
463 TestApplication application;
465 Property::Map texturedQuadVertexFormat;
466 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
467 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
469 unsigned int size = 5u;
470 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, size );
471 DALI_TEST_EQUALS( propertyBuffer.GetProperty<unsigned int>(PropertyBuffer::Property::SIZE), size, TEST_LOCATION );
472 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
475 propertyBuffer.SetSize( size );
476 DALI_TEST_EQUALS( propertyBuffer.GetProperty<unsigned int>(PropertyBuffer::Property::SIZE), size, TEST_LOCATION );
477 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
480 propertyBuffer.SetProperty(PropertyBuffer::Property::SIZE, size );
481 DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );