mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 08:16:21 +02:00
rename parameters and reuse previously registered quad if geometry didn't change
This commit is contained in:
parent
be137534b5
commit
28569836bb
2 changed files with 107 additions and 67 deletions
|
@ -667,15 +667,17 @@ void GeometryCache::renderWireCube(float size) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID) {
|
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID) {
|
||||||
|
|
||||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||||
Vec2Pair key(topLeft, bottomRight);
|
Vec2Pair key(minCorner, maxCorner);
|
||||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key];
|
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key];
|
||||||
|
|
||||||
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
||||||
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
||||||
if (registeredQuad && vbo.first != 0) {
|
if (registeredQuad && vbo.first != 0) {
|
||||||
|
Vec2Pair& lastKey = _lastRegisteredQuad2D[quadID];
|
||||||
|
if (lastKey != key) {
|
||||||
glDeleteBuffers(1, &vbo.first);
|
glDeleteBuffers(1, &vbo.first);
|
||||||
glDeleteBuffers(1, &vbo.second);
|
glDeleteBuffers(1, &vbo.second);
|
||||||
vbo.first = vbo.second = 0;
|
vbo.first = vbo.second = 0;
|
||||||
|
@ -683,25 +685,32 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
||||||
qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD";
|
qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD";
|
||||||
#endif // def WANT_DEBUG
|
#endif // def WANT_DEBUG
|
||||||
}
|
}
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
else {
|
||||||
|
qDebug() << "renderQuad() vec2... REUSING PREVIOUSLY REGISTERED QUAD";
|
||||||
|
}
|
||||||
|
#endif // def WANT_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 2;
|
const int FLOATS_PER_VERTEX = 2;
|
||||||
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||||
const int vertices = 4;
|
const int vertices = 4;
|
||||||
const int indices = 4;
|
const int indices = 4;
|
||||||
if (vbo.first == 0) {
|
if (vbo.first == 0) {
|
||||||
|
_lastRegisteredQuad2D[quadID] = key;
|
||||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
|
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
|
||||||
GLfloat* vertex = vertexData;
|
GLfloat* vertex = vertexData;
|
||||||
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
||||||
|
|
||||||
vertex[0] = topLeft.x;
|
vertex[0] = minCorner.x;
|
||||||
vertex[1] = topLeft.y;
|
vertex[1] = minCorner.y;
|
||||||
vertex[2] = bottomRight.x;
|
vertex[2] = maxCorner.x;
|
||||||
vertex[3] = topLeft.y;
|
vertex[3] = minCorner.y;
|
||||||
vertex[4] = bottomRight.x;
|
vertex[4] = maxCorner.x;
|
||||||
vertex[5] = bottomRight.y;
|
vertex[5] = maxCorner.y;
|
||||||
vertex[6] = topLeft.x;
|
vertex[6] = minCorner.x;
|
||||||
vertex[7] = bottomRight.y;
|
vertex[7] = maxCorner.y;
|
||||||
|
|
||||||
glGenBuffers(1, &vbo.first);
|
glGenBuffers(1, &vbo.first);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
@ -741,16 +750,17 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
|
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||||
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID) {
|
const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID) {
|
||||||
|
|
||||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||||
Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
|
Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner));
|
||||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key];
|
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key];
|
||||||
|
|
||||||
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
||||||
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
|
||||||
if (registeredQuad && vbo.first != 0) {
|
if (registeredQuad && vbo.first != 0) {
|
||||||
|
Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[quadID];
|
||||||
|
if (lastKey != key) {
|
||||||
glDeleteBuffers(1, &vbo.first);
|
glDeleteBuffers(1, &vbo.first);
|
||||||
glDeleteBuffers(1, &vbo.second);
|
glDeleteBuffers(1, &vbo.second);
|
||||||
vbo.first = vbo.second = 0;
|
vbo.first = vbo.second = 0;
|
||||||
|
@ -758,37 +768,44 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
||||||
qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD";
|
qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD";
|
||||||
#endif // def WANT_DEBUG
|
#endif // def WANT_DEBUG
|
||||||
}
|
}
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
else {
|
||||||
|
qDebug() << "renderQuad() vec2 + texture... REUSING PREVIOUSLY REGISTERED QUAD";
|
||||||
|
}
|
||||||
|
#endif // def WANT_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices
|
const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices
|
||||||
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||||
const int vertices = 4;
|
const int vertices = 4;
|
||||||
const int indices = 4;
|
const int indices = 4;
|
||||||
if (vbo.first == 0) {
|
if (vbo.first == 0) {
|
||||||
|
_lastRegisteredQuad2DTexture[quadID] = key;
|
||||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
|
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
|
||||||
GLfloat* vertex = vertexData;
|
GLfloat* vertex = vertexData;
|
||||||
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
||||||
int v = 0;
|
int v = 0;
|
||||||
|
|
||||||
vertex[v++] = topLeft.x;
|
vertex[v++] = minCorner.x;
|
||||||
vertex[v++] = topLeft.y;
|
vertex[v++] = minCorner.y;
|
||||||
vertex[v++] = texCoordTopLeft.x;
|
vertex[v++] = texCoordMinCorner.x;
|
||||||
vertex[v++] = texCoordTopLeft.y;
|
vertex[v++] = texCoordMinCorner.y;
|
||||||
|
|
||||||
vertex[v++] = bottomRight.x;
|
vertex[v++] = maxCorner.x;
|
||||||
vertex[v++] = topLeft.y;
|
vertex[v++] = minCorner.y;
|
||||||
vertex[v++] = texCoordBottomRight.x;
|
vertex[v++] = texCoordMaxCorner.x;
|
||||||
vertex[v++] = texCoordTopLeft.y;
|
vertex[v++] = texCoordMinCorner.y;
|
||||||
|
|
||||||
vertex[v++] = bottomRight.x;
|
vertex[v++] = maxCorner.x;
|
||||||
vertex[v++] = bottomRight.y;
|
vertex[v++] = maxCorner.y;
|
||||||
vertex[v++] = texCoordBottomRight.x;
|
vertex[v++] = texCoordMaxCorner.x;
|
||||||
vertex[v++] = texCoordBottomRight.y;
|
vertex[v++] = texCoordMaxCorner.y;
|
||||||
|
|
||||||
vertex[v++] = topLeft.x;
|
vertex[v++] = minCorner.x;
|
||||||
vertex[v++] = bottomRight.y;
|
vertex[v++] = maxCorner.y;
|
||||||
vertex[v++] = texCoordTopLeft.x;
|
vertex[v++] = texCoordMinCorner.x;
|
||||||
vertex[v++] = texCoordBottomRight.y;
|
vertex[v++] = texCoordMaxCorner.y;
|
||||||
|
|
||||||
glGenBuffers(1, &vbo.first);
|
glGenBuffers(1, &vbo.first);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
@ -832,15 +849,17 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID) {
|
void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID) {
|
||||||
|
|
||||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||||
Vec3Pair key(topLeft, bottomRight);
|
Vec3Pair key(minCorner, maxCorner);
|
||||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key];
|
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key];
|
||||||
|
|
||||||
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
||||||
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
||||||
if (registeredQuad && vbo.first != 0) {
|
if (registeredQuad && vbo.first != 0) {
|
||||||
|
Vec3Pair& lastKey = _lastRegisteredQuad3D[quadID];
|
||||||
|
if (lastKey != key) {
|
||||||
glDeleteBuffers(1, &vbo.first);
|
glDeleteBuffers(1, &vbo.first);
|
||||||
glDeleteBuffers(1, &vbo.second);
|
glDeleteBuffers(1, &vbo.second);
|
||||||
vbo.first = vbo.second = 0;
|
vbo.first = vbo.second = 0;
|
||||||
|
@ -848,33 +867,40 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
||||||
qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD";
|
qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD";
|
||||||
#endif // def WANT_DEBUG
|
#endif // def WANT_DEBUG
|
||||||
}
|
}
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
else {
|
||||||
|
qDebug() << "renderQuad() vec3... REUSING PREVIOUSLY REGISTERED QUAD";
|
||||||
|
}
|
||||||
|
#endif // def WANT_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 3;
|
const int FLOATS_PER_VERTEX = 3;
|
||||||
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||||
const int vertices = 4;
|
const int vertices = 4;
|
||||||
const int indices = 4;
|
const int indices = 4;
|
||||||
if (vbo.first == 0) {
|
if (vbo.first == 0) {
|
||||||
|
_lastRegisteredQuad3D[quadID] = key;
|
||||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices
|
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices
|
||||||
GLfloat* vertex = vertexData;
|
GLfloat* vertex = vertexData;
|
||||||
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
||||||
int v = 0;
|
int v = 0;
|
||||||
|
|
||||||
vertex[v++] = topLeft.x;
|
vertex[v++] = minCorner.x;
|
||||||
vertex[v++] = topLeft.y;
|
vertex[v++] = minCorner.y;
|
||||||
vertex[v++] = topLeft.z;
|
vertex[v++] = minCorner.z;
|
||||||
|
|
||||||
vertex[v++] = bottomRight.x;
|
vertex[v++] = maxCorner.x;
|
||||||
vertex[v++] = topLeft.y;
|
vertex[v++] = minCorner.y;
|
||||||
vertex[v++] = topLeft.z;
|
vertex[v++] = minCorner.z;
|
||||||
|
|
||||||
vertex[v++] = bottomRight.x;
|
vertex[v++] = maxCorner.x;
|
||||||
vertex[v++] = bottomRight.y;
|
vertex[v++] = maxCorner.y;
|
||||||
vertex[v++] = bottomRight.z;
|
vertex[v++] = maxCorner.z;
|
||||||
|
|
||||||
vertex[v++] = topLeft.x;
|
vertex[v++] = minCorner.x;
|
||||||
vertex[v++] = bottomRight.y;
|
vertex[v++] = maxCorner.y;
|
||||||
vertex[v++] = bottomRight.z;
|
vertex[v++] = maxCorner.z;
|
||||||
|
|
||||||
glGenBuffers(1, &vbo.first);
|
glGenBuffers(1, &vbo.first);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
@ -936,6 +962,8 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
||||||
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
// if this is a registered quad, and we have buffers, then clear them and rebuild
|
||||||
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
// TODO: would be nice to only rebuild if the geometry changed from last time.
|
||||||
if (registeredQuad && vbo.first != 0) {
|
if (registeredQuad && vbo.first != 0) {
|
||||||
|
Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[quadID];
|
||||||
|
if (lastKey != key) {
|
||||||
glDeleteBuffers(1, &vbo.first);
|
glDeleteBuffers(1, &vbo.first);
|
||||||
glDeleteBuffers(1, &vbo.second);
|
glDeleteBuffers(1, &vbo.second);
|
||||||
vbo.first = vbo.second = 0;
|
vbo.first = vbo.second = 0;
|
||||||
|
@ -943,12 +971,19 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
||||||
qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD";
|
qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD";
|
||||||
#endif // def WANT_DEBUG
|
#endif // def WANT_DEBUG
|
||||||
}
|
}
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
else {
|
||||||
|
qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD";
|
||||||
|
}
|
||||||
|
#endif // def WANT_DEBUG
|
||||||
|
}
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 5; // text coords & vertices
|
const int FLOATS_PER_VERTEX = 5; // text coords & vertices
|
||||||
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||||
const int vertices = 4;
|
const int vertices = 4;
|
||||||
const int indices = 4;
|
const int indices = 4;
|
||||||
if (vbo.first == 0) {
|
if (vbo.first == 0) {
|
||||||
|
_lastRegisteredQuad3DTexture[quadID] = key;
|
||||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
|
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
|
||||||
GLfloat* vertex = vertexData;
|
GLfloat* vertex = vertexData;
|
||||||
|
|
|
@ -96,12 +96,12 @@ public:
|
||||||
void renderQuad(int x, int y, int width, int height, int quadID = UNKNOWN_QUAD_ID)
|
void renderQuad(int x, int y, int width, int height, int quadID = UNKNOWN_QUAD_ID)
|
||||||
{ renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), quadID); }
|
{ renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), quadID); }
|
||||||
|
|
||||||
void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID = UNKNOWN_QUAD_ID);
|
void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID = UNKNOWN_QUAD_ID);
|
||||||
|
|
||||||
void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
|
void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||||
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID = UNKNOWN_QUAD_ID);
|
const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID = UNKNOWN_QUAD_ID);
|
||||||
|
|
||||||
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID = UNKNOWN_QUAD_ID);
|
void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID = UNKNOWN_QUAD_ID);
|
||||||
|
|
||||||
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft,
|
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft,
|
||||||
const glm::vec3& bottomRight, const glm::vec3& topRight,
|
const glm::vec3& bottomRight, const glm::vec3& topRight,
|
||||||
|
@ -139,6 +139,11 @@ private:
|
||||||
QHash<int, VerticesIndices> _registeredQuadVBOs;
|
QHash<int, VerticesIndices> _registeredQuadVBOs;
|
||||||
int _nextQuadID;
|
int _nextQuadID;
|
||||||
|
|
||||||
|
QHash<int, Vec2Pair> _lastRegisteredQuad2D;
|
||||||
|
QHash<int, Vec2PairPair> _lastRegisteredQuad2DTexture;
|
||||||
|
QHash<int, Vec3Pair> _lastRegisteredQuad3D;
|
||||||
|
QHash<int, Vec3PairVec2Pair> _lastRegisteredQuad3DTexture;
|
||||||
|
|
||||||
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
||||||
|
|
||||||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||||
|
|
Loading…
Reference in a new issue