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( PropertyBuffer::STATIC,
52 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( PropertyBuffer::STATIC,
75 texturedQuadVertexFormat, 4 );
77 BaseHandle handle(propertyBuffer);
78 PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
79 DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
83 int UtcDaliPropertyBufferDownCast02(void)
85 TestApplication application;
87 Handle handle = Handle::New(); // Create a custom object
88 PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
89 DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
94 int UtcDaliPropertyBufferConstraint01(void)
96 TestApplication application;
98 tet_infoline("Test that a non-uniform propertyBuffer property can be constrained");
100 Shader shader = Shader::New("VertexSource", "FragmentSource");
101 Material material = Material::New( shader );
102 material.SetProperty(Material::Property::COLOR, Color::WHITE);
104 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
105 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
106 Renderer renderer = Renderer::New( geometry, material );
108 Actor actor = Actor::New();
109 actor.AddRenderer(renderer);
110 actor.SetSize(400, 400);
111 Stage::GetCurrent().Add(actor);
113 Vector4 initialColor = Color::WHITE;
114 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
116 application.SendNotification();
117 application.Render(0);
118 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
121 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
123 application.SendNotification();
124 application.Render(0);
126 // Expect no blue component in either buffer - yellow
127 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
128 application.Render(0);
129 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
131 propertyBuffer.RemoveConstraints();
132 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
133 application.SendNotification();
134 application.Render(0);
135 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
140 int UtcDaliPropertyBufferConstraint02(void)
142 TestApplication application;
144 tet_infoline("Test that a uniform map propertyBuffer property can be constrained");
146 Shader shader = Shader::New("VertexSource", "FragmentSource");
147 Material material = Material::New( shader );
148 material.SetProperty(Material::Property::COLOR, Color::WHITE);
150 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
151 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
152 Renderer renderer = Renderer::New( geometry, material );
154 Actor actor = Actor::New();
155 actor.AddRenderer(renderer);
156 actor.SetSize(400, 400);
157 Stage::GetCurrent().Add(actor);
158 application.SendNotification();
159 application.Render(0);
161 Vector4 initialColor = Color::WHITE;
162 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
163 propertyBuffer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
165 TestGlAbstraction& gl = application.GetGlAbstraction();
167 application.SendNotification();
168 application.Render(0);
170 Vector4 actualValue(Vector4::ZERO);
171 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
172 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
175 Constraint constraint = Constraint::New<Vector4>( propertyBuffer, colorIndex, TestConstraintNoBlue );
177 application.SendNotification();
178 application.Render(0);
180 // Expect no blue component in either buffer - yellow
181 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
182 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
184 application.Render(0);
185 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
186 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
188 propertyBuffer.RemoveConstraints();
189 propertyBuffer.SetProperty(colorIndex, Color::WHITE );
190 application.SendNotification();
191 application.Render(0);
193 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
194 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
201 int UtcDaliPropertyBufferAnimatedProperty01(void)
203 TestApplication application;
205 tet_infoline("Test that a non-uniform propertyBuffer property can be animated");
207 Shader shader = Shader::New("VertexSource", "FragmentSource");
208 Material material = Material::New( shader );
209 material.SetProperty(Material::Property::COLOR, Color::WHITE);
211 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
212 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
213 Renderer renderer = Renderer::New( geometry, material );
215 Actor actor = Actor::New();
216 actor.AddRenderer(renderer);
217 actor.SetSize(400, 400);
218 Stage::GetCurrent().Add(actor);
220 Vector4 initialColor = Color::WHITE;
221 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
223 application.SendNotification();
224 application.Render(0);
225 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
227 Animation animation = Animation::New(1.0f);
228 KeyFrames keyFrames = KeyFrames::New();
229 keyFrames.Add(0.0f, initialColor);
230 keyFrames.Add(1.0f, Color::TRANSPARENT);
231 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
234 application.SendNotification();
235 application.Render(500);
237 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
239 application.Render(500);
241 DALI_TEST_EQUALS( propertyBuffer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
246 int UtcDaliPropertyBufferAnimatedProperty02(void)
248 TestApplication application;
250 tet_infoline("Test that a uniform map propertyBuffer property can be animated");
252 Shader shader = Shader::New("VertexSource", "FragmentSource");
253 Material material = Material::New( shader );
254 material.SetProperty(Material::Property::COLOR, Color::WHITE);
256 PropertyBuffer propertyBuffer = CreatePropertyBuffer();
257 Geometry geometry = CreateQuadGeometryFromBuffer(propertyBuffer);
258 Renderer renderer = Renderer::New( geometry, material );
260 Actor actor = Actor::New();
261 actor.AddRenderer(renderer);
262 actor.SetSize(400, 400);
263 Stage::GetCurrent().Add(actor);
264 application.SendNotification();
265 application.Render(0);
267 Vector4 initialColor = Color::WHITE;
268 Property::Index colorIndex = propertyBuffer.RegisterProperty( "fade-color", initialColor );
269 propertyBuffer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
271 TestGlAbstraction& gl = application.GetGlAbstraction();
273 application.SendNotification();
274 application.Render(0);
276 Vector4 actualValue(Vector4::ZERO);
277 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
278 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
280 Animation animation = Animation::New(1.0f);
281 KeyFrames keyFrames = KeyFrames::New();
282 keyFrames.Add(0.0f, initialColor);
283 keyFrames.Add(1.0f, Color::TRANSPARENT);
284 animation.AnimateBetween( Property( propertyBuffer, colorIndex ), keyFrames );
287 application.SendNotification();
288 application.Render(500);
290 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
291 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
293 application.Render(500);
294 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
295 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
300 int UtcDaliPropertyBufferSetData01(void)
302 TestApplication application;
304 Property::Map texturedQuadVertexFormat;
305 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
306 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
308 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
309 texturedQuadVertexFormat, 4 );
310 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
312 const float halfQuadSize = .5f;
313 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
314 TexturedQuadVertex texturedQuadVertexData[4] = {
315 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
316 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
317 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
318 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
320 propertyBuffer.SetData( texturedQuadVertexData );
322 Geometry geometry = Geometry::New();
323 geometry.AddVertexBuffer( propertyBuffer );
325 Material material = CreateMaterial(1.f);
326 Renderer renderer = Renderer::New(geometry, material);
327 Actor actor = Actor::New();
328 actor.SetSize(Vector3::ONE * 100.f);
329 actor.AddRenderer(renderer);
330 Stage::GetCurrent().Add(actor);
332 application.SendNotification();
333 application.Render(0);
334 application.Render();
335 application.SendNotification();
337 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
338 application.GetGlAbstraction().GetBufferDataCalls();
340 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
342 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
347 int UtcDaliPropertyBufferSetData02(void)
349 TestApplication application;
351 Property::Map texturedQuadVertexFormat;
352 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
353 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
355 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
356 texturedQuadVertexFormat, 4 );
357 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
359 const float halfQuadSize = .5f;
360 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
361 TexturedQuadVertex texturedQuadVertexData[4] = {
362 { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
363 { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
364 { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
365 { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
367 propertyBuffer.SetData( texturedQuadVertexData );
369 Geometry geometry = Geometry::New();
370 geometry.AddVertexBuffer( propertyBuffer );
372 Material material = CreateMaterial(1.f);
373 Renderer renderer = Renderer::New(geometry, material);
374 Actor actor = Actor::New();
375 actor.SetSize(Vector3::ONE * 100.f);
376 actor.AddRenderer(renderer);
377 Stage::GetCurrent().Add(actor);
379 application.SendNotification();
380 application.Render(0);
381 application.Render();
382 application.SendNotification();
385 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
386 application.GetGlAbstraction().GetBufferDataCalls();
388 DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
390 DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
393 // Re-upload the data on the propertyBuffer
394 propertyBuffer.SetData( texturedQuadVertexData );
396 application.SendNotification();
397 application.Render(0);
398 application.Render();
399 application.SendNotification();
402 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
403 application.GetGlAbstraction().GetBufferSubDataCalls();
405 DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
407 if ( bufferSubDataCalls.size() )
409 DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
416 int UtcDaliPropertyBufferSetSize01(void)
418 TestApplication application;
420 Property::Map texturedQuadVertexFormat;
421 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
422 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
424 PropertyBuffer propertyBuffer = PropertyBuffer::New( PropertyBuffer::STATIC,
425 texturedQuadVertexFormat,
427 DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
429 size_t size = propertyBuffer.GetSize();
430 DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
432 propertyBuffer.SetSize( 10u );
433 size = propertyBuffer.GetSize();
434 DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );