setting materials via direct pointer in overlayelement

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
Chas
Gnoblar
Posts: 8
Joined: Thu Jul 13, 2006 12:35 am

setting materials via direct pointer in overlayelement

Post by Chas » Thu May 27, 2010 1:45 am

Hello,

Sorry if this has already been debated, but would it be an issue to be able to set materials not only in Ogre::Entity but also in Ogre::OverlayElement by a material pointer (or a shared pointer) in addition to a string name? My intent is to reduce the costs associated with a vector of strings and instead to use a vector of basic pointers to manage materials. Thanks.

Chas

E.G.
Ogre::OverlayElement->setMaterial(Ogre::Material*);
Ogre::Entity->setMaterial(Ogre::Material*);
0 x

User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1668
Joined: Mon Jan 21, 2008 10:26 pm

Re: setting materials via direct pointer in overlayelement

Post by madmarx » Thu May 27, 2010 6:14 pm

Out of curiosity, for your problem, the solution seems obvious : Can't you do setMaterial(thePointerOfTheMaterial->getName()) ? That way you can manipulate your material pointers. Am I missing something? extending overlayelement?
0 x
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0

User avatar
Chas
Gnoblar
Posts: 8
Joined: Thu Jul 13, 2006 12:35 am

Re: setting materials via direct pointer in overlayelement

Post by Chas » Thu May 27, 2010 6:38 pm

yeah sorry, i was a little vague on my scenario. at the moment, i manage a vector of Ogre::String* where i have to new and delete strings at startup and shutdown. My overlays and entities change materials by accessing (with an index) the material names which are organized in a vector in my engine core. if i could just use the Ogre::Material* from Ogre to change the OverlayElement material and just store that in my std::vector, then that would save some housekeeping. what i'm doing now works fine, but using Ogre::Material* instead might be a more efficient (perhaps/probably to the overlayelement object as well) alternative. thanks.
0 x

User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1668
Joined: Mon Jan 21, 2008 10:26 pm

Re: setting materials via direct pointer in overlayelement

Post by madmarx » Thu May 27, 2010 8:07 pm

if i could just use the Ogre::Material* from Ogre to change the OverlayElement material and just store that in my std::vector, then that would save some housekeeping
Yes, but you already can. There is no problem to do that, this is not linked to the overlayelement interface.
You can get the pointer through : Ogre::MaterialManager::getSingleton().getByName(..thename..).
0 x
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0

User avatar
Chas
Gnoblar
Posts: 8
Joined: Thu Jul 13, 2006 12:35 am

Re: setting materials via direct pointer in overlayelement

Post by Chas » Thu May 27, 2010 8:20 pm

yes, getting the material pointer is no problem, but can you set Ogre::OverlayElement->setMaterial(const MaterialPtr&) like you can with "void Ogre::Entity::setMaterial(const MaterialPtr& material)" all i found was "void Ogre::OverlayElement::setMaterialName(const String& matName)". Ogre::Entity has both functions but Ogre::OverlayElement only has the function accepting the string&. My question is not getting the material pointer but setting the overlayelement's material via material pointer instead of a string&.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: setting materials via direct pointer in overlayelement

Post by jacmoe » Thu May 27, 2010 8:21 pm

Patch.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1668
Joined: Mon Jan 21, 2008 10:26 pm

Re: setting materials via direct pointer in overlayelement

Post by madmarx » Fri May 28, 2010 9:06 am

I have no problem with a patch, but my point is :
If you already got the material*, then you got the material name! It's just 1 function call (material::getName())!

Therefore your justifications seems not logical. Isn't it more only because you suspect an optimization by transmitting the pointer, than for any other reason?

If you transmit a Material*, then inside OverlayElement you are bound to extract a shared pointer, and the safe way to do it is to access the MaterialManager (other wise you will get several MaterialPtr on the same resource without the same counter).

If you transmit a MaterialPtr, then it means you are storing your MaterialPtr in a std::vector in your program, which is not that much efficient (compared to a std::string with move semantics....). AFAIK MaterialPtr does not have move semantics so it's much slower...
This is why I find the whole thing funny :).

I have no problem with a patch though.
0 x
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0

User avatar
Chas
Gnoblar
Posts: 8
Joined: Thu Jul 13, 2006 12:35 am

Re: setting materials via direct pointer in overlayelement

Post by Chas » Fri May 28, 2010 12:43 pm

Thanks for the reply. I was just curious why the inconsistency in the interface between Entity and OverlayElement, and I wanted to avoid "unnecessary" string comparisions occuring inside Ogre. I know that smart pointers have costs associated and would prefer to use dumb pointers but I understand the rationale for the smart pointers. Anyway, that is water under the bridge and I am not interested in a religious coding debate. If some stroustrup wants to submit a patch for this, great, if not, that's fine too.
0 x

Post Reply