Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 8 files). Show all
Unified · Split
| @@ -765,7 +765,6 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, · 764 unmodified lines | ||
| 765 | 765 | |
| 766 | 766 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 767 | 767 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 768 | − | |
| 769 | 768 | } |
| 770 | 769 | |
| 771 | 770 | void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id) { |
| @@ -1153,6 +1152,176 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 381 unmodified lines | ||
| 1153 | 1152 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1154 | 1153 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 1155 | 1154 | } |
| 1155 | + | |
| 1156 | +void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) { | |
| 1157 | + bool registeredLine = (id != UNKNOWN_ID); | |
| 1158 | + Vec3Pair key(p1, p2); | |
| 1159 | + VerticesIndices& vbo = registeredLine ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; | |
| 1160 | + | |
| 1161 | + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed | |
| 1162 | + if (registeredLine && vbo.first != 0) { | |
| 1163 | + Vec3Pair& lastKey = _lastRegisteredLine3D[id]; | |
| 1164 | + if (lastKey != key) { | |
| 1165 | + glDeleteBuffers(1, &vbo.first); | |
| 1166 | + glDeleteBuffers(1, &vbo.second); | |
| 1167 | + vbo.first = vbo.second = 0; | |
| 1168 | + #if 1 // def WANT_DEBUG | |
| 1169 | + qDebug() << "renderLine() 3D ... RELEASING REGISTERED line"; | |
| 1170 | + #endif // def WANT_DEBUG | |
| 1171 | + } | |
| 1172 | + #if 1 // def WANT_DEBUG | |
| 1173 | + else { | |
| 1174 | + qDebug() << "renderLine() 3D ... REUSING PREVIOUSLY REGISTERED line"; | |
| 1175 | + } | |
| 1176 | + #endif // def WANT_DEBUG | |
| 1177 | + } | |
| 1178 | + | |
| 1179 | + const int FLOATS_PER_VERTEX = 3; | |
| 1180 | + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | |
| 1181 | + const int vertices = 2; | |
| 1182 | + const int indices = 2; | |
| 1183 | + if (vbo.first == 0) { | |
| 1184 | + _lastRegisteredLine3D[id] = key; | |
| 1185 | + | |
| 1186 | + int vertexPoints = vertices * FLOATS_PER_VERTEX; | |
| 1187 | + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad | |
| 1188 | + GLfloat* vertex = vertexData; | |
| 1189 | + static GLubyte cannonicalIndices[indices] = {0, 1}; | |
| 1190 | + | |
| 1191 | + int vertexPoint = 0; | |
| 1192 | + | |
| 1193 | + // p1 | |
| 1194 | + vertex[vertexPoint++] = p1.x; | |
| 1195 | + vertex[vertexPoint++] = p1.y; | |
| 1196 | + vertex[vertexPoint++] = p1.z; | |
| 1197 | + | |
| 1198 | + // p2 | |
| 1199 | + vertex[vertexPoint++] = p2.x; | |
| 1200 | + vertex[vertexPoint++] = p2.y; | |
| 1201 | + vertex[vertexPoint++] = p2.z; | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + glGenBuffers(1, &vbo.first); | |
| 1205 | + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 1206 | + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); | |
| 1207 | + delete[] vertexData; | |
| 1208 | + | |
| 1209 | + GLushort* indexData = new GLushort[indices]; | |
| 1210 | + GLushort* index = indexData; | |
| 1211 | + for (int i = 0; i < indices; i++) { | |
| 1212 | + index[i] = cannonicalIndices[i]; | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + glGenBuffers(1, &vbo.second); | |
| 1216 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 1217 | + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); | |
| 1218 | + delete[] indexData; | |
| 1219 | + | |
| 1220 | + #if 1 // def WANT_DEBUG | |
| 1221 | + if (id == UNKNOWN_ID) { | |
| 1222 | + qDebug() << "new renderLine() 3D VBO made -- _line3DVBOs.size():" << _line3DVBOs.size(); | |
| 1223 | + } else { | |
| 1224 | + qDebug() << "new registered renderLine() 3D VBO made -- _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); | |
| 1225 | + } | |
| 1226 | + #endif | |
| 1227 | + | |
| 1228 | + } else { | |
| 1229 | + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 1230 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 1231 | + } | |
| 1232 | + glEnableClientState(GL_VERTEX_ARRAY); | |
| 1233 | + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); | |
| 1234 | + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); | |
| 1235 | + glDisableClientState(GL_VERTEX_ARRAY); | |
| 1236 | + | |
| 1237 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 1238 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 1239 | +} | |
| 1240 | + | |
| 1241 | +void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) { | |
| 1242 | + bool registeredLine = (id != UNKNOWN_ID); | |
| 1243 | + Vec2Pair key(p1, p2); | |
| 1244 | + VerticesIndices& vbo = registeredLine ? _registeredLine2DVBOs[id] : _line2DVBOs[key]; | |
| 1245 | + | |
| 1246 | + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed | |
| 1247 | + if (registeredLine && vbo.first != 0) { | |
| 1248 | + Vec2Pair& lastKey = _lastRegisteredLine2D[id]; | |
| 1249 | + if (lastKey != key) { | |
| 1250 | + glDeleteBuffers(1, &vbo.first); | |
| 1251 | + glDeleteBuffers(1, &vbo.second); | |
| 1252 | + vbo.first = vbo.second = 0; | |
| 1253 | + #if 1 // def WANT_DEBUG | |
| 1254 | + qDebug() << "renderLine() 2D... RELEASING REGISTERED line"; | |
| 1255 | + #endif // def WANT_DEBUG | |
| 1256 | + } | |
| 1257 | + #if 1 // def WANT_DEBUG | |
| 1258 | + else { | |
| 1259 | + qDebug() << "renderLine() 2D... REUSING PREVIOUSLY REGISTERED line"; | |
| 1260 | + } | |
| 1261 | + #endif // def WANT_DEBUG | |
| 1262 | + } | |
| 1263 | + | |
| 1264 | + const int FLOATS_PER_VERTEX = 2; | |
| 1265 | + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | |
| 1266 | + const int vertices = 2; | |
| 1267 | + const int indices = 2; | |
| 1268 | + if (vbo.first == 0) { | |
| 1269 | + _lastRegisteredLine2D[id] = key; | |
| 1270 | + | |
| 1271 | + int vertexPoints = vertices * FLOATS_PER_VERTEX; | |
| 1272 | + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad | |
| 1273 | + GLfloat* vertex = vertexData; | |
| 1274 | + static GLubyte cannonicalIndices[indices] = {0, 1}; | |
| 1275 | + | |
| 1276 | + int vertexPoint = 0; | |
| 1277 | + | |
| 1278 | + // p1 | |
| 1279 | + vertex[vertexPoint++] = p1.x; | |
| 1280 | + vertex[vertexPoint++] = p1.y; | |
| 1281 | + | |
| 1282 | + // p2 | |
| 1283 | + vertex[vertexPoint++] = p2.x; | |
| 1284 | + vertex[vertexPoint++] = p2.y; | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + glGenBuffers(1, &vbo.first); | |
| 1288 | + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 1289 | + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); | |
| 1290 | + delete[] vertexData; | |
| 1291 | + | |
| 1292 | + GLushort* indexData = new GLushort[indices]; | |
| 1293 | + GLushort* index = indexData; | |
| 1294 | + for (int i = 0; i < indices; i++) { | |
| 1295 | + index[i] = cannonicalIndices[i]; | |
| 1296 | + } | |
| 1297 | + | |
| 1298 | + glGenBuffers(1, &vbo.second); | |
| 1299 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 1300 | + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); | |
| 1301 | + delete[] indexData; | |
| 1302 | + | |
| 1303 | + #if 1 // def WANT_DEBUG | |
| 1304 | + if (id == UNKNOWN_ID) { | |
| 1305 | + qDebug() << "new renderLine() 2D VBO made -- _line2DVBOs.size():" << _line2DVBOs.size(); | |
| 1306 | + } else { | |
| 1307 | + qDebug() << "new registered renderLine() 2D VBO made -- _registeredLine2DVBOs.size():" << _registeredLine2DVBOs.size(); | |
| 1308 | + } | |
| 1309 | + #endif | |
| 1310 | + | |
| 1311 | + } else { | |
| 1312 | + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 1313 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 1314 | + } | |
| 1315 | + glEnableClientState(GL_VERTEX_ARRAY); | |
| 1316 | + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); | |
| 1317 | + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); | |
| 1318 | + glDisableClientState(GL_VERTEX_ARRAY); | |
| 1319 | + | |
| 1320 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 1321 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 1322 | +} | |
| 1323 | + | |
| 1324 | + | |
| 1156 | 1325 | QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { |
| 1157 | 1326 | return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>(); |
| 1158 | 1327 | } |