diff -r eee644f88e93 -r 3af627f7a40f src/gl/common.h --- 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 +#include #include -#include +#include +#include +#include +#include #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 + void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value) + { + const float (*array)[4][4] = reinterpret_cast(glm::value_ptr(value)); + this->setUniformValue(uniformName, *array); + } + template + void setUniformVector(const char* uniformName, const glm::vec& value) + { + const Float (*array)[N] = reinterpret_cast(glm::value_ptr(value)); + this->setUniformValue(uniformName, array); + } +}; + struct gl::Polygon { enum Type : qint8