Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi Sergey, thank you, now its working perfectly cheers, ParticlePeter Hi, Peter This is because osg tries to compute bound of drawable based on vertices it uses. So if your restart index behind memory allocated for vertices storage osg will go out of array bound when computing bounds of drawable, thats where your access violation comes from. You can try to avoid this with setting initial bound yourself and\or setting your own computeBoundCallback on drawable. Another way is to add additional vertex to vertex array and use it index as restart index to make osg bound computation happy. Cheers, Sergey. 07.08.2011, 00:26, Peter Wrobelparticlepe...@gmx.de: Hi J-S, Yes, thank you, that did the trick, now it works. And to answer my question above, it has to be glEnableClientState, otherwise its not working. I have one more issue now. Sergey, I am getting a Access Violation Exception directly after calling viewer.run inside osg::Vec3f line 84, if I use the the default restart index of USHRT_MAX. To debug this, I added a method to set the index, and got wired results. I created an 18 Elements TriStrip, code is bellow. When I set the restart index between 0 and 18 (18 is not a typo ), everything is fine. When I set it to 19 and higher I get this in the console: Code: CullVisitor::apply(Geode) detected NaN, depth=-1.IND, center=(-2 0 -7.942e+037), matrix={ 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN } If I set the index between 1000 and 2000 it works right ( ! ), and if I set it to 5000 and above I get the Access Violation Exception again. Do you have any idea what's going on ? Is this related to not creating an StateAttribute ? TestCode, uses the class posted by hybr: Code: #include DrawElementsUShortRestart.h #includeosg/Geode #includeosg/Geometry #includeosg/PolygonMode osg::ref_ptr osg::Node createDrawElements() { osg::Geometry * geom = new osg::Geometry() ; osg::Vec3Array * vrts = new osg::Vec3Array() ; geom - setVertexArray( vrts ) ; unsigned int numVrts = 18 ; // Create Vertex Positions for TriStripe for( unsigned int i = 0 ; i numVrts / 2 ; ++i ) { vrts - push_back( osg::Vec3( i , 1.f , 0.f ) ) ; vrts - push_back( osg::Vec3( i ,-1.f , 0.f ) ) ; } // Create a PrimitiveRestart DrawElements DrawElementsUShortRestart * drawElems = new DrawElementsUShortRestart() ; // This is set to false by default in the constructors initializer list drawElems - enableRestart( true ) ; // Added this method to the DrawElementsUShortRestart Class drawElems - setRestartIndex( 1000 ) ; // Try also 20 and USHRT_MAX for( unsigned int i = 0 ; i numVrts ; ++i ) { if ( i == 9 ) drawElems - push_back( 1000 ) ; // Try also 20 and USHRT_MAX drawElems - push_back( i ) ; } geom - addPrimitiveSet( drawElems ) ; geom - getOrCreateStateSet() - setMode( GL_LIGHTING , osg::StateAttribute::OFF ) ; geom - getOrCreateStateSet() - setAttributeAndModes( new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ) ) ; osg::ref_ptr osg::Geode geode = new osg::Geode() ; geode - addDrawable( geom ) ; return geode.release() ; } Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41911#41911 ___ 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] osg::Geometry and GL_PRIMITVE_RESTART
Hi, Peter This is because osg tries to compute bound of drawable based on vertices it uses. So if your restart index behind memory allocated for vertices storage osg will go out of array bound when computing bounds of drawable, thats where your access violation comes from. You can try to avoid this with setting initial bound yourself and\or setting your own computeBoundCallback on drawable. Another way is to add additional vertex to vertex array and use it index as restart index to make osg bound computation happy. Cheers, Sergey. 07.08.2011, 00:26, Peter Wrobel particlepe...@gmx.de: Hi J-S, Yes, thank you, that did the trick, now it works. And to answer my question above, it has to be glEnableClientState, otherwise its not working. I have one more issue now. Sergey, I am getting a Access Violation Exception directly after calling viewer.run inside osg::Vec3f line 84, if I use the the default restart index of USHRT_MAX. To debug this, I added a method to set the index, and got wired results. I created an 18 Elements TriStrip, code is bellow. When I set the restart index between 0 and 18 (18 is not a typo ), everything is fine. When I set it to 19 and higher I get this in the console: Code: CullVisitor::apply(Geode) detected NaN, depth=-1.IND, center=(-2 0 -7.942e+037), matrix={ 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN } If I set the index between 1000 and 2000 it works right ( ! ), and if I set it to 5000 and above I get the Access Violation Exception again. Do you have any idea what's going on ? Is this related to not creating an StateAttribute ? TestCode, uses the class posted by hybr: Code: #include DrawElementsUShortRestart.h #include osg/Geode #include osg/Geometry #include osg/PolygonMode osg::ref_ptr osg::Node createDrawElements() { osg::Geometry * geom = new osg::Geometry() ; osg::Vec3Array * vrts = new osg::Vec3Array() ; geom - setVertexArray( vrts ) ; unsigned int numVrts = 18 ; // Create Vertex Positions for TriStripe for( unsigned int i = 0 ; i numVrts / 2 ; ++i ) { vrts - push_back( osg::Vec3( i , 1.f , 0.f ) ) ; vrts - push_back( osg::Vec3( i ,-1.f , 0.f ) ) ; } // Create a PrimitiveRestart DrawElements DrawElementsUShortRestart * drawElems = new DrawElementsUShortRestart() ; // This is set to false by default in the constructors initializer list drawElems - enableRestart( true ) ; // Added this method to the DrawElementsUShortRestart Class drawElems - setRestartIndex( 1000 ) ; // Try also 20 and USHRT_MAX for( unsigned int i = 0 ; i numVrts ; ++i ) { if ( i == 9 ) drawElems - push_back( 1000 ) ; // Try also 20 and USHRT_MAX drawElems - push_back( i ) ; } geom - addPrimitiveSet( drawElems ) ; geom - getOrCreateStateSet() - setMode( GL_LIGHTING , osg::StateAttribute::OFF ) ; geom - getOrCreateStateSet() - setAttributeAndModes( new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ) ) ; osg::ref_ptr osg::Geode geode = new osg::Geode() ; geode - addDrawable( geom ) ; return geode.release() ; } Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41911#41911 ___ 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] osg::Geometry and GL_PRIMITVE_RESTART
Hi Sergey, unfortunatelly I did not manage to make your code run. I am getting this Link Errors: error LNK2001: unresolved external symbol __imp__glEnableClientState@4 error LNK2001: unresolved external symbol __imp__glDisableClientState@4 Find my includes bellow, according to me, it should work with including osg/state. Wrong ? Moreover, why are you using glEnableClientState ? Is glEnable not the right one ? In any case both variations give me this link error, while in a non osg App the primitive restart is working ( with glew.h ). Here are my includes and defines #include osg/State #include osg/Geode #include osg/Geometry #include osg/NodeVisitor #include osg/GLExtensions #include osg/PrimitiveSet #define PRIMITIVE_RESTART_NV 0x8558 #define PRIMITIVE_RESTART_INDEX_NV 0x8559 // These I have from glew.h #define GL_PRIMITIVE_RESTART 0x8F9D #define GL_PRIMITIVE_RESTART_INDEX 0x8F9E Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41907#41907 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi Peter, unfortunatelly I did not manage to make your code run. I am getting this Link Errors: error LNK2001: unresolved external symbol __imp__glEnableClientState@4 error LNK2001: unresolved external symbol __imp__glDisableClientState@4 Find my includes bellow, according to me, it should work with including osg/state. Wrong ? Moreover, why are you using glEnableClientState ? Is glEnable not the right one ? In any case both variations give me this link error, while in a non osg App the primitive restart is working ( with glew.h ). The above errors are not compile errors, they are link errors as you noted yourself, so they have nothing to do with what your code is including, but with what your program is linking to. You need to link to opengl32.lib or -lGL for gcc. The reason why this didn't matter before, I suspect, is because in your own code you didn't do any pure OpenGL calls until now. The OSG libs/DLLs already link to OpenGL, so they were fine, and your program only called OSG, so it didn't need to link to OpenGL itself. Now you've put code in your own program that calls OpenGL functions, so you need it to link to OpenGL directly. Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.dyndns-web.com/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi J-S, Yes, thank you, that did the trick, now it works. And to answer my question above, it has to be glEnableClientState, otherwise its not working. I have one more issue now. Sergey, I am getting a Access Violation Exception directly after calling viewer.run inside osg::Vec3f line 84, if I use the the default restart index of USHRT_MAX. To debug this, I added a method to set the index, and got wired results. I created an 18 Elements TriStrip, code is bellow. When I set the restart index between 0 and 18 (18 is not a typo ), everything is fine. When I set it to 19 and higher I get this in the console: Code: CullVisitor::apply(Geode) detected NaN, depth=-1.IND, center=(-2 0 -7.942e+037), matrix={ 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN 1.#QNAN } If I set the index between 1000 and 2000 it works right ( ! ), and if I set it to 5000 and above I get the Access Violation Exception again. Do you have any idea what's going on ? Is this related to not creating an StateAttribute ? TestCode, uses the class posted by hybr: Code: #include DrawElementsUShortRestart.h #include osg/Geode #include osg/Geometry #include osg/PolygonMode osg::ref_ptr osg::Node createDrawElements() { osg::Geometry * geom = new osg::Geometry() ; osg::Vec3Array * vrts = new osg::Vec3Array() ; geom - setVertexArray( vrts ) ; unsigned int numVrts = 18 ; // Create Vertex Positions for TriStripe for( unsigned int i = 0 ; i numVrts / 2 ; ++i ) { vrts - push_back( osg::Vec3( i , 1.f , 0.f ) ) ; vrts - push_back( osg::Vec3( i ,-1.f , 0.f ) ) ; } // Create a PrimitiveRestart DrawElements DrawElementsUShortRestart * drawElems = new DrawElementsUShortRestart() ; // This is set to false by default in the constructors initializer list drawElems - enableRestart( true ) ; // Added this method to the DrawElementsUShortRestart Class drawElems - setRestartIndex( 1000 ) ; // Try also 20 and USHRT_MAX for( unsigned int i = 0 ; i numVrts ; ++i ) { if ( i == 9 ) drawElems - push_back( 1000 ) ; // Try also 20 and USHRT_MAX drawElems - push_back( i ) ; } geom - addPrimitiveSet( drawElems ) ; geom - getOrCreateStateSet() - setMode( GL_LIGHTING , osg::StateAttribute::OFF ) ; geom - getOrCreateStateSet() - setAttributeAndModes( new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ) ) ; osg::ref_ptr osg::Geode geode = new osg::Geode() ; geode - addDrawable( geom ) ; return geode.release() ; } Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41911#41911 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi all There are no direct support in osg for primitive restart extension. I've tried using it in osg in custom drawable, but i've found that it was about 3x times slower than either display lists with short tristrips or vbos with indexed triangle list on my hardware (295 gtx) so there isn't much reason to use them for me. If you going for primitive restart to get speed up you better test it first on your target hardware. Cheers, Sergey. 03.08.2011, 17:21, Aurelien Albert aurelien.alb...@alyotech.fr: Hi, I'm facing the same problem : I try to use Code: glPrimitiveRestartIndex(0x); glEnableClientState(GL_PRIMITIVE_RESTART); In my OSG 3.0 project. Is there any way to use these functions without a big hack of osg ? Thank you! Cheers, Aurelien -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41823#41823 ___ 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] osg::Geometry and GL_PRIMITVE_RESTART
Hi, Would it be possible for you to share you're implementation ? For me it is still not clear how to extend osg ( as you see on my question above ). I found this thread: http://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg46962.html Sergey ( @hybr, is this you ? ) has created a new extension class: class MyExtensions: public osg::Referenced wher he adds all possible extensions. I just wonder if this is the right way, or if one should not just be able to add the particular extension required to add a custom Drawable and or StateAttribute. Its really hard to find any documentation on that part of osg. Community, it would be very nice if somebody could create a simple explanatory example, please. Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41878#41878 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
example of drawElementsUShort with primitive restart class DrawElementsUShortRestart: public osg::DrawElementsUShort { public: DrawElementsUShortRestart(const osg::DrawElementsUShort); DrawElementsUShortRestart(GLenum mode=GL_TRIANGLE_STRIP): osg::DrawElementsUShort(mode), _enabled(false), _index(USHRT_MAX) {} DrawElementsUShortRestart(std::vectorosg::DrawElementsUShort*); DrawElementsUShortRestart(GLenum mode, unsigned int no, const GLushort* ptr, int numInstances=0) : DrawElementsUShort(mode,no,ptr,numInstances), _enabled(false), _index(USHRT_MAX) {} void draw(osg::State state, bool useVertexBufferObjects) const; void setRestartIndex(unsigned index) { _index = index; } int getRestartIndex() { if (_enabled) return -1; return _index; } private: void glPrimitiveRestartIndexNV(GLuint index, unsigned contextID) const { std::mapunsigned, PrimitiveRestartIndexNV::iterator itr = _map.find(contextID); if (itr==_map.end()) { PrimitiveRestartIndexNV ptr = 0; osg::setGLExtensionFuncPtr(ptr, glPrimitiveRestartIndexNV ); if (!ptr) throw std::runtime_error(glPrimitiveRestartIndexNV is not supported or smth); _map[contextID] = ptr; ptr(index); } else itr-second(index); }; typedef void (APIENTRY * PrimitiveRestartIndexNV)(GLuint); static std::mapunsigned, PrimitiveRestartIndexNV _map; bool _enabled; GLushort _index; }; DrawElementsUShortRestart::DrawElementsUShortRestart(std::vectorosg::DrawElementsUShort* vec) :DrawElementsUShort(GL_TRIANGLE_STRIP), _enabled(true), _index(USHRT_MAX-1) { for (unsigned i = 0; i vec.size(); i++) { for (unsigned j = 0; j vec[i]-getNumIndices(); j++) { addElement(vec[i]-getElement(j)); } if (i vec.size() - 1) addElement(_index); } }; void DrawElementsUShortRestart::draw(osg::State state, bool useVertexBufferObjects) const { if (_enabled) { glEnableClientState(GL_PRIMITIVE_RESTART_NV); glPrimitiveRestartIndexNV(_index, state.getContextID()); } osg::DrawElementsUShort::draw(state, useVertexBufferObjects); if (_enabled) glDisableClientState(GL_PRIMITIVE_RESTART_NV); }; std::mapunsigned, DrawElementsUShortRestart::PrimitiveRestartIndexNV DrawElementsUShortRestart::_map; //i used this visitor to merge short primitivesets with triangle strips into one large with primitive restart class MakeDrawElementsRestartVisitor: public osg::NodeVisitor { public: MakeDrawElementsRestartVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { setNodeMaskOverride(~0x0); } using osg::NodeVisitor::apply; void apply(osg::Geode node) { std::cerrnode.getNumDrawables():node.getNumDrawables()std::endl; for (unsigned i = 0; i node.getNumDrawables(); i++) { osg::Geometry* geom = node.getDrawable(i)-asGeometry(); std::vectorosg::DrawElementsUShort* vec; std::cerrgeom-getNumPrimitiveSets():geom-getNumPrimitiveSets()std::endl; if (geom-getNumPrimitiveSets()==1) { DrawElementsUShortRestart* deusr = new DrawElementsUShortRestart(); } for (unsigned j = 0; j geom-getNumPrimitiveSets(); j++) { osg::PrimitiveSet* ps = geom-getPrimitiveSet(j); osg::DrawElementsUShort* deus = dynamic_castosg::DrawElementsUShort*(ps); if (!deus) { std::cerrreturn on (!deus)std::endl; return; } if (ps-getMode()!=GL_TRIANGLE_STRIP) { std::cerrreturn on ps-getMode() is not GL_TRIANGLE_STRIPstd::endl; return; } vec.push_back(deus); } DrawElementsUShortRestart* deusr = new DrawElementsUShortRestart(vec); geom-removePrimitiveSet(0, geom-getNumPrimitiveSets()); geom-addPrimitiveSet(deusr);
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi Sergey, thank you for your code, I will study it. :-) Thank you! Cheers, ParticlePeter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41893#41893 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi, I'm facing the same problem : I try to use Code: glPrimitiveRestartIndex(0x); glEnableClientState(GL_PRIMITIVE_RESTART); In my OSG 3.0 project. Is there any way to use these functions without a big hack of osg ? Thank you! Cheers, Aurelien -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=41823#41823 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi, I found this sceniX forum post http://developer.nvidia.com/forums/index.php?showtopic=5357pid=16495mode=threadedstart= and wonder if this is akin to the osg approach. If so, how can osg be extended in the right way so that currently not supported GL3 features are accessible ? Thank you! Cheers, Peter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38097#38097 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Geometry and GL_PRIMITVE_RESTART
Hi, Peter There are some similarities with osg in that regard, osg caches current state to avoid redundant state changes and if you make gl calls yourself you should tell osg state that you changed something, look into osg::State docs about that. Most gl changes in osg done through statesets with setMode(...) which set opengl modes like in glEnable(...)\glDisable(...) and stateattributes. If you need some functionality that not implemented you can create new stateattribute if can fit functionality needed. In case of primitive restart i believe you can enable that with setMode call, and you will need to either write your drawable (or state attribute or drawable draw callback) to be able to set restart index. Cheers, Sergey. 31.03.2011, 11:41, Peter Wrobrl particlepe...@gmx.de: Hi, I found this sceniX forum post http://developer.nvidia.com/forums/index.php?showtopic=5357pid=16495mode=threadedstart= and wonder if this is akin to the osg approach. If so, how can osg be extended in the right way so that currently not supported GL3 features are accessible ? Thank you! Cheers, Peter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38097#38097 ___ 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] osg::Geometry and GL_PRIMITVE_RESTART
Thank you very much, that helps a lot in understanding. So I assume there is no example for this one ... Anyway, many thanks. Cheers, Peter -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38121#38121 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org