updated IndexBuffer to use Initialize() methods instead of doing it all in the constructor
This commit is contained in:
parent
2ec3ed3673
commit
ee9928ad79
|
@ -4,25 +4,10 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
IndexBuffer::IndexBuffer(uint32_t numIndices, BOOL isStatic)
|
IndexBuffer::IndexBuffer()
|
||||||
: BufferObject(BUFFEROBJECT_TYPE_INDEX, isStatic ? BUFFEROBJECT_USAGE_STATIC : BUFFEROBJECT_USAGE_DYNAMIC)
|
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
m_currentIndex = 0;
|
m_currentIndex = 0;
|
||||||
Resize(numIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexBuffer::IndexBuffer(const IndexBuffer *source)
|
|
||||||
: BufferObject(BUFFEROBJECT_TYPE_INDEX, source->GetUsage())
|
|
||||||
{
|
|
||||||
STACK_TRACE;
|
|
||||||
ASSERT(source != NULL);
|
|
||||||
ASSERT(source->GetNumElements() > 0);
|
|
||||||
|
|
||||||
m_currentIndex = 0;
|
|
||||||
Resize(source->GetNumElements());
|
|
||||||
|
|
||||||
memcpy(&m_buffer[0], source->GetBuffer(), GetNumElements() * GetElementWidthInBytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexBuffer::~IndexBuffer()
|
IndexBuffer::~IndexBuffer()
|
||||||
|
@ -30,6 +15,57 @@ IndexBuffer::~IndexBuffer()
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL IndexBuffer::Initialize(uint32_t numIndices, BUFFEROBJECT_USAGE usage)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
return Initialize(NULL, numIndices, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL IndexBuffer::Initialize(GraphicsDevice *graphicsDevice, uint32_t numIndices, BUFFEROBJECT_USAGE usage)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
ASSERT(m_buffer.size() == 0);
|
||||||
|
if (m_buffer.size() > 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
ASSERT(numIndices > 0);
|
||||||
|
if (numIndices == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!BufferObject::Initialize(graphicsDevice, BUFFEROBJECT_TYPE_INDEX, usage))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
Resize(numIndices);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL IndexBuffer::Initialize(const IndexBuffer *source)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
return Initialize(NULL, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL IndexBuffer::Initialize(GraphicsDevice *graphicsDevice, const IndexBuffer *source)
|
||||||
|
{
|
||||||
|
STACK_TRACE;
|
||||||
|
ASSERT(m_buffer.size() == 0);
|
||||||
|
if (m_buffer.size() > 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
ASSERT(source != NULL);
|
||||||
|
if (source == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
ASSERT(source->GetNumElements() > 0);
|
||||||
|
if (source->GetNumElements() == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
Resize(source->GetNumElements());
|
||||||
|
|
||||||
|
memcpy(&m_buffer[0], source->GetBuffer(), GetNumElements() * GetElementWidthInBytes());
|
||||||
|
}
|
||||||
|
|
||||||
void IndexBuffer::Set(const uint16_t *indices, uint32_t numIndices)
|
void IndexBuffer::Set(const uint16_t *indices, uint32_t numIndices)
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
|
@ -39,6 +75,10 @@ void IndexBuffer::Set(const uint16_t *indices, uint32_t numIndices)
|
||||||
void IndexBuffer::Resize(uint32_t numIndices)
|
void IndexBuffer::Resize(uint32_t numIndices)
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
|
ASSERT(numIndices > 0);
|
||||||
|
if (numIndices == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
m_buffer.resize(numIndices, 0);
|
m_buffer.resize(numIndices, 0);
|
||||||
|
|
||||||
if (!IsClientSideBuffer())
|
if (!IsClientSideBuffer())
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <stdlib.h> // for abs()
|
#include <stdlib.h> // for abs()
|
||||||
#include <stl/vector.h>
|
#include <stl/vector.h>
|
||||||
|
|
||||||
|
class GraphicsDevice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps management of an array of vertex indexes to be used for
|
* Wraps management of an array of vertex indexes to be used for
|
||||||
* optimized rendering of vertices.
|
* optimized rendering of vertices.
|
||||||
|
@ -14,21 +16,42 @@
|
||||||
class IndexBuffer : public BufferObject
|
class IndexBuffer : public BufferObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
IndexBuffer();
|
||||||
* Creates an index buffer.
|
|
||||||
* @param numIndices the initial number of indices the buffer should hold
|
|
||||||
* @param isStatic whether the index data is static or dynamic (used as
|
|
||||||
* a hint for index data stored in video memory)
|
|
||||||
*/
|
|
||||||
IndexBuffer(uint32_t numIndices, BOOL isStatic);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an index buffer.
|
|
||||||
* @param source the source buffer to copy during creation of this buffer
|
|
||||||
*/
|
|
||||||
IndexBuffer(const IndexBuffer *source);
|
|
||||||
|
|
||||||
virtual ~IndexBuffer();
|
virtual ~IndexBuffer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the index buffer.
|
||||||
|
* @param numIndices the initial number of indices the buffer should hold
|
||||||
|
* @param usage the expected usage pattern of this index buffer
|
||||||
|
* @return TRUE if successful, FALSE if not
|
||||||
|
*/
|
||||||
|
BOOL Initialize(uint32_t numIndices, BUFFEROBJECT_USAGE usage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the index buffer.
|
||||||
|
* @param graphicsDevice the graphics device to use to create this buffer
|
||||||
|
* on the GPU
|
||||||
|
* @param numIndices the initial number of indices the buffer should hold
|
||||||
|
* @param usage the expected usage pattern of this index buffer
|
||||||
|
* @return TRUE if successful, FALSE if not
|
||||||
|
*/
|
||||||
|
BOOL Initialize(GraphicsDevice *graphicsDevice, uint32_t numIndices, BUFFEROBJECT_USAGE usage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the index buffer.
|
||||||
|
* @param source the source buffer to copy during creation of this buffer
|
||||||
|
* @return TRUE if successful, FALSE if not
|
||||||
|
*/
|
||||||
|
BOOL Initialize(const IndexBuffer *source);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the index buffer.
|
||||||
|
* @param graphicsDevice the graphics device to use to create this buffer
|
||||||
|
* on the GPU
|
||||||
|
* @param source the source buffer to copy during creation of this buffer
|
||||||
|
* @return TRUE if successful, FALSE if not
|
||||||
|
*/
|
||||||
|
BOOL Initialize(GraphicsDevice *graphicsDevice, const IndexBuffer *source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies the source indices over top of this buffer's existing indices.
|
* Copies the source indices over top of this buffer's existing indices.
|
||||||
|
|
Reference in a new issue