more work on removing immediate mode GL_QUADS

This commit is contained in:
ZappoMan 2014-12-22 17:43:02 -08:00
parent 14458ac8fd
commit 3d42d532e4
9 changed files with 147 additions and 132 deletions

View file

@ -1306,21 +1306,13 @@ void Audio::renderToolBox(int x, int y, bool boxed) {
} else {
glColor3f(0.41f, 0.41f, 0.41f);
}
glBegin(GL_QUADS);
glTexCoord2f(1, 1);
glVertex2f(boxBounds.left(), boxBounds.top());
glTexCoord2f(0, 1);
glVertex2f(boxBounds.right(), boxBounds.top());
glTexCoord2f(0, 0);
glVertex2f(boxBounds.right(), boxBounds.bottom());
glTexCoord2f(1, 0);
glVertex2f(boxBounds.left(), boxBounds.bottom());
glEnd();
glm::vec2 topLeft(boxBounds.left(), boxBounds.top());
glm::vec2 bottomRight(boxBounds.right(), boxBounds.bottom());
glm::vec2 texCoordTopLeft(1,1);
glm::vec2 texCoordBottomRight(0,0);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
}
_iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
@ -1345,21 +1337,14 @@ void Audio::renderToolBox(int x, int y, bool boxed) {
}
glColor3f(_iconColor, _iconColor, _iconColor);
glBegin(GL_QUADS);
glm::vec2 topLeft(_iconBounds.left(), _iconBounds.top());
glm::vec2 bottomRight(_iconBounds.right(), _iconBounds.bottom());
glm::vec2 texCoordTopLeft(1,1);
glm::vec2 texCoordBottomRight(0,0);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(_iconBounds.left(), _iconBounds.top());
glTexCoord2f(0.0f, 1.0f);
glVertex2f(_iconBounds.right(), _iconBounds.top());
glTexCoord2f(0.0f, 0.0f);
glVertex2f(_iconBounds.right(), _iconBounds.bottom());
glTexCoord2f(1.0f, 0.0f);
glVertex2f(_iconBounds.left(), _iconBounds.bottom());
glEnd();
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
glDisable(GL_TEXTURE_2D);
}

View file

@ -633,17 +633,14 @@ void Avatar::renderBillboard() {
glScalef(size, size, size);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1.0f, 1.0f);
glEnd();
glm::vec2 topLeft(-1.0f, -1.0f);
glm::vec2 bottomRight(1.0f, 1.0f);
glm::vec2 texCoordTopLeft(0.0f, 0.0f);
glm::vec2 texCoordBottomRight(1.0f, 1.0f);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
glPopMatrix();

View file

@ -229,13 +229,14 @@ void ApplicationOverlay::displayOverlayTexture() {
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBegin(GL_QUADS); {
glColor4f(1.0f, 1.0f, 1.0f, _alpha);
glTexCoord2f(0, 0); glVertex2i(0, glCanvas->getDeviceHeight());
glTexCoord2f(1, 0); glVertex2i(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
glTexCoord2f(1, 1); glVertex2i(glCanvas->getDeviceWidth(), 0);
glTexCoord2f(0, 1); glVertex2i(0, 0);
} glEnd();
glColor4f(1.0f, 1.0f, 1.0f, _alpha);
glm::vec2 topLeft(0.0f, 0.0f);
glm::vec2 bottomRight(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
glm::vec2 texCoordTopLeft(0.0f, 1.0f);
glm::vec2 texCoordBottomRight(1.0f, 0.0f);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
} glPopMatrix();
glDisable(GL_TEXTURE_2D);
@ -658,16 +659,16 @@ void ApplicationOverlay::renderControllerPointers() {
mouseX -= reticleSize / 2.0f;
mouseY += reticleSize / 2.0f;
glBegin(GL_QUADS);
glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
glTexCoord2d(0.0f, 0.0f); glVertex2i(mouseX, mouseY);
glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + reticleSize, mouseY);
glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + reticleSize, mouseY - reticleSize);
glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - reticleSize);
glm::vec2 topLeft(mouseX, mouseY);
glm::vec2 bottomRight(mouseX + reticleSize, mouseY - reticleSize);
glm::vec2 texCoordTopLeft(0.0f, 0.0f);
glm::vec2 texCoordBottomRight(1.0f, 1.0f);
glEnd();
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
}
}
@ -862,8 +863,6 @@ void ApplicationOverlay::renderAudioMeter() {
audioLevel = AUDIO_RED_START;
}
//glBegin(GL_QUADS);
if (audioLevel > AUDIO_GREEN_START) {
if (!isClipping) {
glColor3fv(AUDIO_METER_GREEN);

View file

@ -140,22 +140,14 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture
}
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(iconBounds.left(), iconBounds.bottom());
glTexCoord2f(0, 1);
glVertex2f(iconBounds.left(), iconBounds.top());
glTexCoord2f(1, 1);
glVertex2f(iconBounds.right(), iconBounds.top());
glTexCoord2f(1, 0);
glVertex2f(iconBounds.right(), iconBounds.bottom());
}
glEnd();
glm::vec2 topLeft(iconBounds.left(), iconBounds.top());
glm::vec2 bottomRight(iconBounds.right(), iconBounds.bottom());
glm::vec2 texCoordTopLeft(0.0f, 1.0f);
glm::vec2 texCoordBottomRight(1.0f, 0.0f);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

View file

@ -96,21 +96,16 @@ void BillboardOverlay::render(RenderArgs* args) {
xColor color = getColor();
float alpha = getAlpha();
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
glBegin(GL_QUADS); {
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
(float)_fromImage.y() / (float)_size.height());
glm::vec2 topLeft(-x, -y);
glm::vec2 bottomRight(x, y);
glm::vec2 texCoordTopLeft((float)_fromImage.x() / (float)_size.width(),
(float)_fromImage.y() / (float)_size.height());
glm::vec2 texCoordBottomRight(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
glVertex2f(-x, -y);
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
(float)_fromImage.y() / (float)_size.height());
glVertex2f(x, -y);
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
glVertex2f(x, y);
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
glVertex2f(-x, y);
} glEnd();
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
}
} glPopMatrix();

View file

@ -14,6 +14,9 @@
#include <QGLWidget>
#include <QPainter>
#include <QSvgRenderer>
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <SharedUtil.h>
#include "ImageOverlay.h"
@ -105,27 +108,16 @@ void ImageOverlay::render(RenderArgs* args) {
int top = _bounds.top();
int bottom = _bounds.bottom() + 1;
glBegin(GL_QUADS);
if (_renderImage) {
glTexCoord2f(x, 1.0f - y);
}
glVertex2f(left, top);
glm::vec2 topLeft(left, top);
glm::vec2 bottomRight(right, bottom);
glm::vec2 texCoordTopLeft(x, 1.0f - y);
glm::vec2 texCoordBottomRight(x + w, 1.0f - (y + h));
if (_renderImage) {
glTexCoord2f(x + w, 1.0f - y);
}
glVertex2f(right, top);
if (_renderImage) {
glTexCoord2f(x + w, 1.0f - (y + h));
}
glVertex2f(right, bottom);
if (_renderImage) {
glTexCoord2f(x, 1.0f - (y + h));
}
glVertex2f(left, bottom);
glEnd();
if (_renderImage) {
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
} else {
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight);
}
if (_renderImage) {
glDisable(GL_TEXTURE_2D);

View file

@ -665,22 +665,15 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
Vec2Pair key(topLeft, bottomRight);
VerticesIndices& vbo = _quad2DVBOs[key];
const int FLOATS_PER_VERTEX = 2;
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
const int vertices = 4;
const int indices = 4;
if (vbo.first == 0) {
int vertexPoints = vertices * FLOATS_PER_VERTEX;
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
GLfloat* vertex = vertexData;
// index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge
static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 };
//glBegin(GL_QUADS);
// glVertex2f(left, top);
// glVertex2f(right, top);
// glVertex2f(right, bottom);
// glVertex2f(left, bottom);
//glEnd();
vertex[0] = topLeft.x;
vertex[1] = topLeft.y;
vertex[2] = bottomRight.x;
@ -722,12 +715,77 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
}
/*
void GeometryCache::renderQuad(cont glm::vec2& topLeft, cont glm::vec2& bottomRight,
cont glm::vec2& texCoordTopLeft, cont glm::vec2& texCoordBottomRight) {
}
*/
void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) {
Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
VerticesIndices& vbo = _quad2DTextureVBOs[key];
const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices
const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
const int vertices = 4;
const int indices = 4;
if (vbo.first == 0) {
int vertexPoints = vertices * FLOATS_PER_VERTEX;
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
GLfloat* vertex = vertexData;
static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 };
int v = 0;
vertex[v++] = topLeft.x;
vertex[v++] = topLeft.y;
vertex[v++] = texCoordTopLeft.x;
vertex[v++] = texCoordTopLeft.y;
vertex[v++] = bottomRight.x;
vertex[v++] = topLeft.y;
vertex[v++] = texCoordBottomRight.x;
vertex[v++] = texCoordTopLeft.y;
vertex[v++] = bottomRight.x;
vertex[v++] = bottomRight.y;
vertex[v++] = texCoordBottomRight.x;
vertex[v++] = texCoordBottomRight.y;
vertex[v++] = topLeft.x;
vertex[v++] = bottomRight.y;
vertex[v++] = texCoordTopLeft.x;
vertex[v++] = texCoordBottomRight.y;
glGenBuffers(1, &vbo.first);
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
delete[] vertexData;
GLushort* indexData = new GLushort[indices];
GLushort* index = indexData;
for (int i = 0; i < indices; i++) {
index[i] = cannonicalIndices[i];
}
glGenBuffers(1, &vbo.second);
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 -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
} else {
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0);
glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(2 * sizeof(float)));
glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();

View file

@ -70,11 +70,9 @@ public:
void renderWireCube(float size);
void renderQuad(int x, int y, int width, int height) {
renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height));
};
void renderQuad(int x, int y, int width, int height) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height)); }
void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight);
void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight);
@ -104,7 +102,7 @@ private:
QHash<float, VerticesIndices> _wireCubeVBOs;
QHash<float, VerticesIndices> _solidCubeVBOs;
QHash<Vec2Pair, VerticesIndices> _quad2DVBOs;
//QHash<Vec2PairPair, VerticesIndices> _quad2DTextureVBOs;
QHash<Vec2PairPair, VerticesIndices> _quad2DTextureVBOs;
QHash<IntPair, QOpenGLBuffer> _gridBuffers;

View file

@ -10,17 +10,16 @@
//
#include <gpu/GPUConfig.h>
#include <DependencyManager.h>
#include "GeometryCache.h"
#include "RenderUtil.h"
void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) {
glBegin(GL_QUADS);
glTexCoord2f(sMin, tMin);
glVertex2f(-1.0f, -1.0f);
glTexCoord2f(sMax, tMin);
glVertex2f(1.0f, -1.0f);
glTexCoord2f(sMax, tMax);
glVertex2f(1.0f, 1.0f);
glTexCoord2f(sMin, tMax);
glVertex2f(-1.0f, 1.0f);
glEnd();
glm::vec2 topLeft(-1.0f, -1.0f);
glm::vec2 bottomRight(1.0f, 1.0f);
glm::vec2 texCoordTopLeft(sMin, tMin);
glm::vec2 texCoordBottomRight(sMax, tMax);
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight);
}