History

Revert "attempt to get color working for 3d textured quads"

This reverts commit 0f390a98b8add9b4c18f7b09d46ac0d998aec480.

ZappoMan committed 11 years ago

Commit 87e91a51 parent 0f390a93 files · +87 −107Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 3 files). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+81−74
@@ -1254,9 +1254,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 1253 unmodified lines
12541254 const glm::vec3& bottomRight, const glm::vec3& topRight,
12551255 const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
12561256 const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight,
1257− const glm::vec4& color, int id) {
1257+ const glm::vec4& quadColor, int id) {
12581258
1259− #if 1 // def WANT_DEBUG
1259+ #ifdef WANT_DEBUG
12601260 qDebug() << "renderQuad() vec3 + texture VBO...";
12611261 qDebug() << " topLeft:" << topLeft;
12621262 qDebug() << " bottomLeft:" << bottomLeft;
@@ -1264,99 +1264,106 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 1 unmodified line
12641264 qDebug() << " topRight:" << topRight;
12651265 qDebug() << " texCoordTopLeft:" << texCoordTopLeft;
12661266 qDebug() << " texCoordBottomRight:" << texCoordBottomRight;
1267− qDebug() << " color:" << color;
12681267 #endif //def WANT_DEBUG
12691268
1270− bool registered = (id != UNKNOWN_ID);
1271− Vec3PairVec4Pair key(Vec3Pair(topLeft, bottomRight),
1272− Vec4Pair(glm::vec4(texCoordTopLeft.x,texCoordTopLeft.y,texCoordBottomRight.x,texCoordBottomRight.y),
1273− color));
1274−
1275− BatchItemDetails& details = registered ? _registeredQuad3DTextures[id] : _quad3DTextures[key];
1276−
1269+ bool registeredQuad = (id != UNKNOWN_ID);
1270+ Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
1271+ VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DTextureVBOs[key];
1272+
12771273 // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed
1278− if (registered && details.isCreated) {
1279− Vec3PairVec4Pair& lastKey = _lastRegisteredQuad3DTexture[id];
1274+ if (registeredQuad && vbo.first != 0) {
1275+ Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[id];
12801276 if (lastKey != key) {
1281− details.clear();
1282− _lastRegisteredQuad3DTexture[id] = key;
1277+ glDeleteBuffers(1, &vbo.first);
1278+ glDeleteBuffers(1, &vbo.second);
1279+ vbo.first = vbo.second = 0;
12831280 #ifdef WANT_DEBUG
1284− qDebug() << "renderQuad() 3D+texture ... RELEASING REGISTERED";
1281+ qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD";
12851282 #endif // def WANT_DEBUG
12861283 }
12871284 #ifdef WANT_DEBUG
12881285 else {
1289− qDebug() << "renderQuad() 3D+texture ... REUSING PREVIOUSLY REGISTERED";
1286+ qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD";
12901287 }
12911288 #endif // def WANT_DEBUG
12921289 }
1293−
1294− const int FLOATS_PER_VERTEX = 3 + 2; // 3d vertices + text coords
1295− const int vertices = 4;
1296− const int NUM_POS_COORDS = 3;
1297− const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float);
1298−
1299− if (!details.isCreated) {
1300−
1301− details.isCreated = true;
1302− details.vertices = vertices;
1303− details.vertexSize = FLOATS_PER_VERTEX; // NOTE: this isn't used for BatchItemDetails maybe we can get rid of it
1304−
1305− gpu::BufferPointer verticesBuffer(new gpu::Buffer());
1306− gpu::BufferPointer colorBuffer(new gpu::Buffer());
1307− gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format());
1308− gpu::BufferStreamPointer stream(new gpu::BufferStream());
1309−
1310− details.verticesBuffer = verticesBuffer;
1311− details.colorBuffer = colorBuffer;
1312− details.streamFormat = streamFormat;
1313− details.stream = stream;
13141290
1315− details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0);
1316− details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET);
1317− details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA));
1318−
1319− details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride);
1320− details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride);
1321−
1322−
1323− float vertexBuffer[vertices * FLOATS_PER_VERTEX] = {
1324− topLeft.x, topLeft.y, topLeft.z, texCoordTopLeft.x, texCoordTopLeft.y,
1325− bottomLeft.x, bottomLeft.y, bottomLeft.z, texCoordBottomLeft.x, texCoordBottomLeft.y,
1326− bottomRight.x, bottomRight.y, bottomRight.z, texCoordBottomRight.x, texCoordBottomRight.y,
1327− topRight.x, topRight.y, topRight.z, texCoordTopRight.x, texCoordTopRight.y,
1328− };
1329−
1330− const int NUM_COLOR_SCALARS_PER_QUAD = 4;
1331− int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
1332− ((int(color.y * 255.0f) & 0xFF) << 8) |
1333− ((int(color.z * 255.0f) & 0xFF) << 16) |
1334− ((int(color.w * 255.0f) & 0xFF) << 24);
1335− int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor };
1336−
1291+ const int FLOATS_PER_VERTEX = 5; // text coords & vertices
1292+ const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
1293+ const int vertices = 4;
1294+ const int indices = 4;
1295+ if (vbo.first == 0) {
1296+ _lastRegisteredQuad3DTexture[id] = key;
1297+ int vertexPoints = vertices * FLOATS_PER_VERTEX;
1298+ GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
1299+ GLfloat* vertex = vertexData;
1300+ static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3};
1301+ int v = 0;
1302+
1303+ vertex[v++] = topLeft.x;
1304+ vertex[v++] = topLeft.y;
1305+ vertex[v++] = topLeft.z;
1306+ vertex[v++] = texCoordTopLeft.x;
1307+ vertex[v++] = texCoordTopLeft.y;
1308+
1309+ vertex[v++] = bottomLeft.x;
1310+ vertex[v++] = bottomLeft.y;
1311+ vertex[v++] = bottomLeft.z;
1312+ vertex[v++] = texCoordBottomLeft.x;
1313+ vertex[v++] = texCoordBottomLeft.y;
1314+
1315+ vertex[v++] = bottomRight.x;
1316+ vertex[v++] = bottomRight.y;
1317+ vertex[v++] = bottomRight.z;
1318+ vertex[v++] = texCoordBottomRight.x;
1319+ vertex[v++] = texCoordBottomRight.y;
1320+
1321+ vertex[v++] = topRight.x;
1322+ vertex[v++] = topRight.y;
1323+ vertex[v++] = topRight.z;
1324+ vertex[v++] = texCoordTopRight.x;
1325+ vertex[v++] = texCoordTopRight.y;
1326+
1327+ glGenBuffers(1, &vbo.first);
1328+ glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
1329+ glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
1330+ delete[] vertexData;
1331+
1332+ GLushort* indexData = new GLushort[indices];
1333+ GLushort* index = indexData;
1334+ for (int i = 0; i < indices; i++) {
1335+ index[i] = cannonicalIndices[i];
1336+ }
1337+
1338+ glGenBuffers(1, &vbo.second);
1339+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
1340+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
1341+ delete[] indexData;
13371342
1338− details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer);
1339− details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors);
1343+ #ifdef WANT_DEBUG
1344+ if (id == UNKNOWN_ID) {
1345+ qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
1346+ } else {
1347+ qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
1348+ }
1349+ #endif
1350+ } else {
1351+ glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
1352+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
13401353 }
13411354
1342− gpu::Batch batch;
1343−
1344− glEnable(GL_TEXTURE_2D);
1345− //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific...
1346−
1347− batch.setInputFormat(details.streamFormat);
1348− batch.setInputStream(0, *details.stream);
1349− batch.draw(gpu::QUADS, 4, 0);
1355+ glEnableClientState(GL_VERTEX_ARRAY);
1356+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1357+ glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0);
1358+ glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float)));
13501359
1351− gpu::GLBackend::renderBatch(batch);
1360+ glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
13521361
13531362 glDisableClientState(GL_VERTEX_ARRAY);
13541363 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1355− glDisableClientState(GL_COLOR_ARRAY);
1356−
1364+
13571365 glBindBuffer(GL_ARRAY_BUFFER, 0);
1358− glBindTexture(GL_TEXTURE_2D, 0);
1359− glDisable(GL_TEXTURE_2D);
1366+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
13601367 }
13611368
13621369 void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t