X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Fpublic-api%2Floader%2Fparse-renderer-state.cpp;h=63b7d5815fb544b9e2f23cecd181ee281ed8e164;hb=HEAD;hp=3c01701d2622ccd0d1f1314acbb5e2ce7d5d4f65;hpb=9c86dc1ea5d8ec24c79da0abf05c5c23301c8a3a;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/public-api/loader/parse-renderer-state.cpp b/dali-scene3d/public-api/loader/parse-renderer-state.cpp index 3c01701..63b7d58 100644 --- a/dali-scene3d/public-api/loader/parse-renderer-state.cpp +++ b/dali-scene3d/public-api/loader/parse-renderer-state.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. @@ -15,126 +15,142 @@ * */ -#include "dali-scene3d/public-api/loader/parse-renderer-state.h" +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include #include -#include "dali/devel-api/common/map-wrapper.h" -namespace Dali -{ -namespace Scene3D -{ -namespace Loader +namespace Dali::Scene3D::Loader { namespace RendererState { namespace { -std::map COMPARISONS{ -#define DECL_COMPARISON(x) {#x, Comparison::x} - DECL_COMPARISON(NEVER), - DECL_COMPARISON(ALWAYS), - DECL_COMPARISON(LESS), - DECL_COMPARISON(GREATER), - DECL_COMPARISON(EQUAL), - DECL_COMPARISON(NOT_EQUAL), - DECL_COMPARISON(LESS_EQUAL), - DECL_COMPARISON(GREATER_EQUAL), -#undef DECL_COMPARISON -}; +const std::map& GetComparisons() +{ + static const std::map COMPARISONS{ + #define DECL_COMPARISON(x) {#x, Comparison::x} + DECL_COMPARISON(NEVER), + DECL_COMPARISON(ALWAYS), + DECL_COMPARISON(LESS), + DECL_COMPARISON(GREATER), + DECL_COMPARISON(EQUAL), + DECL_COMPARISON(NOT_EQUAL), + DECL_COMPARISON(LESS_EQUAL), + DECL_COMPARISON(GREATER_EQUAL), + #undef DECL_COMPARISON + }; + return COMPARISONS; +} Type InterpretComparison(const std::string_view& str) { Type value = 0x0; - auto iFind = COMPARISONS.find(str); - if(iFind != COMPARISONS.end()) + auto iFind = GetComparisons().find(str); + if(iFind != GetComparisons().end()) { value = iFind->second; } return value; } -std::map BLEND_FACTORS{ -#define DECL_BLEND_FACTOR(x) {#x, Dali::Scene3D::Loader::BlendFactor::x} - DECL_BLEND_FACTOR(ZERO), - DECL_BLEND_FACTOR(ONE), - DECL_BLEND_FACTOR(SRC_COLOR), - DECL_BLEND_FACTOR(ONE_MINUS_SRC_COLOR), - DECL_BLEND_FACTOR(SRC_ALPHA), - DECL_BLEND_FACTOR(ONE_MINUS_SRC_ALPHA), - DECL_BLEND_FACTOR(DST_ALPHA), - DECL_BLEND_FACTOR(ONE_MINUS_DST_ALPHA), - DECL_BLEND_FACTOR(DST_COLOR), - DECL_BLEND_FACTOR(ONE_MINUS_DST_COLOR), - DECL_BLEND_FACTOR(SRC_ALPHA_SATURATE), - DECL_BLEND_FACTOR(CONSTANT_COLOR), - DECL_BLEND_FACTOR(ONE_MINUS_CONSTANT_COLOR), - DECL_BLEND_FACTOR(CONSTANT_ALPHA), - DECL_BLEND_FACTOR(ONE_MINUS_CONSTANT_ALPHA), -#undef DECL_BLEND_FACTOR -}; +const std::map& GetBlendFactors() +{ + static const std::map BLEND_FACTORS{ + #define DECL_BLEND_FACTOR(x) {#x, Dali::Scene3D::Loader::BlendFactor::x} + DECL_BLEND_FACTOR(ZERO), + DECL_BLEND_FACTOR(ONE), + DECL_BLEND_FACTOR(SRC_COLOR), + DECL_BLEND_FACTOR(ONE_MINUS_SRC_COLOR), + DECL_BLEND_FACTOR(SRC_ALPHA), + DECL_BLEND_FACTOR(ONE_MINUS_SRC_ALPHA), + DECL_BLEND_FACTOR(DST_ALPHA), + DECL_BLEND_FACTOR(ONE_MINUS_DST_ALPHA), + DECL_BLEND_FACTOR(DST_COLOR), + DECL_BLEND_FACTOR(ONE_MINUS_DST_COLOR), + DECL_BLEND_FACTOR(SRC_ALPHA_SATURATE), + DECL_BLEND_FACTOR(CONSTANT_COLOR), + DECL_BLEND_FACTOR(ONE_MINUS_CONSTANT_COLOR), + DECL_BLEND_FACTOR(CONSTANT_ALPHA), + DECL_BLEND_FACTOR(ONE_MINUS_CONSTANT_ALPHA), + #undef DECL_BLEND_FACTOR + }; + return BLEND_FACTORS; +} Type InterpretBlendFactor(const std::string_view& str, uint8_t item) { Type value = 0x0; - auto iFind = BLEND_FACTORS.find(str); - if(iFind != BLEND_FACTORS.end()) + auto iFind = GetBlendFactors().find(str); + if(iFind != GetBlendFactors().end()) { value = iFind->second << (BLEND_FACTOR_BASE_SHIFT + BLEND_FACTOR_ITEM_BITS * item); } return value; } -std::map BUFFER_MODES{ -#define DECL_BUFFER_MODE(x) {#x, BufferMode::x} - DECL_BUFFER_MODE(NONE), - DECL_BUFFER_MODE(AUTO), - DECL_BUFFER_MODE(COLOR), - DECL_BUFFER_MODE(STENCIL), - DECL_BUFFER_MODE(COLOR_STENCIL), -}; +const std::map& GetBufferModes() +{ + static const std::map BUFFER_MODES{ + #define DECL_BUFFER_MODE(x) {#x, BufferMode::x} + DECL_BUFFER_MODE(NONE), + DECL_BUFFER_MODE(AUTO), + DECL_BUFFER_MODE(COLOR), + DECL_BUFFER_MODE(STENCIL), + DECL_BUFFER_MODE(COLOR_STENCIL), + #undef DECL_BUFFER_MODE + }; + return BUFFER_MODES; +} Type InterpretBufferMode(const std::string_view& str) { Type value = 0x0; - auto iFind = BUFFER_MODES.find(str); - if(iFind != BUFFER_MODES.end()) + auto iFind = GetBufferModes().find(str); + if(iFind != GetBufferModes().end()) { value = iFind->second << BUFFER_MODE_SHIFT; } return value; } -std::map RENDERER_STATE_PROCESSORS{ - {"DEPTH_WRITE", [](const std::string_view&) -> Type { return DEPTH_WRITE; }}, - {"DEPTH_TEST", [](const std::string_view&) -> Type { return DEPTH_TEST; }}, - {"CULL_FRONT", [](const std::string_view&) -> Type { return CULL_FRONT; }}, - {"CULL_BACK", [](const std::string_view&) -> Type { return CULL_BACK; }}, - {"ALPHA_BLEND", [](const std::string_view&) -> Type { return ALPHA_BLEND; }}, - {"DEPTH_FUNC", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? (InterpretComparison(std::string_view(arg.data() + 1, arg.size() - 1)) << DEPTH_FUNCTION_SHIFT) : 0x0; - return value; - }}, - {"BLEND_SRC_RGB", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 0) : 0x0; - return value; - }}, - {"BLEND_DST_RGB", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 1) : 0x0; - return value; - }}, - {"BLEND_SRC_ALPHA", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 2) : 0x0; - return value; - }}, - {"BLEND_DST_ALPHA", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 3) : 0x0; - return value; - }}, - {"BUFFER_MODE", [](const std::string_view& arg) -> Type { - Type value = (arg[0] == ':') ? InterpretBufferMode(std::string_view(arg.data() + 1, arg.size() - 1)) : 0x0; - return value; - }}, -}; +const std::map& GetRendererStateProcessors() +{ + static const std::map RENDERER_STATE_PROCESSORS{ + {"DEPTH_WRITE", [](const std::string_view&) -> Type { return DEPTH_WRITE; }}, + {"DEPTH_TEST", [](const std::string_view&) -> Type { return DEPTH_TEST; }}, + {"CULL_FRONT", [](const std::string_view&) -> Type { return CULL_FRONT; }}, + {"CULL_BACK", [](const std::string_view&) -> Type { return CULL_BACK; }}, + {"ALPHA_BLEND", [](const std::string_view&) -> Type { return ALPHA_BLEND; }}, + {"DEPTH_FUNC", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? (InterpretComparison(std::string_view(arg.data() + 1, arg.size() - 1)) << DEPTH_FUNCTION_SHIFT) : 0x0; + return value; + }}, + {"BLEND_SRC_RGB", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 0) : 0x0; + return value; + }}, + {"BLEND_DST_RGB", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 1) : 0x0; + return value; + }}, + {"BLEND_SRC_ALPHA", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 2) : 0x0; + return value; + }}, + {"BLEND_DST_ALPHA", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 3) : 0x0; + return value; + }}, + {"BUFFER_MODE", [](const std::string_view& arg) -> Type { + Type value = (arg[0] == ':') ? InterpretBufferMode(std::string_view(arg.data() + 1, arg.size() - 1)) : 0x0; + return value; + }}, + }; + return RENDERER_STATE_PROCESSORS; +} } // namespace @@ -151,8 +167,8 @@ Type Parse(const char* string, size_t length, StringCallback onError) { auto iNextToken = std::find(string, iEnd, '|'); auto iColon = std::find(string, iNextToken, ':'); - auto i = RENDERER_STATE_PROCESSORS.find(std::string_view(string, iColon - string)); - if(i != RENDERER_STATE_PROCESSORS.end() && size_t(std::distance(string, iNextToken)) >= i->first.size()) + auto i = GetRendererStateProcessors().find(std::string_view(string, iColon - string)); + if(i != GetRendererStateProcessors().end() && size_t(std::distance(string, iNextToken)) >= i->first.size()) { value |= i->second(std::string_view(string + i->first.size(), iNextToken - iColon)); } @@ -168,6 +184,4 @@ Type Parse(const char* string, size_t length, StringCallback onError) } } // namespace RendererState -} // namespace Loader -} // namespace Scene3D -} // namespace Dali +} // namespace Dali::Scene3D::Loader