• 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_SHADER_STATE_LOADER_H
17 #define LOADER_SHADER_STATE_LOADER_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/vector.h>
21 #include <base/util/uid.h>
22 #include <core/namespace.h>
23 #include <render/device/intf_shader_manager.h>
24 #include <render/device/pipeline_state_desc.h>
25 #include <render/namespace.h>
26 
27 CORE_BEGIN_NAMESPACE()
28 class IFileManager;
29 CORE_END_NAMESPACE()
RENDER_BEGIN_NAMESPACE()30 RENDER_BEGIN_NAMESPACE()
31 
32 /** Shader state loader.
33  * A class that can be used to load shader (graphics) state data from a json.
34  */
35 class ShaderStateLoader final {
36 public:
37     /** Describes result of the parsing operation. */
38     struct LoadResult {
39         LoadResult() = default;
40         explicit LoadResult(BASE_NS::string error) : success(false), error(BASE_NS::move(error)) {}
41 
42         /** Indicates, whether the parsing operation is successful. */
43         bool success { true };
44 
45         /** In case of parsing error, contains the description of the error. */
46         BASE_NS::string error;
47     };
48 
49     struct GraphicsStates {
50         BASE_NS::vector<GraphicsState> states;
51         BASE_NS::vector<IShaderManager::ShaderStateLoaderVariantData> variantData;
52     };
53 
54     /** Retrieve uri of shader state.
55      * @return String view to uri of shader state.
56      */
57     BASE_NS::string_view GetUri() const;
58 
59     /** Retrieve graphics state variant names.
60      * @return Graphics state variant names, as defined in the json file.
61      */
62     BASE_NS::array_view<const IShaderManager::ShaderStateLoaderVariantData> GetGraphicsStateVariantData() const;
63 
64     /** Retrieve graphics states.
65      * @return Graphics states, as defined in the json file.
66      */
67     BASE_NS::array_view<const GraphicsState> GetGraphicsStates() const;
68 
69     /** Loads shader state from given uri, using file manager.
70      * @param fileManager A file manager to access the file in given uri.
71      * @param uri Uri to json file.
72      * @return A structure containing result for the parsing operation.
73      */
74     LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
75 
76 private:
77     BASE_NS::string uri_;
78     BASE_NS::vector<GraphicsState> graphicsStates_;
79     BASE_NS::vector<IShaderManager::ShaderStateLoaderVariantData> graphicsStateVariantData_;
80 };
81 RENDER_END_NAMESPACE()
82 
83 #endif // LOADER_SHADER_STATE_LOADER_H
84