/// Reconstruct render resources based on the maximum render viewport size. /// /// @param[in] width Maximum viewport width, in pixels. /// @param[in] height Maximum viewport height, in pixels. void RenderResourceManager::UpdateMaxViewportSize( uint32_t width, uint32_t height ) { if ( width == m_viewportWidthMax && height == m_viewportHeightMax ) { return; } m_spDepthStencilSurface.Release(); m_spShadowDepthTexture.Release(); m_spSceneTexture.Release(); Renderer* pRenderer = Renderer::GetInstance(); if ( !pRenderer ) { m_viewportWidthMax = 0; m_viewportHeightMax = 0; m_shadowMode = GraphicsConfig::EShadowMode::NONE; m_shadowDepthTextureUsableSize = 0; return; } // Don't create any surfaces for zero-sized viewports. if ( width == 0 || height == 0 ) { m_viewportWidthMax = 0; m_viewportHeightMax = 0; return; } // Due to restrictions with render target settings on certain platforms (namely when using Direct3D), the scene // texture, depth-stencil surface, and shadow depth texture must all be the same size. // XXX WDI: Implement support for the NULL FOURCC format for Direct3D to avoid this restriction when possible. uint32_t bufferWidth = Max( width, m_shadowDepthTextureUsableSize ); uint32_t bufferHeight = Max( height, m_shadowDepthTextureUsableSize ); m_spSceneTexture = pRenderer->CreateTexture2d( bufferWidth, bufferHeight, 1, RENDERER_PIXEL_FORMAT_R16G16B16A16_FLOAT, RENDERER_BUFFER_USAGE_RENDER_TARGET ); if ( !m_spSceneTexture ) { HELIUM_TRACE( TraceLevels::Error, "Failed to create scene render texture of size %" PRIu32 "x%" PRIu32 ".\n", bufferWidth, bufferHeight ); } m_spDepthStencilSurface = pRenderer->CreateDepthStencilSurface( bufferWidth, bufferHeight, RENDERER_SURFACE_FORMAT_DEPTH_STENCIL, 0 ); if ( !m_spDepthStencilSurface ) { HELIUM_TRACE( TraceLevels::Error, "Failed to create scene depth-stencil surface of size %" PRIu32 "x%" PRIu32 ".\n", bufferWidth, bufferHeight ); } if ( m_shadowMode != GraphicsConfig::EShadowMode::NONE && m_shadowMode != GraphicsConfig::EShadowMode::INVALID && m_shadowDepthTextureUsableSize != 0 ) { m_spShadowDepthTexture = pRenderer->CreateTexture2d( bufferWidth, bufferHeight, 1, RENDERER_PIXEL_FORMAT_DEPTH, RENDERER_BUFFER_USAGE_DEPTH_STENCIL ); if ( !m_spShadowDepthTexture ) { HELIUM_TRACE( TraceLevels::Error, "Failed to create shadow depth texture of size %" PRIu32 "x%" PRIu32 ".\n", bufferWidth, bufferHeight ); } } }