Add clamping for AA and shadows quality to prevent crashes on invalid usage

This commit is contained in:
Wojtek Figat
2021-09-03 19:58:14 +02:00
parent 6e08c1aac9
commit 9c76d0c3cb
3 changed files with 4 additions and 3 deletions

View File

@@ -64,6 +64,7 @@ void FXAA::Dispose()
void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)
{
auto context = GPUDevice::Instance->GetMainContext();
const auto qualityLevel = Math::Clamp(static_cast<int32>(Graphics::AAQuality), 0, static_cast<int32>(Quality::MAX));
// Ensure to have valid data
if (checkIfSkipPass())
@@ -86,6 +87,6 @@ void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureVie
// Render
context->SetRenderTarget(output);
context->SetState(_psFXAA.Get(static_cast<int32>(Graphics::AAQuality)));
context->SetState(_psFXAA.Get(qualityLevel));
context->DrawFullscreenTriangle();
}

View File

@@ -95,7 +95,7 @@ void SMAA::Dispose()
void SMAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)
{
auto context = GPUDevice::Instance->GetMainContext();
const auto qualityLevel = static_cast<int32>(Graphics::AAQuality);
const auto qualityLevel = Math::Clamp(static_cast<int32>(Graphics::AAQuality), 0, static_cast<int32>(Quality::MAX));
// Ensure to have valid data
if (checkIfSkipPass())

View File

@@ -243,7 +243,7 @@ void ShadowsPass::Prepare(RenderContext& renderContext, GPUContext* context)
if (shadowMapsQuality != _currentShadowMapsQuality)
updateShadowMapSize();
auto shadowsQuality = Graphics::ShadowsQuality;
maxShadowsQuality = Math::Min<int32>(static_cast<int32>(shadowsQuality), static_cast<int32>(view.MaxShadowsQuality));
maxShadowsQuality = Math::Clamp(Math::Min<int32>(static_cast<int32>(shadowsQuality), static_cast<int32>(view.MaxShadowsQuality)), 0, static_cast<int32>(Quality::MAX));
// Use the current render view to sync model LODs with the shadow maps rendering stage
_shadowContext.LodProxyView = &renderContext.View;