1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LOADER_VERTEX_INPUT_DECLARATION_LOADER_H 17 #define LOADER_VERTEX_INPUT_DECLARATION_LOADER_H 18 19 #include <base/containers/string.h> 20 #include <core/namespace.h> 21 #include <render/device/pipeline_state_desc.h> 22 #include <render/namespace.h> 23 24 CORE_BEGIN_NAMESPACE() 25 class IFileManager; 26 CORE_END_NAMESPACE() 27 RENDER_BEGIN_NAMESPACE() 28 29 /** Vertex input declaration loader. 30 * A class that can be used to load vertex input declaration from json structure. 31 */ 32 class VertexInputDeclarationLoader final { 33 public: 34 /** Describes result of the parsing operation. */ 35 struct LoadResult { 36 LoadResult() = default; LoadResultfinal::LoadResult37 explicit LoadResult(const BASE_NS::string& error) : success(false), error(error) {} 38 39 /** Indicates, whether the parsing operation is successful. */ 40 bool success { true }; 41 42 /** In case of parsing error, contains the description of the error. */ 43 BASE_NS::string error; 44 }; 45 46 /** Retrieve uri of the vertex input declaration. 47 * @return String view to uri of the vertex input declaration. 48 */ 49 BASE_NS::string_view GetUri() const; 50 51 /** Retrieve vertex input declaration. 52 * @return A view to vertex input declaration structure, as defined in the json file. 53 */ 54 VertexInputDeclarationView GetVertexInputDeclarationView() const; 55 56 /** Loads vertex input declaration from json string. 57 * @param jsonString A string containing valid json as content. 58 * @return A structure containing result for the parsing operation. 59 */ 60 LoadResult Load(BASE_NS::string_view jsonString); 61 62 /** Loads vertex input declaration from given uri, using file manager. 63 * @param fileManager A file manager to access the file in given uri. 64 * @param uri Uri to json file. 65 * @return A structure containing result for the parsing operation. 66 */ 67 LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri); 68 69 private: 70 VertexInputDeclarationData vertexInputDeclarationData_; 71 BASE_NS::string uri_; 72 }; 73 RENDER_END_NAMESPACE() 74 75 #endif // LOADER_VERTEX_INPUT_DECLARATION_LOADER_H 76