Alright so I adjusted my code to do everything through the osg::State,
including trying the osg::State's glDrawElementsInstanced instead of the
normal GL glDrawElements, and I am still having the same issue. It still
works normally but crashes when I enable stats. Is there a call I need
to make that I am missing? Here is the adjusted code:
Void MyDrawable::drawImplementation(osg::RenderInfo& ri)
{
//get the current active buffer
VertBuffer buffer = getCurBuffer();
//get osg State and apply vertex and normal pointers
osg::State &state = *ri.getState();
state.setVertexPointer(3, GL_FLOAT, 0, (GLvoid*)pmCoords);
state.setNormalPointer(GL_FLOAT, 0, (GLvoid*)pmNormals);
//draw
if (buffer.vertexList.size() > 0)
{
state.glDrawElementsInstanced(GL_TRIANGLES,
buffer.vertexList.size(), GL_UNSIGNED_INT, &(buffer.vertexList)[0], 1);
}
//disable vertex and normal pointers
state.disableNormalPointer();
state.disableVertexPointer();
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert
Osfield
Sent: Wednesday, September 12, 2012 4:15 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Using glDrawElements causes crash with
osg::Stats
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
> int> 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.or
g
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org