2 * Copyright (c) 2021 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-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
23 #include <mesh-builder.h>
25 void vertexBuffer_test_startup(void)
27 test_return_value = TET_UNDEF;
30 void vertexBuffer_test_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliVertexBufferNew01(void)
37 TestApplication application;
39 Property::Map texturedQuadVertexFormat;
40 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
41 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
43 VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
45 DALI_TEST_EQUALS((bool)vertexBuffer, true, TEST_LOCATION);
49 int UtcDaliVertexBufferNew02(void)
51 TestApplication application;
52 VertexBuffer vertexBuffer;
53 DALI_TEST_EQUALS((bool)vertexBuffer, false, TEST_LOCATION);
57 int UtcDaliVertexBufferDownCast01(void)
59 TestApplication application;
61 Property::Map texturedQuadVertexFormat;
62 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
63 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
65 VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
67 BaseHandle handle(vertexBuffer);
68 VertexBuffer vertexBuffer2 = VertexBuffer::DownCast(handle);
69 DALI_TEST_EQUALS((bool)vertexBuffer2, true, TEST_LOCATION);
73 int UtcDaliVertexBufferDownCast02(void)
75 TestApplication application;
77 Handle handle = Handle::New(); // Create a custom object
78 VertexBuffer vertexBuffer = VertexBuffer::DownCast(handle);
79 DALI_TEST_EQUALS((bool)vertexBuffer, false, TEST_LOCATION);
83 int UtcDaliVertexBufferCopyConstructor(void)
85 TestApplication application;
87 VertexBuffer vertexBuffer = CreateVertexBuffer();
89 VertexBuffer vertexBufferCopy(vertexBuffer);
91 DALI_TEST_EQUALS((bool)vertexBufferCopy, true, TEST_LOCATION);
92 DALI_TEST_EQUALS(vertexBufferCopy.GetSize(), 0u, TEST_LOCATION);
97 int UtcDaliVertexBufferAssignmentOperator(void)
99 TestApplication application;
101 VertexBuffer vertexBuffer = CreateVertexBuffer();
103 VertexBuffer vertexBuffer2;
104 DALI_TEST_EQUALS((bool)vertexBuffer2, false, TEST_LOCATION);
106 vertexBuffer2 = vertexBuffer;
107 DALI_TEST_EQUALS((bool)vertexBuffer2, true, TEST_LOCATION);
108 DALI_TEST_EQUALS(vertexBuffer2.GetSize(), 0u, TEST_LOCATION);
113 int UtcDaliVertexBufferMoveConstructor(void)
115 TestApplication application;
117 VertexBuffer vertexBuffer = CreateVertexBuffer();
118 DALI_TEST_CHECK(vertexBuffer);
119 DALI_TEST_EQUALS(1, vertexBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
120 DALI_TEST_EQUALS(0u, vertexBuffer.GetSize(), TEST_LOCATION);
122 VertexBuffer move = std::move(vertexBuffer);
123 DALI_TEST_CHECK(move);
124 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
125 DALI_TEST_EQUALS(0u, move.GetSize(), TEST_LOCATION);
126 DALI_TEST_CHECK(!vertexBuffer);
131 int UtcDaliVertexBufferMoveAssignment(void)
133 TestApplication application;
135 VertexBuffer vertexBuffer = CreateVertexBuffer();
136 DALI_TEST_CHECK(vertexBuffer);
137 DALI_TEST_EQUALS(1, vertexBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
138 DALI_TEST_EQUALS(0u, vertexBuffer.GetSize(), TEST_LOCATION);
141 move = std::move(vertexBuffer);
142 DALI_TEST_CHECK(move);
143 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
144 DALI_TEST_EQUALS(0u, move.GetSize(), TEST_LOCATION);
145 DALI_TEST_CHECK(!vertexBuffer);
150 int UtcDaliVertexBufferSetData01(void)
152 TestApplication application;
154 Property::Map texturedQuadVertexFormat;
155 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
156 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
159 VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
160 DALI_TEST_EQUALS((bool)vertexBuffer, true, TEST_LOCATION);
162 const float halfQuadSize = .5f;
163 struct TexturedQuadVertex
166 Vector2 textureCoordinates;
168 TexturedQuadVertex texturedQuadVertexData[4] = {
169 {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
170 {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
171 {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
172 {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
174 vertexBuffer.SetData(texturedQuadVertexData, 4);
176 Geometry geometry = Geometry::New();
177 geometry.AddVertexBuffer(vertexBuffer);
179 Shader shader = CreateShader();
180 Renderer renderer = Renderer::New(geometry, shader);
181 Actor actor = Actor::New();
182 actor.SetProperty(Actor::Property::SIZE, Vector3::ONE * 100.f);
183 actor.AddRenderer(renderer);
184 application.GetScene().Add(actor);
186 application.SendNotification();
187 application.Render(0);
188 application.Render();
189 application.SendNotification();
191 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
192 application.GetGlAbstraction().GetBufferDataCalls();
194 DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
196 DALI_TEST_EQUALS(bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION);
198 // end of scope to let the buffer and geometry die; do another notification and render to get the deletion processed
199 application.SendNotification();
200 application.Render(0);
205 int UtcDaliVertexBufferSetData02(void)
207 TestApplication application;
209 Property::Map texturedQuadVertexFormat;
210 texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
211 texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2;
213 VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
214 DALI_TEST_EQUALS((bool)vertexBuffer, true, TEST_LOCATION);
216 const float halfQuadSize = .5f;
217 struct TexturedQuadVertex
220 Vector2 textureCoordinates;
222 TexturedQuadVertex texturedQuadVertexData[4] = {
223 {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
224 {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
225 {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
226 {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
228 vertexBuffer.SetData(texturedQuadVertexData, 4);
230 Geometry geometry = Geometry::New();
231 geometry.AddVertexBuffer(vertexBuffer);
233 Shader shader = CreateShader();
234 Renderer renderer = Renderer::New(geometry, shader);
235 Actor actor = Actor::New();
236 actor.SetProperty(Actor::Property::SIZE, Vector3::ONE * 100.f);
237 actor.AddRenderer(renderer);
238 application.GetScene().Add(actor);
240 application.SendNotification();
241 application.Render();
244 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
245 application.GetGlAbstraction().GetBufferDataCalls();
247 DALI_TEST_EQUALS(bufferDataCalls.size(), 2u, TEST_LOCATION);
249 DALI_TEST_EQUALS(bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION);
252 // Re-upload the data on the vertexBuffer
253 vertexBuffer.SetData(texturedQuadVertexData, 4);
255 application.SendNotification();
256 application.Render(0);
259 const TestGlAbstraction::BufferSubDataCalls& bufferSubDataCalls =
260 application.GetGlAbstraction().GetBufferSubDataCalls();
262 const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
263 application.GetGlAbstraction().GetBufferDataCalls();
265 // Should be 17 (using single uniform buffer now)
266 DALI_TEST_EQUALS(bufferSubDataCalls.size(), 17u, TEST_LOCATION);
267 DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
269 if(bufferSubDataCalls.size())
271 DALI_TEST_EQUALS(bufferSubDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION);
278 int UtcDaliVertexBufferInvalidTypeN(void)
280 TestApplication application;
282 Property::Map texturedQuadVertexFormat;
283 texturedQuadVertexFormat["aPosition"] = Property::MAP;
284 texturedQuadVertexFormat["aVertexCoord"] = Property::STRING;
288 VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
289 tet_result(TET_FAIL);
291 catch(Dali::DaliException& e)
293 DALI_TEST_ASSERT(e, "Property::Type not supported in VertexBuffer", TEST_LOCATION);
298 int UtcDaliVertexBufferSetDataNegative(void)
300 TestApplication application;
301 Dali::VertexBuffer instance;
305 unsigned long arg2(0u);
306 instance.SetData(arg1, arg2);
307 DALI_TEST_CHECK(false); // Should not get here
311 DALI_TEST_CHECK(true); // We expect an assert
316 int UtcDaliVertexBufferGetSizeNegative(void)
318 TestApplication application;
319 Dali::VertexBuffer instance;
323 DALI_TEST_CHECK(false); // Should not get here
327 DALI_TEST_CHECK(true); // We expect an assert