/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include <3d/implementation_uids.h> #include <3d/ecs/components/transform_component.h> #include <3d/ecs/systems/intf_render_system.h> #include "dotfield/implementation_uids.h" #include "dotfield/ecs/components/dotfield_component.h" #include "dotfield/ecs/systems/dotfield_system.h" #include "dotfield/render/intf_render_data_store_default_dotfield.h" #include "render/render_node_dotfield_render.h" #include "render/render_node_dotfield_simulation.h" #include "render/render_data_store_default_dotfield.h" // Rofs Data. extern "C" const void* const DOTFIELD_BIN[]; extern "C" const uint64_t DOTFIELD_BIN_SIZE; CORE_BEGIN_NAMESPACE() #if defined(CORE_PLUGIN) && (CORE_PLUGIN == 1) IPluginRegister* gPluginRegistry{ nullptr }; IPluginRegister& GetPluginRegister() { return *gPluginRegistry; } #endif CORE_END_NAMESPACE() namespace { static constexpr RENDER_NS::IShaderManager::ShaderFilePathDesc SHADER_FILE_PATHS{ "dotfieldshaders://", "dotfieldshaderstates://", "dotfieldpipelinelayouts://", "dotfieldvertexinputdeclarations://", }; } namespace Dotfield { using CORE_NS::GetName; using namespace BASE_NS; using namespace CORE_NS; using namespace RENDER_NS; using namespace CORE3D_NS; const char* GetVersionInfo(); constexpr string_view ROFS = "dotfieldrofs"; constexpr string_view SHADERS = "dotfieldshaders"; constexpr string_view VIDS = "dotfieldvertexinputdeclarations"; constexpr string_view PIDS = "dotfieldpipelinelayouts"; constexpr string_view SSTATES = "dotfieldshaderstates"; constexpr string_view SHADER_PATH = "dotfieldrofs://shaders/"; constexpr string_view VID_PATH = "dotfieldrofs://vertexinputdeclarations/"; constexpr string_view PID_PATH = "dotfieldrofs://pipelinelayouts/"; constexpr string_view SHADER_STATE_PATH = "dotfieldrofs://shaderstates/"; constexpr BASE_NS::Uid PLUGIN_DEPENDENCIES[] = { RENDER_NS::UID_RENDER_PLUGIN, CORE3D_NS::UID_3D_PLUGIN }; IComponentManager* IDotfieldComponentManagerInstance(IEcs&); ISystem* IDotfieldSystemInstance(IEcs&); void IDotfieldComponentManagerDestroy(IComponentManager*); void IDotfieldSystemDestroy(ISystem*); constexpr RenderDataStoreTypeInfo RenderDataDefaultDotfieldTypeInfo = { RenderDataStoreTypeInfo::UID, RenderDataStoreDefaultDotfield::UID, RenderDataStoreDefaultDotfield::TYPE_NAME, RenderDataStoreDefaultDotfield::Create, RenderDataStoreDefaultDotfield::Destroy, }; constexpr RenderDataStoreTypeInfo gRenderDataStores[] = { RenderDataDefaultDotfieldTypeInfo, }; constexpr RenderNodeTypeInfo RenderNodeDotfieldSimulationTypeInfo = { RenderNodeTypeInfo::UID, RenderNodeDotfieldSimulation::UID, RenderNodeDotfieldSimulation::TYPE_NAME, RenderNodeDotfieldSimulation::Create, RenderNodeDotfieldSimulation::Destroy, RenderNodeDotfieldSimulation::BACKEND_FLAGS, RenderNodeDotfieldSimulation::CLASS_TYPE, }; constexpr RenderNodeTypeInfo RenderNodeDotfieldRenderTypeInfo = { RenderNodeTypeInfo::UID, RenderNodeDotfieldRender::UID, RenderNodeDotfieldRender::TYPE_NAME, RenderNodeDotfieldRender::Create, RenderNodeDotfieldRender::Destroy, RenderNodeDotfieldRender::BACKEND_FLAGS, RenderNodeDotfieldRender::CLASS_TYPE, }; constexpr RenderNodeTypeInfo gRenderNodes[] = { RenderNodeDotfieldSimulationTypeInfo, RenderNodeDotfieldRenderTypeInfo, }; constexpr ComponentManagerTypeInfo DotfieldComponentTypeInfo = { ComponentManagerTypeInfo::UID, IDotfieldComponentManager::UID, GetName().data(), IDotfieldComponentManagerInstance, IDotfieldComponentManagerDestroy, }; constexpr ComponentManagerTypeInfo gComponentManagers[] = { DotfieldComponentTypeInfo }; constexpr Uid DotfieldSourceSystemRDeps[] = { ITransformComponentManager::UID, IDotfieldComponentManager::UID, }; constexpr SystemTypeInfo gSystems[] = { { SystemTypeInfo::UID, IDotfieldSystem::UID, GetName().data(), IDotfieldSystemInstance, IDotfieldSystemDestroy, {}, DotfieldSourceSystemRDeps, }, }; array_view GetRenderDataStores() { return gRenderDataStores; } array_view GetRenderNodes() { return gRenderNodes; } array_view GetComponentManagers() { return gComponentManagers; } array_view GetSystems() { return gSystems; } PluginToken Initialize(IRenderContext& context) { auto& fm = context.GetEngine().GetFileManager(); // Create dotfieldrofs:// filesystem that points to embedded asset files. auto rofs = fm.CreateROFilesystem(DOTFIELD_BIN, DOTFIELD_BIN_SIZE); fm.RegisterFilesystem(ROFS, move(rofs)); // And register it under the needed proxy protocols. fm.RegisterPath(SHADERS, SHADER_PATH, false); fm.RegisterPath(VIDS, VID_PATH, false); fm.RegisterPath(PIDS, PID_PATH, false); fm.RegisterPath(SSTATES, SHADER_STATE_PATH, false); auto& renderDataStoreManager = context.GetRenderDataStoreManager(); renderDataStoreManager.Create(IRenderDataStoreDefaultDotfield::UID, "RenderDataStoreDefaultDotfield"); { IRenderDataStorePod* rsp = static_cast(renderDataStoreManager.Create(IRenderDataStorePod::UID, "DotfieldPodStore")); if (rsp) { struct { Math::Vec4 texSizeInvTexSize{ 2.f, 2.f, 1.f / 2.f, 1.f / 2.f }; } config; rsp->CreatePod("TexSizeConfig", "TexSizeShaderConfig", arrayviewU8(config)); } } context.GetDevice().GetShaderManager().LoadShaderFiles(SHADER_FILE_PATHS); return &context; } void Uninitialize(PluginToken token) { auto context = static_cast(token); context->GetDevice().GetShaderManager().UnloadShaderFiles(SHADER_FILE_PATHS); auto& fm = context->GetEngine().GetFileManager(); fm.UnregisterPath(SHADERS, SHADER_PATH); fm.UnregisterPath(VIDS, VID_PATH); fm.UnregisterPath(PIDS, PID_PATH); fm.UnregisterFilesystem(ROFS); } PluginToken InitializeEcs(IEcs&) { return {}; } void UninitializeEcs(PluginToken) {} static constexpr IRenderPlugin RENDER_PLUGIN(Initialize, Uninitialize); static constexpr IEcsPlugin ECS_PLUGIN(InitializeEcs, UninitializeEcs); PluginToken RegisterInterfaces(IPluginRegister& pluginRegistry) { #if defined(CORE_PLUGIN) && (CORE_PLUGIN == 1) gPluginRegistry = &pluginRegistry; #endif for (const auto& info : gRenderDataStores) { pluginRegistry.RegisterTypeInfo(info); } for (const auto& info : gRenderNodes) { pluginRegistry.RegisterTypeInfo(info); } for (const auto& info : gComponentManagers) { pluginRegistry.RegisterTypeInfo(info); } for (const auto& info : gSystems) { pluginRegistry.RegisterTypeInfo(info); } pluginRegistry.RegisterTypeInfo(RENDER_PLUGIN); pluginRegistry.RegisterTypeInfo(ECS_PLUGIN); return &pluginRegistry; } void UnregisterInterfaces(PluginToken token) { auto& pluginRegistry = *static_cast(token); for (const auto& info : gRenderDataStores) { pluginRegistry.UnregisterTypeInfo(info); } for (const auto& info : gRenderNodes) { pluginRegistry.UnregisterTypeInfo(info); } for (const auto& info : gComponentManagers) { pluginRegistry.UnregisterTypeInfo(info); } for (const auto& info : gSystems) { pluginRegistry.UnregisterTypeInfo(info); } pluginRegistry.UnregisterTypeInfo(ECS_PLUGIN); pluginRegistry.UnregisterTypeInfo(RENDER_PLUGIN); } } // namespace Dotfield extern "C" { PLUGIN_DATA(DotfieldPlugin){ { CORE_NS::IPlugin::UID }, "DotfieldPlugin", { Dotfield::UID_DOTFIELD_PLUGIN, Dotfield::GetVersionInfo }, Dotfield::RegisterInterfaces, Dotfield::UnregisterInterfaces, { Dotfield::PLUGIN_DEPENDENCIES }, }; }