src/gl/compiler.cpp

changeset 28
c92c1daf735f
parent 27
c57fb7a5ffa3
child 30
1536f23cfab7
equal deleted inserted replaced
27:c57fb7a5ffa3 28:c92c1daf735f
34 uniform mat4 CameraTransformation; 34 uniform mat4 CameraTransformation;
35 35
36 void main() 36 void main()
37 { 37 {
38 vColor = color; 38 vColor = color;
39 gl_Position = projection * modelview * CameraTransformation * vec4(position, 1.0); 39 gl_Position = CameraTransformation * vec4(position, 1.0);
40 } 40 }
41 )"; 41 )";
42 42
43 static const char* fragmentShaderSource = R"( 43 static const char* fragmentShaderSource = R"(
44 #version 330 core 44 #version 330 core
70 for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1) 70 for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1)
71 { 71 {
72 auto& object = this->glObjects[i]; 72 auto& object = this->glObjects[i];
73 object.program = new QOpenGLShaderProgram; 73 object.program = new QOpenGLShaderProgram;
74 object.program->create(); 74 object.program->create();
75 object.program->addShaderFromSourceCode(QOpenGLShader::Vertex, ::vertexShaderSource); 75 const bool vertexShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Vertex, ::vertexShaderSource);
76 object.program->addShaderFromSourceCode(QOpenGLShader::Fragment, ::fragmentShaderSource); 76 QString log;
77 if (not vertexShaderCompiled)
78 {
79 log += "\n" + tr("Vertex shader:") + "\n" + object.program->log();
80 }
81 const bool fragmentShaderCompiled = object.program->addShaderFromSourceCode(QOpenGLShader::Fragment, ::fragmentShaderSource);
82 if (not fragmentShaderCompiled)
83 {
84 log += "\n" + tr("Fragment shader:") + "\n" + object.program->log();
85 }
86 if (not vertexShaderCompiled or not fragmentShaderCompiled)
87 {
88 QMessageBox::critical(nullptr, tr("Shader compile error"), tr("Could not compile shaders.") + "\n" + log);
89 std::exit(-1);
90 }
77 object.program->link(); 91 object.program->link();
78 object.program->bind(); 92 object.program->bind();
79 object.buffer.create(); 93 object.buffer.create();
80 object.buffer.bind(); 94 object.buffer.bind();
81 object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); 95 object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
231 int gl::vboIndex(const VboAddress vboAddress) 245 int gl::vboIndex(const VboAddress vboAddress)
232 { 246 {
233 return static_cast<std::uint8_t>(vboAddress.vboClass) * gl::numVboSubclasses 247 return static_cast<std::uint8_t>(vboAddress.vboClass) * gl::numVboSubclasses
234 + static_cast<std::uint8_t>(vboAddress.vboSubclass); 248 + static_cast<std::uint8_t>(vboAddress.vboSubclass);
235 } 249 }
250
251 QMatrix4x4 gl::toQMatrix(const glm::mat4& matrix)
252 {
253 return {
254 matrix[0][0],
255 matrix[0][1],
256 matrix[0][2],
257 matrix[0][3],
258 matrix[1][0],
259 matrix[1][1],
260 matrix[1][2],
261 matrix[1][3],
262 matrix[2][0],
263 matrix[2][1],
264 matrix[2][2],
265 matrix[2][3],
266 matrix[3][0],
267 matrix[3][1],
268 matrix[3][2],
269 matrix[3][3],
270 };
271 }

mercurial