[osg-users] Explicitly requesting default state for attribute

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Fri Dec 11 11:38:26 PST 2020


Hi,

I'm working on a node visitor that converts FFP state to shaders and am 
extending it so it can handle more than it used to. To avoid unnecessary 
state switches for things now handled by my shaders, I'm attempting to 
remove fixed-function-related state from the nodes which have had shaders 
set up.

With modes, this works well - I can just set them off and protected, and 
the glEnable/glDisable calls go away. However, it's proving difficult to 
achieve the same behaviour with StateAttributes. The obvious solution would 
be removing the attribute from the StateSet it's attached to, but it might 
be higher in the scenegraph so also affect nodes which aren't having 
shaders attached, so it's only really safe to modify the stateset the 
shader program gets attached to.

So far, the best thing I've got is default-constructing the particular 
StateAttribute I'm interested in and attaching that to the stateset. This 
means the default state is set when the draw call happens, but I can see a 
lot of apply calls (resulting in a lot of GL calls) toggling between this 
copy of the default attribute and the copy in the state's attribute stack 
(via applyGlobalDefaultAttribute). I don't think it's wildly different from 
the number of unnecessary GL calls I was getting before I tried this.

A solution that I think would work would be 
calling getGlobalDefaultAttribute on the State object as then the pointers 
would compare equal and the apply call would get skipped, but I don't have 
any clean way of getting the State instance to my visitor.

Ideally, there'd be some neat trick I've missed that lets me say "any 
subgraph of this node doesn't care about this attribute type, so set the 
default/leave whatever's there from the last draw call" that would work 
with the normal state composition mechanisms so I could override it from a 
parent stateset or make it protected so it couldn't be overridden by parent 
statesets. Maybe a custom StateAttribute could do that, but maybe someone 
on this mailing list knows something I don't already.

Cheers,

Chris

-- 
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/5132cc44-84f8-4395-bd54-b2e88d02f67en%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20201211/fc65bffe/attachment.html>


More information about the osg-users mailing list