Wrap IBO index type into one definition

Makes it easier to switch between types (eg. 32 -> 16 bit).
This commit is contained in:
Jonas Kulla 2014-07-11 02:09:53 +02:00
parent 295e0e5b15
commit caae9c5689
4 changed files with 18 additions and 11 deletions

View File

@ -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();
}
};

View File

@ -176,7 +176,7 @@ struct Quad
}
VAO::bind(vao);
gl.DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
gl.DrawElements(GL_TRIANGLES, 6, _GL_INDEX_TYPE, 0);
VAO::unbind();
}
};

View File

@ -31,9 +31,6 @@
#include <stdint.h>
typedef uint32_t index_t;
#define _GL_INDEX_TYPE GL_UNSIGNED_INT
/* A small hack to get mutable QuadArray constructors */
inline void initBufferBindings(Vertex *)
{

View File

@ -28,6 +28,7 @@
#include "sharedstate.h"
#include "glstate.h"
#include "gl-util.h"
#include "global-ibo.h"
#include "etc-internal.h"
#include "quadarray.h"
#include "texpool.h"
@ -1124,12 +1125,12 @@ void GroundLayer::draw()
void GroundLayer::drawInt()
{
gl.DrawElements(GL_TRIANGLES, vboCount, GL_UNSIGNED_INT, (GLvoid*) 0);
gl.DrawElements(GL_TRIANGLES, vboCount, _GL_INDEX_TYPE, (GLvoid*) 0);
}
void GroundLayer::drawFlashInt()
{
gl.DrawElements(GL_TRIANGLES, p->flash.quadCount * 6, GL_UNSIGNED_INT, 0);
gl.DrawElements(GL_TRIANGLES, p->flash.quadCount * 6, _GL_INDEX_TYPE, 0);
}
void GroundLayer::onGeometryChange(const Scene::Geometry &geo)
@ -1154,7 +1155,7 @@ void ScanRow::setIndex(int value)
z = calculateZ(p, index);
scene->reinsert(*this);
vboOffset = p->scanrowBases[index] * sizeof(uint32_t) * 6;
vboOffset = p->scanrowBases[index] * sizeof(index_t) * 6;
vboCount = p->scanrowSize(index) * 6;
}
@ -1178,7 +1179,7 @@ void ScanRow::draw()
void ScanRow::drawInt()
{
gl.DrawElements(GL_TRIANGLES, vboBatchCount, GL_UNSIGNED_INT, (GLvoid*) vboOffset);
gl.DrawElements(GL_TRIANGLES, vboBatchCount, _GL_INDEX_TYPE, (GLvoid*) vboOffset);
}
int ScanRow::calculateZ(TilemapPrivate *p, int index)