Wrap IBO index type into one definition
Makes it easier to switch between types (eg. 32 -> 16 bit).
This commit is contained in:
parent
295e0e5b15
commit
caae9c5689
4 changed files with 18 additions and 11 deletions
|
@ -25,11 +25,18 @@
|
|||
#include "gl-util.h"
|
||||
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t index_t;
|
||||
#define INDEX_T_MAX std::numeric_limits<index_t>::max()
|
||||
#define _GL_INDEX_TYPE GL_UNSIGNED_INT
|
||||
|
||||
struct GlobalIBO
|
||||
{
|
||||
IBO::ID ibo;
|
||||
std::vector<uint32_t> buffer;
|
||||
std::vector<index_t> buffer;
|
||||
|
||||
GlobalIBO()
|
||||
{
|
||||
|
@ -43,6 +50,8 @@ struct GlobalIBO
|
|||
|
||||
void ensureSize(size_t quadCount)
|
||||
{
|
||||
assert(quadCount*6 < INDEX_T_MAX);
|
||||
|
||||
if (buffer.size() >= quadCount*6)
|
||||
return;
|
||||
|
||||
|
@ -51,14 +60,14 @@ struct GlobalIBO
|
|||
|
||||
for (size_t i = startInd; i < quadCount; ++i)
|
||||
{
|
||||
static const uint32_t indTemp[] = { 0, 1, 2, 2, 3, 0 };
|
||||
static const index_t indTemp[] = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
for (size_t j = 0; j < 6; ++j)
|
||||
buffer.push_back(i * 4 + indTemp[j]);
|
||||
}
|
||||
|
||||
IBO::bind(ibo);
|
||||
IBO::uploadData(buffer.size() * sizeof(uint32_t), &buffer[0]);
|
||||
IBO::uploadData(buffer.size() * sizeof(index_t), &buffer[0]);
|
||||
IBO::unbind();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue