diff --git a/examples/WidgetDemo/main.cpp b/examples/WidgetDemo/main.cpp index a2f83c77f..d1294dea3 100644 --- a/examples/WidgetDemo/main.cpp +++ b/examples/WidgetDemo/main.cpp @@ -25,10 +25,6 @@ NAZARA_REQUEST_DEDICATED_GPU() int main() { - std::filesystem::path resourceDir = "assets/examples"; - if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) - resourceDir = "../.." / resourceDir; - Nz::Renderer::Config rendererConfig; std::cout << "Run using Vulkan? (y/n)" << std::endl; if (std::getchar() != 'n') @@ -46,7 +42,13 @@ int main() auto& ecs = app.AddComponent(); auto& fs = app.AddComponent(); - fs.RegisterPath(resourceDir); + { + std::filesystem::path resourceDir = "assets/examples"; + if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) + resourceDir = "../.." / resourceDir; + + fs.Mount("assets", resourceDir); + } Nz::RenderSystem& renderSystem = ecs.AddSystem(); auto& windowSwapchain = renderSystem.CreateSwapchain(mainWindow); @@ -74,12 +76,8 @@ int main() Nz::TextureSamplerInfo samplerInfo; samplerInfo.anisotropyLevel = 8; - Nz::TextureParams texParams; - texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice(); - texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB; - std::shared_ptr materialInstance = material->Instantiate(); - materialInstance->SetTextureProperty("BaseColorMap", fs.GetOrLoad("Spaceship/Texture/diffuse.png", texParams)); + materialInstance->SetTextureProperty("BaseColorMap", fs.GetOrLoad("assets/lynix.jpg")); Nz::ImageWidget* imageWidget = canvas2D.Add(materialInstance); imageWidget->SetPosition(1200.f, 200.f); diff --git a/include/Nazara/Audio/SoundBuffer.hpp b/include/Nazara/Audio/SoundBuffer.hpp index 9ae9a80cf..69b725978 100644 --- a/include/Nazara/Audio/SoundBuffer.hpp +++ b/include/Nazara/Audio/SoundBuffer.hpp @@ -45,6 +45,8 @@ namespace Nz friend Sound; public: + using Params = SoundBufferParams; + SoundBuffer() = default; SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples); SoundBuffer(const SoundBuffer&) = delete; diff --git a/include/Nazara/Audio/SoundStream.hpp b/include/Nazara/Audio/SoundStream.hpp index 2eaec5128..d250c3b3e 100644 --- a/include/Nazara/Audio/SoundStream.hpp +++ b/include/Nazara/Audio/SoundStream.hpp @@ -18,7 +18,7 @@ namespace Nz { - struct SoundStreamParams : public ResourceParameters + struct SoundStreamParams : ResourceParameters { bool forceMono = false; @@ -33,6 +33,8 @@ namespace Nz class NAZARA_AUDIO_API SoundStream : public Resource { public: + using Params = SoundStreamParams; + SoundStream() = default; virtual ~SoundStream(); diff --git a/include/Nazara/Core/AppFilesystemComponent.hpp b/include/Nazara/Core/AppFilesystemComponent.hpp index a3c16e163..6ef996c4f 100644 --- a/include/Nazara/Core/AppFilesystemComponent.hpp +++ b/include/Nazara/Core/AppFilesystemComponent.hpp @@ -10,32 +10,50 @@ #include #include #include +#include #include #include #include namespace Nz { + class Font; + class Image; + class ImageStream; + class Material; + class MaterialInstance; + class Mesh; + class SoundBuffer; + class SoundStream; + class Texture; + class NAZARA_CORE_API AppFilesystemComponent : public ApplicationComponent { public: - using ApplicationComponent::ApplicationComponent; + inline AppFilesystemComponent(ApplicationBase& app); AppFilesystemComponent(const AppFilesystemComponent&) = delete; AppFilesystemComponent(AppFilesystemComponent&&) = delete; ~AppFilesystemComponent() = default; - template std::shared_ptr GetOrLoad(std::string_view assetPath, Args&&... args); + template const typename T::Params* GetDefaultResourceParameters() const; - inline const VirtualDirectoryPtr& RegisterPath(std::filesystem::path filepath); - inline const VirtualDirectoryPtr& RegisterVirtualDirectory(VirtualDirectoryPtr directory); + template std::shared_ptr GetOrLoad(std::string_view assetPath); + template std::shared_ptr GetOrLoad(std::string_view assetPath, typename T::Params params); - inline void UnregisterVirtualDirectory(const VirtualDirectoryPtr& directory); + inline const VirtualDirectoryPtr& Mount(std::string_view name, std::filesystem::path filepath); + inline const VirtualDirectoryPtr& Mount(std::string_view name, VirtualDirectoryPtr directory); + + template void SetDefaultResourceParameters(typename T::Params params); AppFilesystemComponent& operator=(const AppFilesystemComponent&) = delete; AppFilesystemComponent& operator=(AppFilesystemComponent&&) = delete; private: - std::vector m_virtualDirectories; + template std::shared_ptr GetOrLoadImpl(std::string_view assetPath, const typename T::Params& params); + inline void RegisterResourceTypes(); + + std::vector> m_defaultParameters; + VirtualDirectoryPtr m_rootDirectory; }; } diff --git a/include/Nazara/Core/AppFilesystemComponent.inl b/include/Nazara/Core/AppFilesystemComponent.inl index 3ca6e7d4c..cb48e65b3 100644 --- a/include/Nazara/Core/AppFilesystemComponent.inl +++ b/include/Nazara/Core/AppFilesystemComponent.inl @@ -4,68 +4,153 @@ #include #include +#include +#include #include namespace Nz { - template - std::shared_ptr AppFilesystemComponent::GetOrLoad(std::string_view assetPath, Args&&... args) + namespace Detail { - std::shared_ptr resource; - for (const VirtualDirectoryPtr& virtualDir : m_virtualDirectories) - { - auto callback = [&](const VirtualDirectory::Entry& entry) - { - return std::visit([&](auto&& arg) - { - using Param = std::decay_t; - if constexpr (std::is_base_of_v) - { - NazaraError(std::string(assetPath) + " is a directory"); - return false; - } - else if constexpr (std::is_same_v) - { - resource = T::LoadFromMemory(arg.data, arg.size, std::forward(args)...); - return true; - } - else if constexpr (std::is_same_v) - { - resource = T::LoadFromMemory(&arg.data[0], arg.data.size(), std::forward(args)...); - return true; - } - else if constexpr (std::is_same_v) - { - resource = T::LoadFromFile(arg.filePath, std::forward(args)...); - return true; - } - else - static_assert(AlwaysFalse(), "unhandled case"); - }, entry); - }; + template + struct ResourceParameterHasMerge : std::false_type {}; - if (virtualDir->GetEntry(assetPath, callback) && resource) - return resource; + template + struct ResourceParameterHasMerge().Merge(std::declval()))>> : std::true_type {}; + } + + inline AppFilesystemComponent::AppFilesystemComponent(ApplicationBase& app) : + ApplicationComponent(app) + { + RegisterResourceTypes(); + } + + template + const typename T::Params* AppFilesystemComponent::GetDefaultResourceParameters() const + { + std::size_t resourceIndex = ResourceRegistry::GetResourceId(); + if (resourceIndex >= m_defaultParameters.size()) + return nullptr; + + return static_cast(m_defaultParameters[resourceIndex].get()); + } + + template + std::shared_ptr AppFilesystemComponent::GetOrLoad(std::string_view assetPath) + { + return GetOrLoad(assetPath, typename T::Params{}); + } + + template + std::shared_ptr AppFilesystemComponent::GetOrLoad(std::string_view assetPath, typename T::Params params) + { + if constexpr (Detail::ResourceParameterHasMerge::value) + { + if (const auto* defaultParams = GetDefaultResourceParameters()) + params.Merge(*defaultParams); } + return GetOrLoadImpl(assetPath, params); + } + + inline const VirtualDirectoryPtr& AppFilesystemComponent::Mount(std::string_view name, std::filesystem::path filepath) + { + return Mount(name, std::make_shared(std::move(filepath))); + } + + inline const VirtualDirectoryPtr& AppFilesystemComponent::Mount(std::string_view name, VirtualDirectoryPtr directory) + { + if (name.empty()) + { + m_rootDirectory = std::move(directory); + return m_rootDirectory; + } + + if (!m_rootDirectory) + m_rootDirectory = std::make_shared(); + + return m_rootDirectory->StoreDirectory(name, std::move(directory)).directory; + } + + template + void AppFilesystemComponent::SetDefaultResourceParameters(typename T::Params params) + { + std::size_t resourceIndex = ResourceRegistry::GetResourceId(); + if (resourceIndex >= m_defaultParameters.size()) + m_defaultParameters.resize(resourceIndex + 1); + + m_defaultParameters[resourceIndex] = std::make_unique(std::move(params)); + } + + template + std::shared_ptr AppFilesystemComponent::GetOrLoadImpl(std::string_view assetPath, const typename T::Params& params) + { + std::shared_ptr resource; + if (!m_rootDirectory) + return resource; + + auto callback = [&](const VirtualDirectory::Entry& entry) + { + return std::visit([&](auto&& arg) + { + using Param = std::decay_t; + if constexpr (std::is_base_of_v) + { + NazaraError(std::string(assetPath) + " is a directory"); + return false; + } + else if constexpr (std::is_same_v) + { + resource = T::LoadFromMemory(arg.data, arg.size, params); + return true; + } + else if constexpr (std::is_same_v) + { + resource = T::LoadFromMemory(&arg.data[0], arg.data.size(), params); + return true; + } + else if constexpr (std::is_same_v) + { + resource = T::LoadFromFile(arg.filePath, params); + return true; + } + else + static_assert(AlwaysFalse(), "unhandled case"); + }, entry); + }; + + m_rootDirectory->GetEntry(assetPath, callback); return resource; } - inline const VirtualDirectoryPtr& AppFilesystemComponent::RegisterPath(std::filesystem::path filepath) + inline void AppFilesystemComponent::RegisterResourceTypes() { - return RegisterVirtualDirectory(std::make_shared(std::move(filepath))); - } + if (ResourceRegistry::GetResourceId() != 0) + throw std::runtime_error("Font has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - inline const VirtualDirectoryPtr& AppFilesystemComponent::RegisterVirtualDirectory(VirtualDirectoryPtr directory) - { - return m_virtualDirectories.emplace_back(std::move(directory)); - } + if (ResourceRegistry::GetResourceId() != 1) + throw std::runtime_error("Image has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); - inline void AppFilesystemComponent::UnregisterVirtualDirectory(const VirtualDirectoryPtr& directory) - { - auto it = std::find(m_virtualDirectories.begin(), m_virtualDirectories.end(), directory); - if (it == m_virtualDirectories.end()) - m_virtualDirectories.erase(it); + if (ResourceRegistry::GetResourceId() != 2) + throw std::runtime_error("ImageStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 3) + throw std::runtime_error("Material has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 4) + throw std::runtime_error("MaterialInstance has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 5) + throw std::runtime_error("Mesh has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 6) + throw std::runtime_error("SoundBuffer has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 7) + throw std::runtime_error("SoundStream has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); + + if (ResourceRegistry::GetResourceId() != 8) + throw std::runtime_error("Texture has wrong resource index, please initialize AppFilesystemComponent before using ResourceRegistry"); } } diff --git a/include/Nazara/Core/Application.hpp b/include/Nazara/Core/Application.hpp index f0e8350f8..681d0783c 100644 --- a/include/Nazara/Core/Application.hpp +++ b/include/Nazara/Core/Application.hpp @@ -24,6 +24,8 @@ namespace Nz Application(Application&&) = delete; ~Application(); + template T& AddComponent(Args&&... args); + Application& operator=(const Application&) = delete; Application& operator=(Application&&) = delete; diff --git a/include/Nazara/Core/Application.inl b/include/Nazara/Core/Application.inl index 46bfbf061..7c05362b3 100644 --- a/include/Nazara/Core/Application.inl +++ b/include/Nazara/Core/Application.inl @@ -7,6 +7,39 @@ namespace Nz { + namespace Detail + { + template + struct ModuleHasRegister : std::false_type {}; + + template + struct ModuleHasRegister().RegisterComponent(std::declval()))>> : std::true_type {}; + + template struct ModuleRegisterer; + + template + struct ModuleRegisterer> + { + template + static void Register(T& modules, C& component) + { + if constexpr (ModuleHasRegister::value) + modules.template Get().RegisterComponent(component); + + ModuleRegisterer>::Register(modules, component); + } + }; + + template<> + struct ModuleRegisterer> + { + template + static void Register(T& /*modules*/, C& /*component*/) + { + } + }; + } + template template Application::Application(ModuleConfig&&... configs) : @@ -30,6 +63,16 @@ namespace Nz { } + template + template + T& Application::AddComponent(Args&&... args) + { + T& component = ApplicationBase::AddComponent(std::forward(args)...); + Detail::ModuleRegisterer::template Register(m_modules, component); + + return component; + } + template Application::~Application() { diff --git a/include/Nazara/Core/ApplicationBase.hpp b/include/Nazara/Core/ApplicationBase.hpp index 291585c25..f2c856a77 100644 --- a/include/Nazara/Core/ApplicationBase.hpp +++ b/include/Nazara/Core/ApplicationBase.hpp @@ -26,7 +26,6 @@ namespace Nz ApplicationBase(ApplicationBase&&) = delete; ~ApplicationBase() = default; - template T& AddComponent(Args&&... args); template void AddUpdater(F&& functor); inline void ClearComponents(); @@ -43,6 +42,9 @@ namespace Nz ApplicationBase& operator=(const ApplicationBase&) = delete; ApplicationBase& operator=(ApplicationBase&&) = delete; + protected: + template T& AddComponent(Args&&... args); + private: std::atomic_bool m_running; std::vector> m_components; diff --git a/include/Nazara/Core/ApplicationComponentRegistry.inl b/include/Nazara/Core/ApplicationComponentRegistry.inl index 486eb7ccc..3c9139cd9 100644 --- a/include/Nazara/Core/ApplicationComponentRegistry.inl +++ b/include/Nazara/Core/ApplicationComponentRegistry.inl @@ -9,7 +9,7 @@ namespace Nz { namespace Detail { - std::size_t ComponentCounter() + inline std::size_t ComponentCounter() { static std::size_t counter = 0; return counter++; diff --git a/include/Nazara/Core/Modules.hpp b/include/Nazara/Core/Modules.hpp index f1ada391e..03c1459cb 100644 --- a/include/Nazara/Core/Modules.hpp +++ b/include/Nazara/Core/Modules.hpp @@ -13,14 +13,13 @@ namespace Nz { namespace Detail { - template - struct BuildDepList; - template struct ModuleTuple : ModuleTuple, ModuleTuple { template ModuleTuple(ModuleConfig&&... configs); + + template T& Get(); }; template @@ -29,10 +28,16 @@ namespace Nz template ModuleTuple(ModuleConfig&&... configs); + template T& Get(); + Module m; }; } + template struct OrderedModuleDependencyList; + + template using OrderedModuleDependencies = TypeListUnique::Result>; + template class Modules { @@ -41,12 +46,31 @@ namespace Nz Modules(ModuleConfig&&... configs); ~Modules() = default; + template T& Get(); + + using ModuleTypeList = OrderedModuleDependencies>; + private: - using OrderedModuleList = TypeListUnique>::Result>; - using Tuple = TypeListInstantiate; + using Tuple = TypeListInstantiate; Tuple m_modules; }; + + + template<> + struct OrderedModuleDependencyList> + { + using Result = TypeList<>; + }; + + template + struct OrderedModuleDependencyList> + { + using ModuleDependencies = typename OrderedModuleDependencyList::Result; + using ModuleDependenciesIncModule = TypeListAppend; + using RestDependencies = typename OrderedModuleDependencyList>::Result; + using Result = TypeListConcat; + }; } #include diff --git a/include/Nazara/Core/Modules.inl b/include/Nazara/Core/Modules.inl index c3f4a4f58..848e05375 100644 --- a/include/Nazara/Core/Modules.inl +++ b/include/Nazara/Core/Modules.inl @@ -39,6 +39,16 @@ namespace Nz { } + template + template + T& ModuleTuple::Get() + { + if constexpr (std::is_same_v) + return ModuleTuple::template Get(); + else + return ModuleTuple::template Get(); + } + template template ModuleTuple::ModuleTuple(ModuleConfig&&... configs) : @@ -46,20 +56,13 @@ namespace Nz { } - template<> - struct BuildDepList> + template + template + T& ModuleTuple::Get() { - using Result = TypeList<>; - }; - - template - struct BuildDepList> - { - using ModuleDependencies = typename BuildDepList::Result; - using ModuleDependenciesIncModule = TypeListAppend; - using RestDependencies = typename BuildDepList>::Result; - using Result = TypeListConcat; - }; + static_assert(std::is_same_v, "module is not in the list"); + return m; + } } template @@ -68,6 +71,13 @@ namespace Nz m_modules(std::forward(configs)...) { } + + template + template + T& Modules::Get() + { + return m_modules.template Get(); + } } #include diff --git a/include/Nazara/Core/ResourceRegistry.hpp b/include/Nazara/Core/ResourceRegistry.hpp new file mode 100644 index 000000000..282302232 --- /dev/null +++ b/include/Nazara/Core/ResourceRegistry.hpp @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CORE_RESOURCEREGISTRY_HPP +#define NAZARA_CORE_RESOURCEREGISTRY_HPP + +#include +#include + +namespace Nz +{ + template + struct ResourceRegistry + { + static std::size_t GetResourceId(); + }; +} + +#include + +#endif // NAZARA_CORE_RESOURCEREGISTRY_HPP diff --git a/include/Nazara/Core/ResourceRegistry.inl b/include/Nazara/Core/ResourceRegistry.inl new file mode 100644 index 000000000..eb33dff1d --- /dev/null +++ b/include/Nazara/Core/ResourceRegistry.inl @@ -0,0 +1,27 @@ +// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Detail + { + inline std::size_t ResourceTypeIndexCounter() + { + static std::size_t counter = 0; + return counter++; + } + } + + template + std::size_t ResourceRegistry::GetResourceId() + { + static std::size_t typeId = Detail::ResourceTypeIndexCounter(); + return typeId; + } +} + +#include diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index e2350e10d..cd6afd86a 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -22,6 +22,7 @@ namespace Nz { + class AppFilesystemComponent; class RenderBuffer; class NAZARA_GRAPHICS_API Graphics : public ModuleBase @@ -55,6 +56,8 @@ namespace Nz inline TextureSamplerCache& GetSamplerCache(); inline const std::shared_ptr& GetShaderModuleResolver() const; + void RegisterComponent(AppFilesystemComponent& component); + struct Config { RenderDeviceFeatures forceDisableFeatures; diff --git a/include/Nazara/Graphics/Material.hpp b/include/Nazara/Graphics/Material.hpp index c15d0134a..daa4cc620 100644 --- a/include/Nazara/Graphics/Material.hpp +++ b/include/Nazara/Graphics/Material.hpp @@ -43,6 +43,7 @@ namespace Nz public: struct TextureData; struct UniformBlockData; + using Params = MaterialParams; Material(MaterialSettings settings, const std::string& referenceModuleName); Material(MaterialSettings settings, const nzsl::Ast::ModulePtr& referenceModule); diff --git a/include/Nazara/Graphics/MaterialInstance.hpp b/include/Nazara/Graphics/MaterialInstance.hpp index 4c10caf94..18260a562 100644 --- a/include/Nazara/Graphics/MaterialInstance.hpp +++ b/include/Nazara/Graphics/MaterialInstance.hpp @@ -44,6 +44,8 @@ namespace Nz struct CopyToken {}; public: + using Params = MaterialInstanceParams; + MaterialInstance(std::shared_ptr parent); MaterialInstance(const MaterialInstance&) = delete; MaterialInstance(const MaterialInstance& material, CopyToken); diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 89f57e025..070f5241f 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -49,6 +49,7 @@ namespace Nz TextureUsageFlags usageFlags = TextureUsage::ShaderSampling | TextureUsage::TransferDestination; bool IsValid() const; + void Merge(const TextureParams& params); }; class Texture; @@ -60,6 +61,8 @@ namespace Nz class NAZARA_RENDERER_API Texture : public AbstractImage, public Resource, public std::enable_shared_from_this //< FIXME { public: + using Params = TextureParams; + Texture() = default; Texture(const Texture&) = delete; Texture(Texture&&) = delete; diff --git a/include/Nazara/Utility/Font.hpp b/include/Nazara/Utility/Font.hpp index b6a3e9e71..a35f3f4c8 100644 --- a/include/Nazara/Utility/Font.hpp +++ b/include/Nazara/Utility/Font.hpp @@ -43,6 +43,7 @@ namespace Nz public: struct Glyph; struct SizeInfo; + using Params = FontParams; Font(); Font(const Font&) = delete; diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 6ba6d1cec..650af043a 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -34,6 +34,7 @@ namespace Nz UInt8 levelCount = 0; bool IsValid() const; + void Merge(const ImageParams& params); }; class Image; @@ -46,6 +47,7 @@ namespace Nz class NAZARA_UTILITY_API Image : public AbstractImage, public Resource { public: + using Params = ImageParams; struct SharedImage; Image(); diff --git a/include/Nazara/Utility/ImageStream.hpp b/include/Nazara/Utility/ImageStream.hpp index 0d6bfd3b4..a5fdf448e 100644 --- a/include/Nazara/Utility/ImageStream.hpp +++ b/include/Nazara/Utility/ImageStream.hpp @@ -30,6 +30,8 @@ namespace Nz class NAZARA_UTILITY_API ImageStream : public Resource { public: + using Params = ImageStreamParams; + ImageStream() = default; virtual ~ImageStream(); diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 430bc389f..848fe0f5f 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -93,6 +93,8 @@ namespace Nz class NAZARA_UTILITY_API Mesh : public Resource { public: + using Params = MeshParams; + inline Mesh(); Mesh(const Mesh&) = delete; Mesh(Mesh&&) = delete; diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 37c9f4e67..cb8938569 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -174,6 +175,14 @@ namespace Nz m_defaultTextures = DefaultTextures{}; } + void Graphics::RegisterComponent(AppFilesystemComponent& component) + { + TextureParams defaultTexParams; + defaultTexParams.renderDevice = m_renderDevice; + + component.SetDefaultResourceParameters(defaultTexParams); + } + void Graphics::BuildBlitPipeline() { RenderPipelineLayoutInfo layoutInfo; diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index f60be6f92..426ccc98c 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -32,6 +32,16 @@ namespace Nz return true; } + void TextureParams::Merge(const TextureParams& params) + { + ImageParams::Merge(params); + + if (!renderDevice) + renderDevice = params.renderDevice; + + usageFlags |= params.usageFlags; + } + std::shared_ptr Texture::CreateFromImage(const Image& image, const TextureParams& params) { NazaraAssert(params.IsValid(), "Invalid TextureParams"); diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 43c59cac9..ce178480e 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -39,6 +39,13 @@ namespace Nz return true; // Rien à vérifier } + void ImageParams::Merge(const ImageParams& params) + { + if (loadFormat == PixelFormat::Undefined) + loadFormat = params.loadFormat; + } + + Image::Image() : m_sharedImage(&emptyImage) {