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 "glincludes.h"
|
||||
#include "glutils.h"
|
||||
#include "graphicsdevice.h"
|
||||
|
||||
BufferObject::BufferObject(BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage)
|
||||
: GraphicsContextResource()
|
||||
BufferObject::BufferObject()
|
||||
{
|
||||
STACK_TRACE;
|
||||
m_type = type;
|
||||
m_usage = usage;
|
||||
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_type = BUFFEROBJECT_TYPE_VERTEX;
|
||||
m_usage = BUFFEROBJECT_USAGE_STATIC;
|
||||
m_bufferId = 0;
|
||||
m_isDirty = FALSE;
|
||||
m_sizeInBytes = 0;
|
||||
|
@ -34,6 +21,21 @@ BufferObject::~BufferObject()
|
|||
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()
|
||||
{
|
||||
STACK_TRACE;
|
||||
|
|
|
@ -26,23 +26,7 @@ enum BUFFEROBJECT_USAGE
|
|||
class BufferObject : public GraphicsContextResource
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 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);
|
||||
|
||||
BufferObject();
|
||||
virtual ~BufferObject();
|
||||
|
||||
/**
|
||||
|
@ -101,6 +85,15 @@ public:
|
|||
void OnLostContext();
|
||||
|
||||
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
|
||||
* buffer's data there yet. This only allocates the buffer object in
|
||||
|
|
|
@ -9,18 +9,26 @@ GraphicsContextResource::GraphicsContextResource()
|
|||
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);
|
||||
}
|
||||
|
||||
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:
|
||||
GraphicsContextResource();
|
||||
GraphicsContextResource(GraphicsDevice *graphicsDevice);
|
||||
|
||||
virtual ~GraphicsContextResource();
|
||||
|
||||
/**
|
||||
|
@ -30,6 +28,10 @@ public:
|
|||
|
||||
GraphicsDevice* GetGraphicsDevice() const { return m_graphicsDevice; }
|
||||
|
||||
protected:
|
||||
BOOL Initialize();
|
||||
BOOL Initialize(GraphicsDevice *graphicsDevice);
|
||||
|
||||
private:
|
||||
GraphicsDevice *m_graphicsDevice;
|
||||
};
|
||||
|
|
Reference in a new issue