Page 1 of 1

Add CompositorInstance::Listener::notifyMaterialRemoved

Posted: Thu Jan 31, 2013 1:42 pm
by Xavyiy
Hi guys,

I've a simple papercut related to the compositor instance listener: add another function to notify when a compositor local/temporal material has been "removed" (== the target operation has been removed), so the material is no longer valid.

Changes:
OgreCompositorInstance.h:
Inside the Listener class

Code: Select all

/** Notification of when a render target operation involving a material (like
				rendering a quad) is destroyed, so the temporal material is no longer valid
				@param pass_id	Pass identifier within Compositor instance, this is specified 
								by the user by CompositionPass::setIdentifier().
				@param mat		Material, this may be changed at will and will only affect
								the current instance of the Compositor, not the global material
								it was cloned from.
			 */
			virtual void notifyMaterialRemoved(uint32 pass_id, MaterialPtr &mat);

Code: Select all

/** Notify listeners when a material is no longer valir
		*/
		void _fireNotifyMaterialRemoved(uint32 pass_id, MaterialPtr &mat);
OgreCompositorInstance.cpp:
Inside the RSQuadOperation class, add a destructor:

Code: Select all

~RSQuadOperation()
	{
		instance->_fireNotifyMaterialRemoved(pass_id, mat);
	}

Code: Select all

void CompositorInstance::_fireNotifyMaterialRemoved(uint32 pass_id, MaterialPtr &mat)
{
	Listeners::iterator i, iend=mListeners.end();
	for(i=mListeners.begin(); i!=iend; ++i)
		(*i)->notifyMaterialRemoved(pass_id, mat);
}

Code: Select all

void CompositorInstance::Listener::notifyMaterialRemoved(uint32 pass_id, MaterialPtr &mat)
{
}
Edit: due to how the compositor is designed, we need to ensure that the rende operations will be destroyed before it's parent technique, so we've to add clearCompiledState() to the the following compositor chain functions: (OgreCompositorChain.cpp)

Code: Select all

//-----------------------------------------------------------------------
void CompositorChain::removeCompositor(size_t index)
{
	clearCompiledState();

    assert (index < mInstances.size() && "Index out of bounds.");
    Instances::iterator i = mInstances.begin() + index;
    OGRE_DELETE *i;
    mInstances.erase(i);
    
    mDirty = true;
}
//-----------------------------------------------------------------------
size_t CompositorChain::getNumCompositors()
{
    return mInstances.size();
}
//-----------------------------------------------------------------------
void CompositorChain::removeAllCompositors()
{
	clearCompiledState();

    Instances::iterator i, iend;
    iend = mInstances.end();
    for (i = mInstances.begin(); i != iend; ++i)
    {
		OGRE_DELETE *i;
    }
    mInstances.clear();
    
    mDirty = true;
}
Not a very smart solution, but it works :). Any better solution would require deeper changes so, since in Ogre 2.0 the compositor system will be updated (see dark_sylinc notes), I think it's ok for now.

Re: Add CompositorInstance::Listener::notifyMaterialRemoved

Posted: Thu Jan 31, 2013 4:04 pm
by spacegaier
Would it be possibly to create either a JIRA ticket for that or even better, provide a quick pull request? Would speed up the process a lot :) .

Re: Add CompositorInstance::Listener::notifyMaterialRemoved

Posted: Thu Jan 31, 2013 7:40 pm
by Xavyiy
Sure, I'll open a JIRA ticket for it. (I'm not used to bitbucket so the pull request will be harder :roll: )

I'm still fighting with it (see the previous post edition), one time all will be working I'll open the JIRA ticket :)

Xavier