Showing the changes to interface/src/VoxelSystem.cpp (1 of 8 files). Show all
Unified · Split
| @@ -415,6 +415,11 @@ void VoxelSystem::updateNodeInArrays(glBufferIndex nodeIndex, const glm::vec3& s · 414 unmodified lines | ||
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | +glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const { | |
| 419 | + const float* identityVertex = identityVertices + index * 3; | |
| 420 | + return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale; | |
| 421 | +} | |
| 422 | + | |
| 418 | 423 | ProgramObject* VoxelSystem::_perlinModulateProgram = 0; |
| 419 | 424 | GLuint VoxelSystem::_permutationNormalTextureID = 0; |
| 420 | 425 | |
| @@ -609,8 +614,8 @@ void VoxelSystem::render(bool texture) { · 188 unmodified lines | ||
| 609 | 614 | // get the lock so that the update thread won't change anything |
| 610 | 615 | pthread_mutex_lock(&_bufferWriteLock); |
| 611 | 616 | |
| 612 | − glPushMatrix(); | |
| 613 | 617 | updateVBOs(); |
| 618 | + | |
| 614 | 619 | // tell OpenGL where to find vertex and color information |
| 615 | 620 | glEnableClientState(GL_VERTEX_ARRAY); |
| 616 | 621 | glEnableClientState(GL_NORMAL_ARRAY); |
| @@ -625,7 +630,7 @@ void VoxelSystem::render(bool texture) { · 8 unmodified lines | ||
| 625 | 630 | glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID); |
| 626 | 631 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); |
| 627 | 632 | |
| 628 | − bindProgram(texture); | |
| 633 | + applyScaleAndBindProgram(texture); | |
| 629 | 634 | |
| 630 | 635 | // for performance, disable blending and enable backface culling |
| 631 | 636 | glDisable(GL_BLEND); |
| @@ -633,14 +638,13 @@ void VoxelSystem::render(bool texture) { · 1 unmodified line | ||
| 633 | 638 | |
| 634 | 639 | // draw the number of voxels we have |
| 635 | 640 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID); |
| 636 | − glScalef(_treeScale, _treeScale, _treeScale); | |
| 637 | 641 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTICES_PER_VOXEL * _voxelsInReadArrays - 1, |
| 638 | 642 | 36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); |
| 639 | 643 | |
| 640 | 644 | glEnable(GL_BLEND); |
| 641 | 645 | glDisable(GL_CULL_FACE); |
| 642 | 646 | |
| 643 | − releaseProgram(texture); | |
| 647 | + removeScaleAndReleaseProgram(texture); | |
| 644 | 648 | |
| 645 | 649 | // deactivate vertex and color arrays after drawing |
| 646 | 650 | glDisableClientState(GL_VERTEX_ARRAY); |
| @@ -650,21 +654,24 @@ void VoxelSystem::render(bool texture) { · 3 unmodified lines | ||
| 650 | 654 | // bind with 0 to switch back to normal operation |
| 651 | 655 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 652 | 656 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 653 | − | |
| 654 | − // scale back down to 1 so heads aren't massive | |
| 655 | − glPopMatrix(); | |
| 656 | 657 | |
| 657 | 658 | pthread_mutex_unlock(&_bufferWriteLock); |
| 658 | 659 | } |
| 659 | 660 | |
| 660 | −void VoxelSystem::bindProgram(bool texture) { | |
| 661 | +void VoxelSystem::applyScaleAndBindProgram(bool texture) { | |
| 662 | + glPushMatrix(); | |
| 663 | + glScalef(_treeScale, _treeScale, _treeScale); | |
| 664 | + | |
| 661 | 665 | if (texture) { |
| 662 | 666 | _perlinModulateProgram->bind(); |
| 663 | 667 | glBindTexture(GL_TEXTURE_2D, _permutationNormalTextureID); |
| 664 | 668 | } |
| 665 | 669 | } |
| 666 | 670 | |
| 667 | −void VoxelSystem::releaseProgram(bool texture) { | |
| 671 | +void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { | |
| 672 | + // scale back down to 1 so heads aren't massive | |
| 673 | + glPopMatrix(); | |
| 674 | + | |
| 668 | 675 | if (texture) { |
| 669 | 676 | _perlinModulateProgram->release(); |
| 670 | 677 | glBindTexture(GL_TEXTURE_2D, 0); |