<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;
        mso-fareast-language:EN-US;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 2.0cm 2.0cm 2.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="IT" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Thanks Sebastian,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">I’m simply trying to get the alpha value of the diffuse component of the material properties, because I have to pass it to an underlying<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">graphic library that I use for rendering that custom drawable.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">BTW, I further investigated.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">In the following function:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas;color:windowtext;mso-fareast-language:IT">State::captureCurrentState(StateSet& stateset)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">The _attributeMap actually contains as MATERIAL attribute exactly the pointer to the osg::Material property that I created.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">But in the attribute stack it appears as the ‘last_applied_attribute’, and ‘changed’ is set to true.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">For all other attributes the pointers stored in ‘last_applied_attribute’ are correct as well, but ‘changed’ is set to false.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Also, in that AttributeStack the member attributeVec contains just one element, that is not the correct one (it points to a different osg::Material).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">While for all the other attributes, which have ‘changed’ set to false, last_applied_attribute coincides with the first element in attributeVec.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">I don’t know anything of that code, but I don’t understand why osg::Material appears to be changed, while other attributes not.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Or should I use a different API to get the current osg::Material?
</span><span lang="EN-US" style="color:#1F497D">I found this in State header file:</span><span lang="EN-US" style="color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:windowtext;mso-fareast-language:IT">        /** Get the current specified attribute, return NULL if one has not yet been applied.*/<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:windowtext;mso-fareast-language:IT">        const StateAttribute* getLastAppliedAttribute(StateAttribute::Type type, unsigned int member=0)
 const;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:windowtext;mso-fareast-language:IT"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="color:#1F497D">So, it looks like the current value of an attribute is actually the last applied!?! That is how the API is described.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="color:#1F497D">So, what captureCurrentState should do instead?</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:windowtext;mso-fareast-language:IT"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Gianluca Natale<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="color:windowtext;mso-fareast-language:IT">From:</span></b><span lang="EN-US" style="color:windowtext;mso-fareast-language:IT"> osg-users [<a href="mailto:osg-users-bounces@lists.openscenegraph.org">mailto:osg-users-bounces@lists.openscenegraph.org</a>]
<b>On Behalf Of </b>Sebastian Messerschmidt<br>
<b>Sent:</b> marted́ 23 giugno 2015 18:15<br>
<b>To:</b> OpenSceneGraph Users; Osg Users<br>
<b>Subject:</b> Re: [osg-users] issue about getting the material properties from the current state in rendering info<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt;mso-fareast-language:IT"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal">Am 23.06.2015 18:05, schrieb Gianluca Natale:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US">Hi all,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I’m using OSG 3.0.1.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I have an issue when I try to retrieve the material properties from the rendering info, in my custom drawable.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">To be clearer:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I have a custom drawable, for which I implemented a</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">myDrawable::drawImplementation(osg::RenderInfo& osgRenderInfo).</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">When I try to get the material properties inside that function, by following code:</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">osg::StateSet  drwbStateSet;</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">osg::State *state = osgRenderInfo.getState();</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">state->captureCurrentState(drwbStateSet);</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">the returned material properties is invalid.</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">Specifically, I put a breakpoint in following function:</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none">StateSet::setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value)<o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"> <o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">that is called inside captureCurrentState.</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">When the attribute is an osg::Material, the _ptr is different from the one allocated when the material has been set, in the state set associated to a parent node of that drawable.</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">Furthermore, _userDataContainer is 0x0000000000000000, so no valid osg::Material is returned in the captured state set.</span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:IT">User data defaults to nullptr. So if you're not setting it up that is expected.<br>
As you don't explain why you are trying to inspect state during draw it is hard to guess what you are after.<br>
I simply guess that your state is set up somewhere further up in the stategraph (i.e. in one of the parents) and that state is set up lazy.
<br>
Maybe Robert can give some insights here. <br>
<br>
<br>
<o:p></o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">Any idea of the possible cause of the issue? Where did I go wrong?</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">BTW, all other attributes (polygon offset, polygon mode, etc…) are returned correctly.</span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:IT">Are you sure you are setting up an osg::Material state attribute somewhere?<o:p></o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">Gianluca Natale</span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:IT"><br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>osg-users mailing list<o:p></o:p></pre>
<pre><a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><o:p></o:p></pre>
<pre><a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:IT"><o:p> </o:p></span></p>
</div>
</body>
</html>