From 33f19e55b8ae076e4b72b1673ddea750c74a264f Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 18 May 2014 23:47:52 +0200 Subject: [PATCH] Fix for shadows. --- src/graphics/glwrap.cpp | 15 ++++++++++++--- src/graphics/rtts.cpp | 5 +++-- src/graphics/rtts.hpp | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 117ec9f2c..0dc0aebb2 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -534,9 +534,18 @@ FrameBuffer::FrameBuffer(const std::vector &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); } diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 955a9d8bb..c661c7673 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -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 {shadowColorTex}, shadowDepthTex, 1024, 1024); + shadowFBO = new FrameBuffer(std::vector {shadowColorTex}, shadowDepthTex, 1024, 1024); } glBindFramebuffer(GL_FRAMEBUFFER, 0); } RTT::~RTT() { + delete shadowFBO; glDeleteTextures(RTT_COUNT, RenderTargetTextures); glDeleteTextures(1, &DepthStencilTexture); if (irr_driver->getGLSLVersion() >= 150) diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 6307235b8..96127b3f2 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -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(); };