OSGRenderer 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2017 Mike Krus
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License as
  5. // published by the Free Software Foundation; either version 2 of the
  6. // License, or (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #ifndef OSGRENDERER_H
  17. #define OSGRENDERER_H
  18. #include <osgQOpenGL/Export>
  19. #include <QObject>
  20. #include <osgViewer/Viewer>
  21. class QInputEvent;
  22. class QKeyEvent;
  23. class QMouseEvent;
  24. class QWheelEvent;
  25. namespace eveBIM
  26. {
  27. class ViewerWidget;
  28. }
  29. class OSGQOPENGL_EXPORT OSGRenderer : public QObject, public osgViewer::Viewer
  30. {
  31. bool m_osgInitialized {false};
  32. osg::ref_ptr<osgViewer::GraphicsWindow> m_osgWinEmb;
  33. float m_windowScale {1.0f};
  34. bool m_continuousUpdate {true};
  35. int _timerId{0};
  36. osg::Timer _lastFrameStartTime;
  37. bool _applicationAboutToQuit {false};
  38. bool _osgWantsToRenderFrame{true};
  39. Q_OBJECT
  40. friend class eveBIM::ViewerWidget;
  41. public:
  42. explicit OSGRenderer(QObject* parent = nullptr);
  43. explicit OSGRenderer(osg::ArgumentParser* arguments, QObject* parent = nullptr);
  44. ~OSGRenderer() override;
  45. bool continuousUpdate() const
  46. {
  47. return m_continuousUpdate;
  48. }
  49. void setContinuousUpdate(bool continuousUpdate)
  50. {
  51. m_continuousUpdate = continuousUpdate;
  52. }
  53. virtual void keyPressEvent(QKeyEvent* event);
  54. virtual void keyReleaseEvent(QKeyEvent* event);
  55. virtual void mousePressEvent(QMouseEvent* event);
  56. virtual void mouseReleaseEvent(QMouseEvent* event);
  57. virtual void mouseDoubleClickEvent(QMouseEvent* event);
  58. virtual void mouseMoveEvent(QMouseEvent* event);
  59. virtual void wheelEvent(QWheelEvent* event);
  60. virtual void resize(int windowWidth, int windowHeight, float windowScale);
  61. void setupOSG(int windowWidth, int windowHeight, float windowScale);
  62. // overrided from osgViewer::Viewer
  63. virtual bool checkNeedToDoFrame() override;
  64. // overrided from osgViewer::ViewerBase
  65. void frame(double simulationTime = USE_REFERENCE_TIME) override;
  66. // overrided from osgViewer::Viewer
  67. void requestRedraw() override;
  68. // overrided from osgViewer::Viewer
  69. bool checkEvents() override;
  70. void update();
  71. protected:
  72. void timerEvent(QTimerEvent* event) override;
  73. void setKeyboardModifiers(QInputEvent* event);
  74. };
  75. #endif // OSGRENDERER_H