src/glRenderer.h

changeset 1098
0b837bed121d
parent 1097
9a9e6ce0c5dc
child 1099
14276e435640
equal deleted inserted replaced
1097:9a9e6ce0c5dc 1098:0b837bed121d
17 */ 17 */
18 18
19 #pragma once 19 #pragma once
20 #include <QGLWidget> 20 #include <QGLWidget>
21 #include "main.h" 21 #include "main.h"
22 #include "macros.h" 22 #include "model.h"
23 #include "ldObject.h"
24 #include "ldDocument.h"
25 #include "glShared.h" 23 #include "glShared.h"
26 #include "editmodes/abstractEditMode.h" 24 #include "editmodes/abstractEditMode.h"
27 25
28 class GLCompiler; 26 class GLCompiler;
29 class MessageManager; 27 class MessageManager;
48 // 46 //
49 // Meta for overlays 47 // Meta for overlays
50 // 48 //
51 struct LDGLOverlay 49 struct LDGLOverlay
52 { 50 {
53 LDGLOverlay();
54 ~LDGLOverlay(); 51 ~LDGLOverlay();
55 52
56 Vertex v0, 53 Vertex v0,
57 v1; 54 v1;
58 int offsetX, 55 int offsetX,
59 offsetY; 56 offsetY;
60 double width, 57 double width,
61 height; 58 height;
62 QString fileName; 59 QString fileName;
63 QImage* image; 60 QImage* image = nullptr;
64 bool invalid; 61 bool invalid = false;
65 };
66
67 //
68 // Document-specific data
69 //
70 struct LDGLData
71 {
72 QGenericMatrix<4, 4, GLfloat> rotationMatrix;
73 double panX[7];
74 double panY[7];
75 double zoom[7];
76 double depthValues[6];
77 LDGLOverlay overlays[6];
78 bool init;
79 bool needZoomToFit;
80
81 LDGLData() :
82 init (false),
83 needZoomToFit (true)
84 {
85 for (int i = 0; i < 7; ++i)
86 {
87 if (i < 6)
88 {
89 overlays[i].image = nullptr;
90 overlays[i].invalid = false;
91 depthValues[i] = 0.0f;
92 }
93
94 zoom[i] = 30.0;
95 panX[i] = 0.0;
96 panY[i] = 0.0;
97 }
98 }
99 }; 62 };
100 63
101 enum Camera 64 enum Camera
102 { 65 {
103 TopCamera, 66 TopCamera,
124 class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement 87 class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement
125 { 88 {
126 Q_OBJECT 89 Q_OBJECT
127 90
128 public: 91 public:
129 GLRenderer(LDDocument* document, QWidget* parent = nullptr); 92 GLRenderer(Model* model, QWidget* parent = nullptr);
130 ~GLRenderer(); 93 ~GLRenderer();
131 94
132 Camera camera() const; 95 Camera camera() const;
133 const CameraInfo& cameraInfo(Camera camera) const; 96 const CameraInfo& cameraInfo(Camera camera) const;
134 QString cameraName(Camera camera) const; 97 QString cameraName(Camera camera) const;
139 Vertex convert2dTo3d(const QPoint& pos2d, bool snap) const; 102 Vertex convert2dTo3d(const QPoint& pos2d, bool snap) const;
140 QPoint convert3dTo2d(const Vertex& pos3d) const; 103 QPoint convert3dTo2d(const Vertex& pos3d) const;
141 QString currentCameraName() const; 104 QString currentCameraName() const;
142 EditModeType currentEditModeType() const; 105 EditModeType currentEditModeType() const;
143 int depthNegateFactor() const; 106 int depthNegateFactor() const;
144 LDDocument* document() const; 107 Model* model() const;
145 void drawPoint(QPainter& painter, QPointF pos, QColor color = QColor (64, 192, 0)) const; 108 void drawPoint(QPainter& painter, QPointF pos, QColor color = QColor (64, 192, 0)) const;
146 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d); 109 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d);
147 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos); 110 void drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos);
148 void drawGLScene(); 111 void drawGLScene();
149 void forgetObject(LDObject* obj); 112 void forgetObject(LDObject* obj);
199 void paintEvent(QPaintEvent* ev); 162 void paintEvent(QPaintEvent* ev);
200 void resizeGL(int w, int h); 163 void resizeGL(int w, int h);
201 void wheelEvent(QWheelEvent* ev); 164 void wheelEvent(QWheelEvent* ev);
202 165
203 private: 166 private:
204 LDDocument* m_document = nullptr; 167 Model* const m_model;
205 GLCompiler* m_compiler; 168 GLCompiler* m_compiler;
206 LDObject* m_objectAtCursor = nullptr; 169 LDObject* m_objectAtCursor = nullptr;
207 CameraIcon m_cameraIcons[7]; 170 CameraIcon m_cameraIcons[7];
208 QTimer* m_toolTipTimer; 171 QTimer* m_toolTipTimer;
209 Qt::MouseButtons m_lastButtons; 172 Qt::MouseButtons m_lastButtons;
210 Qt::KeyboardModifiers m_currentKeyboardModifiers; 173 Qt::KeyboardModifiers m_currentKeyboardModifiers;
211 Vertex m_position3D; 174 Vertex m_position3D;
212 double m_virtualWidth; 175 double m_virtualWidth;
213 double m_virtualHeight; 176 double m_virtualHeight;
177 QGenericMatrix<4, 4, GLfloat> m_rotationMatrix;
178 double m_panX[7] = {0};
179 double m_panY[7] = {0};
180 double m_zoom[7] = {30};
181 double m_depthValues[6];
182 LDGLOverlay m_overlays[6];
214 bool m_useDarkBackground = false; 183 bool m_useDarkBackground = false;
215 bool m_drawToolTip = false; 184 bool m_drawToolTip = false;
216 bool m_takingScreenCapture = false; 185 bool m_takingScreenCapture = false;
217 bool m_panning = false; 186 bool m_panning = false;
218 bool m_initialized = false; 187 bool m_initialized = false;
219 bool m_isDrawOnly = false; 188 bool m_isDrawOnly = false;
220 bool m_isDrawingSelectionScene = false; 189 bool m_isDrawingSelectionScene = false;
221 bool m_isCameraMoving = false; 190 bool m_isCameraMoving = false;
191 bool m_needZoomToFit = true;
222 QPoint m_mousePosition; 192 QPoint m_mousePosition;
223 QPoint m_globalpos; 193 QPoint m_globalpos;
224 QPointF m_mousePositionF; 194 QPointF m_mousePositionF;
225 QPen m_thinBorderPen; 195 QPen m_thinBorderPen;
226 Camera m_camera; 196 Camera m_camera;
233 AbstractEditMode* m_currentEditMode = nullptr; 203 AbstractEditMode* m_currentEditMode = nullptr;
234 GLuint m_axesVbo; 204 GLuint m_axesVbo;
235 GLuint m_axesColorVbo; 205 GLuint m_axesColorVbo;
236 206
237 void calcCameraIcons(); 207 void calcCameraIcons();
238 LDGLData& currentDocumentData() const;
239 void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type); 208 void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type);
240 LDOverlay* findOverlayObject (Camera cam); 209 LDOverlay* findOverlayObject (Camera cam);
241 double& panning (Axis ax); 210 double& panning (Axis ax);
242 double panning (Axis ax) const; 211 double panning (Axis ax) const;
243 double& zoom(); 212 double& zoom();

mercurial