Re: [osg-users] threading and captureCurrentState
Hi John, If you need this to setup uniforms for shadow fragment shaders then maybe standard GL gl_FrontFacing variable could do the trick ? Its available at least in GLSL 1.50 and above. I have not checked when it was introduced maybe its available in earlier GLSL profiles. Wojtek From: PCJohn Sent: Thursday, August 05, 2010 12:41 AM To: OpenSceneGraph Users Subject: Re: [osg-users] threading and captureCurrentState Yes. There is. Oh. I see. Sorry for confusion, you call it attribute stack and that is a correct name for it. Anyway, there is State::_attributeMap that is composed of AttributeStack structs and they have a member attributeVec that is serving as a stack of attributes. The top of the stack is current attribute or the last pushed attribute. That is the one I need to get. Until now, I see a threading issue like two threads manipulating the attribute stack. I'll say it again: you can't access those attribute stacks from the cull traversal. They don't contain anything sensible. I that case a different question: How to get current osg::FrontFace attribute? I mean the one that would be active for any drawable traversed at the present moment during cull traversal that is just in progress and I am handling it in my custom Shadow class that is already working perfectly except some attribute values that user may pass from the scene graph above and that need to be properly handled to cast shadows correctly. The answer: you do not need it would be wrong at the moment. Thx, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
Hi guys, thanks for all your answers. Unfortunately, I am leaving for a week holidays in one hour. Anyway, the problem is following: - I am generating shadow volumes on the fly in cull visitor - It works perfectly, except the cases when mirrors are used - let's recall that mirror turns right-handed coordinate system to left-handed, thus the programmer needs to change FrontFace setting to keep face culling working properly. - Ignoring FrontFace settings, I may construct anti-shadow volume that produces wrong results when mixed with non-anti volumes, etc. - Moreover, blending and alpha test settings should be detected and semi-transparent object should not cast shadows. I can detect them bellow in the scene graph during triangle collecting traversal, but what about attributes above my shadow node? Ignoring them may result in wrong results. I guess, the best solution is to query current traversal state for blending and front face settings. At least that is what I have done in another scene graph library. Other option is to traverse scene graph up from my shadowed node to see if there are any attributes important for myself. But if there is no nice solution, lets leave the problem. I just wanted to create complete issue-free solution, as this solution may be contributed back to OSG one day when stable enough. John Wojciech Lewandowski wrote: Hi John, If you need this to setup uniforms for shadow fragment shaders then maybe standard GL gl_FrontFacing variable could do the trick ? Its available at least in GLSL 1.50 and above. I have not checked when it was introduced maybe its available in earlier GLSL profiles. Wojtek *From:* PCJohn mailto:pec...@fit.vutbr.cz *Sent:* Thursday, August 05, 2010 12:41 AM *To:* OpenSceneGraph Users mailto:osg-users@lists.openscenegraph.org *Subject:* Re: [osg-users] threading and captureCurrentState Yes. There is. Oh. I see. Sorry for confusion, you call it attribute stack and that is a correct name for it. Anyway, there is State::_attributeMap that is composed of AttributeStack structs and they have a member attributeVec that is serving as a stack of attributes. The top of the stack is current attribute or the last pushed attribute. That is the one I need to get. Until now, I see a threading issue like two threads manipulating the attribute stack. I'll say it again: you can't access those attribute stacks from the cull traversal. They don't contain anything sensible. I that case a different question: How to get current osg::FrontFace attribute? I mean the one that would be active for any drawable traversed at the present moment during cull traversal that is just in progress and I am handling it in my custom Shadow class that is already working perfectly except some attribute values that user may pass from the scene graph above and that need to be properly handled to cast shadows correctly. The answer: you do not need it would be wrong at the moment. Thx, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
Hi, captureCurrentState name is misleading - it is not capturing state from OpenGL. It should be, maybe, getCurrentState. It is just taking last pushed attributes on the state stack. These attributes are returned in the StateSet given as parameter. Thus, the function should work any time during cull traversal, I guess. I do not understand, but it work with SingleThreaded and CullDrawThreadPerContext while it crashes with DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext. It seems to me like two threads are accessing state stack... John Wojciech Lewandowski wrote: Hi, I don't think its allowed to call captureCurrentState in Cull stage. I am not certain about this, but would expect that captureCurrentState would read OpenGL state and update osg::State accordingly. If this is the case then it does require valid OpenGL context, which is only guaranteed to be valid in Render stage. SingleThreaded mode is bit different and manages SceneViews differently which has the side effect that OpenGL context often remains valid beetwen Render stages . Wojtek -- From: PCJohn pec...@fit.vutbr.cz Sent: Tuesday, August 03, 2010 4:38 PM To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Subject: [osg-users] threading and captureCurrentState Hi, I see a threading issue when capturing current attributes in cull phase. My code placed in my derived ShadowTechnique::cull(): void MyShadowVolume::cull( osgUtil::CullVisitor cv ) { ref_ptr StateSet currentState = new StateSet; cv.getState()-captureCurrentState( *currentState ); cv.pushStateSet( _ss1 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); cv.pushStateSet( _ss2 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); } StateSets are not changing. It crashes inside captureCurrentState while I have to wait few seconds. However, the time changes (race-condition?). It looks like threading issue and if I set viewer.setThreadingModel( SingleThreaded ), the problem seems to disappear. Is the code above correct? Am I using captureCurrentState correctly? I need it to determine FrontFace attribute settings. Thanks, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
I see. Apologies for the misinformation. WL -- From: PCJohn pec...@fit.vutbr.cz Sent: Wednesday, August 04, 2010 9:33 AM To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Subject: Re: [osg-users] threading and captureCurrentState Hi, captureCurrentState name is misleading - it is not capturing state from OpenGL. It should be, maybe, getCurrentState. It is just taking last pushed attributes on the state stack. These attributes are returned in the StateSet given as parameter. Thus, the function should work any time during cull traversal, I guess. I do not understand, but it work with SingleThreaded and CullDrawThreadPerContext while it crashes with DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext. It seems to me like two threads are accessing state stack... John Wojciech Lewandowski wrote: Hi, I don't think its allowed to call captureCurrentState in Cull stage. I am not certain about this, but would expect that captureCurrentState would read OpenGL state and update osg::State accordingly. If this is the case then it does require valid OpenGL context, which is only guaranteed to be valid in Render stage. SingleThreaded mode is bit different and manages SceneViews differently which has the side effect that OpenGL context often remains valid beetwen Render stages . Wojtek -- From: PCJohn pec...@fit.vutbr.cz Sent: Tuesday, August 03, 2010 4:38 PM To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Subject: [osg-users] threading and captureCurrentState Hi, I see a threading issue when capturing current attributes in cull phase. My code placed in my derived ShadowTechnique::cull(): void MyShadowVolume::cull( osgUtil::CullVisitor cv ) { ref_ptr StateSet currentState = new StateSet; cv.getState()-captureCurrentState( *currentState ); cv.pushStateSet( _ss1 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); cv.pushStateSet( _ss2 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); } StateSets are not changing. It crashes inside captureCurrentState while I have to wait few seconds. However, the time changes (race-condition?). It looks like threading issue and if I set viewer.setThreadingModel( SingleThreaded ), the problem seems to disappear. Is the code above correct? Am I using captureCurrentState correctly? I need it to determine FrontFace attribute settings. Thanks, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
On Wed, Aug 4, 2010 at 9:33 AM, PCJohn pec...@fit.vutbr.cz wrote: Hi, captureCurrentState name is misleading - it is not capturing state from OpenGL. It should be, maybe, getCurrentState. It is just taking last pushed attributes on the state stack. These attributes are returned in the StateSet given as parameter. Thus, the function should work any time during cull traversal, I guess. No. CullVisitor::pushStateSet does not affect the graphics state immediately. It is used to build the state graph that is used during the draw traversal to change the state. You really can't use osg::State for much outside of the graphics traversal. I do not understand, but it work with SingleThreaded and CullDrawThreadPerContext while it crashes with DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext. It seems to me like two threads are accessing state stack... There isn't a state stack. See http://www.bricoworks.com/articles/stateset/stateset.html and http://www.bricoworks.com/articles/stategraph/stategraph.html. Tim John Wojciech Lewandowski wrote: Hi, I don't think its allowed to call captureCurrentState in Cull stage. I am not certain about this, but would expect that captureCurrentState would read OpenGL state and update osg::State accordingly. If this is the case then it does require valid OpenGL context, which is only guaranteed to be valid in Render stage. SingleThreaded mode is bit different and manages SceneViews differently which has the side effect that OpenGL context often remains valid beetwen Render stages . Wojtek -- From: PCJohn pec...@fit.vutbr.cz Sent: Tuesday, August 03, 2010 4:38 PM To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Subject: [osg-users] threading and captureCurrentState Hi, I see a threading issue when capturing current attributes in cull phase. My code placed in my derived ShadowTechnique::cull(): void MyShadowVolume::cull( osgUtil::CullVisitor cv ) { ref_ptr StateSet currentState = new StateSet; cv.getState()-captureCurrentState( *currentState ); cv.pushStateSet( _ss1 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); cv.pushStateSet( _ss2 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); } StateSets are not changing. It crashes inside captureCurrentState while I have to wait few seconds. However, the time changes (race-condition?). It looks like threading issue and if I set viewer.setThreadingModel( SingleThreaded ), the problem seems to disappear. Is the code above correct? Am I using captureCurrentState correctly? I need it to determine FrontFace attribute settings. Thanks, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
Hi Tim, Tim Moore wrote: On Wed, Aug 4, 2010 at 9:33 AM, PCJohn pec...@fit.vutbr.cz mailto:pec...@fit.vutbr.cz wrote: Hi, captureCurrentState name is misleading - it is not capturing state from OpenGL. It should be, maybe, getCurrentState. It is just taking last pushed attributes on the state stack. These attributes are returned in the StateSet given as parameter. Thus, the function should work any time during cull traversal, I guess. No. CullVisitor::pushStateSet does not affect the graphics state immediately. It is used to build the state graph that is used during the draw traversal to change the state. You really can't use osg::State for much outside of the graphics traversal. We do not understand each other. I am not using it outside cull traversal, neither I want to do anything with OpenGL state. I do not understand, but it work with SingleThreaded and CullDrawThreadPerContext while it crashes with DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext. It seems to me like two threads are accessing state stack... There isn't a state stack. See http://www.bricoworks.com/articles/stateset/stateset.html and http://www.bricoworks.com/articles/stategraph/stategraph.html. Yes. There is. Oh. I see. Sorry for confusion, you call it attribute stack and that is a correct name for it. Anyway, there is State::_attributeMap that is composed of AttributeStack structs and they have a member attributeVec that is serving as a stack of attributes. The top of the stack is current attribute or the last pushed attribute. That is the one I need to get. Until now, I see a threading issue like two threads manipulating the attribute stack. John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
On Wed, Aug 4, 2010 at 2:19 PM, PCJohn pec...@fit.vutbr.cz wrote: Hi Tim, Tim Moore wrote: On Wed, Aug 4, 2010 at 9:33 AM, PCJohn pec...@fit.vutbr.cz wrote: Hi, captureCurrentState name is misleading - it is not capturing state from OpenGL. It should be, maybe, getCurrentState. It is just taking last pushed attributes on the state stack. These attributes are returned in the StateSet given as parameter. Thus, the function should work any time during cull traversal, I guess. No. CullVisitor::pushStateSet does not affect the graphics state immediately. It is used to build the state graph that is used during the draw traversal to change the state. You really can't use osg::State for much outside of the graphics traversal. We do not understand each other. I am not using it outside cull traversal, neither I want to do anything with OpenGL state. You can not use captureCurrentState() to do anything sensible in the cull traversal. The State object is not modified during the cull traversal. By the way, although changes to the State don't necessarily cause an immediate change to the OpenGL state, those changes usuallly follow soon after. I do not understand, but it work with SingleThreaded and CullDrawThreadPerContext while it crashes with DrawThreadPerContext and CullThreadPerCameraDrawThreadPerContext. It seems to me like two threads are accessing state stack... There isn't a state stack. See http://www.bricoworks.com/articles/stateset/stateset.html and http://www.bricoworks.com/articles/stategraph/stategraph.html. Yes. There is. Oh. I see. Sorry for confusion, you call it attribute stack and that is a correct name for it. Anyway, there is State::_attributeMap that is composed of AttributeStack structs and they have a member attributeVec that is serving as a stack of attributes. The top of the stack is current attribute or the last pushed attribute. That is the one I need to get. Until now, I see a threading issue like two threads manipulating the attribute stack. I'll say it again: you can't access those attribute stacks from the cull traversal. They don't contain anything sensible. Tim John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
Yes. There is. Oh. I see. Sorry for confusion, you call it attribute stack and that is a correct name for it. Anyway, there is State::_attributeMap that is composed of AttributeStack structs and they have a member attributeVec that is serving as a stack of attributes. The top of the stack is current attribute or the last pushed attribute. That is the one I need to get. Until now, I see a threading issue like two threads manipulating the attribute stack. I'll say it again: you can't access those attribute stacks from the cull traversal. They don't contain anything sensible. I that case a different question: How to get current osg::FrontFace attribute? I mean the one that would be active for any drawable traversed at the present moment during cull traversal that is just in progress and I am handling it in my custom Shadow class that is already working perfectly except some attribute values that user may pass from the scene graph above and that need to be properly handled to cast shadows correctly. The answer: you do not need it would be wrong at the moment. Thx, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] threading and captureCurrentState
Hi, I don't think its allowed to call captureCurrentState in Cull stage. I am not certain about this, but would expect that captureCurrentState would read OpenGL state and update osg::State accordingly. If this is the case then it does require valid OpenGL context, which is only guaranteed to be valid in Render stage. SingleThreaded mode is bit different and manages SceneViews differently which has the side effect that OpenGL context often remains valid beetwen Render stages . Wojtek -- From: PCJohn pec...@fit.vutbr.cz Sent: Tuesday, August 03, 2010 4:38 PM To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Subject: [osg-users] threading and captureCurrentState Hi, I see a threading issue when capturing current attributes in cull phase. My code placed in my derived ShadowTechnique::cull(): void MyShadowVolume::cull( osgUtil::CullVisitor cv ) { ref_ptr StateSet currentState = new StateSet; cv.getState()-captureCurrentState( *currentState ); cv.pushStateSet( _ss1 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); cv.pushStateSet( _ss2 ); _shadowedScene-Group::traverse( cv ); cv.popStateSet(); } StateSets are not changing. It crashes inside captureCurrentState while I have to wait few seconds. However, the time changes (race-condition?). It looks like threading issue and if I set viewer.setThreadingModel( SingleThreaded ), the problem seems to disappear. Is the code above correct? Am I using captureCurrentState correctly? I need it to determine FrontFace attribute settings. Thanks, John ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org