19 #pragma once |
19 #pragma once |
20 #include "main.h" |
20 #include "main.h" |
21 #include "gl/common.h" |
21 #include "gl/common.h" |
22 #include "types/boundingbox.h" |
22 #include "types/boundingbox.h" |
23 #include <glm/glm.hpp> |
23 #include <glm/glm.hpp> |
|
24 #include <glm/gtc/type_ptr.hpp> |
24 #include <QMap> |
25 #include <QMap> |
25 #include <QSet> |
26 #include <QSet> |
26 #include <QOpenGLVertexArrayObject> |
27 #include <QOpenGLVertexArrayObject> |
27 #include <QOpenGLBuffer> |
28 #include <QOpenGLBuffer> |
28 #include <QOpenGLShaderProgram> |
29 #include <QOpenGLShaderProgram> |
57 double modelDistance() const; |
58 double modelDistance() const; |
58 void initialize(); |
59 void initialize(); |
59 void bindVertexArray(gl::ArrayClass arrayClass); |
60 void bindVertexArray(gl::ArrayClass arrayClass); |
60 void releaseVertexArray(gl::ArrayClass arrayClass); |
61 void releaseVertexArray(gl::ArrayClass arrayClass); |
61 void buildShaders(int arrayId); |
62 void buildShaders(int arrayId); |
|
63 |
62 template<typename T> |
64 template<typename T> |
63 void setUniform(const char* uniformName, T&& value) |
65 void setUniform(const char* uniformName, T&& value) |
64 { |
66 { |
65 Q_ASSERT(this->initialized); |
67 Q_ASSERT(this->initialized); |
66 for (auto& object : this->glObjects) |
68 for (auto& object : this->glObjects) |
69 const int location = glGetUniformLocation(object.program->programId(), uniformName); |
71 const int location = glGetUniformLocation(object.program->programId(), uniformName); |
70 Q_ASSERT(location != -1); |
72 Q_ASSERT(location != -1); |
71 object.program->setUniformValue(location, std::forward<T>(value)); |
73 object.program->setUniformValue(location, std::forward<T>(value)); |
72 object.program->release(); |
74 object.program->release(); |
73 } |
75 } |
|
76 } |
|
77 |
|
78 template<typename Float, glm::qualifier Prec> |
|
79 void setUniformMatrix(const char* uniformName, const glm::mat<4, 4, Float, Prec>& value) |
|
80 { |
|
81 const float (*array)[4][4] = reinterpret_cast<const float(*)[4][4]>(glm::value_ptr(value)); |
|
82 this->setUniform(uniformName, *array); |
74 } |
83 } |
75 private: |
84 private: |
76 bool m_vboChanged[gl::numVbos] = {true}; |
85 bool m_vboChanged[gl::numVbos] = {true}; |
77 std::size_t storedVboSizes[gl::numVbos] = {0_z}; |
86 std::size_t storedVboSizes[gl::numVbos] = {0_z}; |
78 bool initialized = false; |
87 bool initialized = false; |