END_TEST;
}
-int UtcDaliVertexBufferSetDataNegative(void)
+int UtcDaliVertexBufferInvalidTypeN02(void)
+{
+ TestApplication application;
+
+ Property::Map texturedQuadVertexFormat = Property::Map{{"aPosition", Property::MAP},
+ {"aTexCoord", Property::STRING},
+ {"aColor", Property::VECTOR4}};
+
+ try
+ {
+ VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
+ tet_result(TET_FAIL);
+ }
+ catch(Dali::DaliException& e)
+ {
+ DALI_TEST_ASSERT(e, "Property::Type not supported in VertexBuffer", TEST_LOCATION);
+ }
+ END_TEST;
+}
+
+int UtcDaliVertexBufferSetDataNegative01(void)
{
TestApplication application;
Dali::VertexBuffer instance;
END_TEST;
}
+int UtcDaliVertexBufferSetDataNegative02(void)
+{
+ TestApplication application;
+
+ Property::Map texturedQuadVertexFormat = Property::Map{{"aPosition", Property::VECTOR2},
+ {"aTexCoord", Property::VECTOR2},
+ {"aColor", Property::VECTOR4}};
+
+ try
+ {
+ VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
+
+ void* data(nullptr);
+ uint32_t dataSize(1u);
+
+ vertexBuffer.SetData(data, dataSize);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(Dali::DaliException& e)
+ {
+ DALI_TEST_ASSERT(e, "VertexBuffer::SetData() data was nullptr but size is not zero!", TEST_LOCATION);
+ }
+ END_TEST;
+}
+
+int UtcDaliVertexBufferSetDataWithZeroLength(void)
+{
+ TestApplication application;
+
+ Property::Map texturedQuadVertexFormat = Property::Map{{"aPosition", Property::VECTOR2},
+ {"aTexCoord", Property::VECTOR2},
+ {"aColor", Property::VECTOR4}};
+
+ try
+ {
+ VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
+
+ void* data(nullptr);
+ uint32_t dataSize(0u);
+
+ vertexBuffer.SetData(data, dataSize);
+
+ Geometry geometry = Geometry::New();
+ geometry.AddVertexBuffer(vertexBuffer);
+
+ Shader shader = CreateShader();
+ Renderer renderer = Renderer::New(geometry, shader);
+ Actor actor = Actor::New();
+ actor.SetProperty(Actor::Property::SIZE, Vector3::ONE * 100.f);
+ actor.AddRenderer(renderer);
+ application.GetScene().Add(actor);
+
+ application.SendNotification();
+ application.Render();
+
+ const float halfQuadSize = .5f;
+ struct TexturedQuadVertex
+ {
+ Vector2 position;
+ Vector2 textureCoordinates;
+ };
+ TexturedQuadVertex texturedQuadVertexData[4] = {
+ {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
+ {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
+ {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
+ {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
+
+ // Re-upload the data on the vertexBuffer with zero length
+ vertexBuffer.SetData(texturedQuadVertexData, 0u);
+
+ application.SendNotification();
+ application.Render(0);
+
+ DALI_TEST_CHECK(true); // Should get here without exception
+ }
+ catch(Dali::DaliException& e)
+ {
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ END_TEST;
+}
+
int UtcDaliVertexBufferGetSizeNegative(void)
{
TestApplication application;
void VertexBuffer::SetData(const void* data, uint32_t size)
{
+ DALI_ASSERT_ALWAYS((data || (size == 0u)) && "VertexBuffer::SetData() data was nullptr but size is not zero!");
+
mSize = size; // size is the number of elements
uint32_t bufferSize = mBufferFormatSize * mSize;
OwnerPointer<Vector<uint8_t> > bufferCopy = new Dali::Vector<uint8_t>();
bufferCopy->ResizeUninitialized(bufferSize);
- // copy the data
- const uint8_t* source = static_cast<const uint8_t*>(data);
- uint8_t* destination = &((*bufferCopy)[0]);
- std::copy(source, source + bufferSize, destination);
+ if(DALI_LIKELY(bufferSize > 0u))
+ {
+ // copy the data
+ const uint8_t* source = static_cast<const uint8_t*>(data);
+ uint8_t* destination = &((*bufferCopy)[0]);
+ std::copy(source, source + bufferSize, destination);
+ }
// Ownership of the bufferCopy is passed to the message ( uses an owner pointer )
SceneGraph::SetVertexBufferData(mEventThreadServices.GetUpdateManager(), *mRenderObject, bufferCopy, mSize);