--- a/src/gl/common.h Sat Feb 08 00:08:57 2020 +0200 +++ b/src/gl/common.h Thu Feb 13 12:51:27 2020 +0200 @@ -18,24 +18,46 @@ #pragma once #include <QColor> +#include <QOpenGLBuffer> #include <QOpenGLFunctions> -#include <QGenericMatrix> +#include <QOpenGLShader> +#include <QOpenGLShaderProgram> +#include <QOpenGLVertexArrayObject> +#include <glm/gtc/type_ptr.hpp> #include "basics.h" #include "colors.h" namespace gl { - // Transformation matrices for projection cameras. - static const QMatrix4x4 topCameraMatrix = {}; - static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; - static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; - static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; - static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; - static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; - static constexpr QRgb BlackRgb = 0xff000000; struct Polygon; + class ShaderProgram; + + void buildShaders( + QOpenGLShaderProgram* shaderProgram, + const char* vertexShaderSource, + const char* fragmentShaderSource); + void checkForGLErrors(QWidget* parent); } +class gl::ShaderProgram : public QOpenGLShaderProgram +{ +public: + using QOpenGLShaderProgram::QOpenGLShaderProgram; + // for some reason I cannot overload setUniformValue properly with this template thing + template<typename Float, glm::qualifier Prec> + void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value) + { + const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value)); + this->setUniformValue(uniformName, *array); + } + template<int N, typename Float, glm::qualifier Prec> + void setUniformVector(const char* uniformName, const glm::vec<N, Float, Prec>& value) + { + const Float (*array)[N] = reinterpret_cast<const Float(*)[N]>(glm::value_ptr(value)); + this->setUniformValue(uniformName, array); + } +}; + struct gl::Polygon { enum Type : qint8