Showing the changes to interface/src/VoxelSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -107,7 +107,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 106 unmodified lines | |||
| 107 | 107 | ||
| 108 | void VoxelSystem::copyWrittenDataToReadArrays() { | 108 | void VoxelSystem::copyWrittenDataToReadArrays() { |
| 109 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it | 109 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it |
| 110 | pthread_mutex_lock(&bufferWriteLock); | 110 | |
| 111 | // store a pointer to the current end so it doesn't change during copy | 111 | // store a pointer to the current end so it doesn't change during copy |
| 112 | GLfloat *endOfCurrentVerticesData = writeVerticesEndPointer; | 112 | GLfloat *endOfCurrentVerticesData = writeVerticesEndPointer; |
| 113 | // copy the vertices and colors | 113 | // copy the vertices and colors |
| @@ -116,7 +116,6 @@ void VoxelSystem::copyWrittenDataToReadArrays() { · 2 unmodified lines | |||
| 116 | 116 | ||
| 117 | // set the read vertices end pointer to the correct spot so the GPU knows how much to pull | 117 | // set the read vertices end pointer to the correct spot so the GPU knows how much to pull |
| 118 | readVerticesEndPointer = readVerticesArray + (endOfCurrentVerticesData - writeVerticesArray); | 118 | readVerticesEndPointer = readVerticesArray + (endOfCurrentVerticesData - writeVerticesArray); |
| 119 | pthread_mutex_unlock(&bufferWriteLock); | ||
| 120 | } | 119 | } |
| 121 | 120 | ||
| 122 | int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { | 121 | int VoxelSystem::treeToArrays(VoxelNode *currentNode, float nodePosition[3]) { |
| @@ -233,22 +232,16 @@ void VoxelSystem::render() { · 110 unmodified lines | |||
| 233 | 232 | ||
| 234 | 233 | ||
| 235 | if (readVerticesEndPointer != readVerticesArray) { | 234 | if (readVerticesEndPointer != readVerticesArray) { |
| 236 | // try to lock on the buffer write | 235 | |
| 237 | // just avoid pulling new data if it is currently being written | 236 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 238 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { | 237 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 239 | 238 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); | |
| 240 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 239 | |
| 241 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 240 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 242 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); | 241 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 243 | 242 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); | |
| 244 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 243 | |
| 245 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 244 | readVerticesEndPointer = readVerticesArray; |
| 246 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); | ||
| 247 | |||
| 248 | readVerticesEndPointer = readVerticesArray; | ||
| 249 | |||
| 250 | pthread_mutex_unlock(&bufferWriteLock); | ||
| 251 | } | ||
| 252 | } | 245 | } |
| 253 | 246 | ||
| 254 | // tell OpenGL where to find vertex and color information | 247 | // tell OpenGL where to find vertex and color information |