You have to update this Irrlicht parts for usage MRT:
Code: Select all
*** Irrlicht Include ***
------------------------------------- IVideoDriver.h -------------------------------------
virtual bool setRenderTarget(core::array<video::ITexture*> texture, bool clearBackBuffer=true, bool clearZBuffer=true, SColor color=video::SColor(0,0,0,0)) = 0;
------------------------------------------------------------------------------------------
********************************************************************
*** Irrlicht Source ***
------------------------------------- CNullDriver.h -------------------------------------
virtual bool setRenderTarget(core::array<video::ITexture*> texture, bool clearBackBuffer, bool clearZBuffer, SColor color);
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------ CNullDriver.cpp ------------------------------------
bool CNullDriver::setRenderTarget(core::array<video::ITexture*> texture, bool clearBackBuffer, bool clearZBuffer, SColor color)
{
return false;
}
------------------------------------------------------------------------------------------
********************************************************************
------------------------------------ CD3D9Driver.h ------------------------------------
virtual bool setRenderTarget(core::array<video::ITexture*> texture, bool clearBackBuffer=false, bool clearZBuffer=false, SColor color=video::SColor(0,0,0,0));
------------------------------------------------------------------------------------------
********************************************************************
----------------------------------- CD3D9Driver.cpp -----------------------------------
bool CD3D9Driver::setRenderTarget(core::array<video::ITexture*> texture,
bool clearBackBuffer, bool clearZBuffer,
SColor color)
{
// check for right driver type
for(int i = 0; i < texture.size(); i++)
{
if (texture[i] && texture[i]->getDriverType() != EDT_DIRECT3D9)
{
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
return false;
}
// check for valid render target
CD3D9Texture* tex = (CD3D9Texture*)texture[i];
if (texture[i] && !tex->isRenderTarget())
{
os::Printer::log("Fatal Error: Tried to set a non render target texture as render target.", ELL_ERROR);
return false;
}
if (texture[i] && (tex->getSize().Width > ScreenSize.Width ||
tex->getSize().Height > ScreenSize.Height ))
{
os::Printer::log("Error: Tried to set a render target texture which is bigger than the screen.", ELL_ERROR);
return false;
}
}
// check if we should set the previous RT back
bool ret = true;
// check only first texture from array
if (texture[0] == 0)
{
if (PrevRenderTarget)
{
if (FAILED(pID3DDevice->SetRenderTarget(0, PrevRenderTarget)))
{
os::Printer::log("Error: Could not set back to previous render target.", ELL_ERROR);
ret = false;
}
CurrentRendertargetSize = core::dimension2d<s32>(0,0);
PrevRenderTarget->Release();
PrevRenderTarget = 0;
for(int i = 1; i < texture.size(); i++)
{
pID3DDevice->SetRenderTarget(i, NULL);
}
}
}
else
{
// we want to set a new target. so do this.
// store previous target
if (!PrevRenderTarget)
if (FAILED(pID3DDevice->GetRenderTarget(0, &PrevRenderTarget)))
{
os::Printer::log("Could not get previous render target.", ELL_ERROR);
return false;
}
// set new render target
for(int i = 0; i < texture.size(); i++)
{
// set current texture
CD3D9Texture* tex = (CD3D9Texture*)texture[i];
if (FAILED(pID3DDevice->SetRenderTarget(i, tex->getRenderTargetSurface())))
{
os::Printer::log("Error: Could not set render target.", ELL_ERROR);
return false;
}
CurrentRendertargetSize = tex->getSize();
}
}
if (clearBackBuffer || clearZBuffer)
{
DWORD flags = 0;
if (clearBackBuffer)
flags |= D3DCLEAR_TARGET;
if (clearZBuffer)
flags |= D3DCLEAR_ZBUFFER;
pID3DDevice->Clear(0, NULL, flags, color.color, 1.0f, 0);
}
return ret;
}
------------------------------------------------------------------------------------------
********************************************************************
Simple usage:
Code: Select all
// You have to create RTT textures with good resolutions (no diffrence!)
ITexture* RTT1 = Driver->createRenderTargetTexture(dimension2d<s32>(512,512));
ITexture* RTT2 = Driver->createRenderTargetTexture(dimension2d<s32>(512,512));
// You have to create Array with this textures usage in MRT
array<ITexture*> arrTex;
// You have put textures to this array
arrTex.push_back(RTT1);
arrTex.push_back(RTT2);
// Now You setRenderTarget with textures array:
Driver->setRenderTarget(arrTex, true, true, SColor(255,0,0,0));
// Draw Yours data and write per shaders infos to Yours Textures
// You have to disable Render Target, so You have to change first component of array to 'NULL'
arrTex[0] = 0;
// Now array with 'NULL' value disable Render Target
Driver->setRenderTarget(arrTex);
// You have to set good value for first array component
arrTex[0] = RTT1;
// It's all! You have MRT support in Yours application!