almost completely eliminate immediate mode QUADS

This commit is contained in:
ZappoMan 2014-12-24 11:14:50 -08:00
parent 02a1721185
commit 0790bd77b7
3 changed files with 70 additions and 40 deletions

View file

@ -110,10 +110,13 @@ void renderReticle(glm::quat orientation, float alpha) {
glm::vec3 axis = glm::axis(orientation);
glRotatef(glm::degrees(glm::angle(orientation)), axis.x, axis.y, axis.z);
glm::vec3 topLeft = getPoint(reticleSize / 2.0f, -reticleSize / 2.0f);
glm::vec3 topRight = getPoint(-reticleSize / 2.0f, -reticleSize / 2.0f);
glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f);
glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f);
glm::vec2 texCoordTopLeft(0.0f, 0.0f);
glm::vec2 texCoordBottomRight(1.0f, 1.0f);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomLeft, bottomRight, topRight,
glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f),
glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f));
} glPopMatrix();
}
@ -363,11 +366,12 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as
GLfloat y = -halfQuadHeight;
glDisable(GL_DEPTH_TEST);
glm::vec3 topLeft(x, y + quadHeight, -distance);
glm::vec3 bottomRight(x + quadWidth, y, -distance);
glm::vec2 texCoordTopLeft(0.0f, 1.0f);
glm::vec2 texCoordBottomRight(1.0f, 0.0f);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
DependencyManager::get<GeometryCache>()->renderQuad(glm::vec3(x, y + quadHeight, -distance),
glm::vec3(x + quadWidth, y + quadHeight, -distance),
glm::vec3(x + quadWidth, y, -distance),
glm::vec3(x, y, -distance),
glm::vec2(0.0f, 1.0f), glm::vec2(1.0f, 1.0f),
glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 0.0f));
GLCanvas::SharedPointer glCanvas = DependencyManager::get<GLCanvas>();
if (_crosshairTexture == 0) {
@ -385,12 +389,13 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as
glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
glm::vec3 reticleTopLeft(x + mouseX, y + mouseY, -distance);
glm::vec3 reticleBottomRight(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance);
glm::vec2 reticleTexCoordTopLeft(0.0f, 0.0f);
glm::vec2 reticleTexCoordBottomRight(1.0f, 1.0f);
DependencyManager::get<GeometryCache>()->renderQuad(reticleTopLeft, reticleBottomRight, reticleTexCoordTopLeft, reticleTexCoordBottomRight);
DependencyManager::get<GeometryCache>()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance),
glm::vec3(x + mouseX + reticleSize, y + mouseY, -distance),
glm::vec3(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance),
glm::vec3(x + mouseX, y + mouseY - reticleSize, -distance),
glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f),
glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f));
glEnable(GL_DEPTH_TEST);
glPopMatrix();
@ -736,13 +741,13 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool
glEnable(GL_TEXTURE_2D);
}
glColor4f(1.0f, 1.0f, 1.0f, _alpha);
DependencyManager::get<GeometryCache>()->renderQuad(bottomLeft, bottomRight, topRight, topLeft,
glm::vec2(magnifyULeft, magnifyVBottom),
glm::vec2(magnifyURight, magnifyVBottom),
glm::vec2(magnifyURight, magnifyVTop),
glm::vec2(magnifyULeft, magnifyVTop));
glBegin(GL_QUADS); {
glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
glTexCoord2f(magnifyURight, magnifyVBottom); glVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
glTexCoord2f(magnifyURight, magnifyVTop); glVertex3f(topRight.x, topRight.y, topRight.z);
glTexCoord2f(magnifyULeft, magnifyVTop); glVertex3f(topLeft.x, topLeft.y, topLeft.z);
} glEnd();
} glPopMatrix();
}

View file

@ -699,7 +699,9 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
delete[] indexData;
qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
#ifdef WANT_DEBUG
qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
#endif
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
@ -767,7 +769,9 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
delete[] indexData;
qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
#ifdef WANT_DEBUG
qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
#endif
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
@ -833,7 +837,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
delete[] indexData;
qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
#ifdef WANT_DEBUG
qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
#endif
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
@ -849,8 +855,20 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
}
void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) {
void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft,
const glm::vec3& bottomRight, const glm::vec3& topRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight) {
#ifdef WANT_DEBUG
qDebug() << "renderQuad() vec3 + texture VBO...";
qDebug() << " topLeft:" << topLeft;
qDebug() << " bottomLeft:" << bottomLeft;
qDebug() << " bottomRight:" << bottomRight;
qDebug() << " topRight:" << topRight;
qDebug() << " texCoordTopLeft:" << texCoordTopLeft;
qDebug() << " texCoordBottomRight:" << texCoordBottomRight;
#endif //def WANT_DEBUG
Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
@ -872,11 +890,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
vertex[v++] = texCoordTopLeft.x;
vertex[v++] = texCoordTopLeft.y;
vertex[v++] = bottomRight.x;
vertex[v++] = topLeft.y;
vertex[v++] = topLeft.z;
vertex[v++] = texCoordBottomRight.x;
vertex[v++] = texCoordTopLeft.y;
vertex[v++] = bottomLeft.x;
vertex[v++] = bottomLeft.y;
vertex[v++] = bottomLeft.z;
vertex[v++] = texCoordBottomLeft.x;
vertex[v++] = texCoordBottomLeft.y;
vertex[v++] = bottomRight.x;
vertex[v++] = bottomRight.y;
@ -884,11 +902,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
vertex[v++] = texCoordBottomRight.x;
vertex[v++] = texCoordBottomRight.y;
vertex[v++] = topLeft.x;
vertex[v++] = bottomRight.y;
vertex[v++] = bottomRight.z;
vertex[v++] = texCoordTopLeft.x;
vertex[v++] = texCoordBottomRight.y;
vertex[v++] = topRight.x;
vertex[v++] = topRight.y;
vertex[v++] = topRight.z;
vertex[v++] = texCoordTopRight.x;
vertex[v++] = texCoordTopRight.y;
glGenBuffers(1, &vbo.first);
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
@ -905,8 +923,10 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
delete[] indexData;
qDebug() << "new quad + texture VBO made -- _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
#ifdef WANT_DEBUG
qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
#endif
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
@ -914,7 +934,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0);
glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0);
glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float)));
glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);

View file

@ -100,8 +100,13 @@ public:
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight);
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight);
//void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight,
// const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight);
void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft,
const glm::vec3& bottomRight, const glm::vec3& topRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight);
/// Loads geometry from the specified URL.
/// \param fallback a fallback URL to load if the desired one is unavailable