[osg-users] About Interleaved Array Support

Julien Valentin julienvalentin51 at gmail.com
Tue Oct 9 16:13:59 PDT 2018


Hi,
I have an implementation of InterleavedGeometry : public Drawable
I think it's really something missing for a long time in osg
Would it worse a pr...?

here's a sample usage  to review chosen api

Code:

    ///test interleavedGeometry
    InterleavedGeometry * igeom=new InterleavedGeometry();
    igeom->setUseDisplayList(false);
    igeom->setUseVertexBufferObjects(true);
    igeom->setUseVertexArrayObject(true);

    struct example{
        float pos[3],norm[3],texcoor[3],padding[3];//add 3 float padding for mem alignement
    };
    unsigned int stride=sizeof(struct example); 
    osg::ref_ptr<osg::BufferTemplate< std::vector<example>  > >  hostarray=new osg::BufferTemplate< std::vector<example>  >;
    hostarray->resize(4);
    hostarray->setBinding(osg::Array::BIND_PER_VERTEX);
    hostarray->setBufferObject(new osg::VertexBufferObject);
  InterleavedGeometry::RangedBufferData *rbd=new InterleavedGeometry::RangedBufferData;
  InterleavedGeometry::RangeDesc interleaveddesc;
  interleaveddesc.push_back(InterleavedGeometry::SubDataDesc(GL_FLOAT,3,0));
  interleaveddesc.push_back(InterleavedGeometry::SubDataDesc(GL_FLOAT,3,3*sizeof(GLfloat)));
  interleaveddesc.push_back(InterleavedGeometry::SubDataDesc(GL_FLOAT,3,6*sizeof(GLfloat)));
  igeom->addRangedBufferData(0,2,hostarray,interleaveddesc,stride );

    for(int j=0;j<2;j++){
        for(int i=0;i<2;i++){
            for(int k=0;k<3;k++){
        float * fdata=igeom->getRangedBufferData(0)->data<float>(i*2+j,k);
       *fdata++=float(i)*1.0f;
       *fdata++=float(j)*1.0f;
       *fdata++=0;
       }
    }
    }



Julien[/code]

------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75058#75058







More information about the osg-users mailing list