osg 60Hz帧率限制

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/kasteluo/article/details/79719766

对于osg程序,程序内部会使用两种方式进行帧率限制,一种是通过算法实现帧率限制在60Hz,另一种是使用显卡垂直同步限制在60Hz,为什么是60Hz呢,因为大部分显示器都是60Hz的刷新频率运行。一下分别演示两种限制如何取消。

软件算法设置的帧率限制,可以通过设置setRunMaxFrameRate来设置需要将帧率限制在某一个数值,不过这个限制只能将帧率提高到显示器的刷新频率60Hz。

如果程序开启了显卡的垂直同步,则需要设置 setSyncToVBlank(false);


 
 
  1. #include <iostream>
  2. #include <osgViewer/viewer>
  3. #include <osgViewer/ViewerEventHandlers>
  4. #include <osg/Node>
  5. #include <osg/Group>
  6. #include <osg/Vec3>
  7. #include <osg/Matrix>
  8. #include <osg/MatrixTransform>
  9. #include <osgDB/ReadFile>
  10. #include <osg/GraphicsContext>
  11. #include <osgGA/TrackballManipulator>
  12. class SysncOperation:public osg::GraphicsOperation
  13. {
  14. public:
  15. SysncOperation():osg::GraphicsOperation("SysncOperation",false)
  16. {
  17. }
  18. virtual void operator() (osg::GraphicsContext* context)
  19. {
  20. if(context)
  21. {
  22. context->makeCurrent();
  23. if(osgViewer::GraphicsWindow* window = dynamic_cast <osgViewer::GraphicsWindow*>(context))
  24. {
  25. window->setSyncToVBlank(false); // 关闭显卡垂直同步
  26. }
  27. }
  28. }
  29. };
  30. int main()
  31. {
  32. osgViewer::Viewer viewer;
  33. osg::Node* pNode = osgDB::readNodeFile("cow.osg");
  34. osg::ref_ptr <osg::Group> root = new osg::Group;
  35. for(int i = 0; i < 2; ++i)
  36. for(int j = 0; j <1; ++j)
  37. {
  38. osg::ref_ptr<osg::MatrixTransform> transfrom = new osg::MatrixTransform();
  39. transfrom->addChild(pNode);
  40. transfrom->setMatrix(osg::Matrix::translate(osg::Vec3(10*i,10*j,0)));
  41. root->addChild(transfrom);
  42. }
  43. if(root)
  44. {
  45. viewer.setSceneData(root);
  46. }
  47. viewer.setRealizeOperation(new SysncOperation());
  48. viewer.addEventHandler(new osgViewer::StatsHandler());
  49. //viewer.setCameraManipulator(new osgGA::TrackballManipulator());
  50. // viewer.setRunMaxFrameRate(40);
  51. viewer.realize();
  52. viewer.run();
  53. return 0;
  54. }



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值