Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -90,6 +90,8 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 89 unmodified lines | |||
| 90 | connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int))); | 90 | connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int))); |
| 91 | 91 | ||
| 92 | _useVoxelShader = false; | 92 | _useVoxelShader = false; |
| 93 | _voxelsAsPoints = false; | ||
| 94 | _voxelShaderModeWhenVoxelsAsPointsEnabled = false; | ||
| 93 | 95 | ||
| 94 | _writeVoxelShaderData = NULL; | 96 | _writeVoxelShaderData = NULL; |
| 95 | _readVoxelShaderData = NULL; | 97 | _readVoxelShaderData = NULL; |
| @@ -219,7 +221,6 @@ void VoxelSystem::setMaxVoxels(int maxVoxels) { · 123 unmodified lines | |||
| 219 | if (maxVoxels == _maxVoxels) { | 221 | if (maxVoxels == _maxVoxels) { |
| 220 | return; | 222 | return; |
| 221 | } | 223 | } |
| 222 | pthread_mutex_lock(&_bufferWriteLock); | ||
| 223 | bool wasInitialized = _initialized; | 224 | bool wasInitialized = _initialized; |
| 224 | if (wasInitialized) { | 225 | if (wasInitialized) { |
| 225 | clearAllNodesBufferIndex(); | 226 | clearAllNodesBufferIndex(); |
| @@ -227,9 +228,8 @@ void VoxelSystem::setMaxVoxels(int maxVoxels) { · 1 unmodified line | |||
| 227 | } | 228 | } |
| 228 | _maxVoxels = maxVoxels; | 229 | _maxVoxels = maxVoxels; |
| 229 | if (wasInitialized) { | 230 | if (wasInitialized) { |
| 230 | init(); | 231 | initVoxelMemory(); |
| 231 | } | 232 | } |
| 232 | pthread_mutex_unlock(&_bufferWriteLock); | ||
| 233 | if (wasInitialized) { | 233 | if (wasInitialized) { |
| 234 | forceRedrawEntireTree(); | 234 | forceRedrawEntireTree(); |
| 235 | } | 235 | } |
| @@ -240,7 +240,6 @@ void VoxelSystem::setUseVoxelShader(bool useVoxelShader) { · 4 unmodified lines | |||
| 240 | return; | 240 | return; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | pthread_mutex_lock(&_bufferWriteLock); | ||
| 244 | bool wasInitialized = _initialized; | 243 | bool wasInitialized = _initialized; |
| 245 | if (wasInitialized) { | 244 | if (wasInitialized) { |
| 246 | clearAllNodesBufferIndex(); | 245 | clearAllNodesBufferIndex(); |
| @@ -248,10 +247,50 @@ void VoxelSystem::setUseVoxelShader(bool useVoxelShader) { · 1 unmodified line | |||
| 248 | } | 247 | } |
| 249 | _useVoxelShader = useVoxelShader; | 248 | _useVoxelShader = useVoxelShader; |
| 250 | if (wasInitialized) { | 249 | if (wasInitialized) { |
| 251 | init(); | 250 | initVoxelMemory(); |
| 251 | } | ||
| 252 | |||
| 253 | if (wasInitialized) { | ||
| 254 | forceRedrawEntireTree(); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { | ||
| 259 | if (_voxelsAsPoints == voxelsAsPoints) { | ||
| 260 | return; | ||
| 261 | } | ||
| 262 | |||
| 263 | bool wasInitialized = _initialized; | ||
| 264 | |||
| 265 | // If we're "turning on" Voxels as points, we need to double check that we're in voxel shader mode. | ||
| 266 | // Voxels as points uses the VoxelShader memory model, so if we're not in voxel shader mode, | ||
| 267 | // then set it to voxel shader mode. | ||
| 268 | if (voxelsAsPoints) { | ||
| 269 | Menu::getInstance()->getUseVoxelShader()->setEnabled(false); | ||
| 270 | |||
| 271 | // If enabling this... then do it before checking voxel shader status, that way, if voxel | ||
| 272 | // shader is already enabled, we just start drawing as points. | ||
| 273 | _voxelsAsPoints = true; | ||
| 274 | |||
| 275 | if (!_useVoxelShader) { | ||
| 276 | setUseVoxelShader(true); | ||
| 277 | _voxelShaderModeWhenVoxelsAsPointsEnabled = false; | ||
| 278 | } else { | ||
| 279 | _voxelShaderModeWhenVoxelsAsPointsEnabled = true; | ||
| 280 | } | ||
| 281 | } else { | ||
| 282 | Menu::getInstance()->getUseVoxelShader()->setEnabled(true); | ||
| 283 | // if we're turning OFF voxels as point mode, then we check what the state of voxel shader was when we enabled | ||
| 284 | // voxels as points, if it was OFF, then we return it to that value. | ||
| 285 | if (_voxelShaderModeWhenVoxelsAsPointsEnabled == false) { | ||
| 286 | setUseVoxelShader(false); | ||
| 287 | } | ||
| 288 | // If disabling this... then do it AFTER checking previous voxel shader status, that way, if voxel | ||
| 289 | // shader is was not enabled, we switch back to normal mode before turning off points. | ||
| 290 | _voxelsAsPoints = false; | ||
| 252 | } | 291 | } |
| 253 | pthread_mutex_unlock(&_bufferWriteLock); | ||
| 254 | 292 | ||
| 293 | // Set our voxels as points | ||
| 255 | if (wasInitialized) { | 294 | if (wasInitialized) { |
| 256 | forceRedrawEntireTree(); | 295 | forceRedrawEntireTree(); |
| 257 | } | 296 | } |
| @@ -259,6 +298,8 @@ void VoxelSystem::setUseVoxelShader(bool useVoxelShader) { · 1 unmodified line | |||
| 259 | 298 | ||
| 260 | void VoxelSystem::cleanupVoxelMemory() { | 299 | void VoxelSystem::cleanupVoxelMemory() { |
| 261 | if (_initialized) { | 300 | if (_initialized) { |
| 301 | pthread_mutex_lock(&_bufferWriteLock); | ||
| 302 | _initialized = false; // no longer initialized | ||
| 262 | if (_useVoxelShader) { | 303 | if (_useVoxelShader) { |
| 263 | // these are used when in VoxelShader mode. | 304 | // these are used when in VoxelShader mode. |
| 264 | glDeleteBuffers(1, &_vboVoxelsID); | 305 | glDeleteBuffers(1, &_vboVoxelsID); |
| @@ -266,6 +307,9 @@ void VoxelSystem::cleanupVoxelMemory() { · 1 unmodified line | |||
| 266 | 307 | ||
| 267 | delete[] _writeVoxelShaderData; | 308 | delete[] _writeVoxelShaderData; |
| 268 | delete[] _readVoxelShaderData; | 309 | delete[] _readVoxelShaderData; |
| 310 | |||
| 311 | _writeVoxelShaderData = _readVoxelShaderData = NULL; | ||
| 312 | |||
| 269 | } else { | 313 | } else { |
| 270 | // Destroy glBuffers | 314 | // Destroy glBuffers |
| 271 | glDeleteBuffers(1, &_vboVerticesID); | 315 | glDeleteBuffers(1, &_vboVerticesID); |
| @@ -282,11 +326,18 @@ void VoxelSystem::cleanupVoxelMemory() { · 10 unmodified lines | |||
| 282 | delete[] _writeVerticesArray; | 326 | delete[] _writeVerticesArray; |
| 283 | delete[] _readColorsArray; | 327 | delete[] _readColorsArray; |
| 284 | delete[] _writeColorsArray; | 328 | delete[] _writeColorsArray; |
| 329 | |||
| 330 | _readVerticesArray = NULL; | ||
| 331 | _writeVerticesArray = NULL; | ||
| 332 | _readColorsArray = NULL; | ||
| 333 | _writeColorsArray = NULL; | ||
| 334 | |||
| 285 | } | 335 | } |
| 286 | delete[] _writeVoxelDirtyArray; | 336 | delete[] _writeVoxelDirtyArray; |
| 287 | delete[] _readVoxelDirtyArray; | 337 | delete[] _readVoxelDirtyArray; |
| 338 | _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL; | ||
| 339 | pthread_mutex_unlock(&_bufferWriteLock); | ||
| 288 | } | 340 | } |
| 289 | _initialized = false; // no longer initialized | ||
| 290 | } | 341 | } |
| 291 | 342 | ||
| 292 | void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndices[]) { | 343 | void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndices[]) { |
| @@ -318,11 +369,11 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 25 unmodified lines | |||
| 318 | } | 369 | } |
| 319 | 370 | ||
| 320 | void VoxelSystem::initVoxelMemory() { | 371 | void VoxelSystem::initVoxelMemory() { |
| 321 | _initialMemoryUsageGPU = getFreeMemoryGPU(); | 372 | pthread_mutex_lock(&_bufferWriteLock); |
| 373 | |||
| 322 | _memoryUsageRAM = 0; | 374 | _memoryUsageRAM = 0; |
| 323 | _memoryUsageVBO = 0; // our VBO allocations as we know them | 375 | _memoryUsageVBO = 0; // our VBO allocations as we know them |
| 324 | if (_useVoxelShader) { | 376 | if (_useVoxelShader) { |
| 325 | qDebug("Using Voxel Shader...\n"); | ||
| 326 | GLuint* indicesArray = new GLuint[_maxVoxels]; | 377 | GLuint* indicesArray = new GLuint[_maxVoxels]; |
| 327 | 378 | ||
| 328 | // populate the indicesArray | 379 | // populate the indicesArray |
| @@ -418,6 +469,10 @@ void VoxelSystem::initVoxelMemory() { · 89 unmodified lines | |||
| 418 | _perlinModulateProgram.release(); | 469 | _perlinModulateProgram.release(); |
| 419 | } | 470 | } |
| 420 | } | 471 | } |
| 472 | |||
| 473 | _initialized = true; | ||
| 474 | |||
| 475 | pthread_mutex_unlock(&_bufferWriteLock); | ||
| 421 | } | 476 | } |
| 422 | 477 | ||
| 423 | void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { | 478 | void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { |
| @@ -544,7 +599,12 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 120 unmodified lines | |||
| 544 | 599 | ||
| 545 | void VoxelSystem::setupNewVoxelsForDrawing() { | 600 | void VoxelSystem::setupNewVoxelsForDrawing() { |
| 546 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 601 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 547 | "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated | 602 | "setupNewVoxelsForDrawing()"); |
| 603 | |||
| 604 | if (!_initialized) { | ||
| 605 | return; // bail early if we're not initialized | ||
| 606 | } | ||
| 607 | |||
| 548 | uint64_t start = usecTimestampNow(); | 608 | uint64_t start = usecTimestampNow(); |
| 549 | uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000; | 609 | uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000; |
| 550 | 610 | ||
| @@ -587,7 +647,11 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 36 unmodified lines | |||
| 587 | } | 647 | } |
| 588 | 648 | ||
| 589 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it | 649 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it |
| 590 | pthread_mutex_lock(&_bufferWriteLock); | 650 | { |
| 651 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | ||
| 652 | "setupNewVoxelsForDrawing()... pthread_mutex_lock(&_bufferWriteLock)"); | ||
| 653 | pthread_mutex_lock(&_bufferWriteLock); | ||
| 654 | } | ||
| 591 | 655 | ||
| 592 | if (_voxelsUpdated) { | 656 | if (_voxelsUpdated) { |
| 593 | _voxelsDirty=true; | 657 | _voxelsDirty=true; |
| @@ -957,14 +1021,13 @@ void VoxelSystem::init() { · 363 unmodified lines | |||
| 957 | _setupNewVoxelsForDrawingLastElapsed = 0; | 1021 | _setupNewVoxelsForDrawingLastElapsed = 0; |
| 958 | _lastViewCullingElapsed = _lastViewCulling = 0; | 1022 | _lastViewCullingElapsed = _lastViewCulling = 0; |
| 959 | 1023 | ||
| 960 | // When we change voxels representations in the arrays, we'll update this | ||
| 961 | _voxelsDirty = false; | 1024 | _voxelsDirty = false; |
| 962 | _voxelsInWriteArrays = 0; | 1025 | _voxelsInWriteArrays = 0; |
| 963 | _voxelsInReadArrays = 0; | 1026 | _voxelsInReadArrays = 0; |
| 964 | 1027 | ||
| 965 | // VBO for the verticesArray | 1028 | // VBO for the verticesArray |
| 1029 | _initialMemoryUsageGPU = getFreeMemoryGPU(); | ||
| 966 | initVoxelMemory(); | 1030 | initVoxelMemory(); |
| 967 | _initialized = true; | ||
| 968 | 1031 | ||
| 969 | // our own _removedVoxels doesn't need to be notified of voxel deletes | 1032 | // our own _removedVoxels doesn't need to be notified of voxel deletes |
| 970 | VoxelNode::removeDeleteHook(&_removedVoxels); | 1033 | VoxelNode::removeDeleteHook(&_removedVoxels); |
| @@ -1071,16 +1134,14 @@ void VoxelSystem::render(bool texture) { · 100 unmodified lines | |||
| 1071 | return; | 1134 | return; |
| 1072 | } | 1135 | } |
| 1073 | 1136 | ||
| 1074 | // get the lock so that the update thread won't change anything | ||
| 1075 | pthread_mutex_lock(&_bufferWriteLock); | ||
| 1076 | |||
| 1077 | updateVBOs(); | 1137 | updateVBOs(); |
| 1078 | 1138 | ||
| 1139 | bool dontCallOpenGLDraw = Menu::getInstance()->isOptionChecked(MenuOption::DontCallOpenGLForVoxels); | ||
| 1140 | // if not don't... then do... | ||
| 1079 | if (_useVoxelShader) { | 1141 | if (_useVoxelShader) { |
| 1080 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 1142 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 1081 | "render().. _useVoxelShader openGL.."); | 1143 | "render().. _useVoxelShader openGL.."); |
| 1082 | 1144 | ||
| 1083 | Application::getInstance()->getVoxelShader().begin(); | ||
| 1084 | 1145 | ||
| 1085 | //Define this somewhere in your header file | 1146 | //Define this somewhere in your header file |
| 1086 | #define BUFFER_OFFSET(i) ((void*)(i)) | 1147 | #define BUFFER_OFFSET(i) ((void*)(i)) |
| @@ -1088,14 +1149,29 @@ void VoxelSystem::render(bool texture) { · 1 unmodified line | |||
| 1088 | glBindBuffer(GL_ARRAY_BUFFER, _vboVoxelsID); | 1149 | glBindBuffer(GL_ARRAY_BUFFER, _vboVoxelsID); |
| 1089 | glEnableClientState(GL_VERTEX_ARRAY); | 1150 | glEnableClientState(GL_VERTEX_ARRAY); |
| 1090 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(0)); //The starting point of the VBO, for the vertices | 1151 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(0)); //The starting point of the VBO, for the vertices |
| 1091 | int loc = Application::getInstance()->getVoxelShader().attributeLocation("voxelSizeIn"); | 1152 | |
| 1092 | glEnableVertexAttribArray(loc); | 1153 | int attributeLocation; |
| 1093 | glVertexAttribPointer(loc, 1, GL_FLOAT, false, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(3*sizeof(float))); | 1154 | |
| 1155 | if (!_voxelsAsPoints) { | ||
| 1156 | Application::getInstance()->getVoxelShader().begin(); | ||
| 1157 | |||
| 1158 | attributeLocation = Application::getInstance()->getVoxelShader().attributeLocation("voxelSizeIn"); | ||
| 1159 | glEnableVertexAttribArray(attributeLocation); | ||
| 1160 | glVertexAttribPointer(attributeLocation, 1, GL_FLOAT, false, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(3*sizeof(float))); | ||
| 1161 | } else { | ||
| 1162 | const float POINT_SIZE = 4.0; | ||
| 1163 | glPointSize(POINT_SIZE); | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | |||
| 1094 | glEnableClientState(GL_COLOR_ARRAY); | 1167 | glEnableClientState(GL_COLOR_ARRAY); |
| 1095 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(4*sizeof(float)));//The starting point of colors | 1168 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelShaderVBOData), BUFFER_OFFSET(4*sizeof(float)));//The starting point of colors |
| 1096 | 1169 | ||
| 1097 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboVoxelsIndicesID); | 1170 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboVoxelsIndicesID); |
| 1098 | glDrawElements(GL_POINTS, _voxelsInReadArrays, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); //The starting point of the IBO | 1171 | |
| 1172 | if (!dontCallOpenGLDraw) { | ||
| 1173 | glDrawElements(GL_POINTS, _voxelsInReadArrays, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); //The starting point of the IBO | ||
| 1174 | } | ||
| 1099 | 1175 | ||
| 1100 | // deactivate vertex and color arrays after drawing | 1176 | // deactivate vertex and color arrays after drawing |
| 1101 | glDisableClientState(GL_VERTEX_ARRAY); | 1177 | glDisableClientState(GL_VERTEX_ARRAY); |
| @@ -1105,11 +1181,13 @@ void VoxelSystem::render(bool texture) { · 3 unmodified lines | |||
| 1105 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 1181 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1106 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 1182 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 1107 | 1183 | ||
| 1108 | Application::getInstance()->getVoxelShader().end(); | 1184 | if (!_voxelsAsPoints) { |
| 1109 | 1185 | Application::getInstance()->getVoxelShader().end(); | |
| 1186 | glDisableVertexAttribArray(attributeLocation); | ||
| 1187 | } | ||
| 1110 | } else { | 1188 | } else { |
| 1111 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "render().. openGL..."); | 1189 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "render().. openGL..."); |
| 1112 | 1190 | ||
| 1113 | // tell OpenGL where to find vertex and color information | 1191 | // tell OpenGL where to find vertex and color information |
| 1114 | glEnableClientState(GL_VERTEX_ARRAY); | 1192 | glEnableClientState(GL_VERTEX_ARRAY); |
| 1115 | glEnableClientState(GL_COLOR_ARRAY); | 1193 | glEnableClientState(GL_COLOR_ARRAY); |
| @@ -1121,47 +1199,48 @@ void VoxelSystem::render(bool texture) { · 5 unmodified lines | |||
| 1121 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); | 1199 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); |
| 1122 | 1200 | ||
| 1123 | applyScaleAndBindProgram(texture); | 1201 | applyScaleAndBindProgram(texture); |
| 1124 | 1202 | ||
| 1125 | // for performance, enable backface culling | 1203 | // for performance, enable backface culling |
| 1126 | glEnable(GL_CULL_FACE); | 1204 | glEnable(GL_CULL_FACE); |
| 1127 | 1205 | ||
| 1128 | // draw voxels in 6 passes | 1206 | // draw voxels in 6 passes |
| 1129 | 1207 | ||
| 1130 | glNormal3f(0,1.0f,0); | 1208 | if (!dontCallOpenGLDraw) { |
| 1131 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop); | 1209 | glNormal3f(0,1.0f,0); |
| 1132 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1210 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop); |
| 1133 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1211 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1134 | 1212 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1135 | glNormal3f(0,-1.0f,0); | 1213 | |
| 1136 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom); | 1214 | glNormal3f(0,-1.0f,0); |
| 1137 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1215 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom); |
| 1138 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1216 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1139 | 1217 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1140 | glNormal3f(-1.0f,0,0); | 1218 | |
| 1141 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft); | 1219 | glNormal3f(-1.0f,0,0); |
| 1142 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1220 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft); |
| 1143 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1221 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1144 | 1222 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1145 | glNormal3f(1.0f,0,0); | 1223 | |
| 1146 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight); | 1224 | glNormal3f(1.0f,0,0); |
| 1147 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1225 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight); |
| 1148 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1226 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1149 | 1227 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1150 | glNormal3f(0,0,-1.0f); | 1228 | |
| 1151 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront); | 1229 | glNormal3f(0,0,-1.0f); |
| 1152 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1230 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront); |
| 1153 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1231 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1154 | 1232 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1155 | glNormal3f(0,0,1.0f); | 1233 | |
| 1156 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack); | 1234 | glNormal3f(0,0,1.0f); |
| 1157 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, | 1235 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack); |
| 1158 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | 1236 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1, |
| 1159 | 1237 | INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); | |
| 1238 | } | ||
| 1160 | 1239 | ||
| 1161 | glDisable(GL_CULL_FACE); | 1240 | glDisable(GL_CULL_FACE); |
| 1162 | 1241 | ||
| 1163 | removeScaleAndReleaseProgram(texture); | 1242 | removeScaleAndReleaseProgram(texture); |
| 1164 | 1243 | ||
| 1165 | // deactivate vertex and color arrays after drawing | 1244 | // deactivate vertex and color arrays after drawing |
| 1166 | glDisableClientState(GL_VERTEX_ARRAY); | 1245 | glDisableClientState(GL_VERTEX_ARRAY); |
| 1167 | glDisableClientState(GL_COLOR_ARRAY); | 1246 | glDisableClientState(GL_COLOR_ARRAY); |
| @@ -1170,8 +1249,6 @@ void VoxelSystem::render(bool texture) { · 2 unmodified lines | |||
| 1170 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 1249 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 1171 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 1250 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 1172 | } | 1251 | } |
| 1173 | |||
| 1174 | pthread_mutex_unlock(&_bufferWriteLock); | ||
| 1175 | } | 1252 | } |
| 1176 | 1253 | ||
| 1177 | void VoxelSystem::applyScaleAndBindProgram(bool texture) { | 1254 | void VoxelSystem::applyScaleAndBindProgram(bool texture) { |