diff --git a/include/Nazara/OpenGLRenderer/OpenGLCommandPool.hpp b/include/Nazara/OpenGLRenderer/OpenGLCommandPool.hpp index e64281061..70a3ce065 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLCommandPool.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLCommandPool.hpp @@ -25,7 +25,7 @@ namespace Nz OpenGLCommandPool(OpenGLCommandPool&&) noexcept = default; ~OpenGLCommandPool() = default; - CommandBufferPtr BuildCommandBuffer(const std::function& callback) override; + CommandBufferPtr BuildCommandBuffer(const FunctionRef& callback) override; void UpdateDebugName(std::string_view name) override; diff --git a/include/Nazara/OpenGLRenderer/Wrapper/ContextObject.inl b/include/Nazara/OpenGLRenderer/Wrapper/ContextObject.inl index cf69c062d..ae0afb4ba 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/ContextObject.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/ContextObject.inl @@ -90,7 +90,7 @@ namespace Nz::GL EnsureContext(); if (m_context->glObjectLabel) - m_context->glObjectLabel(ObjectType, m_objectId, SafeCast(name.size()), name.data()); + m_context->glObjectLabel(ObjectType, m_objectId, SafeCaster(name.size()), name.data()); } } diff --git a/include/Nazara/OpenGLRenderer/Wrapper/DeviceObject.inl b/include/Nazara/OpenGLRenderer/Wrapper/DeviceObject.inl index 680f1c01a..41d467912 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/DeviceObject.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/DeviceObject.inl @@ -96,7 +96,7 @@ namespace Nz::GL const Context& context = EnsureDeviceContext(); if (context.glObjectLabel) - context.glObjectLabel(ObjectType, m_objectId, SafeCast(name.size()), name.data()); + context.glObjectLabel(ObjectType, m_objectId, SafeCaster(name.size()), name.data()); } } diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Program.inl b/include/Nazara/OpenGLRenderer/Wrapper/Program.inl index 0d6ef7ed9..981fdbaac 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Program.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/Program.inl @@ -51,7 +51,7 @@ namespace Nz::GL if (activeUniformCount > 0) { - uniformIndices.resize(static_cast(activeUniformCount)); + uniformIndices.resize(SafeCaster(activeUniformCount)); context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, uniformIndices.data()); } diff --git a/include/Nazara/Renderer/CommandPool.hpp b/include/Nazara/Renderer/CommandPool.hpp index b44009a5e..fb6a8c1b4 100644 --- a/include/Nazara/Renderer/CommandPool.hpp +++ b/include/Nazara/Renderer/CommandPool.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Nz { @@ -24,7 +24,7 @@ namespace Nz CommandPool(CommandPool&&) = default; virtual ~CommandPool(); - virtual CommandBufferPtr BuildCommandBuffer(const std::function& callback) = 0; + virtual CommandBufferPtr BuildCommandBuffer(const FunctionRef& callback) = 0; virtual void UpdateDebugName(std::string_view name) = 0; diff --git a/include/Nazara/VulkanRenderer/VulkanCommandPool.hpp b/include/Nazara/VulkanRenderer/VulkanCommandPool.hpp index 5b532e305..e2b0a25d2 100644 --- a/include/Nazara/VulkanRenderer/VulkanCommandPool.hpp +++ b/include/Nazara/VulkanRenderer/VulkanCommandPool.hpp @@ -28,7 +28,7 @@ namespace Nz VulkanCommandPool(VulkanCommandPool&&) noexcept = default; ~VulkanCommandPool() = default; - CommandBufferPtr BuildCommandBuffer(const std::function& callback) override; + CommandBufferPtr BuildCommandBuffer(const FunctionRef& callback) override; void UpdateDebugName(std::string_view name) override; diff --git a/src/Nazara/Network/WebRequest.cpp b/src/Nazara/Network/WebRequest.cpp index 596750737..a5634913c 100644 --- a/src/Nazara/Network/WebRequest.cpp +++ b/src/Nazara/Network/WebRequest.cpp @@ -97,7 +97,7 @@ namespace Nz { auto& libcurl = m_webService.GetCurlLibrary(); - curl_off_t maxSize = SafeCast(maxFileSize); + curl_off_t maxSize = SafeCaster(maxFileSize); libcurl.easy_setopt(m_curlHandle, CURLOPT_MAXFILESIZE_LARGE, maxSize); } #else diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index 4a871f7e3..321851eb1 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -217,7 +217,7 @@ namespace Nz inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const InsertDebugLabelCommand& command) { if (context->glDebugMessageInsert) - context->glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, SafeCast(command.label.size()), command.label.data()); + context->glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, SafeCaster(command.label.size()), command.label.data()); } inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const MemoryBarrier& command) @@ -277,7 +277,7 @@ namespace Nz if (command.framebuffer->GetType() == FramebufferType::Texture) { - const OpenGLFboFramebuffer& fboFramebuffer = static_cast(*command.framebuffer); + const OpenGLFboFramebuffer& fboFramebuffer = SafeCast(*command.framebuffer); invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1); diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandPool.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandPool.cpp index 2cca53594..2a3cf81b5 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandPool.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandPool.cpp @@ -10,7 +10,7 @@ namespace Nz { - CommandBufferPtr OpenGLCommandPool::BuildCommandBuffer(const std::function& callback) + CommandBufferPtr OpenGLCommandPool::BuildCommandBuffer(const FunctionRef& callback) { CommandBufferPtr commandBuffer; for (std::size_t i = 0; i < m_commandPools.size(); ++i) @@ -30,7 +30,7 @@ namespace Nz assert(commandBuffer); } - OpenGLCommandBufferBuilder builder(static_cast(*commandBuffer.get())); + OpenGLCommandBufferBuilder builder(SafeCast(*commandBuffer.get())); callback(builder); return commandBuffer; @@ -68,7 +68,7 @@ namespace Nz void OpenGLCommandPool::Release(CommandBuffer& binding) { - OpenGLCommandBuffer& openglBinding = static_cast(binding); + OpenGLCommandBuffer& openglBinding = SafeCast(binding); std::size_t poolIndex = openglBinding.GetPoolIndex(); std::size_t bindingIndex = openglBinding.GetBindingIndex(); diff --git a/src/Nazara/OpenGLRenderer/OpenGLComputePipeline.cpp b/src/Nazara/OpenGLRenderer/OpenGLComputePipeline.cpp index 812cd25ae..27f8d45ed 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLComputePipeline.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLComputePipeline.cpp @@ -22,14 +22,14 @@ namespace Nz if (!device.GetEnabledFeatures().computeShaders) throw std::runtime_error("compute shaders are not enabled on the device"); - OpenGLRenderPipelineLayout& pipelineLayout = static_cast(*m_pipelineInfo.pipelineLayout); + OpenGLRenderPipelineLayout& pipelineLayout = SafeCast(*m_pipelineInfo.pipelineLayout); if (!m_program.Create(device)) throw std::runtime_error("failed to create program"); NazaraAssert(m_pipelineInfo.shaderModule, "invalid shader module"); - OpenGLShaderModule& shaderModule = static_cast(*m_pipelineInfo.shaderModule); + OpenGLShaderModule& shaderModule = SafeCast(*m_pipelineInfo.shaderModule); std::vector explicitBindings; nzsl::ShaderStageTypeFlags stageFlags = shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping(), &explicitBindings); diff --git a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp index 44bdfefdf..c77606489 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp @@ -91,7 +91,7 @@ namespace Nz for (std::size_t i = 0; i < m_attachments.size(); ++i) { assert(m_attachments[i]); - const OpenGLTexture& glTexture = static_cast(*m_attachments[i]); + const OpenGLTexture& glTexture = SafeCast(*m_attachments[i]); PixelFormat textureFormat = glTexture.GetFormat(); @@ -187,7 +187,7 @@ namespace Nz for (std::size_t i = 0; i < m_colorAttachmentCount; ++i) fboDrawBuffers[i] = GLenum(GL_COLOR_ATTACHMENT0 + i); - framebuffer.DrawBuffers(SafeCast(m_colorAttachmentCount), fboDrawBuffers.data()); + framebuffer.DrawBuffers(SafeCaster(m_colorAttachmentCount), fboDrawBuffers.data()); } else { diff --git a/src/Nazara/OpenGLRenderer/OpenGLRenderImage.cpp b/src/Nazara/OpenGLRenderer/OpenGLRenderImage.cpp index 9f096ab8e..2e39f0ad8 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLRenderImage.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLRenderImage.cpp @@ -46,7 +46,7 @@ namespace Nz void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags /*queueTypeFlags*/) { - OpenGLCommandBuffer* oglCommandBuffer = static_cast(commandBuffer); + OpenGLCommandBuffer* oglCommandBuffer = SafeCast(commandBuffer); oglCommandBuffer->Execute(); } } diff --git a/src/Nazara/OpenGLRenderer/OpenGLRenderPipeline.cpp b/src/Nazara/OpenGLRenderer/OpenGLRenderPipeline.cpp index 6bba5e340..ec8607b6e 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLRenderPipeline.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLRenderPipeline.cpp @@ -22,7 +22,7 @@ namespace Nz { ValidatePipelineInfo(device, m_pipelineInfo); - OpenGLRenderPipelineLayout& pipelineLayout = static_cast(*m_pipelineInfo.pipelineLayout); + OpenGLRenderPipelineLayout& pipelineLayout = SafeCast(*m_pipelineInfo.pipelineLayout); if (!m_program.Create(device)) throw std::runtime_error("failed to create program"); @@ -38,7 +38,7 @@ namespace Nz for (const auto& shaderModulePtr : m_pipelineInfo.shaderModules) { - OpenGLShaderModule& shaderModule = static_cast(*shaderModulePtr); + OpenGLShaderModule& shaderModule = SafeCast(*shaderModulePtr); stageFlags |= shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping(), &explicitBindings); } diff --git a/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp b/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp index d4405eb97..87de2f578 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp @@ -138,7 +138,7 @@ namespace Nz void OpenGLRenderPipelineLayout::Release(ShaderBinding& binding) { - OpenGLShaderBinding& vulkanBinding = static_cast(binding); + OpenGLShaderBinding& vulkanBinding = SafeCast(binding); std::size_t poolIndex = vulkanBinding.GetPoolIndex(); std::size_t bindingIndex = vulkanBinding.GetBindingIndex(); diff --git a/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp b/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp index 934f26bc1..a546bc91d 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLShaderBinding.cpp @@ -102,7 +102,7 @@ namespace Nz storageDescriptor.offset = arg.offset; storageDescriptor.size = arg.range; - if (OpenGLBuffer* glBuffer = static_cast(arg.buffer)) + if (OpenGLBuffer* glBuffer = SafeCast(arg.buffer)) { if (glBuffer->GetType() != BufferType::Storage) throw std::runtime_error("expected storage buffer"); @@ -115,7 +115,7 @@ namespace Nz else if constexpr (std::is_same_v) { auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, binding.bindingIndex); - if (const OpenGLTexture* glTexture = static_cast(arg.texture)) + if (const OpenGLTexture* glTexture = SafeCast(arg.texture)) { std::optional format = DescribeTextureFormat(glTexture->GetFormat()); if (!format) @@ -151,7 +151,7 @@ namespace Nz uboDescriptor.offset = arg.offset; uboDescriptor.size = arg.range; - if (OpenGLBuffer* glBuffer = static_cast(arg.buffer)) + if (OpenGLBuffer* glBuffer = SafeCast(arg.buffer)) { if (glBuffer->GetType() != BufferType::Uniform) throw std::runtime_error("expected uniform buffer"); @@ -177,13 +177,13 @@ namespace Nz { auto& textureDescriptor = m_owner.GetSampledTextureDescriptor(m_poolIndex, m_bindingIndex, bindingIndex); - if (const OpenGLTexture* glTexture = static_cast(textureBinding.texture)) + if (const OpenGLTexture* glTexture = SafeCast(textureBinding.texture)) { // TODO: Add texture view emulation textureDescriptor.texture = glTexture->GetTexture().GetObjectId(); - if (const OpenGLTextureSampler* glSampler = static_cast(textureBinding.sampler)) + if (const OpenGLTextureSampler* glSampler = SafeCast(textureBinding.sampler)) textureDescriptor.sampler = glSampler->GetSampler(glTexture->GetLevelCount() > 1).GetObjectId(); else textureDescriptor.sampler = 0; diff --git a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp index 672c210c3..bc4bb8e23 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp @@ -118,7 +118,7 @@ namespace Nz bool OpenGLTexture::Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos) { - const OpenGLTexture& glTexture = static_cast(source); + const OpenGLTexture& glTexture = SafeCast(source); const GL::Context& context = m_texture.EnsureDeviceContext(); return context.CopyTexture(glTexture, *this, srcBox, dstPos); diff --git a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp index f79209eab..c2fa1e0bf 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp @@ -312,7 +312,7 @@ namespace Nz::GL glClearDepthf = [](GLfloat depth) { - const EGLContextBase* context = static_cast(GetCurrentContext()); + const EGLContextBase* context = SafeCast(GetCurrentContext()); assert(context); context->fallbacks.glClearDepth(depth); }; diff --git a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp index 7eca384aa..94ad58dcc 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp @@ -143,7 +143,7 @@ namespace Nz::GL context = std::make_shared(device, *this); #endif - if (!context->Create(params, static_cast(shareContext))) + if (!context->Create(params, SafeCast(shareContext))) { NazaraError("failed to create context"); return {}; @@ -193,7 +193,7 @@ namespace Nz::GL return {}; } - if (!context->Create(params, handle, static_cast(shareContext))) + if (!context->Create(params, handle, SafeCast(shareContext))) { NazaraError("failed to create context"); return {}; diff --git a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.cpp b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.cpp index 9d9ab1e9d..f35e94a37 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.cpp @@ -254,7 +254,7 @@ namespace Nz::GL glClearDepthf = [](GLfloat depth) { - const WGLContext* context = static_cast(GetCurrentContext()); + const WGLContext* context = SafeCast(GetCurrentContext()); assert(context); context->fallbacks.glClearDepth(depth); }; @@ -328,7 +328,7 @@ namespace Nz::GL int pixelFormat = 0; if (m_params.sampleCount > 1) { - const WGLContext* currentContext = static_cast(GetCurrentContext()); //< Pay TLS cost only once + const WGLContext* currentContext = SafeCast(GetCurrentContext()); //< Pay TLS cost only once if (currentContext) { // WGL_ARB_pixel_format and WGL_EXT_pixel_format are the same, except for the symbol diff --git a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp index fdd1d621d..3853a21bf 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp @@ -96,7 +96,7 @@ namespace Nz::GL std::shared_ptr WGLLoader::CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const { auto context = std::make_shared(device, *this); - if (!context->Create(&m_baseContext, params, static_cast(shareContext))) + if (!context->Create(&m_baseContext, params, SafeCast(shareContext))) { NazaraError("failed to create context"); return {}; @@ -114,7 +114,7 @@ namespace Nz::GL std::shared_ptr WGLLoader::CreateContext(const OpenGLDevice* device, const ContextParams& params, WindowHandle handle, Context* shareContext) const { auto context = std::make_shared(device, *this); - if (!context->Create(&m_baseContext, params, handle, static_cast(shareContext))) + if (!context->Create(&m_baseContext, params, handle, SafeCast(shareContext))) { NazaraError("failed to create context"); return {}; diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index b8be388ee..eda56a43e 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -88,7 +88,7 @@ namespace Nz for (auto& drawCall : m_drawCalls) { builder.BindVertexBuffer(0, *drawCall.vertexBuffer); - builder.Draw(SafeCast(drawCall.vertexCount)); + builder.Draw(SafeCaster(drawCall.vertexCount)); } } diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 4f755872e..11f20ab17 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -80,10 +81,12 @@ namespace Nz void Renderer::LoadBackend(const Config& config) { + using FactoryFunc = FunctionPtr()>; + struct RendererImplementations { #ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS - std::function()> factory; + FactoryFunc factory; #else std::filesystem::path fileName; #endif @@ -97,20 +100,20 @@ namespace Nz preferredAPI = RenderAPI::OpenGL; #ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS - auto RegisterImpl = [&](RenderAPI api, auto ComputeScore, std::function()> factory) + auto RegisterImpl = [&](RenderAPI api, auto ComputeScore, TypeTag RendererTag) { int score = ComputeScore(); if (score >= 0) { auto& impl = implementations.emplace_back(); - impl.factory = std::move(factory); + impl.factory = []() -> std::unique_ptr { return std::make_unique(); }; impl.score = (preferredAPI == api) ? std::numeric_limits::max() : score; } }; - RegisterImpl(RenderAPI::OpenGL, [] { return 50; }, [] { return std::make_unique(); }); + RegisterImpl(RenderAPI::OpenGL, [] { return 50; }, TypeTag{}); #ifndef NAZARA_PLATFORM_WEB - RegisterImpl(RenderAPI::Vulkan, [] { return 100; }, [] { return std::make_unique(); }); + RegisterImpl(RenderAPI::Vulkan, [] { return 100; }, TypeTag{}); #endif #else @@ -202,7 +205,7 @@ namespace Nz m_rendererLib = std::move(chosenLib); #endif - NazaraDebug("Using " + m_rendererImpl->QueryAPIString() + " as renderer"); + NazaraDebug("Using {0} as renderer", m_rendererImpl->QueryAPIString()); } Renderer* Renderer::s_instance = nullptr; diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index 20baba54b..5737466af 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -144,11 +144,11 @@ namespace Nz std::string appName = parameters.GetStringParameter("VkAppInfo_OverrideApplicationName").GetValueOr("Another application made with Nazara Engine"); std::string engineName = parameters.GetStringParameter("VkAppInfo_OverrideEngineName").GetValueOr("Nazara Engine - Vulkan Renderer"); - UInt32 appVersion = SafeCast(parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0))); - UInt32 engineVersion = SafeCast(parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0))); + UInt32 appVersion = SafeCaster(parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0))); + UInt32 engineVersion = SafeCaster(parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0))); if (auto result = parameters.GetIntegerParameter("VkAppInfo_OverrideAPIVersion")) - targetApiVersion = SafeCast(result.GetValue()); + targetApiVersion = SafeCaster(result.GetValue()); if (Vk::Loader::vkEnumerateInstanceVersion) { @@ -171,7 +171,7 @@ namespace Nz targetApiVersion }; - VkInstanceCreateFlags createFlags = SafeCast(parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags").GetValueOr(0)); + VkInstanceCreateFlags createFlags = SafeCaster(parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags").GetValueOr(0)); std::vector enabledLayers; diff --git a/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp b/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp index 9094a7957..6139c4bbd 100644 --- a/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp +++ b/src/Nazara/VulkanRenderer/VulkanCommandPool.cpp @@ -11,7 +11,7 @@ namespace Nz { - CommandBufferPtr VulkanCommandPool::BuildCommandBuffer(const std::function& callback) + CommandBufferPtr VulkanCommandPool::BuildCommandBuffer(const FunctionRef& callback) { Vk::AutoCommandBuffer commandBuffer = m_commandPool.AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY); @@ -57,7 +57,7 @@ namespace Nz void VulkanCommandPool::Release(CommandBuffer& binding) { - VulkanCommandBuffer& vulkanBinding = static_cast(binding); + VulkanCommandBuffer& vulkanBinding = SafeCast(binding); std::size_t poolIndex = vulkanBinding.GetPoolIndex(); std::size_t bindingIndex = vulkanBinding.GetBindingIndex(); diff --git a/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp b/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp index c1ee4eee4..4182d959e 100644 --- a/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp +++ b/src/Nazara/VulkanRenderer/VulkanComputePipeline.cpp @@ -19,7 +19,7 @@ namespace Nz if (!device.GetEnabledFeatures().computeShaders) throw std::runtime_error("compute shaders are not enabled on the device"); - VulkanShaderModule& vulkanModule = static_cast(*m_pipelineInfo.shaderModule); + VulkanShaderModule& vulkanModule = SafeCast(*m_pipelineInfo.shaderModule); const VulkanShaderModule::Stage* computeStage = nullptr; for (const auto& stage : vulkanModule.GetStages()) { @@ -42,7 +42,7 @@ namespace Nz createInfo.stage.pName = computeStage->name.data(); createInfo.stage.stage = ToVulkan(computeStage->stage); - VulkanRenderPipelineLayout& pipelineLayout = *static_cast(m_pipelineInfo.pipelineLayout.get()); + VulkanRenderPipelineLayout& pipelineLayout = *SafeCast(m_pipelineInfo.pipelineLayout.get()); createInfo.layout = pipelineLayout.GetPipelineLayout(); if (!m_pipeline.CreateCompute(device, createInfo)) diff --git a/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp b/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp index 2001596f2..698fa513f 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderImage.cpp @@ -74,7 +74,7 @@ namespace Nz void VulkanRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) { - VulkanCommandBuffer& vkCommandBuffer = *static_cast(commandBuffer); + VulkanCommandBuffer& vkCommandBuffer = *SafeCast(commandBuffer); return SubmitCommandBuffer(vkCommandBuffer.GetCommandBuffer(), queueTypeFlags); } diff --git a/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp b/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp index ce179b23e..b4d006e07 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderPipeline.cpp @@ -205,7 +205,7 @@ namespace Nz { assert(stagePtr); - VulkanShaderModule& vulkanModule = static_cast(*stagePtr); + VulkanShaderModule& vulkanModule = SafeCast(*stagePtr); for (auto& stage : vulkanModule.GetStages()) { VkPipelineShaderStageCreateInfo& createInfo = shaderStageCreateInfos.emplace_back(); @@ -227,7 +227,7 @@ namespace Nz for (const auto& bufferData : pipelineInfo.vertexBuffers) { - std::uint32_t binding = std::uint32_t(bufferData.binding); + std::uint32_t binding = SafeCaster(bufferData.binding); for (const auto& componentInfo : bufferData.declaration->GetComponents()) { @@ -237,7 +237,7 @@ namespace Nz auto& bufferAttribute = vertexAttributes.emplace_back(); bufferAttribute.binding = binding; bufferAttribute.location = locationIndex++; - bufferAttribute.offset = std::uint32_t(componentInfo.offset); + bufferAttribute.offset = SafeCaster(componentInfo.offset); bufferAttribute.format = ToVulkan(componentInfo.type); } } @@ -252,8 +252,8 @@ namespace Nz for (const auto& bufferData : pipelineInfo.vertexBuffers) { auto& bufferBinding = vertexBindings.emplace_back(); - bufferBinding.binding = std::uint32_t(bufferData.binding); - bufferBinding.stride = std::uint32_t(bufferData.declaration->GetStride()); + bufferBinding.binding = SafeCaster(bufferData.binding); + bufferBinding.stride = SafeCaster(bufferData.declaration->GetStride()); bufferBinding.inputRate = ToVulkan(bufferData.declaration->GetInputRate()); } @@ -265,10 +265,10 @@ namespace Nz VkPipelineVertexInputStateCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - createInfo.vertexAttributeDescriptionCount = std::uint32_t(vertexAttributes.size()); + createInfo.vertexAttributeDescriptionCount = SafeCaster(vertexAttributes.size()); createInfo.pVertexAttributeDescriptions = vertexAttributes.data(); - createInfo.vertexBindingDescriptionCount = std::uint32_t(bindingDescriptions.size()); + createInfo.vertexBindingDescriptionCount = SafeCaster(bindingDescriptions.size()); createInfo.pVertexBindingDescriptions = bindingDescriptions.data(); return createInfo; @@ -295,7 +295,7 @@ namespace Nz createInfo.stateData->vertexInputState = BuildVertexInputInfo(pipelineInfo, createInfo.vertexAttributesDescription, createInfo.vertexBindingDescription); createInfo.pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; - createInfo.pipelineInfo.stageCount = std::uint32_t(createInfo.shaderStages.size()); + createInfo.pipelineInfo.stageCount = SafeCaster(createInfo.shaderStages.size()); createInfo.pipelineInfo.pStages = createInfo.shaderStages.data(); createInfo.pipelineInfo.pColorBlendState = &createInfo.stateData->colorBlendState; createInfo.pipelineInfo.pDepthStencilState = &createInfo.stateData->depthStencilState; @@ -306,7 +306,7 @@ namespace Nz createInfo.pipelineInfo.pVertexInputState = &createInfo.stateData->vertexInputState; createInfo.pipelineInfo.pViewportState = &createInfo.stateData->viewportState; - VulkanRenderPipelineLayout& pipelineLayout = *static_cast(pipelineInfo.pipelineLayout.get()); + VulkanRenderPipelineLayout& pipelineLayout = *SafeCast(pipelineInfo.pipelineLayout.get()); createInfo.pipelineInfo.layout = pipelineLayout.GetPipelineLayout(); return createInfo; diff --git a/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp b/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp index 3a23a4869..6a255dec8 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderPipelineLayout.cpp @@ -20,7 +20,7 @@ namespace Nz for (auto& pool : m_descriptorPools) { if (!pool.freeBindings.TestAll()) - NazaraWarning("Not all ShaderBinding have been released!"); + NazaraWarning("not all ShaderBinding have been released!"); } } @@ -43,7 +43,7 @@ namespace Nz ShaderBindingPtr bindingPtr = AllocateFromPool(newPoolIndex, setIndex); if (!bindingPtr) - throw std::runtime_error("Failed to allocate shader binding"); + throw std::runtime_error("failed to allocate shader binding"); return bindingPtr; } @@ -81,7 +81,7 @@ namespace Nz setLayouts[i] = *m_descriptorSetLayouts[i]; } - if (!m_pipelineLayout.Create(*m_device, UInt32(setLayouts.size()), setLayouts.data())) + if (!m_pipelineLayout.Create(*m_device, SafeCaster(setLayouts.size()), setLayouts.data())) return false; return true; @@ -108,7 +108,7 @@ namespace Nz DescriptorPool pool; pool.descriptorPool = std::make_unique(); - if (!pool.descriptorPool->Create(*m_device, MaxSet, UInt32(poolSizes.size()), poolSizes.data(), VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) + if (!pool.descriptorPool->Create(*m_device, MaxSet, SafeCaster(poolSizes.size()), poolSizes.data(), VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) throw std::runtime_error("failed to allocate new descriptor pool: " + TranslateVulkanError(pool.descriptorPool->GetLastErrorCode())); pool.freeBindings.Resize(MaxSet, true); @@ -128,7 +128,7 @@ namespace Nz Vk::DescriptorSet descriptorSet = pool.descriptorPool->AllocateDescriptorSet(*m_descriptorSetLayouts[setIndex]); if (!descriptorSet) { - NazaraWarning("Failed to allocate descriptor set: " + TranslateVulkanError(pool.descriptorPool->GetLastErrorCode())); + NazaraWarningFmt("failed to allocate descriptor set: {}", TranslateVulkanError(pool.descriptorPool->GetLastErrorCode())); return {}; } @@ -140,7 +140,7 @@ namespace Nz void VulkanRenderPipelineLayout::Release(ShaderBinding& binding) { - VulkanShaderBinding& vulkanBinding = static_cast(binding); + VulkanShaderBinding& vulkanBinding = SafeCast(binding); std::size_t poolIndex = vulkanBinding.GetPoolIndex(); std::size_t bindingIndex = vulkanBinding.GetBindingIndex(); diff --git a/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp b/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp index b797afa31..239edfd8a 100644 --- a/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp +++ b/src/Nazara/VulkanRenderer/VulkanShaderBinding.cpp @@ -117,7 +117,7 @@ namespace Nz } else if constexpr (std::is_same_v) { - VulkanBuffer* vkBuffer = static_cast(arg.buffer); + VulkanBuffer* vkBuffer = SafeCast(arg.buffer); VkDescriptorBufferInfo& bufferInfo = bufferBinding.emplace_back(); bufferInfo.buffer = (vkBuffer) ? vkBuffer->GetBuffer() : VK_NULL_HANDLE; diff --git a/src/Nazara/VulkanRenderer/VulkanTexture.cpp b/src/Nazara/VulkanRenderer/VulkanTexture.cpp index ca5a4e2a9..0c57be4e1 100644 --- a/src/Nazara/VulkanRenderer/VulkanTexture.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTexture.cpp @@ -304,42 +304,32 @@ namespace Nz bool VulkanTexture::Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos) { - const VulkanTexture& sourceTexture = static_cast(source); + const VulkanTexture& sourceTexture = SafeCast(source); Vk::AutoCommandBuffer copyCommandBuffer = m_device.AllocateCommandBuffer(QueueType::Graphics); if (!copyCommandBuffer->Begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) return false; - VkImageSubresourceLayers subresourceLayers = { //< FIXME - VK_IMAGE_ASPECT_COLOR_BIT, - 0, //< mipLevel - 0, //< baseArrayLayer - 1 //< layerCount - }; - - VkImageSubresourceRange subresourceRange = { //< FIXME - VK_IMAGE_ASPECT_COLOR_BIT, - 0, //< baseMipLevel - 1, //< levelCount - subresourceLayers.baseArrayLayer, //< baseArrayLayer - subresourceLayers.layerCount //< layerCount - }; + VkImageSubresourceLayers srcSubresourceLayers = sourceTexture.BuildSubresourceLayers(0); + VkImageSubresourceRange srcSubresourceRange = sourceTexture.BuildSubresourceRange(0, 1); + VkImageSubresourceLayers dstSubresourceLayers = BuildSubresourceLayers(0); + VkImageSubresourceRange dstSubresourceRange = BuildSubresourceRange(0, 1); VkImageCopy region = { - subresourceLayers, - VkOffset3D { static_cast(srcBox.x), static_cast(srcBox.y), static_cast(srcBox.z) }, - subresourceLayers, - VkOffset3D { static_cast(dstPos.x), static_cast(dstPos.y), static_cast(dstPos.z) }, - VkExtent3D { static_cast(srcBox.width), static_cast(srcBox.height), static_cast(srcBox.depth) } + .srcSubresource = srcSubresourceLayers, + .srcOffset = VkOffset3D { SafeCast(srcBox.x), SafeCast(srcBox.y), SafeCast(srcBox.z) }, + .dstSubresource = dstSubresourceLayers, + .dstOffset = VkOffset3D { SafeCast(dstPos.x), SafeCast(dstPos.y), SafeCast(dstPos.z) }, + .extent = VkExtent3D { SafeCast(srcBox.width), SafeCast(srcBox.height), SafeCast(srcBox.depth) } }; - copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, subresourceRange); - copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, subresourceRange); + copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, srcSubresourceRange); + copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, dstSubresourceRange); copyCommandBuffer->CopyImage(sourceTexture.GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, region); - copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, subresourceRange); - copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, subresourceRange); + copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, srcSubresourceRange); + copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, dstSubresourceRange); if (!copyCommandBuffer->End()) return false; @@ -455,14 +445,14 @@ namespace Nz VkImageSubresourceLayers subresourceLayers = BuildSubresourceLayers(level, baseLayer, layerCount); VkBufferImageCopy region = { - 0, - 0, - 0, - subresourceLayers, - { // imageOffset + .bufferOffset = 0, + .bufferRowLength = 0, + .bufferImageHeight = 0, + .imageSubresource = subresourceLayers, + .imageOffset = { SafeCast(copyBox.x), SafeCast(copyBox.y), SafeCast(copyBox.z) }, - { // imageExtent + .imageExtent = { copyBox.width, copyBox.height, copyBox.depth } }; diff --git a/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp b/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp index ea5caab43..eef5367e0 100644 --- a/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTextureFramebuffer.cpp @@ -15,27 +15,27 @@ namespace Nz VulkanFramebuffer(FramebufferType::Texture) { assert(renderPass); - const VulkanRenderPass& vkRenderPass = static_cast(*renderPass); + const VulkanRenderPass& vkRenderPass = SafeCast(*renderPass); StackArray imageViews = NazaraStackArrayNoInit(VkImageView, attachments.size()); for (std::size_t i = 0; i < attachments.size(); ++i) { assert(attachments[i]); - const VulkanTexture& vkTexture = static_cast(*attachments[i]); + const VulkanTexture& vkTexture = SafeCast(*attachments[i]); imageViews[i] = vkTexture.GetImageView(); } VkFramebufferCreateInfo createInfo = { - VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, - nullptr, - 0, - vkRenderPass.GetRenderPass(), - UInt32(imageViews.size()), - imageViews.data(), - UInt32(width), - UInt32(height), - 1 + .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, + .pNext = nullptr, + .flags = 0, + .renderPass = vkRenderPass.GetRenderPass(), + .attachmentCount = UInt32(imageViews.size()), + .pAttachments = imageViews.data(), + .width = UInt32(width), + .height = UInt32(height), + .layers = 1 }; if (!m_framebuffer.Create(device, createInfo)) diff --git a/xmake.lua b/xmake.lua index e07558fb4..55634f567 100644 --- a/xmake.lua +++ b/xmake.lua @@ -263,7 +263,7 @@ end add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") -add_requires("entt 3.12.2", "fmt", "frozen", "nazarautils >=2024.01.02") +add_requires("entt 3.12.2", "fmt", "frozen", "nazarautils >=2024.01.13") -- Module dependencies if has_config("audio") then