• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <utility>
20 
21 #include <base/containers/string.h>
22 #include <core/namespace.h>
23 #include <render/device/pipeline_state_desc.h>
24 #include <render/namespace.h>
25 
26 CORE_BEGIN_NAMESPACE()
27 class IFileManager;
28 CORE_END_NAMESPACE()
RENDER_BEGIN_NAMESPACE()29 RENDER_BEGIN_NAMESPACE()
30 
31 /** Vertex input declaration loader.
32  * A class that can be used to load vertex input declaration from json structure.
33  */
34 class VertexInputDeclarationLoader final {
35 public:
36     /** Describes result of the parsing operation. */
37     struct LoadResult {
38         LoadResult() = default;
39         explicit LoadResult(BASE_NS::string error) : success(false), error(BASE_NS::move(error)) {}
40 
41         /** Indicates, whether the parsing operation is successful. */
42         bool success { true };
43 
44         /** In case of parsing error, contains the description of the error. */
45         BASE_NS::string error;
46     };
47 
48     /** Retrieve uri of the vertex input declaration.
49      * @return String view to uri of the vertex input declaration.
50      */
51     BASE_NS::string_view GetUri() const;
52 
53     /** Retrieve vertex input declaration.
54      * @return A view to vertex input declaration structure, as defined in the json file.
55      */
56     VertexInputDeclarationView GetVertexInputDeclarationView() const;
57 
58     /** Get optional render slot.
59      * @return A render slot (optional)
60      */
61     BASE_NS::string_view GetRenderSlot() const;
62 
63     /** Get optional render slot.
64      * @return A render slot (optional)
65      */
66     bool GetDefaultRenderSlot() const;
67 
68     /** Loads vertex input declaration from json string.
69      * @param jsonString A string containing valid json as content.
70      * @return A structure containing result for the parsing operation.
71      */
72     LoadResult Load(BASE_NS::string_view jsonString);
73 
74     /** Loads vertex input declaration from given uri, using file manager.
75      * @param fileManager A file manager to access the file in given uri.
76      * @param uri Uri to json file.
77      * @return A structure containing result for the parsing operation.
78      */
79     LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
80 
81 private:
82     VertexInputDeclarationData vertexInputDeclarationData_;
83     BASE_NS::string uri_;
84     BASE_NS::string renderSlotName_;
85     bool renderSlotDefaultVid_ { false };
86 };
87 RENDER_END_NAMESPACE()
88 
89 #endif // LOADER_VERTEX_INPUT_DECLARATION_LOADER_H
90