diff --git a/src/framework/graphics/graphicscontextresource.cpp b/src/framework/graphics/graphicscontextresource.cpp new file mode 100644 index 0000000..ab3f51e --- /dev/null +++ b/src/framework/graphics/graphicscontextresource.cpp @@ -0,0 +1,26 @@ +#include "../debug.h" + +#include "graphicscontextresource.h" +#include "graphicsdevice.h" + +GraphicsContextResource::GraphicsContextResource() +{ + STACK_TRACE; + m_graphicsDevice = NULL; +} + +GraphicsContextResource::GraphicsContextResource(GraphicsDevice *graphicsDevice) +{ + STACK_TRACE; + ASSERT(graphicsDevice != NULL); + + m_graphicsDevice = graphicsDevice; + m_graphicsDevice->RegisterManagedResource(this); +} + +GraphicsContextResource::~GraphicsContextResource() +{ + STACK_TRACE; + if (m_graphicsDevice != NULL) + m_graphicsDevice->UnregisterManagedResource(this); +} diff --git a/src/framework/graphics/graphicscontextresource.h b/src/framework/graphics/graphicscontextresource.h index 50cafdd..25d4bdd 100644 --- a/src/framework/graphics/graphicscontextresource.h +++ b/src/framework/graphics/graphicscontextresource.h @@ -1,23 +1,37 @@ #ifndef __FRAMEWORK_GRAPHICS_GRAPHICSCONTEXTRESOURCE_H_INCLUDED__ #define __FRAMEWORK_GRAPHICS_GRAPHICSCONTEXTRESOURCE_H_INCLUDED__ +#include "../common.h" + +class GraphicsDevice; + /** - * Interface for objects whose lifecycle is tied to the current graphics + * Base class for objects whose lifecycle is tied to the current graphics * context and should be made aware when the context is lost and/or * recreated. */ class GraphicsContextResource { public: + GraphicsContextResource(); + GraphicsContextResource(GraphicsDevice *graphicsDevice); + + virtual ~GraphicsContextResource(); + /** * New OpenGL graphics context creation callback. */ - virtual void OnNewContext() = 0; + virtual void OnNewContext() {} /** * Lost OpenGL graphics context callback. */ - virtual void OnLostContext() = 0; + virtual void OnLostContext() {} + + GraphicsDevice* GetGraphicsDevice() const { return m_graphicsDevice; } + +private: + GraphicsDevice *m_graphicsDevice; }; #endif