Swap Rendertargets with Compositor

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Swap Rendertargets with Compositor

Post by ChristophLGDV »

Hi,

I want to swap render targets while using compositors:

I have two Textures.

Code: Select all

mHistoryTexture[2]
before each frame I do the 4 steps below:

This is obviously horribly slow.
But, how do I do this?

Thanks for reading!

1. swap Textures:

Code: Select all

std::swap( mHistoryTexture[0],  mHistoryTexture[1]);

2. remove Viewport

Code: Select all

Ogre::RenderTexture* renderTexOld = mHistoryTexture[0]->getBuffer()->getRenderTarget(); 	
	renderTexOld->removeViewport(0);		
3. add a New Rendertarget

Code: Select all

Ogre::RenderTexture* renderTexSwapped = mHistoryTexture[1]->getBuffer()->getRenderTarget(); 		 			
	renderTexSwapped->addViewport(mCam);
	renderTexSwapped->getViewport(0)->setClearEveryFrame(true, Ogre::FBT_COLOUR|Ogre::FBT_DEPTH);
	renderTexSwapped->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
	renderTexSwapped->getViewport(0)->setOverlaysEnabled(false); 	
4. add the other texture as rad texture // *This should not matter

Code: Select all

mMaterialsTXAA->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTexture( mHistoryTexture[0]); 
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 220

Re: Swap Rendertargets with Compositor

Post by scrawl »

What you could do is keep the RenderTargets and Viewports for both textures at all times, but then you set the rendertargets to active or inactive depending on the current frame, e.g.

Code: Select all

# for an even frame
rendertarget0->setActive(false);
rendertarget1->setActive(true);

# for an odd frame
rendertarget0->setActive(true);
rendertarget1->setActive(false);
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Re: Swap Rendertargets with Compositor

Post by ChristophLGDV »

Hi scrawl, thank you for your reply.
That is along the lines to what I did. However I duplicated everything, including the Compositors and viewports
Then I swap everything and trigger the viewport update alternatingly after every update.

That is the most UnOpenGL way I could think of. :)