Create a shadowmap texture and upload light list

This commit is contained in:
Magnus Norddahl 2017-03-01 17:17:33 +01:00
commit 62c285f7b3
5 changed files with 111 additions and 7 deletions

View file

@ -741,6 +741,44 @@ void FGLRenderBuffers::BindEyeFB(int eye, bool readBuffer)
glBindFramebuffer(readBuffer ? GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER, mEyeFBs[eye]);
}
//==========================================================================
//
// Shadow map texture and frame buffers
//
//==========================================================================
void FGLRenderBuffers::BindShadowMapFB()
{
CreateShadowMap();
glBindFramebuffer(GL_FRAMEBUFFER, mShadowMapFB);
}
void FGLRenderBuffers::BindShadowMapTexture(int texunit)
{
CreateShadowMap();
glActiveTexture(GL_TEXTURE0 + texunit);
glBindTexture(GL_TEXTURE_2D, mShadowMapTexture);
}
void FGLRenderBuffers::CreateShadowMap()
{
if (mShadowMapTexture != 0)
return;
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, 1024, 1024);
mShadowMapFB = CreateFrameBuffer("ShadowMapFB", mShadowMapTexture);
glBindTexture(GL_TEXTURE_2D, textureBinding);
glActiveTexture(activeTex);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferBinding);
}
//==========================================================================
//
// Makes the scene frame buffer active (multisample, depth, stecil, etc.)

View file

@ -49,6 +49,9 @@ public:
void BindEyeTexture(int eye, int texunit);
void BindEyeFB(int eye, bool readBuffer = false);
void BindShadowMapFB();
void BindShadowMapTexture(int index);
enum { NumBloomLevels = 4 };
FGLBloomTextureLevel BloomLevels[NumBloomLevels];
@ -89,6 +92,7 @@ private:
void CreateBloom(int width, int height);
void CreateExposureLevels(int width, int height);
void CreateEyeBuffers(int eye);
void CreateShadowMap();
void CreateAmbientOcclusion(int width, int height);
GLuint Create2DTexture(const FString &name, GLuint format, int width, int height, const void *data = nullptr);
GLuint Create2DMultisampleTexture(const FString &name, GLuint format, int width, int height, int samples, bool fixedSampleLocations);
@ -133,6 +137,10 @@ private:
TArray<GLuint> mEyeTextures;
TArray<GLuint> mEyeFBs;
// Shadow map texture
GLuint mShadowMapTexture = 0;
GLuint mShadowMapFB = 0;
static bool FailedCreate;
static bool BuffersActive;
};