VertexBuffer can now be created from Property::Map by initializer list 53/290953/4
authorDavid Steele <david.steele@samsung.com>
Wed, 5 Apr 2023 11:00:21 +0000 (12:00 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 17 Apr 2023 12:15:19 +0000 (13:15 +0100)
VertexBuffer constructor takes a vertex format as it's argument, which
is a PropertyMap of key value pairs. Previously, it assumes that the
value is a property type enumeration cast to an INTEGER type.

However, if the Property::Map is instantiated using initializer lists,
e.g.

  Property::Map format { {"aPosition", Property::VECTOR2},
                         {"aColor", Property::VECTOR4}};
  VertexBuffer vertexBuffer(format);

then the enum is promoted to a Property::Value of that type, so the
vertex buffer doesn't see INTEGER type and asserts.

Modified the VertexBuffer constructor to utilize the value type
if it's not an INTEGER.

Change-Id: I85bc1d08603c31726eb06d786f44f0ca27a62ce9
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali/utc-Dali-VertexBuffer.cpp
dali/internal/event/rendering/vertex-buffer-impl.cpp

index 153e8c9..6efe695 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -280,7 +280,28 @@ int UtcDaliVertexBufferSetData02(void)
   END_TEST;
 }
 
-int UtcDaliVertexBufferInvalidTypeN(void)
+int UtcDaliVertexBufferMapInitializerList(void)
+{
+  TestApplication application;
+
+  Property::Map texturedQuadVertexFormat = Property::Map{{"aPosition", Property::VECTOR2},
+                                                         {"aTexCoord", Property::VECTOR2},
+                                                         {"aColor", Property::VECTOR4}};
+
+  try
+  {
+    VertexBuffer vertexBuffer = VertexBuffer::New(texturedQuadVertexFormat);
+    tet_result(TET_PASS);
+  }
+  catch(Dali::DaliException& e)
+  {
+    // Shouldn't assert any more
+    tet_result(TET_FAIL);
+  }
+  END_TEST;
+}
+
+int UtcDaliVertexBufferInvalidTypeN01(void)
 {
   TestApplication application;
 
@@ -300,6 +321,26 @@ int UtcDaliVertexBufferInvalidTypeN(void)
   END_TEST;
 }
 
+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 UtcDaliVertexBufferSetDataNegative(void)
 {
   TestApplication    application;
index 689d703..b6bbf32 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -222,6 +222,15 @@ void VertexBuffer::Initialize(Dali::Property::Map& formatMap)
     Property::Type type = Property::Type(component.second.Get<int>());
 
     // Get the size and alignment
+    if(type == Property::NONE)
+    {
+      /* Note, Property::Value() has an explicit constructor using Property::Type enum,
+       * which will generate a property value of that type. This constructor is used when
+       * using C++ initializer lists.
+       */
+      type = component.second.GetType();
+    }
+
     if((type == Property::NONE) ||
        (type == Property::STRING) ||
        (type == Property::ARRAY) ||
@@ -229,6 +238,7 @@ void VertexBuffer::Initialize(Dali::Property::Map& formatMap)
     {
       DALI_ABORT("Property::Type not supported in VertexBuffer");
     }
+
     uint32_t elementSize      = GetPropertyImplementationSize(type);
     uint32_t elementAlignment = GetPropertyImplementationAlignment(type);