Hi Mattihas,

Please have a look at the OSG header for include/osg/Geometry, in
particular the section on setVertexIndices() :

        /** deprecated - forces OpenGL slow path, just kept for
backwards compatibility.*/
        void setVertexIndices(IndexArray* array);

See the forces OpenGL slow path...  yep as you are using this you are
basically driving the OSG/OpenGL is least efficient way possible.
This method is only kept for backwards compatibility, but I very
strongly recommended NEVER EVER EVER using for any other application
;-)

Use DrawElements*() instead if you want to use vertex indices.

Robert.

2012/3/21 Matthias Thöny <[email protected]>:
> Hi,
>
> I have some troubles with an OSG integration and tracked down some stuff 
> which I do not really get in conecpt. What I wanted to do in this short 
> program is checking how much triangles can be rendered with OSG with indexed 
> triangle strips in one geode on one side with OSG standard implementation and 
> on the other hand with an overridden drawimplementation of an own geometry 
> class. Why? because I need to know the borders of OSG.
>
> In the picture you see one Geode with one geometry object. This object is set 
> up the following:
>
> Code:
>
> void create()
> {
>   useOpenGL = true;
>   sidelenght = 500;
>   triangleStripPerColumn = sidelenght - 1;
>   triangleCountperSide = sidelenght * 2;
>    dist = 1.0f;
>    vertexCount = sidelenght * sidelenght;
>    indexCountperSide = triangleCountperSide + 2;
>    indexCount = sidelenght * (triangleCountperSide + 2);
>
>    vertices = new osg::Vec3Array(vertexCount);
>    for(int i = 0; i < sidelenght; i++)
>    {
>        for(int j = 0; j < sidelenght; j++)
>        {
>            (*vertices)[j + i * sidelenght].set(dist * j, 0.0f, dist * i);
>            //std::cout << "vertices: " << j + i * sidelenght << " " << 
> (*vertices)[j + i * sidelenght].x() << " " << (*vertices)[j + i * 
> sidelenght].z() << " " << std::endl;
>        }
>    }
>
>    indices = new osg::UIntArray(indexCount);
>    int indexTriangleCount = 0;
>    for(int i = 0; i < sidelenght; i++)
>    {
>        for(int j = 0; j < sidelenght; j++)
>        {
>            (*indices)[indexTriangleCount] = sidelenght * (i + 1) + j;
>            indexTriangleCount++;
>            (*indices)[indexTriangleCount] = (sidelenght * i) + j;
>            indexTriangleCount++;
>        }
>    }
>
>    this->setVertexArray(vertices.get());
>    this->setVertexIndices(indices.get());
>
>    for(int j = 0; j < triangleStripPerColumn; j++)
>    {
>        this->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP,j * 
> sidelenght * 2, triangleCountperSide));
>    }
> }
>
>
>
> So, it is mainly a square 500 vertices widht and height and there is one 
> triangle strip (addPrimitiveSet) per row. The indices are set right, and it 
> seems to be fine in the picture.
>
> But...
>
> why are there 500'000 vertices in the statics, when I created just 250'000. 
> Do I have to delete something here to get this number?
> why are there almost 500'000 triangle strips? I have seen that you are doing 
> a lot of complicated stuff, so how can this be done properly? In fact in this 
> case, it should have 500 or less.
>
> I used a
>
> MacPro 3.1 with
> ATI Radeon HD 2600 XT 256 GB RAM
>
> for this test. This is a configuration which I have seen already causes some 
> problems on OSG, but that's the point on testing in this case. :)
>
> Further on the very interesting thing is, that if you add the following Code 
> piece:
>
> Code:
>
> this->setDataVariance(STATIC);
> this->setUseVertexBufferObjects(true);
> this->setUseDisplayList(false);
>
>
>
> The draw rate increases to 20 ms instead of 0.2 ms. This is Debug version, 
> but compiled in Release it is the same factor 100 or so, which I think is 
> really weared, especially, because vertex buffer object should be faster in 
> this case (if erverything is in native OpenGL implemented without OSG). In 
> this case the OpenGL version is 2.1.
>
> To the draw implementation. If i override the draw Implementation with an own 
> function call just straight forward like:
>
>
> Code:
>
> void drawImplementation(osg::RenderInfo& renderInfo) const
> {
>    osg::State& state = *renderInfo.getState();
>    bool checkForGLErrors = 
> state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
>    if (checkForGLErrors) state.checkGLErrors("start of 
> Geometry::drawImplementation()");
>
>    glEnableClientState( GL_VERTEX_ARRAY );
>    glBindBuffer( GL_ARRAY_BUFFER,0);
>
>    glBindBuffer( GL_ARRAY_BUFFER, vboVertexObject);
>    glVertexPointer(3,GL_FLOAT,0,(char*) NULL);
>
>    //    glBindBuffer( GL_ARRAY_BUFFER, vboIndexObject);
>    //    glIndexPointer(GL_UNSIGNED_INT,0,(char*) NULL);
>
>    glBindBuffer( GL_ARRAY_BUFFER, vboNormalObject);
>    glNormalPointer(GL_FLOAT,0,(char*) NULL);
>
>    for(unsigned int primitiveSetNum = 0; primitiveSetNum != 
> _primitives.size(); ++primitiveSetNum)
>    {
>        glDrawArrays(GL_TRIANGLE_STRIP, triangleCountperSide * 
> primitiveSetNum, triangleCountperSide);
>    }
>
>    // unbind the VBO's if any are used.
>    state.unbindVertexBufferObject();
>    state.unbindElementBufferObject();
>
>    if (checkForGLErrors) state.checkGLErrors("end of 
> Geometry::drawImplementation().");
>
>    //end_draw_time = timer.tick();
> }
>
>
>
> this is in fact working, but with some sideeffect (crash while statics blend 
> in, etc.etc...), but I am really confused about is, why this method is not 
> always called while the draw process, because if my xcode debugger does not 
> lie to me (because it does that a lot of times in version 4.2), this method 
> is reached once. Are you cloneing the object anyhow, to traverse in the draw 
> method (which cannot be overriden), or how does this mechanism work?
>
> There is also the compileGLObjects method which implements the buffer usage 
> and I have seen that, there are no implementations for Vertex Array Objects 
> (OpenGL 3.0). Is there any implementation for that? or is this not supported?
>
> Sorry for the long post and the detailled questions.
> Thank you!
>
> Cheers,
> Matthias
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=46492#46492
>
>
>
>
> _______________________________________________
> 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

Reply via email to