osg.buffered_object是OpenSceneGraph中的一个类,用于创建带缓冲区的对象。它是osg::Drawable的派生类,可用于创建顶点、索引等缓冲区对象。
osg::Object <br> └── osg::Drawable <br> └── osg::buffered_object
class OSG_EXPORT buffered_object : public Drawable
buffered_object()
无。
构造一个空的buffered_object对象。
virtual void addBufferData(BufferData *bd)
virtual void removeBufferData(BufferData *bd)
virtual void removeBufferData(unsigned int index)
virtual void modifyBufferData(unsigned int index,BufferData *bd)
virtual void drawImplementation(RenderInfo &renderInfo) const
virtual osg::Object *cloneType() const
virtual osg::Object *clone(const osg::CopyOp &) const
virtual bool isSameKindAs(const osg::Object *) const
virtual const char* className() const
virtual const char* libraryName() const
virtual void addBufferData(BufferData *bd)
bd
:需要加入对象的BufferData向对象中添加一个BufferData对象。
virtual void removeBufferData(BufferData *bd)
bd
:需要从对象中移除的BufferData从对象中移除指定的BufferData对象。
virtual void removeBufferData(unsigned int index)
index
:需要从对象中移除的BufferData对象的索引从对象中移除指定索引的BufferData对象。
virtual void modifyBufferData(unsigned int index,BufferData *bd)
index
:需要修改的BufferData对象的索引bd
:待修改为的BufferData对象修改对象中的指定BufferData对象。
virtual void drawImplementation(RenderInfo &renderInfo) const
renderInfo
:渲染相关信息绘制函数,实现Drawable接口。
virtual osg::Object *cloneType() const
返回值为osg::buffered_object类型指针。
用于克隆。
virtual osg::Object *clone(const osg::CopyOp &) const
返回值为osg::buffered_object类型指针。
用于克隆。
virtual bool isSameKindAs(const osg::Object *) const
obj
:待比较对象指针相同返回true,否则返回false。
用于类型比较。
virtual const char* className() const
返回值为"buffered_object"。
获取类名。
virtual const char* libraryName() const
返回值为"osg"。
获取库名。
#include <osg/Drawable>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/BufferObject>
#include <osgViewer/Viewer>
int main(int argc, char **argv)
{
// create geode and buffered geometry
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
osg::ref_ptr<osg::buffered_object> bo = new osg::buffered_object();
// define vertex and color arrays
osg::ref_ptr<osg::FloatArray> vertices = new osg::FloatArray();
vertices->push_back(0.f); vertices->push_back(0.f); vertices->push_back(0.f);
vertices->push_back(1.f); vertices->push_back(0.f); vertices->push_back(0.f);
vertices->push_back(0.f); vertices->push_back(1.f); vertices->push_back(0.f);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
colors->push_back(osg::Vec4(1.f,0.f,0.f,1.f));
colors->push_back(osg::Vec4(0.f,1.f,0.f,1.f));
colors->push_back(osg::Vec4(0.f,0.f,1.f,1.f));
// define buffer data
osg::ref_ptr<osg::BufferData> vertexBufferData = new osg::BufferData();
vertexBufferData->setArray(vertices.get());
osg::ref_ptr<osg::BufferData> colorBufferData = new osg::BufferData();
colorBufferData->setArray(colors.get());
// set buffer data to buffered object
bo->addBufferData(vertexBufferData.get());
bo->addBufferData(colorBufferData.get());
geom->setVertexBufferObject(bo.get());
// set geometry primitive
osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3);
geom->addPrimitiveSet(da);
// add geometry to geode and scene graph
geode->addDrawable(geom.get());
osg::ref_ptr<osg::Group> root = new osg::Group();
root->addChild(geode.get());
// create viewer and run
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
return viewer.run();
}