2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "dali-scene-loader/public-api/utils.h"
22 #include "dali/public-api/common/vector-wrapper.h"
23 #include "dali/public-api/animation/constraints.h"
35 thread_local char sExceptionFlingerMessageBuffer[ExceptionFlinger::MESSAGE_BUFFER_SIZE]{};
38 char* ExceptionFlinger::GetMessageBuffer() noexcept(true)
40 return sExceptionFlingerMessageBuffer;
43 std::string FormatString(const char* format, ...)
50 size_t sizeRequired = vsnprintf(nullptr, 0, format, vl);
54 std::string result(sizeRequired, '\0');
55 vsnprintf(&result[0], sizeRequired, format, vl2);
61 std::string LoadTextFile(const char * path, bool* fail)
63 std::ifstream inFile(path);
66 std::istreambuf_iterator<char> eos;
67 std::istreambuf_iterator<char> i(inFile.rdbuf());
68 return std::string(i, eos);
77 Geometry MakeTexturedQuadGeometry(TexturedQuadOptions::Type options)
79 Property::Map properties;
80 properties.Insert("aPosition", Property::VECTOR3);
81 properties.Insert("aTexCoord", Property::VECTOR2);
83 std::vector<uint8_t> bytes;
91 { Vector3(-0.5f, 0.5f, 0.0f), Vector2(0.0f, .0f) },
92 { Vector3(0.5f, 0.5f, 0.0f), Vector2(1.0f, .0f) },
93 { Vector3(-0.5f, -0.5f, 0.0f), Vector2(0.0f, 1.0f) },
94 { Vector3(0.5f, -0.5f, 0.0f), Vector2(1.0f, 1.0f) }
97 bytes.resize(sizeof(vertices));
98 stride = sizeof(vertices[0]);
99 uvOffset = reinterpret_cast<const uint8_t*>(&vertices[0].aTexCoord) - reinterpret_cast<const uint8_t*>(&vertices[0]);
101 std::memcpy(bytes.data(), vertices, sizeof(vertices));
103 if (MaskMatch(options, TexturedQuadOptions::FLIP_VERTICAL))
105 Vector2* uv = reinterpret_cast<Vector2*>(reinterpret_cast<uint8_t*>(bytes.data()) + uvOffset);
106 for (int i = 0; i < 4; ++i)
108 uv->y = 1.0f - uv->y;
109 uv = reinterpret_cast<Vector2*>(reinterpret_cast<uint8_t*>(uv) + stride);
113 VertexBuffer vertexBuffer = VertexBuffer::New(properties);
114 vertexBuffer.SetData(bytes.data(), bytes.size() / stride);
116 Geometry geometry = Geometry::New();
117 geometry.AddVertexBuffer(vertexBuffer);
118 geometry.SetType(Geometry::TRIANGLE_STRIP);
122 void ToUnixFileSeparators(std::string& path)
124 std::replace(path.begin(), path.end(), '\\', '/');