Hi Karl, The OSG uses lazy state updating to aovid calling OpenGL when it's not needed but when you do your own OpenGL calls outside this lazy state update mechanism the OSG doesn't know the OpenGL state is now different than when the OSG last applied something so ends up not applying state when it should.
The way to fix it is to stop the state leakage from your own custom cost vis the glPush*()/glPop*() or to tell the OSG that you've changed the state via the osg::State::haveApplied*() calls or simply to use the osg::State class itself for applying the state you want to change. There are a whole series of methods for doing vertex array set up that you can use so have a look at these. Robert. On 11 September 2012 18:40, Cary, Karl A. <[email protected]> wrote: > I have a situation that is requiring me to use raw gl commands in the > drawImplementation of an osg::Drawable. I have a double buffer that is not > updated fully until draw time as opposed to update time and I am not at > liberty to change this. Currently in the drawImplementation, I get the > current buffer, then perform glVertex and glNormal commands on the list of > vertices in the buffer. This works just fine and there are no problems other > than it can slow down the scene do to the number of verts. I was attempting > to convert this to a glDrawElements call as a quick improvement and saw a > noticeable performance increase. Everything is drawing just fine and I > haven’t found any slow downs or stability issues, with one exception. If I > enable osg::Stats, it crashes immediately and I have no idea why. I was > hoping someone might have some insight for me. Here is the > drawImplementation code: > > > > { > > //get the current active buffer > > VertBuffer buffer = getCurBuffer(); > > > > //set up the client state > > glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); //crashes immediately > without this > > glEnableClientState(GL_VERTEX_ARRAY); > > glEnableClientState(GL_NORMAL_ARRAY); > > > > //set up arrays > > glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)pmCoords); > > glNormalPointer(GL_FLOAT, 0, (GLvoid*)pmNormals); > > > > //draw > > if (buffer.vertexList.size() > 0) > > { > > glDrawElements(GL_TRIANGLES, > buffer.vertexList.size(), GL_UNSIGNED_INT, &(buffer.vertexList)[0]); > > } > > > > //disable client state > > glDisableClientState(GL_VERTEX_ARRAY); > > glDisableClientState(GL_NORMAL_ARRAY); > > glPopClientAttrib(); > > } > > > > In this, VertBuffer, is just a structure that holds a std::vector<unsigned > int> of the vertices to draw (vertexList), and some other info that is not > used during the draw. pmCoords and pmNormals are lists of all available > coordinates and their normals. The vertexList is just a list of indices in > these coordinates to draw at this time. > > > > As I said, everything works fine if the draw is as follows instead: > > > > glBegin(GL_TRIANGLES); > > for (int ii = 0; ii < buffer.vertexList.size(); ii+= 3) > > { > > > glNormal3fv(pmNormals[buffer.vertexList[ii]]; > > glVertex3fv(pmCoords[buffer.vertexList[ii]]; > > glNormal3fv(pmNormals[buffer.vertexList[ii+1]]; > > glVertex3fv(pmCoords[buffer.vertexList[ii+1]]; > > glNormal3fv(pmNormals[buffer.vertexList[ii+2]]; > > glVertex3fv(pmCoords[buffer.vertexList[ii+2]]; > > } > > glEnd(); > > > > I’ve tried copying the data locally from the buffer and that did nothing > different. I even tried to create a small array locally that contained the > same data. If I only drew 1 triangle it was fine, but if I tried to draw > more, it would sometimes work and sometimes crash. > > > > Karl Cary > > SAIC > > Software Developer > > 301-227-5656 > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

