[FIXED] CompositorManager::setCompositorEnabled() hiccups

Minor issues with the Ogre API that can be trivial to fix
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

[FIXED] CompositorManager::setCompositorEnabled() hiccups

Post by dark_sylinc »

According to the documentation:
Disabling a compositor stops it from rendering but does not free any resources. This can be more efficient than using removeCompositor and addCompositor in cases the filter is switched on and off a lot.
However this is CompositorInstance::setEnabled code:

Code: Select all

if (mEnabled != value)
{
    mEnabled = value;

    // Create of free resource.
    if (value)
    {
        createResources(false);
    }
    else
    {
        freeResources(false, true);
    }

	/// Notify chain state needs recompile.
    mChain->_markDirty();
}
What happens? I get a serious hiccup when enabling and disabling a compositor. I'm using one for God rays (also known as "crepuscular rays" "sun shafts") and they need to be disabled when looking away from the sun.

I get a serious spike each time I look to the sun again, which is annoying.

I'm probably going to fix this myself asap as I really need this functionality to work the way it should be.

Suggestions are appreciated.
Last edited by dark_sylinc on Sun Feb 27, 2011 7:23 pm, edited 1 time in total.
User avatar
lingfors
Hobgoblin
Posts: 525
Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79

Re: CompositorManager::setCompositorEnabled() hiccups

Post by lingfors »

Pass a shader constant to the shader telling it if it should be on or off. If off, just bypass everything in the shader and output the corresponding texel without modifications...
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: CompositorManager::setCompositorEnabled() hiccups

Post by dark_sylinc »

That could work... if I weren't doing 5 different fullscreen passes. Thanks for the idea though.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: CompositorManager::setCompositorEnabled() hiccups

Post by dark_sylinc »

Piece of cake! :)

It will remain in my local copy for a few days to check everything works. So far, so good.

Edit: Checked in rev 2678
moagames
Halfling
Posts: 70
Joined: Thu Apr 10, 2008 8:10 pm
x 1

Re: [FIXED] CompositorManager::setCompositorEnabled() hiccup

Post by moagames »

I just tried your changes in the current trunk, but still get a "hiccup" when calling CompositorManager::setCompositorEnabled(false)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: [FIXED] CompositorManager::setCompositorEnabled() hiccup

Post by dark_sylinc »

If the compositor has pooled textures, you may still get hiccups, as the next compositor instance in the chain needs to recreate it's buffers. It happens in a rare case, but it can happen. It's the best explanation why you're getting hiccups when disabling (usually, only reenabling causes the perf. spike).

Additionally, try calling CompositorInstance::setEnabled() instead of CompositorManager::setCompositorEnabled. A pointer to CompositorInstance is returned after calling CompositorManager::addCompositor. If you didn't save the pointer, use this code to get it:

Code: Select all

CompositorChain *chain = compoMgr->getCompositorChain( viewport );
//You can use CompositorChain::InstanceIterator it = chain->getCompositors(); to iterate instead of a for loop
for(size_t pos=0; pos < chain->getNumCompositors(); ++pos)
{
	CompositorInstance *instance = chain->getCompositor(pos);
	if(instance->getCompositor()->getName() == "MyCompositorName")
	{
	}
}
Just to discard stupid mistakes, make sure your Ogre project recompiled, you didn't forget to copy the new DLLs into your app folder, and that you're using default branch, not 1.7 ;)
(if you have a function method named CompositorInstance::setAlive, then you're using default branch)

Edit: What GPU are you using?