Ticket #2513: LOSTexture.patch
File LOSTexture.patch, 3.1 KB (added by , 10 years ago) |
---|
-
source/graphics/LOSTexture.cpp
60 60 CLOSTexture::CLOSTexture(CSimulation2& simulation) : 61 61 m_Simulation(simulation), m_Dirty(true), m_Texture(0), m_smoothFbo(0), m_MapSize(0), m_TextureSize(0), whichTex(true) 62 62 { 63 wasShaderInit = false; 63 64 if (CRenderer::IsInitialised() && g_Renderer.m_Options.m_SmoothLOS) 64 65 { 65 m_smoothShader = g_Renderer.GetShaderManager().LoadEffect(str_los_interp); 66 CShaderProgramPtr shader = m_smoothShader->GetShader(); 67 68 if (m_smoothShader && shader) 69 { 70 pglGenFramebuffersEXT(1, &m_smoothFbo); 71 } 72 else 73 { 74 LOGERROR(L"Failed to load SmoothLOS shader, disabling."); 75 g_Renderer.m_Options.m_SmoothLOS = false; 76 } 66 CreateShader(); 77 67 } 78 68 } 79 69 … … 83 73 DeleteTexture(); 84 74 } 85 75 76 // Create the LOS texture engine.Only run once. 77 void CLOSTexture::CreateShader() 78 { 79 m_smoothShader = g_Renderer.GetShaderManager().LoadEffect(str_los_interp); 80 CShaderProgramPtr shader = m_smoothShader->GetShader(); 81 82 // Check if the shader was created correctly 83 wasShaderInit = m_smoothShader && shader; 84 if (wasShaderInit) 85 { 86 pglGenFramebuffersEXT(1, &m_smoothFbo); 87 } 88 else 89 { 90 LOGERROR(L"Failed to load SmoothLOS shader, disabling."); 91 g_Renderer.m_Options.m_SmoothLOS = false; 92 } 93 } 94 86 95 void CLOSTexture::DeleteTexture() 87 96 { 88 97 glDeleteTextures(1, &m_Texture); 89 if (CRenderer::IsInitialised() && g_Renderer.m_Options.m_SmoothLOS) 90 {98 99 if (m_TextureSmooth1) 91 100 glDeleteTextures(1, &m_TextureSmooth1); 101 102 if (m_TextureSmooth2) 92 103 glDeleteTextures(1, &m_TextureSmooth2); 93 } 104 94 105 m_Texture = 0; 106 m_TextureSmooth1 = 0; 107 m_TextureSmooth2 = 0; 95 108 } 96 109 97 110 void CLOSTexture::MakeDirty() … … 120 133 121 134 void CLOSTexture::InterpolateLOS() 122 135 { 136 // Is the Renderer on and Smooth LOS active? 123 137 if (CRenderer::IsInitialised() && !g_Renderer.m_Options.m_SmoothLOS) 124 138 return; 125 139 140 if (!wasShaderInit) 141 { 142 CreateShader(); 143 144 // RecomputeTexture(0) will not cause the ConstructTexture to run. 145 // Force the textures to be created. 146 DeleteTexture(); 147 ConstructTexture(0); 148 m_Dirty = true; 149 } 150 126 151 if (m_Dirty) 127 152 { 128 153 RecomputeTexture(0); 129 154 m_Dirty = false; 130 155 } 131 156 157 // Get the current return format for simple GL states 132 158 GLint originalFBO; 133 159 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &originalFBO); 134 160 161 // Bind the LOS framebuffer to GL_FRAMEBUFFER_EXT 135 162 pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_smoothFbo); 163 136 164 pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 137 165 whichTex ? m_TextureSmooth2 : m_TextureSmooth1, 0); 138 166 -
source/graphics/LOSTexture.h
78 78 79 79 private: 80 80 void DeleteTexture(); 81 void CreateShader(); 81 82 void ConstructTexture(int unit); 82 83 void RecomputeTexture(int unit); 83 84 … … 88 89 89 90 bool m_Dirty; 90 91 92 bool wasShaderInit; 93 91 94 GLuint m_Texture; 92 95 GLuint m_TextureSmooth1, m_TextureSmooth2; 93 96