History

More work on voxeltars; basic skinning works.

Andrzej Kapolka committed 13 years ago

Commit 8d757e11 parent 35ae08d8 files · +168 −73Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 8 files). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t