Add CompositorInstance::Listener::notifyMaterialRemoved

Minor issues with the Ogre API that can be trivial to fix
Post Reply
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Add CompositorInstance::Listener::notifyMaterialRemoved

Post 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.
Last edited by Xavyiy on Thu Jan 31, 2013 7:38 pm, edited 1 time in total.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Add CompositorInstance::Listener::notifyMaterialRemoved

Post 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 :) .
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Re: Add CompositorInstance::Listener::notifyMaterialRemoved

Post 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
Post Reply