src/gl/gridprogram.cpp

changeset 64
f99d52b1646b
parent 55
cb81ecb5fb23
child 70
f21b800b02a4
equal deleted inserted replaced
63:f7dd937667a5 64:f99d52b1646b
26 uniform mat4 view; 26 uniform mat4 view;
27 uniform mat4 projection; 27 uniform mat4 projection;
28 uniform mat4 model; 28 uniform mat4 model;
29 smooth out vec2 ex_uv; 29 smooth out vec2 ex_uv;
30 const mat4 stretch = mat4(vec4(10000, 0, 0, 0), vec4(0, 10000, 0, 0), vec4(0, 0, 10000, 0), vec4(0, 0, 0, 1)); 30 const mat4 stretch = mat4(vec4(10000, 0, 0, 0), vec4(0, 10000, 0, 0), vec4(0, 0, 10000, 0), vec4(0, 0, 0, 1));
31 const mat4 gridmatrix = mat4(vec4(1, 0, 0, 0), vec4(0, 1, 0, 0), vec4(0, 0, 1, 0), vec4(0, 0, 0, 1)); 31 uniform mat4 grid;
32 32
33 void main() 33 void main()
34 { 34 {
35 gl_Position = projection * view * model * gridmatrix * stretch * vec4(in_position, 0.0, 1.0); 35 gl_Position = projection * view * model * grid * stretch * vec4(in_position, 0.0, 1.0);
36 ex_uv = in_position; 36 ex_uv = in_position;
37 } 37 }
38 )"; 38 )";
39 39
40 const char fragmentShaderSource[] = R"( 40 const char fragmentShaderSource[] = R"(
97 } 97 }
98 } 98 }
99 99
100 void GridProgram::setViewMatrix(const glm::mat4& newViewMatrix) 100 void GridProgram::setViewMatrix(const glm::mat4& newViewMatrix)
101 { 101 {
102 Q_ASSERT(this->isInitialized); 102 this->setMatrix("view", newViewMatrix);
103 this->program->bind();
104 this->program->setUniformMatrix("view", newViewMatrix);
105 this->program->release();
106 this->checkForGLErrors();
107 } 103 }
108 104
109 void GridProgram::setProjectionMatrix(const glm::mat4& newProjectionMatrix) 105 void GridProgram::setProjectionMatrix(const glm::mat4& newProjectionMatrix)
110 { 106 {
111 Q_ASSERT(this->isInitialized); 107 this->setMatrix("projection", newProjectionMatrix);
112 this->program->bind();
113 this->program->setUniformMatrix("projection", newProjectionMatrix);
114 this->program->release();
115 this->checkForGLErrors();
116 } 108 }
117 109
118 void GridProgram::setModelMatrix(const glm::mat4& newModelMatrix) 110 void GridProgram::setModelMatrix(const glm::mat4& newModelMatrix)
119 { 111 {
112 this->setMatrix("model", newModelMatrix);
113 }
114
115 void GridProgram::setGridMatrix(const glm::mat4& newGridMatrix)
116 {
117 this->setMatrix("grid", newGridMatrix);
118 }
119
120 void GridProgram::setMatrix(const char* name, const glm::mat4& matrix)
121 {
120 Q_ASSERT(this->isInitialized); 122 Q_ASSERT(this->isInitialized);
121 this->program->bind(); 123 this->program->bind();
122 this->program->setUniformMatrix("model", newModelMatrix); 124 this->program->setUniformMatrix(name, matrix);
123 this->program->release(); 125 this->program->release();
124 this->checkForGLErrors(); 126 this->checkForGLErrors();
125 } 127 }
126 128
127 void GridProgram::setGridColor(const QColor& newGridColor) 129 void GridProgram::setGridColor(const QColor& newGridColor)

mercurial