CDynamicVertexBuffer: Make use of std::array where applicable
Same behavior, but eliminates hardcoded sizes.
This commit is contained in:
parent
65482ba272
commit
26f847494e
|
@ -1,16 +1,13 @@
|
||||||
#include "CDynamicVertexBuffer.h"
|
#include "CDynamicVertexBuffer.h"
|
||||||
#include "CVertexArrayManager.h"
|
#include "CVertexArrayManager.h"
|
||||||
|
|
||||||
static const uint32 gskAttribSize[] = {
|
#include <array>
|
||||||
|
|
||||||
|
constexpr std::array<uint32, 12> gskAttribSize{
|
||||||
0xC, 0xC, 0x4, 0x4, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8
|
0xC, 0xC, 0x4, 0x4, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8
|
||||||
};
|
};
|
||||||
|
|
||||||
CDynamicVertexBuffer::CDynamicVertexBuffer()
|
CDynamicVertexBuffer::CDynamicVertexBuffer() = default;
|
||||||
: mAttribFlags(EVertexAttribute::None)
|
|
||||||
, mBufferedFlags(EVertexAttribute::None)
|
|
||||||
, mNumVertices(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CDynamicVertexBuffer::~CDynamicVertexBuffer()
|
CDynamicVertexBuffer::~CDynamicVertexBuffer()
|
||||||
{
|
{
|
||||||
|
@ -44,7 +41,7 @@ void CDynamicVertexBuffer::SetActiveAttribs(FVertexDescription AttribFlags)
|
||||||
|
|
||||||
void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pkData)
|
void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pkData)
|
||||||
{
|
{
|
||||||
uint32 Index;
|
size_t Index;
|
||||||
|
|
||||||
switch (Attrib)
|
switch (Attrib)
|
||||||
{
|
{
|
||||||
|
@ -69,9 +66,9 @@ void CDynamicVertexBuffer::BufferAttrib(EVertexAttribute Attrib, const void *pkD
|
||||||
|
|
||||||
void CDynamicVertexBuffer::ClearBuffers()
|
void CDynamicVertexBuffer::ClearBuffers()
|
||||||
{
|
{
|
||||||
for (uint32 iAttrib = 0; iAttrib < 12; iAttrib++)
|
for (uint32 iAttrib = 0; iAttrib < mAttribBuffers.size(); iAttrib++)
|
||||||
{
|
{
|
||||||
int Bit = 1 << iAttrib;
|
const int Bit = 1 << iAttrib;
|
||||||
|
|
||||||
if (mBufferedFlags & Bit)
|
if (mBufferedFlags & Bit)
|
||||||
glDeleteBuffers(1, &mAttribBuffers[iAttrib]);
|
glDeleteBuffers(1, &mAttribBuffers[iAttrib]);
|
||||||
|
@ -86,9 +83,9 @@ GLuint CDynamicVertexBuffer::CreateVAO()
|
||||||
glGenVertexArrays(1, &VertexArray);
|
glGenVertexArrays(1, &VertexArray);
|
||||||
glBindVertexArray(VertexArray);
|
glBindVertexArray(VertexArray);
|
||||||
|
|
||||||
for (uint32 iAttrib = 0; iAttrib < 12; iAttrib++)
|
for (uint32 iAttrib = 0; iAttrib < mAttribBuffers.size(); iAttrib++)
|
||||||
{
|
{
|
||||||
bool HasAttrib = ((3 << (iAttrib * 2)) != 0);
|
const bool HasAttrib = (3 << (iAttrib * 2)) != 0;
|
||||||
|
|
||||||
if (HasAttrib)
|
if (HasAttrib)
|
||||||
{
|
{
|
||||||
|
@ -96,7 +93,7 @@ GLuint CDynamicVertexBuffer::CreateVAO()
|
||||||
GLuint NumComponents;
|
GLuint NumComponents;
|
||||||
GLenum DataType;
|
GLenum DataType;
|
||||||
|
|
||||||
if ((iAttrib == 2) || (iAttrib == 3))
|
if (iAttrib == 2 || iAttrib == 3)
|
||||||
{
|
{
|
||||||
NumComponents = 4;
|
NumComponents = 4;
|
||||||
DataType = GL_UNSIGNED_BYTE;
|
DataType = GL_UNSIGNED_BYTE;
|
||||||
|
@ -107,7 +104,7 @@ GLuint CDynamicVertexBuffer::CreateVAO()
|
||||||
DataType = GL_FLOAT;
|
DataType = GL_FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
glVertexAttribPointer(iAttrib, NumComponents, DataType, GL_FALSE, 0, (void*) 0);
|
glVertexAttribPointer(iAttrib, NumComponents, DataType, GL_FALSE, 0, nullptr);
|
||||||
glEnableVertexAttribArray(iAttrib);
|
glEnableVertexAttribArray(iAttrib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,17 +116,18 @@ GLuint CDynamicVertexBuffer::CreateVAO()
|
||||||
// ************ PRIVATE ************
|
// ************ PRIVATE ************
|
||||||
void CDynamicVertexBuffer::InitBuffers()
|
void CDynamicVertexBuffer::InitBuffers()
|
||||||
{
|
{
|
||||||
if (mBufferedFlags) ClearBuffers();
|
if (mBufferedFlags)
|
||||||
|
ClearBuffers();
|
||||||
|
|
||||||
for (uint32 iAttrib = 0; iAttrib < 12; iAttrib++)
|
for (uint32 iAttrib = 0; iAttrib < mAttribBuffers.size(); iAttrib++)
|
||||||
{
|
{
|
||||||
bool HasAttrib = ((3 << (iAttrib * 2)) != 0);
|
const bool HasAttrib = ((3 << (iAttrib * 2)) != 0);
|
||||||
|
|
||||||
if (HasAttrib)
|
if (HasAttrib)
|
||||||
{
|
{
|
||||||
glGenBuffers(1, &mAttribBuffers[iAttrib]);
|
glGenBuffers(1, &mAttribBuffers[iAttrib]);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]);
|
glBindBuffer(GL_ARRAY_BUFFER, mAttribBuffers[iAttrib]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, gskAttribSize[iAttrib] * mNumVertices, NULL, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, gskAttribSize[iAttrib] * mNumVertices, nullptr, GL_DYNAMIC_DRAW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mBufferedFlags = mAttribFlags;
|
mBufferedFlags = mAttribFlags;
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
#include "Core/Resource/Model/EVertexAttribute.h"
|
#include "Core/Resource/Model/EVertexAttribute.h"
|
||||||
#include <Common/BasicTypes.h>
|
#include <Common/BasicTypes.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <array>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
class CDynamicVertexBuffer
|
class CDynamicVertexBuffer
|
||||||
{
|
{
|
||||||
FVertexDescription mAttribFlags;
|
FVertexDescription mAttribFlags{EVertexAttribute::None};
|
||||||
FVertexDescription mBufferedFlags;
|
FVertexDescription mBufferedFlags{EVertexAttribute::None};
|
||||||
uint32 mNumVertices;
|
uint32 mNumVertices = 0;
|
||||||
GLuint mAttribBuffers[12];
|
std::array<GLuint, 12> mAttribBuffers{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDynamicVertexBuffer();
|
CDynamicVertexBuffer();
|
||||||
|
|
Loading…
Reference in New Issue