There's no such if in 1.7, back then the library could trust the user not to call setRenderTarget twice with the same arguments
The backport ended up being a little involved, so I don't know if you want to put it to the official tree.
edit: But it works, yeah.
Code: Select all
Subject: [PATCH] Backport MRT changing fix from trunk
---
include/IVideoDriver.h | 9 +++++++++
source/Irrlicht/COpenGLDriver.cpp | 31 +++++++++++++++++++++++++++++++
source/Irrlicht/COpenGLDriver.h | 1 +
3 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h
index f6a88e3..7f179c5 100644
--- a/include/IVideoDriver.h
+++ b/include/IVideoDriver.h
@@ -220,6 +220,15 @@ namespace video
TargetType(target), ColorMask(colorMask),
BlendFuncSrc(blendFuncSrc), BlendFuncDst(blendFuncDst),
BlendEnable(blendEnable) {}
+ bool operator!=(const IRenderTarget& other) const
+ {
+ return ((RenderTexture != other.RenderTexture) ||
+ (TargetType != other.TargetType) ||
+ (ColorMask != other.ColorMask) ||
+ (BlendFuncSrc != other.BlendFuncSrc) ||
+ (BlendFuncDst != other.BlendFuncDst) ||
+ (BlendEnable != other.BlendEnable));
+ }
ITexture* RenderTexture;
E_RENDER_TARGET TargetType:8;
E_COLOR_PLANE ColorMask:8;
diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp
index 8fd435b..51e7fce 100644
--- a/source/Irrlicht/COpenGLDriver.cpp
+++ b/source/Irrlicht/COpenGLDriver.cpp
@@ -3660,6 +3660,22 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
return false;
}
+#if defined(GL_EXT_framebuffer_object)
+ if (CurrentTarget==ERT_MULTI_RENDER_TEXTURES)
+ {
+ for (u32 i=0; i<MRTargets.size(); ++i)
+ {
+ if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE)
+ {
+ for (++i; i<MRTargets.size(); ++i)
+ if (MRTargets[i].TargetType==ERT_RENDER_TEXTURE)
+ extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, 0, 0);
+ }
+ }
+ MRTargets.clear();
+ }
+#endif
+
// check if we should set the previous RT back
setActiveTexture(0, 0);
@@ -3686,6 +3702,8 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
CurrentTarget=ERT_FRAME_BUFFER;
glDrawBuffer(Doublebuffer?GL_BACK_LEFT:GL_FRONT_LEFT);
}
+ // we need to update the matrices due to the rendersize change.
+ Transformation3DChanged = true;
clearBuffers(clearBackBuffer, clearZBuffer, false, color);
return true;
@@ -3696,8 +3714,21 @@ bool COpenGLDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuff
bool COpenGLDriver::setRenderTarget(const core::array<video::IRenderTarget>& targets,
bool clearBackBuffer, bool clearZBuffer, SColor color)
{
+ // if simply disabling the MRT via array call
if (targets.size()==0)
return setRenderTarget(0, clearBackBuffer, clearZBuffer, color);
+ // if disabling old MRT, but enabling new one as well
+ if ((MRTargets.size()!=0) && (targets != MRTargets))
+ setRenderTarget(0, clearBackBuffer, clearZBuffer, color);
+ // if no change, simply clear buffers
+ else if (targets == MRTargets)
+ {
+ clearBuffers(clearBackBuffer, clearZBuffer, false, color);
+ return true;
+ }
+
+ // copy to storage for correct disabling
+ MRTargets = targets;
u32 maxMultipleRTTs = core::min_(static_cast<u32>(MaxMultipleRenderTargets), targets.size());
diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h
index b882887..b76477a 100644
--- a/source/Irrlicht/COpenGLDriver.h
+++ b/source/Irrlicht/COpenGLDriver.h
@@ -431,6 +431,7 @@ namespace video
SMaterial Material, LastMaterial;
COpenGLTexture* RenderTargetTexture;
+ core::array<video::IRenderTarget> MRTargets;
const ITexture* CurrentTexture[MATERIAL_MAX_TEXTURES];
core::array<COpenGLFBODepthTexture*> DepthTextures;
struct SUserClipPlane
--
1.7.2.1