Commit a204bb35 authored by hybrid's avatar hybrid

Real fix for the MRT problem. Last time only parts of the problem were fixed....

Real fix for the MRT problem. Last time only parts of the problem were fixed. Now, all RTT states should be fixed again. Also, test results are commited and work for both drivers.
Also changed the FBODepthTexture implementation in that it will not create another FBO, but only the depth/stencil texture or renderbuffer.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3519 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5acaa94c
...@@ -3828,11 +3828,11 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff ...@@ -3828,11 +3828,11 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
if (CurrentTarget==ERT_MULTI_RENDER_TEXTURES) if (CurrentTarget==ERT_MULTI_RENDER_TEXTURES)
{ {
for (u32 i=1; i<MRTargets.size(); ++i) for (u32 i=0; i<MRTargets.size(); ++i)
{ {
if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE) if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE)
{ {
for (; i<MRTargets.size(); ++i) for (++i; i<MRTargets.size(); ++i)
if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE) if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE)
extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, 0, 0); extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, 0, 0);
} }
...@@ -3870,6 +3870,7 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff ...@@ -3870,6 +3870,7 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
// we need to update the matrices due to the rendersize change. // we need to update the matrices due to the rendersize change.
Transformation3DChanged=true; Transformation3DChanged=true;
} }
clearBuffers(clearBackBuffer, clearZBuffer, false, color); clearBuffers(clearBackBuffer, clearZBuffer, false, color);
return true; return true;
...@@ -3994,7 +3995,7 @@ bool COpenGLDriver::setRenderTarget(const core::array<video::IRenderTarget>& tar ...@@ -3994,7 +3995,7 @@ bool COpenGLDriver::setRenderTarget(const core::array<video::IRenderTarget>& tar
#ifdef GL_EXT_framebuffer_object #ifdef GL_EXT_framebuffer_object
// attach texture to FrameBuffer Object on Color [i] // attach texture to FrameBuffer Object on Color [i]
attachment = GL_COLOR_ATTACHMENT0_EXT+i; attachment = GL_COLOR_ATTACHMENT0_EXT+i;
if (targets[i].RenderTexture != RenderTargetTexture) if ((i != 0) && (targets[i].RenderTexture != RenderTargetTexture))
extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, static_cast<COpenGLTexture*>(targets[i].RenderTexture)->getOpenGLTextureName(), 0); extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, static_cast<COpenGLTexture*>(targets[i].RenderTexture)->getOpenGLTextureName(), 0);
#endif #endif
MRTs[i]=attachment; MRTs[i]=attachment;
......
...@@ -630,7 +630,7 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size, ...@@ -630,7 +630,7 @@ COpenGLFBOTexture::COpenGLFBOTexture(const core::dimension2d<u32>& size,
#ifdef GL_EXT_framebuffer_object #ifdef GL_EXT_framebuffer_object
// generate frame buffer // generate frame buffer
Driver->extGlGenFramebuffers(1, &ColorFrameBuffer); Driver->extGlGenFramebuffers(1, &ColorFrameBuffer);
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_EXT, ColorFrameBuffer); bindRTT();
// generate color texture // generate color texture
glGenTextures(1, &TextureName); glGenTextures(1, &TextureName);
...@@ -675,6 +675,7 @@ void COpenGLFBOTexture::bindRTT() ...@@ -675,6 +675,7 @@ void COpenGLFBOTexture::bindRTT()
#ifdef GL_EXT_framebuffer_object #ifdef GL_EXT_framebuffer_object
if (ColorFrameBuffer != 0) if (ColorFrameBuffer != 0)
Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_EXT, ColorFrameBuffer); Driver->extGlBindFramebuffer(GL_FRAMEBUFFER_EXT, ColorFrameBuffer);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
#endif #endif
} }
...@@ -697,7 +698,7 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture( ...@@ -697,7 +698,7 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture(
const io::path& name, const io::path& name,
COpenGLDriver* driver, COpenGLDriver* driver,
bool useStencil) bool useStencil)
: COpenGLFBOTexture(size, name, driver), DepthRenderBuffer(0), : COpenGLTexture(name, driver), DepthRenderBuffer(0),
StencilRenderBuffer(0), UseStencil(useStencil) StencilRenderBuffer(0), UseStencil(useStencil)
{ {
#ifdef _DEBUG #ifdef _DEBUG
...@@ -733,19 +734,14 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture( ...@@ -733,19 +734,14 @@ COpenGLFBODepthTexture::COpenGLFBODepthTexture(
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, ImageSize.Width, glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, ImageSize.Width,
ImageSize.Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0); ImageSize.Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
// we 're in trouble! the code below does not complete // generate stencil texture
// the FBO currently... stencil buffer is only glGenTextures(1, &StencilRenderBuffer);
// supported with EXT_packed_depth_stencil extension glBindTexture(GL_TEXTURE_2D, StencilRenderBuffer);
// (above) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// // generate stencil texture glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glGenTextures(1, &StencilRenderBuffer); glTexImage2D(GL_TEXTURE_2D, 0, GL_STENCIL_INDEX, ImageSize.Width,
// glBindTexture(GL_TEXTURE_2D, StencilRenderBuffer); ImageSize.Height, 0, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, 0);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_STENCIL_INDEX, ImageSize.Width,
// ImageSize.Height, 0, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, 0);
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} }
} }
#ifdef GL_EXT_framebuffer_object #ifdef GL_EXT_framebuffer_object
...@@ -889,6 +885,7 @@ bool checkFBOStatus(COpenGLDriver* Driver) ...@@ -889,6 +885,7 @@ bool checkFBOStatus(COpenGLDriver* Driver)
} }
#endif #endif
os::Printer::log("FBO error", ELL_ERROR); os::Printer::log("FBO error", ELL_ERROR);
_IRR_DEBUG_BREAK_IF(true);
return false; return false;
} }
......
...@@ -172,7 +172,7 @@ protected: ...@@ -172,7 +172,7 @@ protected:
//! OpenGL FBO depth texture. //! OpenGL FBO depth texture.
class COpenGLFBODepthTexture : public COpenGLFBOTexture class COpenGLFBODepthTexture : public COpenGLTexture
{ {
public: public:
//! FrameBufferObject depth constructor //! FrameBufferObject depth constructor
......
...@@ -66,7 +66,7 @@ static bool testWithDriver(video::E_DRIVER_TYPE driverType) ...@@ -66,7 +66,7 @@ static bool testWithDriver(video::E_DRIVER_TYPE driverType)
driver->beginScene (true, true, video::SColor (255, 200, 200, 200)); driver->beginScene (true, true, video::SColor (255, 200, 200, 200));
// render // render
device->getSceneManager()->getActiveCamera()->setPosition(core::vector3df(0,5,0)); device->getSceneManager()->getActiveCamera()->setPosition(core::vector3df(0,0,-15));
driver->setRenderTarget( gbufferlist ); driver->setRenderTarget( gbufferlist );
device->getSceneManager()->drawAll(); device->getSceneManager()->drawAll();
driver->setRenderTarget(0); driver->setRenderTarget(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment