src/glRenderer.cpp

changeset 1133
47f6db5ea24d
parent 1132
825dd975588d
child 1134
daa9808d626e
equal deleted inserted replaced
1132:825dd975588d 1133:47f6db5ea24d
35 #include "documentmanager.h" 35 #include "documentmanager.h"
36 #include "grid.h" 36 #include "grid.h"
37 37
38 const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; 38 const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
39 39
40 // ============================================================================= 40 /*
41 // 41 * Constructs a GL renderer.
42 */
42 GLRenderer::GLRenderer(const Model* model, QWidget* parent) : 43 GLRenderer::GLRenderer(const Model* model, QWidget* parent) :
43 QGLWidget {parent}, 44 QGLWidget {parent},
44 HierarchyElement {parent}, 45 HierarchyElement {parent},
45 m_model {model}, 46 m_model {model},
46 m_cameras { 47 m_cameras {
78 } 79 }
79 80
80 calcCameraIcons(); 81 calcCameraIcons();
81 } 82 }
82 83
83 // ============================================================================= 84 /*
84 // 85 * Cleans up the axes VBOs when the renderer is destroyed.
86 */
85 GLRenderer::~GLRenderer() 87 GLRenderer::~GLRenderer()
86 { 88 {
87 m_compiler->setRenderer (nullptr); 89 glDeleteBuffers(1, &m_axesVbo);
88 delete m_compiler; 90 glDeleteBuffers(1, &m_axesColorVbo);
89 glDeleteBuffers (1, &m_axesVbo); 91 }
90 glDeleteBuffers (1, &m_axesColorVbo); 92
91 } 93 /*
92 94 * Calculates the camera icon locations.
93 // ============================================================================= 95 */
94 // Calculates the "hitboxes" of the camera icons so that we can tell when the
95 // cursor is pointing at the camera icon.
96 //
97 void GLRenderer::calcCameraIcons() 96 void GLRenderer::calcCameraIcons()
98 { 97 {
99 int i = 0; 98 int i = 0;
100 const int columns = 3; 99 const int columns = 3;
101 const int firstAtLastRow = countof(m_cameras) - (countof(m_cameras) % columns); 100 const int firstAtLastRow = countof(m_cameras) - (countof(m_cameras) % columns);
103 for (CameraIcon& cameraIcon : m_cameraIcons) 102 for (CameraIcon& cameraIcon : m_cameraIcons)
104 { 103 {
105 int row = i / columns; 104 int row = i / columns;
106 int column = i % columns; 105 int column = i % columns;
107 106
107 // Do right-justifying on the last row.
108 if (i >= firstAtLastRow) 108 if (i >= firstAtLastRow)
109 column += columns - (countof(m_cameras) % columns); 109 column += columns - (countof(m_cameras) % columns);
110 110
111 int x1 = width() - 48 + (column * 16) - 1; 111 int x1 = width() - 48 + (column * 16) - 1;
112 int y1 = (row * 16) + 1; 112 int y1 = (row * 16) + 1;
122 122
123 ++i; 123 ++i;
124 } 124 }
125 } 125 }
126 126
127 /*
128 * Returns the camera currently in use.
129 */
127 GLCamera& GLRenderer::currentCamera() 130 GLCamera& GLRenderer::currentCamera()
128 { 131 {
129 return m_cameras[static_cast<int>(camera())]; 132 return m_cameras[static_cast<int>(camera())];
130 } 133 }
131 134
135 /*
136 * Returns the camera currently in use.
137 */
132 const GLCamera& GLRenderer::currentCamera() const 138 const GLCamera& GLRenderer::currentCamera() const
133 { 139 {
134 return m_cameras[static_cast<int>(camera())]; 140 return m_cameras[static_cast<int>(camera())];
135 } 141 }
136 142
137 // ============================================================================= 143 /*
138 // 144 * Prepares the GL context for rendering.
145 */
139 void GLRenderer::initGLData() 146 void GLRenderer::initGLData()
140 { 147 {
141 glEnable (GL_BLEND); 148 glEnable (GL_BLEND);
142 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 149 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
143 glEnable (GL_POLYGON_OFFSET_FILL); 150 glEnable (GL_POLYGON_OFFSET_FILL);
158 glDisable (GL_LINE_SMOOTH); 165 glDisable (GL_LINE_SMOOTH);
159 glDisable (GL_POLYGON_SMOOTH); 166 glDisable (GL_POLYGON_SMOOTH);
160 } 167 }
161 } 168 }
162 169
163 bool GLRenderer::isDrawOnly() const 170 /*
164 { 171 * Returns the object currently highlighted by the cursor.
165 return m_isDrawOnly; 172 */
166 }
167
168 void GLRenderer::setDrawOnly (bool value)
169 {
170 m_isDrawOnly = value;
171 }
172
173 GLCompiler* GLRenderer::compiler() const
174 {
175 return m_compiler;
176 }
177
178 LDObject* GLRenderer::objectAtCursor() const 173 LDObject* GLRenderer::objectAtCursor() const
179 { 174 {
180 return m_objectAtCursor; 175 return m_objectAtCursor;
181 } 176 }
182 177
230 glLineWidth (m_config->lineThickness()); 225 glLineWidth (m_config->lineThickness());
231 glLineStipple (1, 0x6666); 226 glLineStipple (1, 0x6666);
232 setAutoFillBackground (false); 227 setAutoFillBackground (false);
233 setMouseTracking (true); 228 setMouseTracking (true);
234 setFocusPolicy (Qt::WheelFocus); 229 setFocusPolicy (Qt::WheelFocus);
235 compiler()->initialize(); 230 m_compiler->initialize();
236 initializeAxes(); 231 initializeAxes();
237 initializeLighting(); 232 initializeLighting();
238 m_initialized = true; 233 m_initialized = true;
239 // Now that GL is initialized, we can reset angles. 234 // Now that GL is initialized, we can reset angles.
240 resetAllAngles(); 235 resetAllAngles();

mercurial