[Tizen] Allow to set empty data for vertex buffer 55/320255/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 31 Dec 2024 05:50:11 +0000 (14:50 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 26 Feb 2025 01:30:45 +0000 (10:30 +0900)
Let we allow to set data with nullptr and size 0 for VertexBuffer

Change-Id: Ife70c7b0a033c883f16a7d36decf1b81c05267d5
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-VertexBuffer.cpp
dali/internal/event/rendering/vertex-buffer-impl.cpp
dali/internal/render/renderers/render-vertex-buffer.cpp

index 153e8c9174af872e9a44e5ed121c19e1e0f80328..b612642e127e6fc82ca9284d46d8b86c286e01e1 100644 (file)
@@ -300,7 +300,27 @@ int UtcDaliVertexBufferInvalidTypeN(void)
   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;
@@ -318,6 +338,88 @@ int UtcDaliVertexBufferSetDataNegative(void)
   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;
index 689d70323ca8fa7aeffdf365e56a76ea445d5e50..68574952c6ce6a5c622163fa089f8ad4f45ec975 100644 (file)
@@ -148,6 +148,8 @@ VertexBufferPtr VertexBuffer::New(Dali::Property::Map& format)
 
 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;
@@ -157,10 +159,13 @@ void VertexBuffer::SetData(const void* data, uint32_t size)
   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);
index 1a881d1a6d10c371a9cf1ead73958fccc5ee9f53..95384f94b79051e63a431d4f97353c643d90772d 100644 (file)
@@ -53,7 +53,12 @@ void VertexBuffer::SetData(Dali::Vector<uint8_t>* data, uint32_t size)
 
 bool VertexBuffer::Update(Graphics::Controller& graphicsController)
 {
-  if(!mData || !mFormat || !mSize)
+  if(!mFormat || !mSize)
+  {
+    return false;
+  }
+
+  if(!mData || mData->Empty())
   {
     return false;
   }
@@ -66,7 +71,7 @@ bool VertexBuffer::Update(Graphics::Controller& graphicsController)
     }
 
     // Update the GpuBuffer
-    if(mGpuBuffer)
+    if(mGpuBuffer && mData && !mData->Empty())
     {
       DALI_ASSERT_DEBUG(mSize && "No data in the property buffer!");
       mGpuBuffer->UpdateDataBuffer(graphicsController, GetDataSize(), &((*mData)[0]));