- Add gl_shadowmap_quality cvar that controls the resolution of the 1D shadow map texture

This commit is contained in:
Magnus Norddahl 2017-06-04 00:44:49 +02:00
commit 7acb492852
8 changed files with 47 additions and 14 deletions

View file

@ -81,6 +81,7 @@ FGLRenderBuffers::~FGLRenderBuffers()
ClearBloom();
ClearExposureLevels();
ClearAmbientOcclusion();
ClearShadowMap();
}
void FGLRenderBuffers::ClearScene()
@ -759,18 +760,27 @@ void FGLRenderBuffers::BindShadowMapTexture(int texunit)
glBindTexture(GL_TEXTURE_2D, mShadowMapTexture);
}
void FGLRenderBuffers::ClearShadowMap()
{
DeleteFrameBuffer(mShadowMapFB);
DeleteTexture(mShadowMapTexture);
mCurrentShadowMapSize = 0;
}
void FGLRenderBuffers::CreateShadowMap()
{
if (mShadowMapTexture != 0)
if (mShadowMapTexture != 0 && gl_shadowmap_quality == mCurrentShadowMapSize)
return;
ClearShadowMap();
GLint activeTex, textureBinding, frameBufferBinding;
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTex);
glActiveTexture(GL_TEXTURE0);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &frameBufferBinding);
mShadowMapTexture = Create2DTexture("ShadowMap", GL_R32F, SHADOWMAP_QUALITY, 1024);
mShadowMapTexture = Create2DTexture("ShadowMap", GL_R32F, gl_shadowmap_quality, 1024);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@ -781,6 +791,8 @@ void FGLRenderBuffers::CreateShadowMap()
glBindTexture(GL_TEXTURE_2D, textureBinding);
glActiveTexture(activeTex);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferBinding);
mCurrentShadowMapSize = gl_shadowmap_quality;
}
//==========================================================================