Manually updating a texture RenderTarget

Problems building or running the engine, queries about how to use features etc.
Post Reply
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Manually updating a texture RenderTarget

Post by cullam »

Hi gang.
I've been doing some work with the Oculus Rift, using the already existing Ogre Oculus library. In order to use the menus already present in our software, I've started rendering the output from CEGUI onto a texture, and placed that texture on a surface in game (basically a plane that hovers in front of the players body, at all times).
The issue I'm having is that since this texture is created manually, it doesn't properly update. If I have an actual menu open, those work fine. But background CEGUI stuff doesn't erase my old curser, so when I move it, it leaves a trail of cursers behind it. But most importantly, when I close a menu, then it stays on screen, in its last state. It's technically closed, but its graphics are still painted onto the canvas.

Here's what I'm doing:

Code: Select all

Ogre::RenderWindow* renderWindow( PresMgr::getInstance()->getRenderWindow() );

    if (VRMODE) // // I shouldn't need a VRMODE switch here. If done correctly, placing the CEGUI canvas in front of the player should work. However, as there are still some issues with this, I'm using the switch for now. FIXME
    { // Sets up CEGUI, to be displayed on the Oculus Rift.
		auto& texMgr = Ogre::TextureManager::getSingleton();
        mGuiGlass = texMgr.createManual( "CEGUITexture", 
											Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
											Ogre::TEX_TYPE_2D, 
											renderWindow->getWidth(), 
											renderWindow->getHeight(), 
											0, 
											Ogre::PF_R8G8B8, 
											Ogre::TU_RENDERTARGET );
        mpRenderer = &( CEGUI::OgreRenderer::bootstrapSystem( * ( mGuiGlass->getBuffer()->getRenderTarget() ) ) ); 
    }
So my question is, how do I keep this texture updating? The CreateManual function indicates that it won't be auto-updated, but doesn't seem to point out how I need to do it manually. Sorry if the answer is obvious. This is probably simple stuff, if you're more familiar with Ogre.
-cullam
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: Manually updating a texture RenderTarget

Post by scrawl »

Sounds like you want Viewport::setClearEveryFrame(true)
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Manually updating a texture RenderTarget

Post by cullam »

That sounds like the right ballpark. However, I'm trying to figure out exactly how it applies to my texture / renderTarget. The viewport that they eventually get passed into already updates, and calling this function, just in case, doesn't seem to help. It's just the CEGUI texture where the issue lies.
The previous code I posted was part of the setupGUI() function. Here is the context where that happens:

Code: Select all

mpPresMgr->setupGUI( mpCameraSceneNode, mpCamera->getDirection(), mpCamera->getUp() ); 

	// Create and add the viewport to the camera.
	Ogre::Viewport* vp = win->addViewport( mpCamera );
	LOG_INFO << "Added a viewport. "; 
	vp->setBackgroundColour( Ogre::ColourValue( 0, 0, 0 ) );
    vp->setVisibilityMask( 0xfffb );
//	vp->setAutoUpdated( true ); 
	vp->setClearEveryFrame( true ); 
I tried both setAutoUpdated and setClearEveryFrame. Neither made a difference to the non-refreshing background issue. I think this is very close to the right answer, but there's clearly something I'm still not understanding here. Probably a murky undserstanding of how renderTargets, Viewports, Cameras, and Textures all interact in Ogre 1.8.
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: Manually updating a texture RenderTarget

Post by scrawl »

You'd want to change this for the viewport of the texture render target, not the viewport of the render window.
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Manually updating a texture RenderTarget

Post by cullam »

OK, I think I'm getting closer to having this figured out!

The first code I posted was inside the GuiSystem constructor, which gets called here, in setupGUI():

Code: Select all

mpGuiSystem = new GuiSystem();
	if (cameraNode == NULL )
	{
		LOG_INFO << "The camera node is null, so you're GUI isn't going to show up. You probably called PresMgr::setupGUI() before creating the camera."; 
		return; 
	}
	mpGuiSystem->setupViewport( camera ); 
A bunch of other stuff happens after that, but I want to concentrate on that last line, that I just added. SetupViewport does this:

Code: Select all

mpViewPort = mGuiGlass->getBuffer()->getRenderTarget()->addViewport( camera ); 
	
	mpViewPort->setAutoUpdated(true);  
//	mpViewPort->setClearEveryFrame(true); 
This has an effect on the GUI! However, it means that the GUI appears as pure black, all of the time. So I think I'm in the ballpark, but this seems to be completely overwriting the texture information that's getting written in from CEGUI. Or possibly I'm causing CEGUI to no longer get rendered to this texture in the first place...
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Manually updating a texture RenderTarget

Post by cullam »

Sorry, I should have mentioned that I tired both the commented out function, and the currently used function, both with the same effect.
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Manually updating a texture RenderTarget

Post by cullam »

Further addition! Adding a viewport with that camera is what actually causes the issue, not the autoUpdate, or clearEveryFrame. Looking into what I've done wrong now.
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Manually updating a texture RenderTarget

Post by cullam »

Still having issues here. I'm telling the viewports to clear every frame, and I've tried adding them to the auto update list. Sill no luck. I'm doing this right as the viewport are created:

Code: Select all

		m_viewports[i] = win->addViewport(m_cameras[i], i+1, 0.5f*i, 0, 0.5f, 1.0f); // the i+1 refers to the z-order, and is a test hack, as the program is currently crashing, saying that that z-order has already been used. FIXME
		m_viewports[i]->setBackgroundColour(g_defaultViewportColour);
		m_viewports[i]->setAutoUpdated( true ); 
		m_viewports[i]->setClearEveryFrame( true ); 
Any idea what I'm still missing?
Post Reply