change BufferObject and GraphicsContextResource to use a simple "do-nothing" constructor, and do all important initialization in a separate method with a return value
This commit is contained in:
parent
75d827ac7c
commit
9d77f6b197
|
@ -3,25 +3,12 @@
|
||||||
#include "bufferobject.h"
|
#include "bufferobject.h"
|
||||||
#include "glincludes.h"
|
#include "glincludes.h"
|
||||||
#include "glutils.h"
|
#include "glutils.h"
|
||||||
#include "graphicsdevice.h"
|
|
||||||
|
|
||||||
BufferObject::BufferObject(BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage)
|
BufferObject::BufferObject()
|
||||||
: GraphicsContextResource()
|
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
m_type = type;
|
m_type = BUFFEROBJECT_TYPE_VERTEX;
|
||||||
m_usage = usage;
|
m_usage = BUFFEROBJECT_USAGE_STATIC;
|
||||||
m_bufferId = 0;
|
|
||||||
m_isDirty = FALSE;
|
|
||||||
m_sizeInBytes = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferObject::BufferObject(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage)
|
|
||||||
: GraphicsContextResource(graphicsDevice)
|
|
||||||
{
|
|
||||||
STACK_TRACE;
|
|
||||||
m_type = type;
|
|
||||||
m_usage = usage;
|
|
||||||
m_bufferId = 0;
|
m_bufferId = 0;
|
||||||
m_isDirty = FALSE;
|
m_isDirty = FALSE;
|
||||||
m_sizeInBytes = 0;
|
m_sizeInBytes = 0;
|
||||||
|
@ -34,6 +21,21 @@ BufferObject::~BufferObject()
|
||||||
FreeBufferObject();
|
FreeBufferObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL BufferObject::Initialize(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
BOOL success = TRUE;
|
||||||
|
if (graphicsDevice != NULL)
|
||||||
|
success = GraphicsContextResource::Initialize(graphicsDevice);
|
||||||
|
else
|
||||||
|
success = GraphicsContextResource::Initialize();
|
||||||
|
|
||||||
|
m_type = type;
|
||||||
|
m_usage = usage;
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
void BufferObject::CreateOnGpu()
|
void BufferObject::CreateOnGpu()
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
|
|
|
@ -26,23 +26,7 @@ enum BUFFEROBJECT_USAGE
|
||||||
class BufferObject : public GraphicsContextResource
|
class BufferObject : public GraphicsContextResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
BufferObject();
|
||||||
* Initializes buffer object handling state
|
|
||||||
* @param type the type of buffer object describing the kind of data that
|
|
||||||
* will be stored in it
|
|
||||||
* @param usage the expected usage pattern of this buffer object
|
|
||||||
*/
|
|
||||||
BufferObject(BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes buffer object handling state
|
|
||||||
* @param graphicsDevice the graphics device this buffer object is for
|
|
||||||
* @param type the type of buffer object describing the kind of data that
|
|
||||||
* will be stored in it
|
|
||||||
* @param usage the expected usage pattern of this buffer object
|
|
||||||
*/
|
|
||||||
BufferObject(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage);
|
|
||||||
|
|
||||||
virtual ~BufferObject();
|
virtual ~BufferObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,6 +85,15 @@ public:
|
||||||
void OnLostContext();
|
void OnLostContext();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Initializes buffer object handling state
|
||||||
|
* @param graphicsDevice the graphics device this buffer object is for
|
||||||
|
* @param type the type of buffer object describing the kind of data that
|
||||||
|
* will be stored in it
|
||||||
|
* @param usage the expected usage pattern of this buffer object
|
||||||
|
*/
|
||||||
|
BOOL Initialize(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a buffer object on the GPU but does not upload this
|
* Creates a buffer object on the GPU but does not upload this
|
||||||
* buffer's data there yet. This only allocates the buffer object in
|
* buffer's data there yet. This only allocates the buffer object in
|
||||||
|
|
|
@ -9,18 +9,26 @@ GraphicsContextResource::GraphicsContextResource()
|
||||||
m_graphicsDevice = NULL;
|
m_graphicsDevice = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsContextResource::GraphicsContextResource(GraphicsDevice *graphicsDevice)
|
|
||||||
{
|
|
||||||
STACK_TRACE;
|
|
||||||
ASSERT(graphicsDevice != NULL);
|
|
||||||
|
|
||||||
m_graphicsDevice = graphicsDevice;
|
|
||||||
m_graphicsDevice->RegisterManagedResource(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsContextResource::~GraphicsContextResource()
|
GraphicsContextResource::~GraphicsContextResource()
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
if (m_graphicsDevice != NULL)
|
if (m_graphicsDevice != NULL)
|
||||||
m_graphicsDevice->UnregisterManagedResource(this);
|
m_graphicsDevice->UnregisterManagedResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL GraphicsContextResource::Initialize()
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL GraphicsContextResource::Initialize(GraphicsDevice *graphicsDevice)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
ASSERT(graphicsDevice != NULL);
|
||||||
|
|
||||||
|
m_graphicsDevice = graphicsDevice;
|
||||||
|
m_graphicsDevice->RegisterManagedResource(this);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ class GraphicsContextResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsContextResource();
|
GraphicsContextResource();
|
||||||
GraphicsContextResource(GraphicsDevice *graphicsDevice);
|
|
||||||
|
|
||||||
virtual ~GraphicsContextResource();
|
virtual ~GraphicsContextResource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +28,10 @@ public:
|
||||||
|
|
||||||
GraphicsDevice* GetGraphicsDevice() const { return m_graphicsDevice; }
|
GraphicsDevice* GetGraphicsDevice() const { return m_graphicsDevice; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
BOOL Initialize();
|
||||||
|
BOOL Initialize(GraphicsDevice *graphicsDevice);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GraphicsDevice *m_graphicsDevice;
|
GraphicsDevice *m_graphicsDevice;
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue