From af671a325b62bfe43f3f7029faa8538a24ea1d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20R=C3=B6mer?= Date: Tue, 4 Aug 2026 10:58:58 +0300 Subject: [PATCH] [NULL] Answer the "Window" custom attribute on the window texture The NULL window's colour texture carries TextureFlags::RenderWindowSpecific but overrode no getCustomAttribute, and TextureGpu's base implementation is an empty no-op. So in if( colourTexture->isRenderWindowSpecific() ) { Window *window; // uninitialised colourTexture->getCustomAttribute( "Window", &window ); return window->getDepthBuffer(); } (RenderSystem::getDepthBufferFor) the call left `window` holding whatever the stack held, and the dereference read from that address. Add NULLTextureGpuWindow, the NULL twin of MetalTextureGpuWindow / VulkanTextureGpuWindow / D3D11TextureGpuWindow / GL3PlusTextureGpuWindow, whose only job is to answer that attribute, and hand the window to createTextureGpuWindow the way the other render systems do. The lookup then returns the window's own depth buffer, which NULLWindow::_initialize has been creating all along. --- .../NULL/include/OgreNULLTextureGpu.h | 16 ++++++++++++++++ .../NULL/include/OgreNULLTextureGpuManager.h | 2 +- RenderSystems/NULL/src/OgreNULLTextureGpu.cpp | 19 +++++++++++++++++++ .../NULL/src/OgreNULLTextureGpuManager.cpp | 12 ++++++------ RenderSystems/NULL/src/OgreNULLWindow.cpp | 4 ++-- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/RenderSystems/NULL/include/OgreNULLTextureGpu.h b/RenderSystems/NULL/include/OgreNULLTextureGpu.h index 35a7f333d23..f80ac353c6e 100644 --- a/RenderSystems/NULL/include/OgreNULLTextureGpu.h +++ b/RenderSystems/NULL/include/OgreNULLTextureGpu.h @@ -86,6 +86,22 @@ namespace Ogre PixelFormatGpu getDesiredDepthBufferFormat() const override; }; + /// A RenderWindow-specific texture. Its only job over the base class is to + /// answer the "Window" custom attribute, which RenderSystem::getDepthBufferFor + /// relies on for every render-window-specific colour target. + class _OgreNULLExport NULLTextureGpuWindow final : public NULLTextureGpuRenderTarget + { + Window *mWindow; + + public: + NULLTextureGpuWindow( GpuPageOutStrategy::GpuPageOutStrategy pageOutStrategy, + VaoManager *vaoManager, IdString name, uint32 textureFlags, + TextureTypes::TextureTypes initialType, TextureGpuManager *textureManager, + Window *window ); + + void getCustomAttribute( IdString name, void *pData ) override; + }; + /** @} */ /** @} */ } // namespace Ogre diff --git a/RenderSystems/NULL/include/OgreNULLTextureGpuManager.h b/RenderSystems/NULL/include/OgreNULLTextureGpuManager.h index b41e4c43ec1..f30290bd54b 100644 --- a/RenderSystems/NULL/include/OgreNULLTextureGpuManager.h +++ b/RenderSystems/NULL/include/OgreNULLTextureGpuManager.h @@ -64,7 +64,7 @@ namespace Ogre NULLTextureGpuManager( VaoManager *vaoManager, RenderSystem *renderSystem ); ~NULLTextureGpuManager() override; - TextureGpu *createTextureGpuWindow(); + TextureGpu *createTextureGpuWindow( Window *window ); }; /** @} */ diff --git a/RenderSystems/NULL/src/OgreNULLTextureGpu.cpp b/RenderSystems/NULL/src/OgreNULLTextureGpu.cpp index c41b0f9a49f..6bbc6dbfdb6 100644 --- a/RenderSystems/NULL/src/OgreNULLTextureGpu.cpp +++ b/RenderSystems/NULL/src/OgreNULLTextureGpu.cpp @@ -102,4 +102,23 @@ namespace Ogre { return mDesiredDepthBufferFormat; } + //----------------------------------------------------------------------------------- + //----------------------------------------------------------------------------------- + //----------------------------------------------------------------------------------- + NULLTextureGpuWindow::NULLTextureGpuWindow( GpuPageOutStrategy::GpuPageOutStrategy pageOutStrategy, + VaoManager *vaoManager, IdString name, + uint32 textureFlags, + TextureTypes::TextureTypes initialType, + TextureGpuManager *textureManager, Window *window ) : + NULLTextureGpuRenderTarget( pageOutStrategy, vaoManager, name, textureFlags, initialType, + textureManager ), + mWindow( window ) + { + } + //----------------------------------------------------------------------------------- + void NULLTextureGpuWindow::getCustomAttribute( IdString name, void *pData ) + { + if( name == "Window" ) + *static_cast( pData ) = mWindow; + } } // namespace Ogre diff --git a/RenderSystems/NULL/src/OgreNULLTextureGpuManager.cpp b/RenderSystems/NULL/src/OgreNULLTextureGpuManager.cpp index 9a222c23a79..c0543dddd99 100644 --- a/RenderSystems/NULL/src/OgreNULLTextureGpuManager.cpp +++ b/RenderSystems/NULL/src/OgreNULLTextureGpuManager.cpp @@ -45,13 +45,13 @@ namespace Ogre //----------------------------------------------------------------------------------- NULLTextureGpuManager::~NULLTextureGpuManager() { destroyAll(); } //----------------------------------------------------------------------------------- - TextureGpu *NULLTextureGpuManager::createTextureGpuWindow() + TextureGpu *NULLTextureGpuManager::createTextureGpuWindow( Window *window ) { - return OGRE_NEW NULLTextureGpuRenderTarget( - GpuPageOutStrategy::Discard, mVaoManager, "RenderWindow", - TextureFlags::NotTexture | TextureFlags::RenderToTexture | - TextureFlags::RenderWindowSpecific | TextureFlags::DiscardableContent, - TextureTypes::Type2D, this ); + return OGRE_NEW NULLTextureGpuWindow( GpuPageOutStrategy::Discard, mVaoManager, "RenderWindow", + TextureFlags::NotTexture | TextureFlags::RenderToTexture | + TextureFlags::RenderWindowSpecific | + TextureFlags::DiscardableContent, + TextureTypes::Type2D, this, window ); } //----------------------------------------------------------------------------------- TextureGpu *NULLTextureGpuManager::createTextureImpl( diff --git a/RenderSystems/NULL/src/OgreNULLWindow.cpp b/RenderSystems/NULL/src/OgreNULLWindow.cpp index ae05f991f88..65f5e5f6f39 100644 --- a/RenderSystems/NULL/src/OgreNULLWindow.cpp +++ b/RenderSystems/NULL/src/OgreNULLWindow.cpp @@ -95,8 +95,8 @@ namespace Ogre NULLTextureGpuManager *textureManager = static_cast( textureGpuManager ); - mTexture = textureManager->createTextureGpuWindow(); - mDepthBuffer = textureManager->createTextureGpuWindow(); + mTexture = textureManager->createTextureGpuWindow( this ); + mDepthBuffer = textureManager->createTextureGpuWindow( this ); mStencilBuffer = mDepthBuffer; setFinalResolution( mRequestedWidth, mRequestedHeight );