diff --git a/src/framework/graphics/bufferobject.cpp b/src/framework/graphics/bufferobject.cpp index 9eddba8..657ae14 100644 --- a/src/framework/graphics/bufferobject.cpp +++ b/src/framework/graphics/bufferobject.cpp @@ -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; diff --git a/src/framework/graphics/bufferobject.h b/src/framework/graphics/bufferobject.h index 78ce063..66855fc 100644 --- a/src/framework/graphics/bufferobject.h +++ b/src/framework/graphics/bufferobject.h @@ -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 diff --git a/src/framework/graphics/graphicscontextresource.cpp b/src/framework/graphics/graphicscontextresource.cpp index ab3f51e..3691157 100644 --- a/src/framework/graphics/graphicscontextresource.cpp +++ b/src/framework/graphics/graphicscontextresource.cpp @@ -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; +} diff --git a/src/framework/graphics/graphicscontextresource.h b/src/framework/graphics/graphicscontextresource.h index 25d4bdd..23166ab 100644 --- a/src/framework/graphics/graphicscontextresource.h +++ b/src/framework/graphics/graphicscontextresource.h @@ -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; };