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
415415 }
416416 }
417417
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+
418423 ProgramObject* VoxelSystem::_perlinModulateProgram = 0;
419424 GLuint VoxelSystem::_permutationNormalTextureID = 0;
420425
@@ -609,8 +614,8 @@ void VoxelSystem::render(bool texture) { · 188 unmodified lines
609614 // get the lock so that the update thread won't change anything
610615 pthread_mutex_lock(&_bufferWriteLock);
611616
612− glPushMatrix();
613617 updateVBOs();
618+
614619 // tell OpenGL where to find vertex and color information
615620 glEnableClientState(GL_VERTEX_ARRAY);
616621 glEnableClientState(GL_NORMAL_ARRAY);
@@ -625,7 +630,7 @@ void VoxelSystem::render(bool texture) { · 8 unmodified lines
625630 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
626631 glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
627632
628− bindProgram(texture);
633+ applyScaleAndBindProgram(texture);
629634
630635 // for performance, disable blending and enable backface culling
631636 glDisable(GL_BLEND);
@@ -633,14 +638,13 @@ void VoxelSystem::render(bool texture) { · 1 unmodified line
633638
634639 // draw the number of voxels we have
635640 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID);
636− glScalef(_treeScale, _treeScale, _treeScale);
637641 glDrawRangeElementsEXT(GL_TRIANGLES, 0, VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
638642 36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
639643
640644 glEnable(GL_BLEND);
641645 glDisable(GL_CULL_FACE);
642646
643− releaseProgram(texture);
647+ removeScaleAndReleaseProgram(texture);
644648
645649 // deactivate vertex and color arrays after drawing
646650 glDisableClientState(GL_VERTEX_ARRAY);
@@ -650,21 +654,24 @@ void VoxelSystem::render(bool texture) { · 3 unmodified lines
650654 // bind with 0 to switch back to normal operation
651655 glBindBuffer(GL_ARRAY_BUFFER, 0);
652656 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
653−
654− // scale back down to 1 so heads aren't massive
655− glPopMatrix();
656657
657658 pthread_mutex_unlock(&_bufferWriteLock);
658659 }
659660
660−void VoxelSystem::bindProgram(bool texture) {
661+void VoxelSystem::applyScaleAndBindProgram(bool texture) {
662+ glPushMatrix();
663+ glScalef(_treeScale, _treeScale, _treeScale);
664+
661665 if (texture) {
662666 _perlinModulateProgram->bind();
663667 glBindTexture(GL_TEXTURE_2D, _permutationNormalTextureID);
664668 }
665669 }
666670
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+
668675 if (texture) {
669676 _perlinModulateProgram->release();
670677 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