CalcMySky  v0.3.1
GLWidget.hpp
1 #ifndef INCLUDE_ONCE_71D92E37_E297_472C_8495_1BF8EA61DC99
2 #define INCLUDE_ONCE_71D92E37_E297_472C_8495_1BF8EA61DC99
3 
4 #include <memory>
5 #include <QOpenGLWidget>
6 #include <QOpenGLTexture>
7 #include <QOpenGLFunctions_3_3_Core>
8 #include "AtmosphereRenderer.hpp"
9 #include "../common/AtmosphereParameters.hpp"
10 
11 class ToolsWidget;
12 class GLWidget : public QOpenGLWidget, public QOpenGLFunctions_3_3_Core
13 {
14  Q_OBJECT
15 
16 public:
17  enum class Projection
18  {
19  Equirectangular,
20  Perspective,
21  Fisheye,
22  };
23  enum class ColorMode
24  {
25  sRGB,
26  ScotopicLuminance,
27  PhotopicLuminance,
28  XYZChromaticity,
29  sRGBlChromaticity,
30  sRGBlChromaticityToMax,
31  };
32 
33 private:
34  std::unique_ptr<ShowMySky::AtmosphereRenderer> renderer;
35  std::unique_ptr<QOpenGLShaderProgram> luminanceToScreenRGB_;
36  std::unique_ptr<QOpenGLShaderProgram> glareProgram_;
37  QOpenGLTexture ditherPatternTexture_;
38  GLuint glareTextures_[2] = {};
39  GLuint glareFBOs_[2] = {};
40  QString pathToData;
41  ToolsWidget* tools;
42  GLuint vao_=0, vbo_=0;
43  QPoint lastRadianceCapturePosition{-1,-1};
44  decltype(::ShowMySky_AtmosphereRenderer_create)* ShowMySky_AtmosphereRenderer_create=nullptr;
45  Projection currentProjection_ = Projection::Equirectangular;
46  ColorMode currentColorMode_ = ColorMode::sRGB;
47 
48  enum class DragMode
49  {
50  None,
51  Sun,
52  Camera,
53  } dragMode_=DragMode::None;
54  int prevMouseX_, prevMouseY_;
55 
56 public:
57  enum class DitheringMode
58  {
59  Color565,
60  Color666,
61  Color888,
62  Color101010,
63  };
64  enum class DitheringMethod
65  {
66  NoDithering,
67  Bayer,
69  };
70 public:
71  explicit GLWidget(QString const& pathToData, ToolsWidget* tools, QWidget* parent=nullptr);
72  ~GLWidget();
73 
74 protected:
75  void initializeGL() override;
76  void paintGL() override;
77  void resizeGL(int w, int h) override;
78  void wheelEvent(QWheelEvent* event) override;
79  void mouseMoveEvent(QMouseEvent* event) override;
80  void mousePressEvent(QMouseEvent* event) override;
81  void mouseReleaseEvent(QMouseEvent* event) override;
82  bool eventFilter(QObject* object, QEvent* event) override;
83  void keyPressEvent(QKeyEvent* event) override;
84 
85 private:
86  void setupBuffers();
87  void reloadShaders();
88  void stepDataLoading();
89  void stepShaderReloading();
90  void stepPreparationToDraw(bool emitProgressStatus);
91  QVector3D rgbMaxValue() const;
92  void makeGlareRenderTarget();
93  void makeDitherPatternTexture();
94  void updateSpectralRadiance(QPoint const& pixelPos);
95  void setDragMode(DragMode mode, int x=0, int y=0) { dragMode_=mode; prevMouseX_=x; prevMouseY_=y; }
96  void setFlatSolarSpectrum();
97  void resetSolarSpectrum();
98  void setBlackBodySolarSpectrum(double temperature);
99  void saveScreenshot();
100  Projection currentProjection() const { return currentProjection_; }
101  ColorMode currentColorMode () const { return currentColorMode_; }
102 
103 signals:
104  void frameFinished(long long timeInUS);
105  void loadProgress(QString const& currentActivity, int stepsDone, int stepsToDo);
106 };
107 
108 #endif
Definition: ToolsWidget.hpp:16
16-bit color (AKA High color) with R5_G6_B5 layout
Unordered dithering using blue noise of amplitude 1.0, with triangular remapping.
24-bit color (AKA True color)
DitheringMode
Definition: GLWidget.hpp:57
TN+film typical color depth in TrueColor mode.
Definition: GLWidget.hpp:12
DitheringMethod
Definition: GLWidget.hpp:64
30-bit color (AKA Deep color)
Ordered dithering using Bayer threshold texture.
Dithering disabled, will leave the infamous color bands.