osg::ref_ptr的get和release方法

get方法会新增加一个内存管理对象。

release方法将一个对象的内存的管理权限丢弃,一般会交给另一个对象。

如果不需要转交管理权,则调用unref_nodelete方法,直接删除内存即可。

对于get到的指针,因为并没有改变引用计数,一定不要执行delete操作(可能还有别的地方在使用这个指针),也没有必要使用ref_ptr来接收get到的指针(除非需要通过ref_ptr增加引用计数)

const ProgramBinary* programBinary = _program->getProgramBinary();

const ProgramBinary* getProgramBinary() const { return _programBinary.get(); }

osg::ref_ptr<ProgramBinary> _programBinary;

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用osgEarth实现圆形扩散的示例代码: ```c++ #include <osgEarth/MapNode> #include <osgEarthUtil/EarthManipulator> #include <osgEarthUtil/ExampleResources> #include <osg/Geode> #include <osg/Geometry> #include <osgViewer/Viewer> using namespace osgEarth; using namespace osgEarth::Util; osg::Geometry* createCircleGeometry(float radius) { osg::ref_ptr<osg::Geometry> geom = new osg::Geometry(); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(); osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(); osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array(); float step = osg::PI / 180.0f; for (float angle = 0.0f; angle <= 2.0f * osg::PI; angle += step) { float x = radius * std::cos(angle); float y = radius * std::sin(angle); vertices->push_back(osg::Vec3(x, y, 0.0f)); normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); texcoords->push_back(osg::Vec2(x / radius * 0.5f + 0.5f, y / radius * 0.5f + 0.5f)); } geom->setVertexArray(vertices.get()); geom->setNormalArray(normals.get()); geom->setTexCoordArray(0, texcoords.get()); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, 0, vertices->size())); return geom.release(); } int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(arguments); osg::ref_ptr<MapNode> mapNode = MapNode::create(Map::create()); viewer->setSceneData(mapNode.get()); osg::ref_ptr<EarthManipulator> manipulator = new EarthManipulator(); viewer->setCameraManipulator(manipulator.get()); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->addDrawable(createCircleGeometry(1000.0f)); osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_BLEND, osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); osg::ref_ptr<osg::Depth> depth = new osg::Depth(); depth->setWriteMask(false); stateset->setAttributeAndModes(depth.get(), osg::StateAttribute::ON); mapNode->addChild(geode.get()); return viewer->run(); } ``` 这段代码首先创建了一个`osg::Geometry`对象,用于存储圆形的顶点、法线和纹理坐标信息。然后使用三角扇(primitive set)绘制圆形。最后将`osg::Geometry`对象添加到场景中。为了让圆形半透明,我们使用了状态集(state set)来设置`GL_BLEND`和`TRANSPARENT_BIN`模式。同时,禁用深度写入,以避免圆形被遮挡。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值