Skip to content

Commit 323aabb

Browse files
Tutorial 19: check if R32F format is renderable
1 parent 72f4b14 commit 323aabb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Tutorials/Tutorial19_RenderPasses/src/Tutorial19_RenderPasses.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -355,7 +355,20 @@ void Tutorial19_RenderPasses::CreateRenderPass()
355355
Attachments[0].LoadOp = ATTACHMENT_LOAD_OP_CLEAR;
356356
Attachments[0].StoreOp = ATTACHMENT_STORE_OP_DISCARD; // We will not need the result after the end of the render pass
357357

358-
Attachments[1].Format = TEX_FORMAT_R32_FLOAT;
358+
for (TEXTURE_FORMAT Fmt : {TEX_FORMAT_R32_FLOAT, TEX_FORMAT_R16_UNORM, TEX_FORMAT_R16_FLOAT})
359+
{
360+
if (m_pDevice->GetTextureFormatInfoExt(Fmt).BindFlags & BIND_RENDER_TARGET)
361+
{
362+
Attachments[1].Format = Fmt;
363+
break;
364+
}
365+
}
366+
if (Attachments[1].Format == TEX_FORMAT_UNKNOWN)
367+
{
368+
LOG_WARNING_MESSAGE("This device does not support rendering to any of R32_FLOAT, R16_UNORM or R16_FLOAT formats. Using R8 as fallback.");
369+
Attachments[1].Format = TEX_FORMAT_R8_UNORM;
370+
}
371+
359372
Attachments[1].InitialState = RESOURCE_STATE_RENDER_TARGET;
360373
Attachments[1].FinalState = RESOURCE_STATE_INPUT_ATTACHMENT;
361374
Attachments[1].LoadOp = ATTACHMENT_LOAD_OP_CLEAR;

0 commit comments

Comments
 (0)