1 /*
2 * Copyright (C) 2023 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 #include <core/intf_engine.h>
17 #include <core/io/intf_file_manager.h>
18 #include <core/plugin/intf_plugin.h>
19 #include <render/namespace.h>
20
21 #include "render_context.h"
22
23 // Include the declarations directly from engine.
24 // NOTE: macro defined by cmake as CORE_STATIC_PLUGIN_HEADER="${CORE_ROOT_DIRECTORY}/src/static_plugin_decl.h"
25 // this is so that the core include directories are not leaked here, but we want this one header in this case.
26 #include CORE_STATIC_PLUGIN_HEADER
27 #include "registry_data.cpp"
28
29 // Rofs Data.
30 extern "C" {
31 extern const void* const BINARYDATAFORRENDER[];
32 extern const uint64_t SIZEOFDATAFORRENDER;
33 }
34
35 RENDER_BEGIN_NAMESPACE()
36 using namespace CORE_NS;
37 using BASE_NS::fixed_string;
38 using BASE_NS::string_view;
39 namespace {
40 constexpr string_view ROFS = "rofsRndr";
41 constexpr string_view SHADERS = "render_shaders";
42 constexpr string_view VIDS = "render_vertexinputdeclarations";
43 constexpr string_view PIDS = "render_pipelinelayouts";
44 constexpr string_view SSTATES = "render_shaderstates";
45 constexpr string_view RENDERDATA = "render_renderdataconfigurations";
46
47 constexpr string_view SHADER_PATH = "rofsRndr://shaders/";
48 constexpr string_view VID_PATH = "rofsRndr://vertexinputdeclarations/";
49 constexpr string_view PID_PATH = "rofsRndr://pipelinelayouts/";
50 constexpr string_view SHADER_STATE_PATH = "rofsRndr://shaderstates/";
51 constexpr string_view RENDERDATA_PATH = "rofsRndr://renderdataconfigurations/";
52
CreatePlugin(IEngine & engine)53 PluginToken CreatePlugin(IEngine& engine)
54 {
55 RenderPluginState* token = new RenderPluginState { engine, {} };
56 auto& registry = *engine.GetInterface<IClassRegister>();
57
58 registry.RegisterInterfaceType(token->interfaceInfo_);
59
60 IFileManager& fileManager = engine.GetFileManager();
61 #if (RENDER_EMBEDDED_ASSETS_ENABLED == 1)
62 // Create engine:// protocol that points to embedded asset files.
63 fileManager.RegisterFilesystem(ROFS, fileManager.CreateROFilesystem(BINARYDATAFORRENDER, SIZEOFDATAFORRENDER));
64 fileManager.RegisterPath(SHADERS, SHADER_PATH, false);
65 fileManager.RegisterPath(VIDS, VID_PATH, false);
66 fileManager.RegisterPath(PIDS, PID_PATH, false);
67 fileManager.RegisterPath(SSTATES, SHADER_STATE_PATH, false);
68 fileManager.RegisterPath(RENDERDATA, RENDERDATA_PATH, false);
69 #endif
70 #if (RENDER_EMBEDDED_ASSETS_ENABLED == 0) || (RENDER_DEV_ENABLED == 1)
71 const BASE_NS::string assets = engine.GetRootPath() + "../LumeRender/assets/render/";
72 fileManager.RegisterPath("engine", assets, true);
73 #endif
74
75 return token;
76 }
77
DestroyPlugin(PluginToken token)78 void DestroyPlugin(PluginToken token)
79 {
80 RenderPluginState* state = static_cast<RenderPluginState*>(token);
81 IFileManager& fileManager = state->engine_.GetFileManager();
82 #if (RENDER_EMBEDDED_ASSETS_ENABLED == 1)
83 fileManager.UnregisterPath(SHADERS, SHADER_PATH);
84 fileManager.UnregisterPath(VIDS, VID_PATH);
85 fileManager.UnregisterPath(PIDS, PID_PATH);
86 fileManager.UnregisterPath(SSTATES, SHADER_STATE_PATH);
87 fileManager.UnregisterPath(RENDERDATA, RENDERDATA_PATH);
88 fileManager.UnregisterFilesystem(ROFS);
89 #endif
90 #if (RENDER_EMBEDDED_ASSETS_ENABLED == 0) || (RENDER_DEV_ENABLED == 1)
91 const auto assets = state->engine_.GetRootPath() + "../LumeRender/assets/render/";
92 fileManager.UnregisterPath("engine", assets);
93 #endif
94 auto& registry = *state->engine_.GetInterface<IClassRegister>();
95
96 registry.UnregisterInterfaceType(state->interfaceInfo_);
97
98 delete state;
99 }
100
101 constexpr IEnginePlugin ENGINE_PLUGIN(CreatePlugin, DestroyPlugin);
102 } // namespace
103
104 extern "C" void InitRegistry(CORE_NS::IPluginRegister& pluginRegistry);
105
RegisterInterfaces(IPluginRegister & pluginRegistry)106 PluginToken RegisterInterfaces(IPluginRegister& pluginRegistry)
107 {
108 InitRegistry(pluginRegistry);
109 pluginRegistry.RegisterTypeInfo(ENGINE_PLUGIN);
110
111 return &pluginRegistry;
112 }
113
UnregisterInterfaces(PluginToken token)114 void UnregisterInterfaces(PluginToken token)
115 {
116 IPluginRegister* pluginRegistry = static_cast<IPluginRegister*>(token);
117 pluginRegistry->UnregisterTypeInfo(ENGINE_PLUGIN);
118 }
119 RENDER_END_NAMESPACE()
120