diff -r eee644f88e93 -r 3af627f7a40f src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Sat Feb 08 00:08:57 2020 +0200 +++ b/src/gl/partrenderer.cpp Thu Feb 13 12:51:27 2020 +0200 @@ -33,7 +33,8 @@ model{model}, documents{documents}, colorTable{colorTable}, - compiler{new gl::Compiler{this->colorTable, this}} + compiler{new gl::Compiler{this->colorTable, this}}, + gridProgram{this} { this->setMouseTracking(true); } @@ -42,6 +43,11 @@ { } +static QVector3D vec3FromQColor(const QColor& color) +{ + return {(float)color.redF(), (float)color.greenF(), (float)color.blueF()}; +} + void PartRenderer::initializeGL() { this->initializeOpenGLFunctions(); @@ -49,6 +55,8 @@ { abort(); } + this->gridProgram.emplace(this); + this->gridProgram->initialize(); this->compiler->initialize(); this->compiler->build(this->model, this->documents, this->renderPreferences); this->initialized = true; @@ -67,6 +75,7 @@ 0.1f, 10000.f); this->compiler->setUniformMatrix("projectionMatrix", this->projectionMatrix); + this->gridProgram->setProjectionMatrix(this->projectionMatrix); } static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) @@ -88,17 +97,12 @@ { glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); - glEnable(GL_MULTISAMPLE); this->renderScene(); } -static QVector3D vec3FromQColor(const QColor& color) -{ - return {(float)color.redF(), (float)color.greenF(), (float)color.blueF()}; -} - void PartRenderer::renderScene() { + this->checkForGLErrors(); if (this->renderPreferences.lineAntiAliasing && this->renderPreferences.style != gl::RenderStyle::PickScene) { glEnable(GL_LINE_SMOOTH); @@ -122,6 +126,7 @@ glClearColor(0.0f, 0.0f, 0.0f, 1.0f); this->compiler->setUniform("useLighting", GL_FALSE); } + this->checkForGLErrors(); this->compiler->setUniform("selectedColor", vec3FromQColor(this->renderPreferences.selectedColor)); this->compiler->setUniform("highlighted", this->highlighted.value); this->checkForGLErrors(); @@ -164,6 +169,10 @@ this->renderAllArrays(); break; } + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + this->gridProgram->draw(); + glDisable(GL_BLEND); glDisable(GL_POLYGON_OFFSET_FILL); } @@ -182,6 +191,7 @@ const double z = 2 * std::exp(this->zoom) * (1 + this->compiler->modelDistance()); this->viewMatrix = glm::lookAt(glm::vec3{0, 0, z}, {0, 0, 0}, {0, -1, 0}); this->compiler->setUniformMatrix("viewMatrix", this->viewMatrix); + this->gridProgram->setViewMatrix(this->viewMatrix); } void PartRenderer::renderVao(const gl::ArrayClass arrayClass) @@ -197,6 +207,11 @@ void PartRenderer::checkForGLErrors() { + gl::checkForGLErrors(this); +} + +void gl::checkForGLErrors(QWidget* parent) +{ GLenum glError; QStringList errors; while ((glError = glGetError()) != GL_NO_ERROR) @@ -206,12 +221,12 @@ } if (not errors.isEmpty()) { - QMessageBox box{this}; + QMessageBox box{parent}; box.setIcon(QMessageBox::Critical); - box.setText(tr("Failed to render: %1").arg(errors.join("\n"))); - box.setWindowTitle(tr("Rendering error")); + box.setText(QObject::tr("OpenGL error: %1").arg(errors.join("\n"))); + box.setWindowTitle(QObject::tr("OpenGL error")); box.setStandardButtons(QMessageBox::Close); - box.button(QMessageBox::Close)->setText(tr("Damn it")); + box.button(QMessageBox::Close)->setText(QObject::tr("Damn it")); box.exec(); } } @@ -231,7 +246,9 @@ const glm::quat q_x = glm::angleAxis(scalar * move_x, glm::vec3{0, -1, 0}); const glm::quat q_y = glm::angleAxis(scalar * move_y, glm::vec3{-1, 0, 0}); this->modelQuaternion = q_x * q_y * this->modelQuaternion; - this->compiler->setUniformMatrix("modelMatrix", glm::mat4_cast(this->modelQuaternion)); + const glm::mat4 modelMatrix = glm::mat4_cast(this->modelQuaternion); + this->compiler->setUniformMatrix("modelMatrix", modelMatrix); + this->gridProgram->setModelMatrix(modelMatrix); this->update(); } this->lastMousePosition = pointToPointF(event->pos());