Page 1 of 1

Viewport::clearFrame

Posted: Wed May 06, 2009 10:26 pm
by KungFooMasta
In Short: Can we add the following API?

void Viewport::clearFrame(unsigned int buffers = FBT_COLOUR | FBT_DEPTH);

How it would help me:

I don't want the viewport to be cleared every frame, but if I set this option to false, I see garbage data on my screen. I'm at work and can't easily trace through the code to see how the viewport actually gets cleared (its not in OgreViewport.cpp, some other class does the actual clearing of the contents). It would be nice to be able to clear the viewport on demand, or at least queue the request for the appropriate time (next frame).

If this helps, this is my setup, where I experience the issue:

Code: Select all

	void SCFogOfWar::_setupVisitedTexture()
	{
		mVisitedTextureName = "FogOfWarVisitedRTT";

		Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( mVisitedTextureName, 
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 
			512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

		mVisitedTextureRenderTarget = texture->getBuffer()->getRenderTarget();

		// Add FoW camera as a source to the Texture's render target
		mVisitedTextureViewport = mVisitedTextureRenderTarget->addViewport(mFoWCam);
		//mVisitedTextureViewport->setClearEveryFrame(false);
	}

Re: Viewport::clearFrame

Posted: Fri May 08, 2009 12:20 pm
by Archangel
You could try this :

Code: Select all

Ogre::RenderSystem* pRS = Ogre::Root::getSingletonPtr()->getRenderSystem();
pRS->_setViewport(pViewport);
pRS->clearFrameBuffer(Ogre::FBT_COLOUR, mColor);
I'm not sure it'll work in your case, but that's the code I use in my GUI (which does not use "set and forget" rendering).

Re: Viewport::clearFrame

Posted: Fri May 08, 2009 6:11 pm
by KungFooMasta
I believe your solution is correct, somebody suggested that in another thread and it worked for me. Still it would be a convenient function to have IMO. If we have the ability to clear the buffer every frame, we should have the ability to clear it in a less automatic manner. I guess it would be low priority, but the solution is basically to write a function and put in code similar to what you wrote. :)

Re: Viewport::clearFrame

Posted: Fri May 08, 2009 6:15 pm
by Archangel
Agreed ;)

Re: Viewport::clearFrame

Posted: Sun May 17, 2009 3:47 pm
by sinbad
A fair request, I'll add it.

Re: Viewport::clearFrame

Posted: Mon May 18, 2009 7:04 pm
by KungFooMasta
Thanks! :D