From: David Steele Date: Wed, 5 Apr 2023 11:00:21 +0000 (+0100) Subject: VertexBuffer can now be created from Property::Map by initializer list X-Git-Tag: dali_2.2.23~3 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=41da2a3a30b5f805876d50fae170e07592c33e86 VertexBuffer can now be created from Property::Map by initializer list 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 --- diff --git a/automated-tests/src/dali/utc-Dali-VertexBuffer.cpp b/automated-tests/src/dali/utc-Dali-VertexBuffer.cpp index 153e8c9..6efe695 100644 --- a/automated-tests/src/dali/utc-Dali-VertexBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-VertexBuffer.cpp @@ -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; diff --git a/dali/internal/event/rendering/vertex-buffer-impl.cpp b/dali/internal/event/rendering/vertex-buffer-impl.cpp index 689d703..b6bbf32 100644 --- a/dali/internal/event/rendering/vertex-buffer-impl.cpp +++ b/dali/internal/event/rendering/vertex-buffer-impl.cpp @@ -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()); // 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);