From ad1f3bc321da42eeab61f0b7be9551005d95d7f0 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 6 Nov 2022 23:45:37 +0100 Subject: [PATCH] Graphics/Graphics: Add preferred depth format --- include/Nazara/Graphics/Graphics.hpp | 2 ++ include/Nazara/Graphics/Graphics.inl | 5 +++++ src/Nazara/Graphics/Graphics.cpp | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index 356c5594d..a1a24e38c 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -48,6 +48,7 @@ namespace Nz inline const MaterialInstanceLoader& GetMaterialInstanceLoader() const; inline MaterialLoader& GetMaterialLoader(); inline const MaterialLoader& GetMaterialLoader() const; + inline PixelFormat GetPreferredDepthFormat() const; inline PixelFormat GetPreferredDepthStencilFormat() const; inline const std::shared_ptr& GetRenderDevice() const; inline const RenderPassCache& GetRenderPassCache() const; @@ -97,6 +98,7 @@ namespace Nz MaterialInstanceLoader m_materialInstanceLoader; MaterialLoader m_materialLoader; MaterialPassRegistry m_materialPassRegistry; + PixelFormat m_preferredDepthFormat; PixelFormat m_preferredDepthStencilFormat; static Graphics* s_instance; diff --git a/include/Nazara/Graphics/Graphics.inl b/include/Nazara/Graphics/Graphics.inl index 4b18d58c8..d909be622 100644 --- a/include/Nazara/Graphics/Graphics.inl +++ b/include/Nazara/Graphics/Graphics.inl @@ -57,6 +57,11 @@ namespace Nz return m_materialLoader; } + inline PixelFormat Graphics::GetPreferredDepthFormat() const + { + return m_preferredDepthFormat; + } + inline PixelFormat Graphics::GetPreferredDepthStencilFormat() const { return m_preferredDepthStencilFormat; diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 199522fb7..0469d8a6b 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -355,6 +355,18 @@ namespace Nz void Graphics::SelectDepthStencilFormats() { + for (PixelFormat depthStencilCandidate : { PixelFormat::Depth24, PixelFormat::Depth32F, PixelFormat::Depth16 }) + { + if (m_renderDevice->IsTextureFormatSupported(depthStencilCandidate, TextureUsage::DepthStencilAttachment)) + { + m_preferredDepthFormat = depthStencilCandidate; + break; + } + } + + if (m_preferredDepthFormat == PixelFormat::Undefined) + throw std::runtime_error("no supported depth format found"); + for (PixelFormat depthStencilCandidate : { PixelFormat::Depth24Stencil8, PixelFormat::Depth32FStencil8, PixelFormat::Depth16Stencil8 }) { if (m_renderDevice->IsTextureFormatSupported(depthStencilCandidate, TextureUsage::DepthStencilAttachment))