Skip to content

Commit

Permalink
AtmosphereNpr: recreate const buffer on device lost
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenegff committed Nov 20, 2024
1 parent 7bad36d commit d48c6aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Components/Atmosphere/include/OgreAtmosphereNpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ THE SOFTWARE.

#include "OgreAtmosphereComponent.h"
#include "OgreColourValue.h"
#include "OgreRenderSystem.h"
#include "OgreSharedPtr.h"
#include "OgreVector3.h"

Expand Down Expand Up @@ -59,7 +60,8 @@ namespace Ogre
A PBR solution is iterative and requires more resources.
*/
class _OgreAtmosphereExport AtmosphereNpr final : public AtmosphereComponent
class _OgreAtmosphereExport AtmosphereNpr final : public AtmosphereComponent,
public RenderSystem::Listener
{
public:
struct Preset
Expand Down Expand Up @@ -202,6 +204,9 @@ namespace Ogre
AtmosphereNpr( VaoManager *vaoManager );
~AtmosphereNpr() override;

/// @see RenderSystem::Listener
void eventOccurred( const String &eventName, const NameValuePairList *parameters ) override;

void setSky( Ogre::SceneManager *sceneManager, bool bEnabled );
void destroySky( Ogre::SceneManager *sceneManager );

Expand Down
18 changes: 18 additions & 0 deletions Components/Atmosphere/src/OgreAtmosphereNpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ namespace Ogre
{
mHlmsBuffer = vaoManager->createConstBuffer( sizeof( AtmoSettingsGpu ), BT_DEFAULT, 0, false );
createMaterial();

RenderSystem::addSharedListener( this );
}
//-------------------------------------------------------------------------
AtmosphereNpr::~AtmosphereNpr()
{
RenderSystem::removeSharedListener( this );

std::map<Ogre::SceneManager *, Rectangle2D *>::const_iterator itor = mSkies.begin();
std::map<Ogre::SceneManager *, Rectangle2D *>::const_iterator endt = mSkies.end();

Expand Down Expand Up @@ -109,6 +113,20 @@ namespace Ogre
mHlmsBuffer = 0;
}
//-------------------------------------------------------------------------
void AtmosphereNpr::eventOccurred( const String &eventName, const NameValuePairList *parameters )
{
if( eventName == "DeviceLost" )
{
mVaoManager->destroyConstBuffer( mHlmsBuffer );
mHlmsBuffer = 0;
}
else if( eventName == "DeviceRestored" )
{
mHlmsBuffer =
mVaoManager->createConstBuffer( sizeof( AtmoSettingsGpu ), BT_DEFAULT, 0, false );
}
}
//-------------------------------------------------------------------------
void AtmosphereNpr::createMaterial()
{
OGRE_ASSERT_LOW( !mMaterial );
Expand Down

0 comments on commit d48c6aa

Please sign in to comment.