Dali 3D User Interface Engine
utc-Dali-PropertyBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
19 #include <dali-test-suite-utils.h>
21 
22 using namespace Dali;
23 
24 #include <mesh-builder.h>
25 
26 namespace
27 {
28 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
29 {
30  current.b = 0.0f;
31 }
32 }
33 
35 {
37 }
38 
40 {
42 }
43 
45 {
46  TestApplication application;
47 
48  Property::Map texturedQuadVertexFormat;
49  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
50  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
51 
52  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
53 
54  DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
55  END_TEST;
56 }
57 
59 {
60  TestApplication application;
61  PropertyBuffer propertyBuffer;
62  DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
63  END_TEST;
64 }
65 
67 {
68  TestApplication application;
69 
70  Property::Map texturedQuadVertexFormat;
71  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
72  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
73 
74  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
75 
76  BaseHandle handle(propertyBuffer);
77  PropertyBuffer propertyBuffer2 = PropertyBuffer::DownCast(handle);
78  DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
79  END_TEST;
80 }
81 
83 {
84  TestApplication application;
85 
86  Handle handle = Handle::New(); // Create a custom object
87  PropertyBuffer propertyBuffer = PropertyBuffer::DownCast(handle);
88  DALI_TEST_EQUALS( (bool)propertyBuffer, false, TEST_LOCATION );
89  END_TEST;
90 }
91 
93 {
94  TestApplication application;
95 
96  PropertyBuffer propertyBuffer = CreatePropertyBuffer();
97 
98  PropertyBuffer propertyBufferCopy(propertyBuffer);
99 
100  DALI_TEST_EQUALS( (bool)propertyBufferCopy, true, TEST_LOCATION );
101  DALI_TEST_EQUALS( propertyBufferCopy.GetSize(), 4u, TEST_LOCATION );
102 
103  END_TEST;
104 }
105 
107 {
108  TestApplication application;
109 
110  PropertyBuffer propertyBuffer = CreatePropertyBuffer();
111 
112  PropertyBuffer propertyBuffer2;
113  DALI_TEST_EQUALS( (bool)propertyBuffer2, false, TEST_LOCATION );
114 
115  propertyBuffer2 = propertyBuffer;
116  DALI_TEST_EQUALS( (bool)propertyBuffer2, true, TEST_LOCATION );
117  DALI_TEST_EQUALS( propertyBuffer2.GetSize(), 4u, TEST_LOCATION );
118 
119  END_TEST;
120 }
121 
123 {
124  TestApplication application;
125 
126  Property::Map texturedQuadVertexFormat;
127  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
128  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
129 
130  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
131  DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
132 
133  const float halfQuadSize = .5f;
134  struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
135  TexturedQuadVertex texturedQuadVertexData[4] = {
136  { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
137  { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
138  { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
139  { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
140 
141  propertyBuffer.SetData( texturedQuadVertexData );
142 
143  Geometry geometry = Geometry::New();
144  geometry.AddVertexBuffer( propertyBuffer );
145 
146  Material material = CreateMaterial();
147  Renderer renderer = Renderer::New(geometry, material);
148  Actor actor = Actor::New();
149  actor.SetSize(Vector3::ONE * 100.f);
150  actor.AddRenderer(renderer);
151  Stage::GetCurrent().Add(actor);
152 
153  application.SendNotification();
154  application.Render(0);
155  application.Render();
156  application.SendNotification();
157 
158  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
159  application.GetGlAbstraction().GetBufferDataCalls();
160 
161  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
162 
163  DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
164 
165  END_TEST;
166 }
167 
169 {
170  TestApplication application;
171 
172  Property::Map texturedQuadVertexFormat;
173  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
174  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
175 
176  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
177  DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
178 
179  const float halfQuadSize = .5f;
180  struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
181  TexturedQuadVertex texturedQuadVertexData[4] = {
182  { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
183  { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
184  { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
185  { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
186 
187  propertyBuffer.SetData( texturedQuadVertexData );
188 
189  Geometry geometry = Geometry::New();
190  geometry.AddVertexBuffer( propertyBuffer );
191 
192  Material material = CreateMaterial();
193  Renderer renderer = Renderer::New(geometry, material);
194  Actor actor = Actor::New();
195  actor.SetSize(Vector3::ONE * 100.f);
196  actor.AddRenderer(renderer);
197  Stage::GetCurrent().Add(actor);
198 
199  application.SendNotification();
200  application.Render(0);
201  application.Render();
202  application.SendNotification();
203 
204  {
205  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
206  application.GetGlAbstraction().GetBufferDataCalls();
207 
208  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
209 
210  DALI_TEST_EQUALS( bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
211  }
212 
213  // Re-upload the data on the propertyBuffer
214  propertyBuffer.SetData( texturedQuadVertexData );
215 
216  application.SendNotification();
217  application.Render(0);
218  application.Render();
219  application.SendNotification();
220 
221  {
222  const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
223  application.GetGlAbstraction().GetBufferSubDataCalls();
224 
225  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
226  application.GetGlAbstraction().GetBufferDataCalls();
227 
228  DALI_TEST_EQUALS( bufferSubDataCalls.size(), 1u, TEST_LOCATION );
229  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
230 
231  if ( bufferSubDataCalls.size() )
232  {
233  DALI_TEST_EQUALS( bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION );
234 
235  }
236  }
237 
238  END_TEST;
239 }
240 
242 {
243  TestApplication application;
244 
245  Property::Map texturedQuadVertexFormat;
246  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
247  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
248 
249  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, 4u );
250  DALI_TEST_EQUALS( (bool)propertyBuffer, true, TEST_LOCATION );
251 
252  size_t size = propertyBuffer.GetSize();
253  DALI_TEST_EQUALS( size, 4u, TEST_LOCATION );
254 
255  propertyBuffer.SetSize( 10u );
256  size = propertyBuffer.GetSize();
257  DALI_TEST_EQUALS( size, 10u, TEST_LOCATION );
258 
259  END_TEST;
260 }
261 
262 //Todo: also test that the SetSize function is equivalent to setting the property SIZE
264 {
265  TestApplication application;
266 
267  Property::Map texturedQuadVertexFormat;
268  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
269  texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
270 
271  std::size_t size = 5u;
272  PropertyBuffer propertyBuffer = PropertyBuffer::New( texturedQuadVertexFormat, size );
273  DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
274  DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
275 
276  size += 3u;
277  propertyBuffer.SetSize( size );
278  DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
279  DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
280 
281  size += 2u;
282  propertyBuffer.SetSize( size );
283  DALI_TEST_EQUALS( propertyBuffer.GetSize(), size, TEST_LOCATION );
284 
285  END_TEST;
286 }
287 
Dali Docs Home
Read more about Dali