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( "uFadeColor", 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( "uFadeColor", initialColor );
162 TestGlAbstraction& gl = application.GetGlAbstraction();
164 application.SendNotification();
165 application.Render(0);
167 Vector4 actualValue(Vector4::ZERO);
168 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
169 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
172 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
174 application.SendNotification();
175 application.Render(0);
177 // Expect no blue component in either buffer - yellow
178 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
179 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
181 application.Render(0);
182 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
183 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
185 propertyBuffer.RemoveConstraints();
186 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
187 application.SendNotification();
188 application.Render(0);
190 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
191 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
198 int UtcDaliPropertyBufferAnimatedProperty01(void)
200 TestApplication application;
202 tet_infoline("Test that a non-uniform propertyBuffer property can be animated");
204 Shader shader = Shader::New("VertexSource", "FragmentSource");
205 Material material = Material::New( shader );
206 material.SetProperty(Material::Property::COLOR, Color::WHITE);
208 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
209 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
210 Renderer renderer = Renderer::New( geometry, material );
212 Actor actor = Actor::New();
213 actor.AddRenderer(renderer);
214 actor.SetSize(400, 400);
215 Stage::GetCurrent().Add(actor);
217 Vector4 initialColor = Color::WHITE;
218 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
220 application.SendNotification();
221 application.Render(0);
222 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
224 Animation animation = Animation::New(1.0f);
225 KeyFrames keyFrames = KeyFrames::New();
226 keyFrames.Add(0.0f, initialColor);
227 keyFrames.Add(1.0f, Color::TRANSPARENT);
228 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
231 application.SendNotification();
232 application.Render(500);
234 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
236 application.Render(500);
238 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
243 int UtcDaliPropertyBufferAnimatedProperty02(void)
245 TestApplication application;
247 tet_infoline("Test that a uniform map propertyBuffer property can be animated");
249 Shader shader = Shader::New("VertexSource", "FragmentSource");
250 Material material = Material::New( shader );
251 material.SetProperty(Material::Property::COLOR, Color::WHITE);
253 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
254 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
255 Renderer renderer = Renderer::New( geometry, material );
257 Actor actor = Actor::New();
258 actor.AddRenderer(renderer);
259 actor.SetSize(400, 400);
260 Stage::GetCurrent().Add(actor);
261 application.SendNotification();
262 application.Render(0);
264 Vector4 initialColor = Color::WHITE;
265 Property::Index colorIndex = propertyBuffer.RegisterProperty( "uFadeColor", initialColor );
267 TestGlAbstraction& gl = application.GetGlAbstraction();
269 application.SendNotification();
270 application.Render(0);
272 Vector4 actualValue(Vector4::ZERO);
273 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
274 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
276 Animation animation = Animation::New(1.0f);
277 KeyFrames keyFrames = KeyFrames::New();
278 keyFrames.Add(0.0f, initialColor);
279 keyFrames.Add(1.0f, Color::TRANSPARENT);
280 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
283 application.SendNotification();
284 application.Render(500);
286 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
287 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
289 application.Render(500);
290 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
291 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
296 int UtcDaliPropertyBufferSetData01(void)
298 TestApplication application;
300 Property::Map texturedQuadVertexFormat;
301 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
302 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
304 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
305 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
307 const float halfQuadSize = .5f;
308 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
309 TexturedQuadVertex texturedQuadVertexData[4] = {
310 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
311 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
312 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
313 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
315 propertyBuffer.SetData( texturedQuadVertexData );
317 Geometry geometry = Geometry::New();
318 geometry.AddVertexBuffer( propertyBuffer );
320 Material material = CreateMaterial(1.f);
321 Renderer renderer = Renderer::New(geometry, material);
322 Actor actor = Actor::New();
323 actor.SetSize(Vector3::ONE * 100.f);
324 actor.AddRenderer(renderer);
325 Stage::GetCurrent().Add(actor);
327 application.SendNotification();
328 application.Render(0);
329 application.Render();
330 application.SendNotification();
332 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
333 application.GetGlAbstraction().GetBufferDataCalls();
335 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
337 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
342 int UtcDaliPropertyBufferSetData02(void)
344 TestApplication application;
346 Property::Map texturedQuadVertexFormat;
347 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
348 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
350 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
351 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
353 const float halfQuadSize = .5f;
354 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
355 TexturedQuadVertex texturedQuadVertexData[4] = {
356 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
357 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
358 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
359 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
361 propertyBuffer.SetData( texturedQuadVertexData );
363 Geometry geometry = Geometry::New();
364 geometry.AddVertexBuffer( propertyBuffer );
366 Material material = CreateMaterial(1.f);
367 Renderer renderer = Renderer::New(geometry, material);
368 Actor actor = Actor::New();
369 actor.SetSize(Vector3::ONE * 100.f);
370 actor.AddRenderer(renderer);
371 Stage::GetCurrent().Add(actor);
373 application.SendNotification();
374 application.Render(0);
375 application.Render();
376 application.SendNotification();
379 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
380 application.GetGlAbstraction().GetBufferDataCalls();
382 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
384 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
387 // Re-upload the data on the propertyBuffer
388 propertyBuffer.SetData( texturedQuadVertexData );
390 application.SendNotification();
391 application.Render(0);
392 application.Render();
393 application.SendNotification();
396 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
397 application.GetGlAbstraction().GetBufferSubDataCalls();
399 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
401 if ( bufferSubDataCalls.size() )
403 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
410 int UtcDaliPropertyBufferSetSize01(void)
412 TestApplication application;
414 Property::Map texturedQuadVertexFormat;
415 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
416 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
418 PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4u );
419 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
421 size_t size = propertyBuffer.GetSize();
422 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
424 propertyBuffer.SetSize( 10u );
425 size = propertyBuffer.GetSize();
426 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );