ccGLWindow.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. #include "qCC_glWindow.h"
  19. //local
  20. #include "ccGLWindowInterface.h"
  21. // Qt
  22. #include <QOpenGLWidget>
  23. //! OpenGL 3D view
  24. class CCGLWINDOW_LIB_API ccGLWindow : public QOpenGLWidget, public ccGLWindowInterface
  25. {
  26. Q_OBJECT
  27. public:
  28. //! Default constructor
  29. ccGLWindow(QSurfaceFormat* format = nullptr, QOpenGLWidget* parent = nullptr, bool silentInitialization = false);
  30. //! Destructor
  31. ~ccGLWindow() override;
  32. //inherited from ccGLWindowInterface
  33. inline qreal getDevicePixelRatio() const override { return devicePixelRatio(); }
  34. inline QFont getFont() const override { return font(); }
  35. inline QOpenGLContext* getOpenGLContext() const override { return context(); }
  36. inline void setWindowCursor(const QCursor& cursor) override { setCursor(cursor); }
  37. void doMakeCurrent() override;
  38. inline QObject* asQObject() override { return this; }
  39. inline const QObject* asQObject() const override { return this; }
  40. inline QString getWindowTitle() const override { return windowTitle(); }
  41. inline void doGrabMouse() override { grabMouse(); }
  42. inline void doReleaseMouse() override { releaseMouse(); }
  43. inline QPoint doMapFromGlobal(const QPoint& P) const override { return mapFromGlobal(P); }
  44. inline void doShowMaximized() override { showMaximized(); }
  45. inline void doResize(int w, int h) override { resize(w, h); }
  46. inline void doResize(const QSize& size) override { resize(size); }
  47. inline QImage doGrabFramebuffer() override { return grabFramebuffer(); }
  48. inline bool isStereo() const override { return false; }
  49. inline QWidget* asWidget() override { return this; }
  50. inline QSize getScreenSize() const override { return size(); }
  51. //inherited from ccGLWindowInterface
  52. inline int qtWidth() const override { return QOpenGLWidget::width(); }
  53. inline int qtHeight() const override { return QOpenGLWidget::height(); }
  54. inline QSize qtSize() const override { return QOpenGLWidget::size(); }
  55. bool enableStereoMode(const StereoParams& params) override;
  56. //inherited from ccGenericGLDisplay
  57. void requestUpdate() override;
  58. //! Creates an instance
  59. static void Create(ccGLWindow*& window, QWidget*& widget, bool silentInitialization = false);
  60. //! Casts a widget to a ccGLWindow instance (if possible)
  61. static ccGLWindow* FromWidget(QWidget* widget);
  62. protected: //rendering
  63. //inherited from ccGLWindowInterface
  64. inline ccQOpenGLFunctions* functions() const override { return context() ? context()->versionFunctions<ccQOpenGLFunctions>() : nullptr; }
  65. inline QSurfaceFormat getSurfaceFormat() const override { return format(); }
  66. inline void doSetMouseTracking(bool enable) override { setMouseTracking(true); }
  67. inline void doShowFullScreen() override { showFullScreen(); }
  68. inline void doShowNormal() override { showNormal(); }
  69. //! Don't call makeCurrent() on this instance, as the FBO would not properly be managed
  70. /** Use doMakeCurrent() instaad.
  71. **/
  72. void makeCurrent() = delete;
  73. protected: //other methods
  74. //! Reacts to the itemPickedFast signal (shortcut)
  75. Q_SLOT void onItemPickedFastSlot(ccHObject* pickedEntity, int pickedItemIndex, int x, int y) { onItemPickedFast(pickedEntity, pickedItemIndex, x, y); }
  76. //inherited from ccGLWindowInterface
  77. int width() const override { return QOpenGLWidget::width(); }
  78. int height() const override { return QOpenGLWidget::height(); }
  79. QSize size() const override { return QOpenGLWidget::size(); }
  80. GLuint defaultQtFBO() const override;
  81. //events handling
  82. void mousePressEvent(QMouseEvent* event) override { processMousePressEvent(event); }
  83. void mouseMoveEvent(QMouseEvent* event) override { processMouseMoveEvent(event); }
  84. void mouseDoubleClickEvent(QMouseEvent* event) override { processMouseDoubleClickEvent(event); }
  85. void mouseReleaseEvent(QMouseEvent* event) override { processMouseReleaseEvent(event); }
  86. void wheelEvent(QWheelEvent* event) override { processWheelEvent(event); }
  87. bool event(QEvent* evt) override;
  88. void initializeGL() override { initialize(); }
  89. void resizeGL(int w, int h) override { onResizeGL(w, h); }
  90. void paintGL() override { doPaintGL(); }
  91. void dragEnterEvent(QDragEnterEvent* event) override { doDragEnterEvent(event); }
  92. void dropEvent(QDropEvent* event) override { doDropEvent(event); }
  93. };