From 21ba9bf4105e67220a4be0024c91eb07229d7259 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 7 Jul 2014 11:22:17 -0700 Subject: [PATCH] Because attempting to compile the new voxel texture shader causes my system (Ubuntu LTS, Intel graphics) to hang, change it to compile lazily when activated. --- interface/src/voxels/VoxelSystem.cpp | 30 +++++++++++++++++----------- interface/src/voxels/VoxelSystem.h | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/interface/src/voxels/VoxelSystem.cpp b/interface/src/voxels/VoxelSystem.cpp index 2b86a58d9b..ca79967109 100644 --- a/interface/src/voxels/VoxelSystem.cpp +++ b/interface/src/voxels/VoxelSystem.cpp @@ -499,17 +499,7 @@ void VoxelSystem::initVoxelMemory() { _memoryUsageRAM += (sizeof(GLubyte) * vertexPointsPerVoxel * _maxVoxels); // create our simple fragment shader if we're the first system to init - if (!_perlinModulateProgram.isLinked()) { - _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() - + "shaders/perlin_modulate.vert"); - _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() - + "shaders/perlin_modulate.frag"); - _perlinModulateProgram.link(); - - _perlinModulateProgram.bind(); - _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); - _perlinModulateProgram.release(); - + if (!_shadowMapProgram.isLinked()) { _shadowMapProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/shadow_map.vert"); _shadowMapProgram.addShaderFromSourceFile(QGLShader::Fragment, @@ -1509,7 +1499,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) { glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getShadowDepthTextureID()); } else if (texture) { - _perlinModulateProgram.bind(); + bindPerlinModulateProgram(); glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID()); } @@ -2159,6 +2149,22 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { return (_initialMemoryUsageGPU - currentFreeMemory); } +void VoxelSystem::bindPerlinModulateProgram() { + if (!_perlinModulateProgram.isLinked()) { + _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, + Application::resourcesPath() + "shaders/perlin_modulate.vert"); + _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, + Application::resourcesPath() + "shaders/perlin_modulate.frag"); + _perlinModulateProgram.link(); + + _perlinModulateProgram.bind(); + _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); + + } else { + _perlinModulateProgram.bind(); + } +} + // Swizzle value of bit pairs of the value of index unsigned short VoxelSystem::_sSwizzledOcclusionBits[64] = { 0x0000, // 00000000 diff --git a/interface/src/voxels/VoxelSystem.h b/interface/src/voxels/VoxelSystem.h index 71abc9ca93..ae8752605a 100644 --- a/interface/src/voxels/VoxelSystem.h +++ b/interface/src/voxels/VoxelSystem.h @@ -236,6 +236,8 @@ private: static ProgramObject _cascadedShadowMapProgram; static int _shadowDistancesLocation; + static void bindPerlinModulateProgram(); + int _hookID; std::vector _freeIndexes; QMutex _freeIndexLock;