src/gl/compiler.cpp

changeset 250
2837b549e616
parent 211
b27b90fb993f
child 259
c27612f0eac0
equal deleted inserted replaced
249:37d3c819cafa 250:2837b549e616
23 #include "gl/compiler.h" 23 #include "gl/compiler.h"
24 #include "documentmanager.h" 24 #include "documentmanager.h"
25 #include "invert.h" 25 #include "invert.h"
26 #include "ring.h" 26 #include "ring.h"
27 27
28 static const char* vertexShaderSource = R"( 28 constexpr char VERTEX_SHADER_SOURCE[] = R"(
29 #version 330 core 29 #version 330 core
30 30
31 layout(location=0) in vec3 position; 31 layout(location=0) in vec3 position;
32 layout(location=1) in vec4 color; 32 layout(location=1) in vec4 color;
33 layout(location=2) in vec3 normal; 33 layout(location=2) in vec3 normal;
95 vFragPos = vec3(modelMatrix * vec4(position, 1.0)); 95 vFragPos = vec3(modelMatrix * vec4(position, 1.0));
96 gl_Position = projectionMatrix * viewMatrix * vec4(vFragPos, 1.0); 96 gl_Position = projectionMatrix * viewMatrix * vec4(vFragPos, 1.0);
97 } 97 }
98 )"; 98 )";
99 99
100 static const char* fragmentShaderSource = R"( 100 constexpr char FRAGMENT_SHADER_SOURCE[] = R"(
101 #version 330 core 101 #version 330 core
102 102
103 in vec4 vColor; 103 in vec4 vColor;
104 in vec3 vFragPos; 104 in vec3 vFragPos;
105 in vec3 vNormal; 105 in vec3 vNormal;
196 void gl::initializeModelShaders(gl::ModelShaders *modelShaders) 196 void gl::initializeModelShaders(gl::ModelShaders *modelShaders)
197 { 197 {
198 if (not modelShaders->initialized) { 198 if (not modelShaders->initialized) {
199 for (auto& shader : modelShaders->shaderObjects) { 199 for (auto& shader : modelShaders->shaderObjects) {
200 shader.program = std::make_unique<QOpenGLShaderProgram>(); 200 shader.program = std::make_unique<QOpenGLShaderProgram>();
201 gl::buildShaders(shader.program.get(), ::vertexShaderSource, ::fragmentShaderSource); 201 gl::buildShaders(shader.program.get(), VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE);
202 shader.program->bind(); 202 shader.program->bind();
203 shader.buffer.create(); 203 shader.buffer.create();
204 shader.buffer.bind(); 204 shader.buffer.bind();
205 shader.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); 205 shader.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
206 shader.vertexArray.create(); 206 shader.vertexArray.create();

mercurial