shift GraphicsDevice's complex initialization to a new Initialize() method
This commit is contained in:
parent
07abad71c2
commit
c9cfceec39
|
@ -92,8 +92,9 @@ BOOL BaseGameApp::Initialize(GameWindowParams *windowParams)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
m_graphics = new GraphicsDevice(m_window);
|
||||
m_graphics = new GraphicsDevice();
|
||||
ASSERT(m_graphics != NULL);
|
||||
m_graphics->Initialize(m_window);
|
||||
|
||||
m_content = new ContentManager(this);
|
||||
ASSERT(m_content != NULL);
|
||||
|
|
|
@ -42,20 +42,47 @@
|
|||
const unsigned int MAX_BOUND_TEXTURES = 8;
|
||||
const unsigned int MAX_GPU_ATTRIB_SLOTS = 8;
|
||||
|
||||
GraphicsDevice::GraphicsDevice(GameWindow *window)
|
||||
GraphicsDevice::GraphicsDevice()
|
||||
{
|
||||
STACK_TRACE;
|
||||
m_hasNewContextRunYet = FALSE;
|
||||
|
||||
m_boundVertexBuffer = NULL;
|
||||
m_boundIndexBuffer = NULL;
|
||||
m_boundShader = NULL;
|
||||
m_shaderVertexAttribsSet = FALSE;
|
||||
|
||||
m_boundTextures = new const Texture*[MAX_BOUND_TEXTURES];
|
||||
m_boundTextures = NULL;
|
||||
m_boundFramebuffer = 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);
|
||||
|
||||
#ifdef MOBILE
|
||||
|
@ -73,28 +100,18 @@ GraphicsDevice::GraphicsDevice(GameWindow *window)
|
|||
|
||||
m_window = window;
|
||||
|
||||
m_activeViewContext = NULL;
|
||||
m_defaultViewContext = new ViewContext();
|
||||
m_defaultViewContext->Create(this);
|
||||
m_activeViewContext = m_defaultViewContext;
|
||||
|
||||
m_currentTextureParams = TEXPARAM_DEFAULT;
|
||||
|
||||
m_debugRenderer = NULL;
|
||||
|
||||
m_solidColorTextures = new SolidColorTextureCache(this);
|
||||
|
||||
m_simpleColorShader = NULL;
|
||||
m_simpleColorTextureShader = NULL;
|
||||
m_simpleTextureShader = NULL;
|
||||
m_simpleTextureVertexLerpShader = NULL;
|
||||
m_simpleTextureVertexSkinningShader = NULL;
|
||||
m_sprite2dShader = NULL;
|
||||
m_sprite3dShader = NULL;
|
||||
m_debugShader = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GraphicsDevice::~GraphicsDevice()
|
||||
void GraphicsDevice::Release()
|
||||
{
|
||||
STACK_TRACE;
|
||||
SAFE_DELETE(m_defaultViewContext);
|
||||
|
@ -109,6 +126,20 @@ GraphicsDevice::~GraphicsDevice()
|
|||
SAFE_DELETE(m_sprite3dShader);
|
||||
SAFE_DELETE(m_debugShader);
|
||||
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()
|
||||
|
|
|
@ -43,14 +43,21 @@ typedef stl::vector<uint32_t> EnabledVertexAttribList;
|
|||
class GraphicsDevice
|
||||
{
|
||||
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.
|
||||
* @param window a window with an active OpenGL context associated with it
|
||||
* @return TRUE if successful, FALSE if not
|
||||
*/
|
||||
GraphicsDevice(GameWindow *window);
|
||||
|
||||
virtual ~GraphicsDevice();
|
||||
BOOL Initialize(GameWindow *window);
|
||||
|
||||
/**
|
||||
* New OpenGL graphics context creation callback.
|
||||
|
|
Reference in a new issue