Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 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 | −GLfloat identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, | |
| 40 | +GLbyte 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, |
| @@ -75,7 +75,9 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 31 unmodified lines | ||
| 75 | 75 | connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float))); |
| 76 | 76 | connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int))); |
| 77 | 77 | |
| 78 | − _useVoxelShader = false; | |
| 78 | + _useVoxelShader = false; | |
| 79 | + _useByteNormals = false; | |
| 80 | + | |
| 79 | 81 | _writeVoxelShaderData = NULL; |
| 80 | 82 | _readVoxelShaderData = NULL; |
| 81 | 83 | |
| @@ -139,6 +141,20 @@ VoxelSystem::~VoxelSystem() { · 57 unmodified lines | ||
| 139 | 141 | VoxelNode::removeDeleteHook(this); |
| 140 | 142 | } |
| 141 | 143 | |
| 144 | +void VoxelSystem::setUseByteNormals(bool useByteNormals) { | |
| 145 | + pthread_mutex_lock(&_bufferWriteLock); | |
| 146 | + bool wasInitialized = _initialized; | |
| 147 | + if (wasInitialized) { | |
| 148 | + cleanupVoxelMemory(); | |
| 149 | + } | |
| 150 | + _useByteNormals = useByteNormals; | |
| 151 | + if (wasInitialized) { | |
| 152 | + init(); | |
| 153 | + } | |
| 154 | + pthread_mutex_unlock(&_bufferWriteLock); | |
| 155 | +} | |
| 156 | + | |
| 157 | + | |
| 142 | 158 | void VoxelSystem::setMaxVoxels(int maxVoxels) { |
| 143 | 159 | pthread_mutex_lock(&_bufferWriteLock); |
| 144 | 160 | bool wasInitialized = _initialized; |
| @@ -194,6 +210,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 49 unmodified lines | ||
| 194 | 210 | |
| 195 | 211 | void VoxelSystem::initVoxelMemory() { |
| 196 | 212 | if (_useVoxelShader) { |
| 213 | + qDebug("Using Voxel Shader...\n"); | |
| 197 | 214 | GLuint* indicesArray = new GLuint[_maxVoxels]; |
| 198 | 215 | |
| 199 | 216 | // populate the indicesArray |
| @@ -241,27 +258,55 @@ void VoxelSystem::initVoxelMemory() { · 41 unmodified lines | ||
| 241 | 258 | } |
| 242 | 259 | } |
| 243 | 260 | |
| 244 | − GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; | |
| 245 | − GLfloat* normalsArrayEndPointer = normalsArray; | |
| 261 | + if (_useByteNormals) { | |
| 262 | + qDebug("Using Byte Normals...\n"); | |
| 263 | + GLbyte* normalsArray = new GLbyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; | |
| 264 | + GLbyte* normalsArrayEndPointer = normalsArray; | |
| 246 | 265 | |
| 247 | − // populate the normalsArray | |
| 248 | − for (int n = 0; n < _maxVoxels; n++) { | |
| 249 | − for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { | |
| 250 | − *(normalsArrayEndPointer++) = identityNormals[i]; | |
| 266 | + // populate the normalsArray | |
| 267 | + for (int n = 0; n < _maxVoxels; n++) { | |
| 268 | + for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { | |
| 269 | + *(normalsArrayEndPointer++) = identityNormals[i]; | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + // VBO for the normalsArray | |
| 274 | + glGenBuffers(1, &_vboNormalsID); | |
| 275 | + glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID); | |
| 276 | + glBufferData(GL_ARRAY_BUFFER, | |
| 277 | + VERTEX_POINTS_PER_VOXEL * sizeof(GLbyte) * _maxVoxels, | |
| 278 | + normalsArray, GL_STATIC_DRAW); | |
| 279 | + | |
| 280 | + // delete the indices and normals arrays that are no longer needed | |
| 281 | + delete[] normalsArray; | |
| 282 | + } else { | |
| 283 | + qDebug("Using Float Normals...\n"); | |
| 284 | + GLfloat* normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels]; | |
| 285 | + GLfloat* normalsArrayEndPointer = normalsArray; | |
| 286 | + | |
| 287 | + // populate the normalsArray | |
| 288 | + for (int n = 0; n < _maxVoxels; n++) { | |
| 289 | + for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { | |
| 290 | + *(normalsArrayEndPointer++) = identityNormals[i]; | |
| 291 | + } | |
| 251 | 292 | } |
| 293 | + | |
| 294 | + // VBO for the normalsArray | |
| 295 | + glGenBuffers(1, &_vboNormalsID); | |
| 296 | + glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID); | |
| 297 | + glBufferData(GL_ARRAY_BUFFER, | |
| 298 | + VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, | |
| 299 | + normalsArray, GL_STATIC_DRAW); | |
| 300 | + | |
| 301 | + // delete the indices and normals arrays that are no longer needed | |
| 302 | + delete[] normalsArray; | |
| 252 | 303 | } |
| 253 | 304 | |
| 305 | + | |
| 254 | 306 | glGenBuffers(1, &_vboVerticesID); |
| 255 | 307 | glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID); |
| 256 | 308 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW); |
| 257 | 309 | |
| 258 | − // VBO for the normalsArray | |
| 259 | − glGenBuffers(1, &_vboNormalsID); | |
| 260 | − glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID); | |
| 261 | − glBufferData(GL_ARRAY_BUFFER, | |
| 262 | − VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, | |
| 263 | − normalsArray, GL_STATIC_DRAW); | |
| 264 | − | |
| 265 | 310 | // VBO for colorsArray |
| 266 | 311 | glGenBuffers(1, &_vboColorsID); |
| 267 | 312 | glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID); |
| @@ -276,7 +321,6 @@ void VoxelSystem::initVoxelMemory() { · 8 unmodified lines | ||
| 276 | 321 | |
| 277 | 322 | // delete the indices and normals arrays that are no longer needed |
| 278 | 323 | delete[] indicesArray; |
| 279 | − delete[] normalsArray; | |
| 280 | 324 | |
| 281 | 325 | |
| 282 | 326 | // we will track individual dirty sections with these arrays of bools |
| @@ -890,7 +934,7 @@ void VoxelSystem::render(bool texture) { · 607 unmodified lines | ||
| 890 | 934 | glVertexPointer(3, GL_FLOAT, 0, 0); |
| 891 | 935 | |
| 892 | 936 | glBindBuffer(GL_ARRAY_BUFFER, _vboNormalsID); |
| 893 | − glNormalPointer(GL_FLOAT, 0, 0); | |
| 937 | + glNormalPointer((_useByteNormals ? GL_BYTE : GL_FLOAT), 0, 0); | |
| 894 | 938 | |
| 895 | 939 | glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID); |
| 896 | 940 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); |
| @@ -1769,7 +1813,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 872 unmodified lines | ||
| 1769 | 1813 | void VoxelSystem::nodeAdded(Node* node) { |
| 1770 | 1814 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 1771 | 1815 | uint16_t nodeID = node->getNodeID(); |
| 1772 | − printf("VoxelSystem... voxel server %u added...\n", nodeID); | |
| 1816 | + qDebug("VoxelSystem... voxel server %u added...\n", nodeID); | |
| 1773 | 1817 | _voxelServerCount++; |
| 1774 | 1818 | } |
| 1775 | 1819 | } |
| @@ -1792,7 +1836,7 @@ void VoxelSystem::nodeKilled(Node* node) { · 16 unmodified lines | ||
| 1792 | 1836 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 1793 | 1837 | _voxelServerCount--; |
| 1794 | 1838 | uint16_t nodeID = node->getNodeID(); |
| 1795 | − printf("VoxelSystem... voxel server %u removed...\n", nodeID); | |
| 1839 | + qDebug("VoxelSystem... voxel server %u removed...\n", nodeID); | |
| 1796 | 1840 | |
| 1797 | 1841 | if (_voxelServerCount > 0) { |
| 1798 | 1842 | // Kill any voxels from the local tree that match this nodeID |