From c80e06226fc625aa642f35efe8f22476656194d0 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 4 Nov 2023 17:52:27 +0100 Subject: [PATCH] Graphics/Graphics: Create default depth texture in preferred depth format --- include/Nazara/Graphics/Graphics.hpp | 2 +- src/Nazara/Graphics/Graphics.cpp | 32 +++++++++------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/include/Nazara/Graphics/Graphics.hpp b/include/Nazara/Graphics/Graphics.hpp index cbc0a6bc0..c6150f591 100644 --- a/include/Nazara/Graphics/Graphics.hpp +++ b/include/Nazara/Graphics/Graphics.hpp @@ -89,9 +89,9 @@ namespace Nz void BuildBlitPipeline(); void BuildDefaultMaterials(); void BuildDefaultTextures(); + template void RegisterEmbedShaderModule(const UInt8(&content)[N]); void RegisterMaterialPasses(); void RegisterShaderModules(); - template void RegisterEmbedShaderModule(const UInt8(&content)[N]); void SelectDepthStencilFormats(); std::optional m_renderPassCache; diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index d1d5982ad..cdbe79850 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -139,11 +139,12 @@ namespace Nz m_renderPassCache.emplace(*m_renderDevice); m_samplerCache.emplace(m_renderDevice); + SelectDepthStencilFormats(); + BuildDefaultTextures(); RegisterShaderModules(); BuildBlitPipeline(); RegisterMaterialPasses(); - SelectDepthStencilFormats(); MaterialPipeline::Initialize(); BuildDefaultMaterials(); @@ -367,22 +368,9 @@ namespace Nz { // Depth textures (white but with a depth format) { - PixelFormat depthFormat = PixelFormat::Undefined; - for (PixelFormat depthStencilCandidate : { PixelFormat::Depth16, PixelFormat::Depth24, PixelFormat::Depth32F }) - { - if (m_renderDevice->IsTextureFormatSupported(depthStencilCandidate, TextureUsage::ShaderSampling)) - { - depthFormat = depthStencilCandidate; - break; - } - } - - if (depthFormat == PixelFormat::Undefined) - throw std::runtime_error("couldn't find a sampling-compatible depth pixel format"); - TextureInfo texInfo; texInfo.width = texInfo.height = texInfo.depth = texInfo.levelCount = 1; - texInfo.pixelFormat = depthFormat; + texInfo.pixelFormat = m_preferredDepthFormat; std::array whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; @@ -416,6 +404,13 @@ namespace Nz } } + template + void Graphics::RegisterEmbedShaderModule(const UInt8(&content)[N]) + { + nzsl::Unserializer unserializer(content, N); + m_shaderModuleResolver->RegisterModule(nzsl::Ast::UnserializeShader(unserializer)); + } + void Graphics::RegisterMaterialPasses() { m_materialPassRegistry.RegisterPass("ForwardPass"); @@ -455,13 +450,6 @@ namespace Nz m_shaderModuleResolver->RegisterModuleDirectory(shaderPath); } - template - void Graphics::RegisterEmbedShaderModule(const UInt8(&content)[N]) - { - nzsl::Unserializer unserializer(content, N); - m_shaderModuleResolver->RegisterModule(nzsl::Ast::UnserializeShader(unserializer)); - } - void Graphics::SelectDepthStencilFormats() { for (PixelFormat depthStencilCandidate : { PixelFormat::Depth24, PixelFormat::Depth32F, PixelFormat::Depth16 })