99 10000.f); |
99 10000.f); |
100 gl::setShaderUniformMatrix(&this->shaders, "projectionMatrix", this->projectionMatrix); |
100 gl::setShaderUniformMatrix(&this->shaders, "projectionMatrix", this->projectionMatrix); |
101 Q_EMIT projectionMatrixChanged(this->projectionMatrix); |
101 Q_EMIT projectionMatrixChanged(this->projectionMatrix); |
102 } |
102 } |
103 |
103 |
104 static constexpr GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) |
|
105 { |
|
106 switch (vboClass) |
|
107 { |
|
108 case gl::ArrayClass::Lines: |
|
109 case gl::ArrayClass::ConditionalLines: |
|
110 return GL_LINES; |
|
111 case gl::ArrayClass::Triangles: |
|
112 return GL_TRIANGLES; |
|
113 case gl::ArrayClass::Quads: |
|
114 return GL_QUADS; |
|
115 } |
|
116 throw std::runtime_error{"bad value for vboClass"}; |
|
117 } |
|
118 |
|
119 void PartRenderer::paintGL() |
104 void PartRenderer::paintGL() |
120 { |
105 { |
121 glEnable(GL_DEPTH_TEST); |
106 glEnable(GL_DEPTH_TEST); |
122 glShadeModel(GL_SMOOTH); |
107 glShadeModel(GL_SMOOTH); |
123 this->renderScene(); |
108 this->renderScene(); |
176 glEnable(GL_POLYGON_OFFSET_FILL); |
161 glEnable(GL_POLYGON_OFFSET_FILL); |
177 glPolygonOffset(1.0f, 1.0f); |
162 glPolygonOffset(1.0f, 1.0f); |
178 glLineWidth(this->renderPreferences.lineThickness); |
163 glLineWidth(this->renderPreferences.lineThickness); |
179 const auto renderAllArrays = [this](){ |
164 const auto renderAllArrays = [this](){ |
180 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. |
165 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. |
181 this->renderVao(gl::ArrayClass::Triangles); |
166 this->renderVao<gl::ArrayClass::Triangles>(); |
182 this->renderVao(gl::ArrayClass::Quads); |
167 this->renderVao<gl::ArrayClass::Quads>(); |
183 this->renderVao(gl::ArrayClass::Lines); |
168 this->renderVao<gl::ArrayClass::Lines>(); |
184 }; |
169 }; |
185 if (this->renderPreferences.wireframe and this->renderPreferences.style != gl::RenderStyle::PickScene) { |
170 if (this->renderPreferences.wireframe and this->renderPreferences.style != gl::RenderStyle::PickScene) { |
186 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
171 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
187 } |
172 } |
188 switch (this->renderPreferences.style) |
173 switch (this->renderPreferences.style) |
193 break; |
178 break; |
194 case gl::RenderStyle::BfcRedGreen: |
179 case gl::RenderStyle::BfcRedGreen: |
195 glEnable(GL_CULL_FACE); |
180 glEnable(GL_CULL_FACE); |
196 glCullFace(GL_BACK); |
181 glCullFace(GL_BACK); |
197 this->setFragmentStyle(gl::FragmentStyle::BfcGreen); |
182 this->setFragmentStyle(gl::FragmentStyle::BfcGreen); |
198 renderVao(gl::ArrayClass::Triangles); |
183 renderVao<gl::ArrayClass::Triangles>(); |
199 renderVao(gl::ArrayClass::Quads); |
184 renderVao<gl::ArrayClass::Quads>(); |
200 glCullFace(GL_FRONT); |
185 glCullFace(GL_FRONT); |
201 this->setFragmentStyle(gl::FragmentStyle::BfcRed); |
186 this->setFragmentStyle(gl::FragmentStyle::BfcRed); |
202 renderVao(gl::ArrayClass::Triangles); |
187 renderVao<gl::ArrayClass::Triangles>(); |
203 renderVao(gl::ArrayClass::Quads); |
188 renderVao<gl::ArrayClass::Quads>(); |
204 glDisable(GL_CULL_FACE); |
189 glDisable(GL_CULL_FACE); |
205 this->setFragmentStyle(gl::FragmentStyle::Normal); |
190 this->setFragmentStyle(gl::FragmentStyle::Normal); |
206 renderVao(gl::ArrayClass::Lines); |
191 renderVao<gl::ArrayClass::Lines>(); |
207 break; |
192 break; |
208 case gl::RenderStyle::RandomColors: |
193 case gl::RenderStyle::RandomColors: |
209 this->setFragmentStyle(gl::FragmentStyle::RandomColors); |
194 this->setFragmentStyle(gl::FragmentStyle::RandomColors); |
210 renderAllArrays(); |
195 renderAllArrays(); |
211 break; |
196 break; |
246 void PartRenderer::build() |
231 void PartRenderer::build() |
247 { |
232 { |
248 this->needBuild = true; |
233 this->needBuild = true; |
249 } |
234 } |
250 |
235 |
251 void PartRenderer::renderVao(const gl::ArrayClass arrayClass) |
236 void PartRenderer::renderVao(const gl::ArrayClass arrayClass, const GLenum glType) |
252 { |
237 { |
253 gl::bindModelShaderVertexArray(&this->shaders, arrayClass); |
238 gl::bindModelShaderVertexArray(&this->shaders, arrayClass); |
254 const std::size_t vertexCount = gl::vertexCount(&this->shaders, arrayClass); |
239 const std::size_t vertexCount = gl::vertexCount(&this->shaders, arrayClass); |
255 this->checkForGLErrors(); |
240 this->checkForGLErrors(); |
256 glDrawArrays(getGlTypeForArrayClass(arrayClass), 0, static_cast<GLsizei>(vertexCount)); |
241 glDrawArrays(glType, 0, static_cast<GLsizei>(vertexCount)); |
257 this->checkForGLErrors(); |
242 this->checkForGLErrors(); |
258 gl::releaseModelShaderVertexArray(&this->shaders, arrayClass); |
243 gl::releaseModelShaderVertexArray(&this->shaders, arrayClass); |
259 this->checkForGLErrors(); |
244 this->checkForGLErrors(); |
260 } |
245 } |
261 |
246 |