From 2de86bfa92e74b4689f42b79e3e698f96c0300b0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 29 Mar 2013 16:22:10 -0700 Subject: [PATCH] Revert "allow the bad triangles to render" This reverts commit b5d1ae1a36b9451f64358558eb3db0a02b3d0831. --- interface/src/VoxelSystem.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 1b2cbfb511..6f859e2c8a 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -107,7 +107,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { void VoxelSystem::copyWrittenDataToReadArrays() { // lock on the buffer write lock so we can't modify the data when the GPU is reading it - + pthread_mutex_lock(&bufferWriteLock); // store a pointer to the current end so it doesn't change during copy GLfloat *endOfCurrentVerticesData = writeVerticesEndPointer; // copy the vertices and colors @@ -116,6 +116,7 @@ void VoxelSystem::copyWrittenDataToReadArrays() { // set the read vertices end pointer to the correct spot so the GPU knows how much to pull readVerticesEndPointer = readVerticesArray + (endOfCurrentVerticesData - writeVerticesArray); + pthread_mutex_unlock(&bufferWriteLock); } int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { @@ -232,16 +233,22 @@ void VoxelSystem::render() { if (readVerticesEndPointer != readVerticesArray) { - - glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); - glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); - glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); - - glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); - glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); - glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); - - readVerticesEndPointer = readVerticesArray; + // try to lock on the buffer write + // just avoid pulling new data if it is currently being written + if (pthread_mutex_trylock(&bufferWriteLock) == 0) { + + glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); + glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); + + glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); + glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); + + readVerticesEndPointer = readVerticesArray; + + pthread_mutex_unlock(&bufferWriteLock); + } } // tell OpenGL where to find vertex and color information