69 |
69 |
70 void GridLayer::setGridMatrix(const glm::mat4& newGridMatrix) |
70 void GridLayer::setGridMatrix(const glm::mat4& newGridMatrix) |
71 { |
71 { |
72 this->gridMatrix = newGridMatrix; |
72 this->gridMatrix = newGridMatrix; |
73 if (this->isInitialized) { |
73 if (this->isInitialized) { |
74 this->shader.setUniformMatrix("grid", newGridMatrix); |
74 gl::set_shader_matrix_uniform(&this->shader, "grid", newGridMatrix); |
75 } |
75 } |
76 } |
76 } |
77 |
77 |
78 void GridLayer::setGridColor(const QColor& newGridColor) |
78 void GridLayer::setGridColor(const QColor& newGridColor) |
79 { |
79 { |
80 this->gridColor = gl::colorToVector4(newGridColor); |
80 this->gridColor = gl::colorToVector4(newGridColor); |
81 if (this->isInitialized) { |
81 if (this->isInitialized) { |
82 this->shader.setUniformVector("gridColor", this->gridColor); |
82 gl::set_shader_vector_uniform(&this->shader, "gridColor", this->gridColor); |
83 } |
83 } |
84 } |
84 } |
85 |
85 |
86 void GridLayer::settingsChanged() |
86 void GridLayer::settingsChanged() |
87 { |
87 { |
88 this->setGridColor(this->renderer->isDark() ? Qt::white : Qt::black); |
88 this->setGridColor(this->renderer->isDark() ? Qt::white : Qt::black); |
89 } |
89 } |
90 |
90 |
91 void GridLayer::initializeGL() |
91 void GridLayer::initializeGL() |
92 { |
92 { |
93 this->shader.initialize( |
93 gl::initialize_basic_shader( |
|
94 &this->shader, |
94 ::vertexShaderSource, |
95 ::vertexShaderSource, |
95 ::fragmentShaderSource, |
96 ::fragmentShaderSource, |
96 QOpenGLBuffer::StaticDraw, |
97 QOpenGLBuffer::StaticDraw, |
97 { |
98 { |
98 GLAttributeSpec{ |
99 GLAttributeSpec{ |
103 }, |
104 }, |
104 } |
105 } |
105 ); |
106 ); |
106 this->isInitialized = true; |
107 this->isInitialized = true; |
107 constexpr auto data = calcGridData<50>(); |
108 constexpr auto data = calcGridData<50>(); |
108 this->shader.setUniformVector("gridColor", this->gridColor); |
109 gl::set_shader_vector_uniform(&this->shader, "gridColor", this->gridColor); |
109 this->setGridMatrix(this->gridMatrix); |
110 this->setGridMatrix(this->gridMatrix); |
110 this->settingsChanged(); |
111 this->settingsChanged(); |
111 this->shader.bufferData(data.data(), data.size(), sizeof data[0]); |
112 gl::buffer_shader_data(&this->shader, data.data(), data.size(), sizeof data[0]); |
112 } |
113 } |
113 |
114 |
114 void GridLayer::paintGL() |
115 void GridLayer::paintGL() |
115 { |
116 { |
116 glLineWidth(1); |
117 glLineWidth(1); |
117 glEnable(GL_BLEND); |
118 glEnable(GL_BLEND); |
118 glLineStipple(1, 0x8888); |
119 glLineStipple(1, 0x8888); |
119 glEnable(GL_LINE_STIPPLE); |
120 glEnable(GL_LINE_STIPPLE); |
120 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
121 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
121 this->shader.draw(GL_LINES); |
122 gl::draw_shader(&this->shader, GL_LINES); |
122 glDisable(GL_BLEND); |
123 glDisable(GL_BLEND); |
123 glDisable(GL_LINE_STIPPLE); |
124 glDisable(GL_LINE_STIPPLE); |
124 } |
125 } |
125 |
126 |
126 void GridLayer::mvpMatrixChanged(const glm::mat4& mvpMatrix) |
127 void GridLayer::mvpMatrixChanged(const glm::mat4& mvpMatrix) |
127 { |
128 { |
128 this->shader.setMvpMatrix(mvpMatrix); |
129 gl::set_shader_matrix_uniform(&this->shader, "mvp", mvpMatrix); |
129 } |
130 } |