Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -37,7 +37,7 @@ float identityVertices[] = { 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0, · 36 unmodified lines | ||
| 37 | 37 | 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, |
| 38 | 38 | 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1 }; |
| 39 | 39 | |
| 40 | −GLbyte identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, | |
| 40 | +GLfloat identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, | |
| 41 | 41 | 0,0,+1, 0,0,+1, 0,0,+1, 0,0,+1, |
| 42 | 42 | 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0, |
| 43 | 43 | 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0, |
| @@ -152,6 +152,10 @@ void VoxelSystem::setUseByteNormals(bool useByteNormals) { · 108 unmodified lines | ||
| 152 | 152 | init(); |
| 153 | 153 | } |
| 154 | 154 | pthread_mutex_unlock(&_bufferWriteLock); |
| 155 | + | |
| 156 | + if (wasInitialized) { | |
| 157 | + forceRedrawEntireTree(); | |
| 158 | + } | |
| 155 | 159 | } |
| 156 | 160 | |
| 157 | 161 | |
| @@ -166,12 +170,17 @@ void VoxelSystem::setMaxVoxels(int maxVoxels) { · 8 unmodified lines | ||
| 166 | 170 | init(); |
| 167 | 171 | } |
| 168 | 172 | pthread_mutex_unlock(&_bufferWriteLock); |
| 173 | + | |
| 174 | + if (wasInitialized) { | |
| 175 | + forceRedrawEntireTree(); | |
| 176 | + } | |
| 169 | 177 | } |
| 170 | 178 | |
| 171 | 179 | void VoxelSystem::setUseVoxelShader(bool useVoxelShader) { |
| 172 | 180 | pthread_mutex_lock(&_bufferWriteLock); |
| 173 | 181 | bool wasInitialized = _initialized; |
| 174 | 182 | if (wasInitialized) { |
| 183 | + clearAllNodesBufferIndex(); | |
| 175 | 184 | cleanupVoxelMemory(); |
| 176 | 185 | } |
| 177 | 186 | _useVoxelShader = useVoxelShader; |
| @@ -179,6 +188,10 @@ void VoxelSystem::setUseVoxelShader(bool useVoxelShader) { · 1 unmodified line | ||
| 179 | 188 | init(); |
| 180 | 189 | } |
| 181 | 190 | pthread_mutex_unlock(&_bufferWriteLock); |
| 191 | + | |
| 192 | + if (wasInitialized) { | |
| 193 | + forceRedrawEntireTree(); | |
| 194 | + } | |
| 182 | 195 | } |
| 183 | 196 | |
| 184 | 197 | void VoxelSystem::cleanupVoxelMemory() { |
| @@ -266,7 +279,7 @@ void VoxelSystem::initVoxelMemory() { · 81 unmodified lines | ||
| 266 | 279 | // populate the normalsArray |
| 267 | 280 | for (int n = 0; n < _maxVoxels; n++) { |
| 268 | 281 | for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { |
| 269 | − *(normalsArrayEndPointer++) = identityNormals[i]; | |
| 282 | + *(normalsArrayEndPointer++) = (identityNormals[i] * CHAR_MAX); | |
| 270 | 283 | } |
| 271 | 284 | } |
| 272 | 285 | |
| @@ -750,20 +763,24 @@ void VoxelSystem::updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& s · 477 unmodified lines | ||
| 750 | 763 | float voxelScale, const nodeColor& color) { |
| 751 | 764 | |
| 752 | 765 | if (_useVoxelShader) { |
| 753 | − VoxelShaderVBOData* writeVerticesAt = &_writeVoxelShaderData[nodeIndex]; | |
| 754 | − writeVerticesAt->x = startVertex.x * TREE_SCALE; | |
| 755 | − writeVerticesAt->y = startVertex.y * TREE_SCALE; | |
| 756 | − writeVerticesAt->z = startVertex.z * TREE_SCALE; | |
| 757 | − writeVerticesAt->s = voxelScale * TREE_SCALE; | |
| 758 | − writeVerticesAt->r = color[RED_INDEX]; | |
| 759 | − writeVerticesAt->g = color[GREEN_INDEX]; | |
| 760 | − writeVerticesAt->b = color[BLUE_INDEX]; | |
| 766 | + if (_writeVoxelShaderData) { | |
| 767 | + VoxelShaderVBOData* writeVerticesAt = &_writeVoxelShaderData[nodeIndex]; | |
| 768 | + writeVerticesAt->x = startVertex.x * TREE_SCALE; | |
| 769 | + writeVerticesAt->y = startVertex.y * TREE_SCALE; | |
| 770 | + writeVerticesAt->z = startVertex.z * TREE_SCALE; | |
| 771 | + writeVerticesAt->s = voxelScale * TREE_SCALE; | |
| 772 | + writeVerticesAt->r = color[RED_INDEX]; | |
| 773 | + writeVerticesAt->g = color[GREEN_INDEX]; | |
| 774 | + writeVerticesAt->b = color[BLUE_INDEX]; | |
| 775 | + } | |
| 761 | 776 | } else { |
| 762 | − for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { | |
| 763 | − GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL); | |
| 764 | − GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL); | |
| 765 | − *(writeVerticesAt+j) = startVertex[j % 3] + (identityVertices[j] * voxelScale); | |
| 766 | − *(writeColorsAt +j) = color[j % 3]; | |
| 777 | + if (_writeVerticesArray && _writeColorsArray) { | |
| 778 | + for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { | |
| 779 | + GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL); | |
| 780 | + GLubyte* writeColorsAt = _writeColorsArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL); | |
| 781 | + *(writeVerticesAt+j) = startVertex[j % 3] + (identityVertices[j] * voxelScale); | |
| 782 | + *(writeColorsAt +j) = color[j % 3]; | |
| 783 | + } | |
| 767 | 784 | } |
| 768 | 785 | } |
| 769 | 786 | } |
| @@ -995,6 +1012,34 @@ void VoxelSystem::killLocalVoxels() { · 225 unmodified lines | ||
| 995 | 1012 | } |
| 996 | 1013 | |
| 997 | 1014 | |
| 1015 | +bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extraData) { | |
| 1016 | + _nodeCount++; | |
| 1017 | + node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); | |
| 1018 | + return true; | |
| 1019 | +} | |
| 1020 | + | |
| 1021 | +void VoxelSystem::clearAllNodesBufferIndex() { | |
| 1022 | + _nodeCount = 0; | |
| 1023 | + _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation); | |
| 1024 | + qDebug("clearing buffer index of %d nodes\n", _nodeCount); | |
| 1025 | + _tree->setDirtyBit(); | |
| 1026 | + setupNewVoxelsForDrawing(); | |
| 1027 | +} | |
| 1028 | + | |
| 1029 | +bool VoxelSystem::forceRedrawEntireTreeOperation(VoxelNode* node, void* extraData) { | |
| 1030 | + _nodeCount++; | |
| 1031 | + node->setDirtyBit(); | |
| 1032 | + return true; | |
| 1033 | +} | |
| 1034 | + | |
| 1035 | +void VoxelSystem::forceRedrawEntireTree() { | |
| 1036 | + _nodeCount = 0; | |
| 1037 | + _tree->recurseTreeWithOperation(forceRedrawEntireTreeOperation); | |
| 1038 | + qDebug("forcing redraw of %d nodes\n", _nodeCount); | |
| 1039 | + _tree->setDirtyBit(); | |
| 1040 | + setupNewVoxelsForDrawing(); | |
| 1041 | +} | |
| 1042 | + | |
| 998 | 1043 | bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) { |
| 999 | 1044 | _nodeCount++; |
| 1000 | 1045 | if (node->isColored()) { |