shift GraphicsDevice's complex initialization to a new Initialize() method

This commit is contained in:
Gered 2013-04-01 19:43:33 -04:00
parent 07abad71c2
commit c9cfceec39
3 changed files with 65 additions and 26 deletions

View file

@ -92,8 +92,9 @@ BOOL BaseGameApp::Initialize(GameWindowParams *windowParams)
return FALSE; return FALSE;
} }
m_graphics = new GraphicsDevice(m_window); m_graphics = new GraphicsDevice();
ASSERT(m_graphics != NULL); ASSERT(m_graphics != NULL);
m_graphics->Initialize(m_window);
m_content = new ContentManager(this); m_content = new ContentManager(this);
ASSERT(m_content != NULL); ASSERT(m_content != NULL);

View file

@ -42,20 +42,47 @@
const unsigned int MAX_BOUND_TEXTURES = 8; const unsigned int MAX_BOUND_TEXTURES = 8;
const unsigned int MAX_GPU_ATTRIB_SLOTS = 8; const unsigned int MAX_GPU_ATTRIB_SLOTS = 8;
GraphicsDevice::GraphicsDevice(GameWindow *window) GraphicsDevice::GraphicsDevice()
{ {
STACK_TRACE; STACK_TRACE;
m_hasNewContextRunYet = FALSE; m_hasNewContextRunYet = FALSE;
m_boundVertexBuffer = NULL; m_boundVertexBuffer = NULL;
m_boundIndexBuffer = NULL; m_boundIndexBuffer = NULL;
m_boundShader = NULL; m_boundShader = NULL;
m_shaderVertexAttribsSet = FALSE; m_shaderVertexAttribsSet = FALSE;
m_boundTextures = NULL;
m_boundTextures = new const Texture*[MAX_BOUND_TEXTURES];
m_boundFramebuffer = NULL; m_boundFramebuffer = NULL;
m_boundRenderbuffer = NULL; m_boundRenderbuffer = NULL;
m_activeViewContext = NULL;
m_defaultViewContext = NULL;
m_debugRenderer = NULL;
m_solidColorTextures = NULL;
m_simpleColorShader = NULL;
m_simpleColorTextureShader = NULL;
m_simpleTextureShader = NULL;
m_simpleTextureVertexLerpShader = NULL;
m_simpleTextureVertexSkinningShader = NULL;
m_sprite2dShader = NULL;
m_sprite3dShader = NULL;
m_debugShader = NULL;
m_isDepthTextureSupported = FALSE;
m_isNonPowerOfTwoTextureSupported = FALSE;
m_window = NULL;
}
BOOL GraphicsDevice::Initialize(GameWindow *window)
{
STACK_TRACE;
ASSERT(m_window == NULL);
if (m_window != NULL)
return FALSE;
ASSERT(window != NULL);
if (window == NULL)
return FALSE;
m_hasNewContextRunYet = FALSE;
m_boundTextures = new const Texture*[MAX_BOUND_TEXTURES];
m_enabledVertexAttribIndices.reserve(MAX_GPU_ATTRIB_SLOTS); m_enabledVertexAttribIndices.reserve(MAX_GPU_ATTRIB_SLOTS);
#ifdef MOBILE #ifdef MOBILE
@ -73,28 +100,18 @@ GraphicsDevice::GraphicsDevice(GameWindow *window)
m_window = window; m_window = window;
m_activeViewContext = NULL;
m_defaultViewContext = new ViewContext(); m_defaultViewContext = new ViewContext();
m_defaultViewContext->Create(this); m_defaultViewContext->Create(this);
m_activeViewContext = m_defaultViewContext; m_activeViewContext = m_defaultViewContext;
m_currentTextureParams = TEXPARAM_DEFAULT; m_currentTextureParams = TEXPARAM_DEFAULT;
m_debugRenderer = NULL;
m_solidColorTextures = new SolidColorTextureCache(this); m_solidColorTextures = new SolidColorTextureCache(this);
m_simpleColorShader = NULL; return TRUE;
m_simpleColorTextureShader = NULL;
m_simpleTextureShader = NULL;
m_simpleTextureVertexLerpShader = NULL;
m_simpleTextureVertexSkinningShader = NULL;
m_sprite2dShader = NULL;
m_sprite3dShader = NULL;
m_debugShader = NULL;
} }
GraphicsDevice::~GraphicsDevice() void GraphicsDevice::Release()
{ {
STACK_TRACE; STACK_TRACE;
SAFE_DELETE(m_defaultViewContext); SAFE_DELETE(m_defaultViewContext);
@ -109,6 +126,20 @@ GraphicsDevice::~GraphicsDevice()
SAFE_DELETE(m_sprite3dShader); SAFE_DELETE(m_sprite3dShader);
SAFE_DELETE(m_debugShader); SAFE_DELETE(m_debugShader);
SAFE_DELETE_ARRAY(m_boundTextures); SAFE_DELETE_ARRAY(m_boundTextures);
m_enabledVertexAttribIndices.clear();
m_managedResources.clear();
m_hasNewContextRunYet = FALSE;
m_boundVertexBuffer = NULL;
m_boundIndexBuffer = NULL;
m_boundShader = NULL;
m_shaderVertexAttribsSet = FALSE;
m_boundFramebuffer = NULL;
m_boundRenderbuffer = NULL;
m_activeViewContext = NULL;
m_isDepthTextureSupported = FALSE;
m_isNonPowerOfTwoTextureSupported = FALSE;
m_window = NULL;
} }
SimpleColorShader* GraphicsDevice::GetSimpleColorShader() SimpleColorShader* GraphicsDevice::GetSimpleColorShader()

View file

@ -43,14 +43,21 @@ typedef stl::vector<uint32_t> EnabledVertexAttribList;
class GraphicsDevice class GraphicsDevice
{ {
public: public:
GraphicsDevice();
virtual ~GraphicsDevice() { Release(); }
/** /**
* Creates a graphics device object based on a parent window that is * Releases all resources associated with this object.
*/
void Release();
/**
* Initializes the graphics device object based on a parent window that is
* hosting the OpenGL context. * hosting the OpenGL context.
* @param window a window with an active OpenGL context associated with it * @param window a window with an active OpenGL context associated with it
* @return TRUE if successful, FALSE if not
*/ */
GraphicsDevice(GameWindow *window); BOOL Initialize(GameWindow *window);
virtual ~GraphicsDevice();
/** /**
* New OpenGL graphics context creation callback. * New OpenGL graphics context creation callback.