| 71 | Bloom::~Bloom() {} |
| 72 | |
| 73 | void Bloom::PrepareResources(IRenderDevice* pDevice, IDeviceContext* pDeviceContext, PostFXContext* pPostFXContext, FEATURE_FLAGS FeatureFlags) |
| 74 | { |
| 75 | DEV_CHECK_ERR(pDevice != nullptr, "pDevice must not be null"); |
| 76 | DEV_CHECK_ERR(pPostFXContext != nullptr, "pPostFXContext must not be null"); |
| 77 | |
| 78 | const auto& FrameDesc = pPostFXContext->GetFrameDesc(); |
| 79 | const auto& SupportedFeatures = pPostFXContext->GetSupportedFeatures(); |
| 80 | |
| 81 | m_CurrentFrameIdx = FrameDesc.Index; |
| 82 | |
| 83 | if (m_BackBufferWidth == FrameDesc.Width && m_BackBufferHeight == FrameDesc.Height && m_FeatureFlags == FeatureFlags) |
| 84 | return; |
| 85 | |
| 86 | for (auto& Iter : m_RenderTech) |
| 87 | Iter.second.SRB.Release(); |
| 88 | |
| 89 | m_BackBufferWidth = FrameDesc.Width; |
| 90 | m_BackBufferHeight = FrameDesc.Height; |
| 91 | m_FeatureFlags = FeatureFlags; |
| 92 | |
| 93 | Uint32 HalfWidth = m_BackBufferWidth / 2u; |
| 94 | Uint32 HalfHeight = m_BackBufferHeight / 2u; |
| 95 | Uint32 TextureCount = ComputeMipLevelsCount(HalfWidth, HalfHeight); |
| 96 | |
| 97 | RenderDeviceWithCache_N Device{pDevice}; |
| 98 | |
| 99 | m_UpsampledTextures.clear(); |
| 100 | for (Uint32 TextureIdx = 0; TextureIdx < TextureCount; TextureIdx++) |
| 101 | { |
| 102 | TextureDesc Desc; |
| 103 | Desc.Name = "Bloom::UpsampledTexture"; |
| 104 | Desc.Type = RESOURCE_DIM_TEX_2D; |
| 105 | Desc.Width = std::max(HalfWidth >> TextureIdx, 1u); |
| 106 | Desc.Height = std::max(HalfHeight >> TextureIdx, 1u); |
| 107 | Desc.Format = TEX_FORMAT_R11G11B10_FLOAT; |
| 108 | Desc.MipLevels = 1; |
| 109 | Desc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET; |
| 110 | m_UpsampledTextures.push_back(Device.CreateTexture(Desc)); |
| 111 | } |
| 112 | |
| 113 | m_DownsampledTextures.clear(); |
| 114 | for (Uint32 TextureIdx = 0; TextureIdx < TextureCount; TextureIdx++) |
| 115 | { |
| 116 | TextureDesc Desc; |
| 117 | Desc.Name = "Bloom::DownsampledTexture"; |
| 118 | Desc.Type = RESOURCE_DIM_TEX_2D; |
| 119 | Desc.Width = std::max(HalfWidth >> TextureIdx, 1u); |
| 120 | Desc.Height = std::max(HalfHeight >> TextureIdx, 1u); |
| 121 | Desc.Format = TEX_FORMAT_R11G11B10_FLOAT; |
| 122 | Desc.MipLevels = 1; |
| 123 | Desc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET; |
| 124 | m_DownsampledTextures.push_back(Device.CreateTexture(Desc)); |
| 125 | } |
| 126 | |
| 127 | { |
| 128 | TextureDesc Desc; |
| 129 | Desc.Name = "Bloom::OutputTexture"; |
| 130 | Desc.Type = RESOURCE_DIM_TEX_2D; |