--- a/src/gl/compiler.cpp Sat Feb 08 00:08:57 2020 +0200 +++ b/src/gl/compiler.cpp Thu Feb 13 12:51:27 2020 +0200 @@ -130,6 +130,42 @@ { } +void gl::buildShaders( + QOpenGLShaderProgram* shaderProgram, + const char* vertexShaderSource, + const char* fragmentShaderSource) +{ + shaderProgram->create(); + const bool vertexShaderCompiled = shaderProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + QString log; + if (not vertexShaderCompiled) + { + log += "\n" + QObject::tr("Vertex shader:") + "\n" + shaderProgram->log(); + } + const bool fragmentShaderCompiled = shaderProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + if (not fragmentShaderCompiled) + { + log += "\n" + QObject::tr("Fragment shader:") + "\n" + shaderProgram->log(); + } + if (not vertexShaderCompiled or not fragmentShaderCompiled) + { + QMessageBox::critical( + nullptr, + QObject::tr("Shader compile error"), + QObject::tr("Could not compile shaders.") + "\n" + log); + std::exit(-1); + } + const bool linkSuccessful = shaderProgram->link(); + if (not linkSuccessful) + { + QMessageBox::critical( + nullptr, + QObject::tr("Shader link error"), + QObject::tr("Could not link shaders: %1").arg(shaderProgram->log()) + ); + } +} + void gl::Compiler::initialize() { if (not this->initialized) @@ -139,24 +175,7 @@ { auto& object = this->glObjects[i]; object.program = new QOpenGLShaderProgram; - object.program->create(); - const bool vertexShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Vertex, ::vertexShaderSource); - QString log; - if (not vertexShaderCompiled) - { - log += "\n" + tr("Vertex shader:") + "\n" + object.program->log(); - } - const bool fragmentShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Fragment, ::fragmentShaderSource); - if (not fragmentShaderCompiled) - { - log += "\n" + tr("Fragment shader:") + "\n" + object.program->log(); - } - if (not vertexShaderCompiled or not fragmentShaderCompiled) - { - QMessageBox::critical(nullptr, tr("Shader compile error"), tr("Could not compile shaders.") + "\n" + log); - std::exit(-1); - } - object.program->link(); + gl::buildShaders(object.program, ::vertexShaderSource, ::fragmentShaderSource); object.program->bind(); object.buffer.create(); object.buffer.bind();