mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Merge pull request #4020 from ZappoMan/gpuStreamizing
Improvements to GeometryCache::renderQuad()
This commit is contained in:
commit
20d66d201e
4 changed files with 230 additions and 79 deletions
|
@ -105,7 +105,7 @@ bool raySphereIntersect(const glm::vec3 &dir, const glm::vec3 &origin, float r,
|
|||
}
|
||||
}
|
||||
|
||||
void renderReticle(glm::quat orientation, float alpha) {
|
||||
void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) {
|
||||
glPushMatrix(); {
|
||||
glm::vec3 axis = glm::axis(orientation);
|
||||
glRotatef(glm::degrees(glm::angle(orientation)), axis.x, axis.y, axis.z);
|
||||
|
@ -114,9 +114,12 @@ void renderReticle(glm::quat orientation, float alpha) {
|
|||
glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f);
|
||||
glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f);
|
||||
glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha);
|
||||
if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_reticleQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
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));
|
||||
glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), _reticleQuad);
|
||||
} glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -126,8 +129,13 @@ ApplicationOverlay::ApplicationOverlay() :
|
|||
_lastMouseMove(0),
|
||||
_alpha(1.0f),
|
||||
_oculusUIRadius(1.0f),
|
||||
_crosshairTexture(0) {
|
||||
|
||||
_crosshairTexture(0),
|
||||
_reticleQuad(GeometryCache::UNKNOWN_QUAD_ID),
|
||||
_magnifierQuad(GeometryCache::UNKNOWN_QUAD_ID),
|
||||
_audioRedQuad(GeometryCache::UNKNOWN_QUAD_ID),
|
||||
_audioGreenQuad(GeometryCache::UNKNOWN_QUAD_ID),
|
||||
_audioBlueQuad(GeometryCache::UNKNOWN_QUAD_ID)
|
||||
{
|
||||
memset(_reticleActive, 0, sizeof(_reticleActive));
|
||||
memset(_magActive, 0, sizeof(_reticleActive));
|
||||
memset(_magSizeMult, 0, sizeof(_magSizeMult));
|
||||
|
@ -389,12 +397,17 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as
|
|||
|
||||
glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]);
|
||||
|
||||
if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_reticleQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
|
||||
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));
|
||||
glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f),
|
||||
_reticleQuad);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
@ -696,7 +709,7 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) {
|
|||
}
|
||||
|
||||
//Renders a small magnification of the currently bound texture at the coordinates
|
||||
void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const {
|
||||
void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) {
|
||||
GLCanvas::SharedPointer glCanvas = DependencyManager::get<GLCanvas>();
|
||||
|
||||
const int widgetWidth = glCanvas->width();
|
||||
|
@ -742,11 +755,16 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool
|
|||
}
|
||||
glColor4f(1.0f, 1.0f, 1.0f, _alpha);
|
||||
|
||||
if (_magnifierQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_magnifierQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(bottomLeft, bottomRight, topRight, topLeft,
|
||||
glm::vec2(magnifyULeft, magnifyVBottom),
|
||||
glm::vec2(magnifyURight, magnifyVBottom),
|
||||
glm::vec2(magnifyURight, magnifyVTop),
|
||||
glm::vec2(magnifyULeft, magnifyVTop));
|
||||
glm::vec2(magnifyULeft, magnifyVTop),
|
||||
_magnifierQuad);
|
||||
|
||||
} glPopMatrix();
|
||||
}
|
||||
|
@ -845,10 +863,14 @@ void ApplicationOverlay::renderAudioMeter() {
|
|||
glColor3f(1, 1, 1);
|
||||
}
|
||||
// Draw Red Quad
|
||||
if (_audioRedQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_audioRedQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START,
|
||||
audioMeterY + AUDIO_METER_INSET,
|
||||
audioLevel - AUDIO_RED_START,
|
||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET);
|
||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET,
|
||||
_audioRedQuad);
|
||||
|
||||
audioLevel = AUDIO_RED_START;
|
||||
}
|
||||
|
@ -860,10 +882,14 @@ void ApplicationOverlay::renderAudioMeter() {
|
|||
glColor3f(1, 1, 1);
|
||||
}
|
||||
// Draw Green Quad
|
||||
if (_audioGreenQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_audioGreenQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START,
|
||||
audioMeterY + AUDIO_METER_INSET,
|
||||
audioLevel - AUDIO_GREEN_START,
|
||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET);
|
||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET,
|
||||
_audioGreenQuad);
|
||||
|
||||
audioLevel = AUDIO_GREEN_START;
|
||||
}
|
||||
|
@ -874,9 +900,13 @@ void ApplicationOverlay::renderAudioMeter() {
|
|||
glColor3f(1, 1, 1);
|
||||
}
|
||||
// Draw Blue (low level) quad
|
||||
if (_audioBlueQuad == GeometryCache::UNKNOWN_QUAD_ID) {
|
||||
_audioBlueQuad = DependencyManager::get<GeometryCache>()->allocateQuad();
|
||||
}
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET,
|
||||
audioMeterY + AUDIO_METER_INSET,
|
||||
audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET);
|
||||
audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET,
|
||||
_audioBlueQuad);
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderStatsAndLogs() {
|
||||
|
|
|
@ -79,8 +79,9 @@ private:
|
|||
VerticesIndices _vbo;
|
||||
};
|
||||
|
||||
void renderReticle(glm::quat orientation, float alpha);
|
||||
void renderPointers();;
|
||||
void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const;
|
||||
void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder);
|
||||
|
||||
void renderControllerPointers();
|
||||
void renderPointersOculus(const glm::vec3& eyePos);
|
||||
|
@ -106,6 +107,12 @@ private:
|
|||
float _trailingAudioLoudness;
|
||||
|
||||
GLuint _crosshairTexture;
|
||||
|
||||
int _reticleQuad;
|
||||
int _magnifierQuad;
|
||||
int _audioRedQuad;
|
||||
int _audioGreenQuad;
|
||||
int _audioBlueQuad;
|
||||
};
|
||||
|
||||
#endif // hifi_ApplicationOverlay_h
|
||||
|
|
|
@ -23,7 +23,13 @@
|
|||
#include "TextureCache.h"
|
||||
#include "GeometryCache.h"
|
||||
|
||||
GeometryCache::GeometryCache() {
|
||||
//#define WANT_DEBUG
|
||||
|
||||
const int GeometryCache::UNKNOWN_QUAD_ID = -1;
|
||||
|
||||
GeometryCache::GeometryCache() :
|
||||
_nextQuadID(0)
|
||||
{
|
||||
}
|
||||
|
||||
GeometryCache::~GeometryCache() {
|
||||
|
@ -661,27 +667,49 @@ void GeometryCache::renderWireCube(float size) {
|
|||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight) {
|
||||
Vec2Pair key(topLeft, bottomRight);
|
||||
VerticesIndices& vbo = _quad2DVBOs[key];
|
||||
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID) {
|
||||
|
||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||
Vec2Pair key(minCorner, maxCorner);
|
||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key];
|
||||
|
||||
// if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed
|
||||
if (registeredQuad && vbo.first != 0) {
|
||||
Vec2Pair& lastKey = _lastRegisteredQuad2D[quadID];
|
||||
if (lastKey != key) {
|
||||
glDeleteBuffers(1, &vbo.first);
|
||||
glDeleteBuffers(1, &vbo.second);
|
||||
vbo.first = vbo.second = 0;
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD";
|
||||
#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 NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||
const int vertices = 4;
|
||||
const int indices = 4;
|
||||
if (vbo.first == 0) {
|
||||
if (vbo.first == 0) {
|
||||
_lastRegisteredQuad2D[quadID] = key;
|
||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
|
||||
GLfloat* vertex = vertexData;
|
||||
static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
|
||||
|
||||
vertex[0] = topLeft.x;
|
||||
vertex[1] = topLeft.y;
|
||||
vertex[2] = bottomRight.x;
|
||||
vertex[3] = topLeft.y;
|
||||
vertex[4] = bottomRight.x;
|
||||
vertex[5] = bottomRight.y;
|
||||
vertex[6] = topLeft.x;
|
||||
vertex[7] = bottomRight.y;
|
||||
vertex[0] = minCorner.x;
|
||||
vertex[1] = minCorner.y;
|
||||
vertex[2] = maxCorner.x;
|
||||
vertex[3] = minCorner.y;
|
||||
vertex[4] = maxCorner.x;
|
||||
vertex[5] = maxCorner.y;
|
||||
vertex[6] = minCorner.x;
|
||||
vertex[7] = maxCorner.y;
|
||||
|
||||
glGenBuffers(1, &vbo.first);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
|
@ -700,7 +728,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
|||
delete[] indexData;
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
|
||||
if (quadID == UNKNOWN_QUAD_ID) {
|
||||
qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
|
||||
} else {
|
||||
qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
@ -717,41 +749,62 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
|||
}
|
||||
|
||||
|
||||
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));
|
||||
void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||
const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID) {
|
||||
|
||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||
Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner));
|
||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key];
|
||||
|
||||
VerticesIndices& vbo = _quad2DTextureVBOs[key];
|
||||
// if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed
|
||||
if (registeredQuad && vbo.first != 0) {
|
||||
Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[quadID];
|
||||
if (lastKey != key) {
|
||||
glDeleteBuffers(1, &vbo.first);
|
||||
glDeleteBuffers(1, &vbo.second);
|
||||
vbo.first = vbo.second = 0;
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD";
|
||||
#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 NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||
const int vertices = 4;
|
||||
const int indices = 4;
|
||||
if (vbo.first == 0) {
|
||||
if (vbo.first == 0) {
|
||||
_lastRegisteredQuad2DTexture[quadID] = key;
|
||||
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++] = minCorner.x;
|
||||
vertex[v++] = minCorner.y;
|
||||
vertex[v++] = texCoordMinCorner.x;
|
||||
vertex[v++] = texCoordMinCorner.y;
|
||||
|
||||
vertex[v++] = bottomRight.x;
|
||||
vertex[v++] = topLeft.y;
|
||||
vertex[v++] = texCoordBottomRight.x;
|
||||
vertex[v++] = texCoordTopLeft.y;
|
||||
vertex[v++] = maxCorner.x;
|
||||
vertex[v++] = minCorner.y;
|
||||
vertex[v++] = texCoordMaxCorner.x;
|
||||
vertex[v++] = texCoordMinCorner.y;
|
||||
|
||||
vertex[v++] = bottomRight.x;
|
||||
vertex[v++] = bottomRight.y;
|
||||
vertex[v++] = texCoordBottomRight.x;
|
||||
vertex[v++] = texCoordBottomRight.y;
|
||||
vertex[v++] = maxCorner.x;
|
||||
vertex[v++] = maxCorner.y;
|
||||
vertex[v++] = texCoordMaxCorner.x;
|
||||
vertex[v++] = texCoordMaxCorner.y;
|
||||
|
||||
vertex[v++] = topLeft.x;
|
||||
vertex[v++] = bottomRight.y;
|
||||
vertex[v++] = texCoordTopLeft.x;
|
||||
vertex[v++] = texCoordBottomRight.y;
|
||||
vertex[v++] = minCorner.x;
|
||||
vertex[v++] = maxCorner.y;
|
||||
vertex[v++] = texCoordMinCorner.x;
|
||||
vertex[v++] = texCoordMaxCorner.y;
|
||||
|
||||
glGenBuffers(1, &vbo.first);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
|
@ -770,7 +823,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
|||
delete[] indexData;
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
|
||||
if (quadID == UNKNOWN_QUAD_ID) {
|
||||
qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
|
||||
} else {
|
||||
qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
|
@ -791,35 +848,57 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom
|
|||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight) {
|
||||
Vec3Pair key(topLeft, bottomRight);
|
||||
VerticesIndices& vbo = _quad3DVBOs[key];
|
||||
void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID) {
|
||||
|
||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||
Vec3Pair key(minCorner, maxCorner);
|
||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key];
|
||||
|
||||
// if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed
|
||||
if (registeredQuad && vbo.first != 0) {
|
||||
Vec3Pair& lastKey = _lastRegisteredQuad3D[quadID];
|
||||
if (lastKey != key) {
|
||||
glDeleteBuffers(1, &vbo.first);
|
||||
glDeleteBuffers(1, &vbo.second);
|
||||
vbo.first = vbo.second = 0;
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD";
|
||||
#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 NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||
const int vertices = 4;
|
||||
const int indices = 4;
|
||||
if (vbo.first == 0) {
|
||||
_lastRegisteredQuad3D[quadID] = key;
|
||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // only 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++] = topLeft.z;
|
||||
vertex[v++] = minCorner.x;
|
||||
vertex[v++] = minCorner.y;
|
||||
vertex[v++] = minCorner.z;
|
||||
|
||||
vertex[v++] = bottomRight.x;
|
||||
vertex[v++] = topLeft.y;
|
||||
vertex[v++] = topLeft.z;
|
||||
vertex[v++] = maxCorner.x;
|
||||
vertex[v++] = minCorner.y;
|
||||
vertex[v++] = minCorner.z;
|
||||
|
||||
vertex[v++] = bottomRight.x;
|
||||
vertex[v++] = bottomRight.y;
|
||||
vertex[v++] = bottomRight.z;
|
||||
vertex[v++] = maxCorner.x;
|
||||
vertex[v++] = maxCorner.y;
|
||||
vertex[v++] = maxCorner.z;
|
||||
|
||||
vertex[v++] = topLeft.x;
|
||||
vertex[v++] = bottomRight.y;
|
||||
vertex[v++] = bottomRight.z;
|
||||
vertex[v++] = minCorner.x;
|
||||
vertex[v++] = maxCorner.y;
|
||||
vertex[v++] = maxCorner.z;
|
||||
|
||||
glGenBuffers(1, &vbo.first);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
|
@ -838,7 +917,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
|||
delete[] indexData;
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
|
||||
if (quadID == UNKNOWN_QUAD_ID) {
|
||||
qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
|
||||
} else {
|
||||
qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
@ -858,7 +941,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
|||
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) {
|
||||
const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID) {
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderQuad() vec3 + texture VBO...";
|
||||
|
@ -869,15 +952,35 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
|||
qDebug() << " texCoordTopLeft:" << texCoordTopLeft;
|
||||
qDebug() << " texCoordBottomRight:" << texCoordBottomRight;
|
||||
#endif //def WANT_DEBUG
|
||||
|
||||
Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
|
||||
|
||||
VerticesIndices& vbo = _quad3DTextureVBOs[key];
|
||||
bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
|
||||
Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
|
||||
VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DTextureVBOs[key];
|
||||
|
||||
// if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed
|
||||
if (registeredQuad && vbo.first != 0) {
|
||||
Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[quadID];
|
||||
if (lastKey != key) {
|
||||
glDeleteBuffers(1, &vbo.first);
|
||||
glDeleteBuffers(1, &vbo.second);
|
||||
vbo.first = vbo.second = 0;
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD";
|
||||
#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 NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
|
||||
const int vertices = 4;
|
||||
const int indices = 4;
|
||||
if (vbo.first == 0) {
|
||||
if (vbo.first == 0) {
|
||||
_lastRegisteredQuad3DTexture[quadID] = key;
|
||||
int vertexPoints = vertices * FLOATS_PER_VERTEX;
|
||||
GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
|
||||
GLfloat* vertex = vertexData;
|
||||
|
@ -925,7 +1028,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
|||
delete[] indexData;
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
|
||||
if (quadID == UNKNOWN_QUAD_ID) {
|
||||
qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
|
||||
} else {
|
||||
qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||
|
|
|
@ -90,23 +90,23 @@ public:
|
|||
void renderSolidCube(float size);
|
||||
void renderWireCube(float size);
|
||||
|
||||
int allocateQuad() { return _nextQuadID++; }
|
||||
static const int UNKNOWN_QUAD_ID;
|
||||
|
||||
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(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); }
|
||||
|
||||
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,
|
||||
const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight);
|
||||
void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner,
|
||||
const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID = UNKNOWN_QUAD_ID);
|
||||
|
||||
|
||||
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& minCorner, const glm::vec3& maxCorner, int quadID = UNKNOWN_QUAD_ID);
|
||||
|
||||
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);
|
||||
const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID = UNKNOWN_QUAD_ID);
|
||||
|
||||
/// Loads geometry from the specified URL.
|
||||
/// \param fallback a fallback URL to load if the desired one is unavailable
|
||||
|
@ -136,6 +136,13 @@ private:
|
|||
QHash<Vec2PairPair, VerticesIndices> _quad2DTextureVBOs;
|
||||
QHash<Vec3Pair, VerticesIndices> _quad3DVBOs;
|
||||
QHash<Vec3PairVec2Pair, VerticesIndices> _quad3DTextureVBOs;
|
||||
QHash<int, VerticesIndices> _registeredQuadVBOs;
|
||||
int _nextQuadID;
|
||||
|
||||
QHash<int, Vec2Pair> _lastRegisteredQuad2D;
|
||||
QHash<int, Vec2PairPair> _lastRegisteredQuad2DTexture;
|
||||
QHash<int, Vec3Pair> _lastRegisteredQuad3D;
|
||||
QHash<int, Vec3PairVec2Pair> _lastRegisteredQuad3DTexture;
|
||||
|
||||
QHash<IntPair, QOpenGLBuffer> _gridBuffers;
|
||||
|
||||
|
|
Loading…
Reference in a new issue