Tue, 28 Jun 2022 17:59:34 +0300
Let's bring GLEW back after all
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/gl/common.h | file | annotate | diff | comparison | revisions | |
src/gl/compiler.cpp | file | annotate | diff | comparison | revisions | |
src/gl/compiler.h | file | annotate | diff | comparison | revisions | |
src/gl/debug.cpp | file | annotate | diff | comparison | revisions | |
src/gl/debug.h | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Tue Jun 28 17:35:56 2022 +0300 +++ b/CMakeLists.txt Tue Jun 28 17:59:34 2022 +0300 @@ -18,6 +18,7 @@ add_library(QtUiPlugin ALIAS Qt5::UiPlugin) endif() find_package(OpenGL REQUIRED) +find_package(GLEW REQUIRED) find_package(GLM REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) @@ -78,7 +79,6 @@ src/vertexmap.cpp src/gl/basicshaderprogram.cpp src/gl/compiler.cpp - src/gl/debug.cpp src/gl/partrenderer.cpp # src/gl/vertexprogram.cpp src/layers/axeslayer.cpp @@ -117,7 +117,6 @@ src/gl/basicshaderprogram.h src/gl/common.h src/gl/compiler.h - src/gl/debug.h src/gl/partrenderer.h # src/gl/vertexprogram.h src/layers/axeslayer.h @@ -142,6 +141,9 @@ src/widgets/colorselectdialog.ui src/widgets/colorindexinput.ui ) +set(SHADER_FILES + shaders/model.vert.glsl +) set(LOCALE_FILES locale/fi.ts @@ -169,11 +171,13 @@ ${QRC_SOURCE} ${FORMS_HEADERS} ${OTHER_FILES} + ${SHADER_FILES} ) set_source_files_properties(${HEADER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties(${QRC_FILE} PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties(${OTHER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE) +set_source_files_properties(${SHADER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE) set_target_properties(${TARGET_NAME} PROPERTIES AUTOMOC 1) target_link_libraries(${TARGET_NAME} PRIVATE Qt::Core) target_link_libraries(${TARGET_NAME} PRIVATE Qt::Widgets)
--- a/src/gl/common.h Tue Jun 28 17:35:56 2022 +0300 +++ b/src/gl/common.h Tue Jun 28 17:59:34 2022 +0300 @@ -17,13 +17,13 @@ */ #pragma once +#include <GL/glew.h> #include <QWidget> #include <QColor> #include <QOpenGLBuffer> #include <QOpenGLShader> #include <QOpenGLShaderProgram> #include <QOpenGLVertexArrayObject> -#include <QOpenGLFunctions> #include <glm/gtc/type_ptr.hpp> #include "src/basics.h" #include "src/colors.h" @@ -47,8 +47,6 @@ } }; -QOpenGLFunctions& glfunc(); - namespace gl { class ShaderProgram;
--- a/src/gl/compiler.cpp Tue Jun 28 17:35:56 2022 +0300 +++ b/src/gl/compiler.cpp Tue Jun 28 17:59:34 2022 +0300 @@ -344,7 +344,7 @@ } const GLsizeiptr size = static_cast<int>(vector.size() * sizeof vector[0]); object.buffer.bind(); - glfunc().glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data()); + glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data()); object.buffer.release(); } }
--- a/src/gl/compiler.h Tue Jun 28 17:35:56 2022 +0300 +++ b/src/gl/compiler.h Tue Jun 28 17:59:34 2022 +0300 @@ -17,6 +17,7 @@ */ #pragma once +#include <GL/glew.h> #include <glm/gtc/type_ptr.hpp> #include <QOpenGLVertexArrayObject> #include <QOpenGLBuffer> @@ -89,7 +90,7 @@ for (gl::ModelShaders::ShaderObject& shader : shaders->shaderObjects) { shader.program->bind(); - const int location = glfunc().glGetUniformLocation(shader.program->programId(), uniformName); + const int location = glGetUniformLocation(shader.program->programId(), uniformName); if (location != -1) { shader.program->setUniformValue(location, std::forward<Ts>(args)...); }
--- a/src/gl/debug.cpp Tue Jun 28 17:35:56 2022 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#include "src/gl/debug.h" - -QString sourceToString(const QOpenGLDebugMessage::Source source) -{ - switch (source) { - case QOpenGLDebugMessage::InvalidSource: - return QObject::tr("invalid"); - case QOpenGLDebugMessage::APISource: - return QObject::tr("API"); - case QOpenGLDebugMessage::WindowSystemSource: - return QObject::tr("window system"); - case QOpenGLDebugMessage::ShaderCompilerSource: - return QObject::tr("shader compiler"); - case QOpenGLDebugMessage::ThirdPartySource: - return QObject::tr("third party"); - case QOpenGLDebugMessage::ApplicationSource: - return QObject::tr("application"); - case QOpenGLDebugMessage::OtherSource: - return QObject::tr("other"); - case QOpenGLDebugMessage::AnySource: - return QObject::tr("any"); - } - return ""; -} - -QString typeToString(const QOpenGLDebugMessage::Type type) -{ - switch (type) { - case QOpenGLDebugMessage::ErrorType: - return QObject::tr("error"); - case QOpenGLDebugMessage::DeprecatedBehaviorType: - return QObject::tr("deprecated behavior"); - case QOpenGLDebugMessage::UndefinedBehaviorType: - return QObject::tr("undefined behavior"); - case QOpenGLDebugMessage::PortabilityType: - return QObject::tr("portability"); - case QOpenGLDebugMessage::PerformanceType: - return QObject::tr("performance"); - case QOpenGLDebugMessage::MarkerType: - return QObject::tr("marker"); - case QOpenGLDebugMessage::GroupPushType: - return QObject::tr("push group"); - case QOpenGLDebugMessage::GroupPopType: - return QObject::tr("pop group"); - case QOpenGLDebugMessage::OtherType: - return QObject::tr("other"); - case QOpenGLDebugMessage::InvalidType: - return QObject::tr("invalid"); - case QOpenGLDebugMessage::AnyType: - return QObject::tr("any"); - } - return ""; -} - -QString severityToString(const QOpenGLDebugMessage::Severity severity) -{ - switch (severity) { - case QOpenGLDebugMessage::HighSeverity: - return QObject::tr("high"); - case QOpenGLDebugMessage::MediumSeverity: - return QObject::tr("medium"); - case QOpenGLDebugMessage::LowSeverity: - return QObject::tr("low"); - case QOpenGLDebugMessage::NotificationSeverity: - return QObject::tr("notification"); - case QOpenGLDebugMessage::InvalidSeverity: - return QObject::tr("invalid"); - case QOpenGLDebugMessage::AnySeverity: - return QObject::tr("any"); - } - return ""; -} - -constexpr Message::Type severityToMessageType(const QOpenGLDebugMessage::Severity severity) -{ - switch (severity) { - case QOpenGLDebugMessage::HighSeverity: - return Message::Error; - case QOpenGLDebugMessage::MediumSeverity: - return Message::Warning; - default: - return Message::Info; - } -} - -Message debugMessageToString(const QOpenGLDebugMessage& glmessage) -{ - QString text; - QTextStream stream{&text}; - stream << QObject::tr("OpenGL debug message [%1]").arg(glmessage.id()) << "\n"; - stream << QObject::tr("Source: %1, ").arg(sourceToString(glmessage.source())); - stream << QObject::tr("type: %1, ").arg(typeToString(glmessage.type())); - stream << QObject::tr("severity: %1\n").arg(severityToString(glmessage.severity())); - stream << glmessage.message(); - return Message{ - .time = QDateTime::currentDateTime(), - .type = severityToMessageType(glmessage.severity()), - .text = text, - }; -}
--- a/src/gl/debug.h Tue Jun 28 17:35:56 2022 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -#pragma once -#include <QOpenGLDebugMessage> -#include "src/basics.h" - -Message debugMessageToString(const QOpenGLDebugMessage& glmessage);
--- a/src/gl/partrenderer.cpp Tue Jun 28 17:35:56 2022 +0300 +++ b/src/gl/partrenderer.cpp Tue Jun 28 17:59:34 2022 +0300 @@ -16,6 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <GL/glew.h> #include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_clip_space.hpp> #include <QOpenGLFramebufferObject> @@ -29,17 +30,10 @@ #include "src/settings.h" #include "src/gl/partrenderer.h" #include "src/gl/compiler.h" -#include "src/gl/debug.h" static constexpr double MIN_ZOOM = -3.0; static constexpr double MAX_ZOOM = 3.0; -QOpenGLFunctions& glfunc() -{ - static QOpenGLFunctions funcs; - return funcs; -} - PartRenderer::PartRenderer( Model* model, DocumentManager* documents, @@ -56,9 +50,6 @@ QSurfaceFormat surfaceFormat; surfaceFormat.setSamples(8); this->setFormat(surfaceFormat); - connect(&this->logger, &QOpenGLDebugLogger::messageLogged, [&](const QOpenGLDebugMessage& glmessage){ - Q_EMIT this->message(debugMessageToString(glmessage)); - }); connect(model, &Model::rowsInserted, [&]{ this->needBuild = true; }); @@ -81,18 +72,9 @@ { } -static QVector3D calcQVector3DFromQColor(const QColor& color) -{ - return { - float_cast(color.redF()), - float_cast(color.greenF()), - float_cast(color.blueF()), - }; -} - void PartRenderer::initializeGL() { - glfunc().initializeOpenGLFunctions(); + glewInit(); gl::initializeModelShaders(&this->shaders); for (RenderLayer* layer : this->activeRenderLayers) { layer->initializeGL(); @@ -100,10 +82,6 @@ for (RenderLayer* layer : this->inactiveRenderLayers) { layer->initializeGL(); } - this->logger.initialize(); - if (setting<Setting::LogOpenGLDebugMessages>()) { - this->logger.startLogging(); - } connect(this->model, &Model::dataChanged, this, &PartRenderer::build); this->initialized = true; this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); @@ -499,15 +477,6 @@ { this->build(); } - if (this->initialized) { - this->makeCurrent(); - if (setting<Setting::LogOpenGLDebugMessages>()) { - this->logger.startLogging(); - } - else { - this->logger.stopLogging(); - } - } Q_EMIT this->renderPreferencesChanged(); this->update(); }
--- a/src/gl/partrenderer.h Tue Jun 28 17:35:56 2022 +0300 +++ b/src/gl/partrenderer.h Tue Jun 28 17:59:34 2022 +0300 @@ -1,11 +1,10 @@ #pragma once -#include <QOpenGLWidget> -#include <QOpenGLDebugLogger> #include "src/basics.h" #include "src/documentmanager.h" #include "src/types/boundingbox.h" #include "src/gl/common.h" #include "src/gl/compiler.h" +#include <QOpenGLWidget> class PartRenderer final : public QOpenGLWidget { @@ -30,7 +29,6 @@ std::vector<RenderLayer*> activeRenderLayers; std::vector<RenderLayer*> inactiveRenderLayers; bool frozen = false; - QOpenGLDebugLogger logger; public: PartRenderer( Model* model,