16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #pragma once |
19 #pragma once |
20 #include <QColor> |
20 #include <QColor> |
|
21 #include <QOpenGLBuffer> |
21 #include <QOpenGLFunctions> |
22 #include <QOpenGLFunctions> |
22 #include <QGenericMatrix> |
23 #include <QOpenGLShader> |
|
24 #include <QOpenGLShaderProgram> |
|
25 #include <QOpenGLVertexArrayObject> |
|
26 #include <glm/gtc/type_ptr.hpp> |
23 #include "basics.h" |
27 #include "basics.h" |
24 #include "colors.h" |
28 #include "colors.h" |
25 |
29 |
26 namespace gl |
30 namespace gl |
27 { |
31 { |
28 // Transformation matrices for projection cameras. |
|
29 static const QMatrix4x4 topCameraMatrix = {}; |
|
30 static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; |
|
31 static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; |
|
32 static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; |
|
33 static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; |
|
34 static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; |
|
35 static constexpr QRgb BlackRgb = 0xff000000; |
|
36 struct Polygon; |
32 struct Polygon; |
|
33 class ShaderProgram; |
|
34 |
|
35 void buildShaders( |
|
36 QOpenGLShaderProgram* shaderProgram, |
|
37 const char* vertexShaderSource, |
|
38 const char* fragmentShaderSource); |
|
39 void checkForGLErrors(QWidget* parent); |
37 } |
40 } |
|
41 |
|
42 class gl::ShaderProgram : public QOpenGLShaderProgram |
|
43 { |
|
44 public: |
|
45 using QOpenGLShaderProgram::QOpenGLShaderProgram; |
|
46 // for some reason I cannot overload setUniformValue properly with this template thing |
|
47 template<typename Float, glm::qualifier Prec> |
|
48 void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value) |
|
49 { |
|
50 const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value)); |
|
51 this->setUniformValue(uniformName, *array); |
|
52 } |
|
53 template<int N, typename Float, glm::qualifier Prec> |
|
54 void setUniformVector(const char* uniformName, const glm::vec<N, Float, Prec>& value) |
|
55 { |
|
56 const Float (*array)[N] = reinterpret_cast<const Float(*)[N]>(glm::value_ptr(value)); |
|
57 this->setUniformValue(uniformName, array); |
|
58 } |
|
59 }; |
38 |
60 |
39 struct gl::Polygon |
61 struct gl::Polygon |
40 { |
62 { |
41 enum Type : qint8 |
63 enum Type : qint8 |
42 { |
64 { |