Graphics/Graphics: Create default depth texture in preferred depth format

This commit is contained in:
SirLynix 2023-11-04 17:52:27 +01:00
parent 4749e6ec80
commit c80e06226f
2 changed files with 11 additions and 23 deletions

View File

@ -89,9 +89,9 @@ namespace Nz
void BuildBlitPipeline();
void BuildDefaultMaterials();
void BuildDefaultTextures();
template<std::size_t N> void RegisterEmbedShaderModule(const UInt8(&content)[N]);
void RegisterMaterialPasses();
void RegisterShaderModules();
template<std::size_t N> void RegisterEmbedShaderModule(const UInt8(&content)[N]);
void SelectDepthStencilFormats();
std::optional<RenderPassCache> m_renderPassCache;

View File

@ -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<UInt8, 6> whitePixels = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
@ -416,6 +404,13 @@ namespace Nz
}
}
template<std::size_t N>
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<std::size_t N>
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 })