Fix for shadows.

This commit is contained in:
vlj 2014-05-18 23:47:52 +02:00
parent 31487814fe
commit 33f19e55b8
3 changed files with 17 additions and 7 deletions

View File

@ -534,9 +534,18 @@ FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, s
{
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
for (unsigned i = 0; i < RTTs.size(); i++)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DS, 0);
if (irr_driver->getGLSLVersion() >= 330)
{
for (unsigned i = 0; i < RTTs.size(); i++)
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, RTTs[i], 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DS, 0);
}
else
{
for (unsigned i = 0; i < RTTs.size(); i++)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DS, 0);
}
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
}

View File

@ -144,15 +144,16 @@ RTT::RTT(size_t width, size_t height)
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, 1024, 1024, 4, 0, GL_RED, GL_UNSIGNED_BYTE, 0);
glGenTextures(1, &shadowDepthTex);
glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_STENCIL, 1024, 1024, 4, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
shadowFBO = FrameBuffer(std::vector<GLuint> {shadowColorTex}, shadowDepthTex, 1024, 1024);
shadowFBO = new FrameBuffer(std::vector<GLuint> {shadowColorTex}, shadowDepthTex, 1024, 1024);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
RTT::~RTT()
{
delete shadowFBO;
glDeleteTextures(RTT_COUNT, RenderTargetTextures);
glDeleteTextures(1, &DepthStencilTexture);
if (irr_driver->getGLSLVersion() >= 150)

View File

@ -37,7 +37,7 @@ public:
RTT(size_t width, size_t height);
~RTT();
FrameBuffer &getShadowFBO() { return shadowFBO; }
FrameBuffer &getShadowFBO() { return *shadowFBO; }
unsigned getShadowDepthTex() const { return shadowDepthTex; }
unsigned getDepthStencilTexture() const { return DepthStencilTexture; }
@ -49,7 +49,7 @@ private:
unsigned DepthStencilTexture;
unsigned shadowColorTex, shadowDepthTex;
FrameBuffer shadowFBO;
FrameBuffer* shadowFBO;
LEAK_CHECK();
};