# HG changeset patch # User Teemu Piippo # Date 1681032212 -10800 # Node ID 41b38b9e05a2308b6e58f1026cb7cd4eedf65679 # Parent 73b6c478378e0a9dcbf80f3ee9dc9ac00b719131 `PartRenderer::renderVao` no longer throws if bad array class is given, this is now checked on compile time diff -r 73b6c478378e -r 41b38b9e05a2 src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Sun Apr 09 01:12:00 2023 +0300 +++ b/src/gl/partrenderer.cpp Sun Apr 09 12:23:32 2023 +0300 @@ -101,21 +101,6 @@ Q_EMIT projectionMatrixChanged(this->projectionMatrix); } -static constexpr GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) -{ - switch (vboClass) - { - case gl::ArrayClass::Lines: - case gl::ArrayClass::ConditionalLines: - return GL_LINES; - case gl::ArrayClass::Triangles: - return GL_TRIANGLES; - case gl::ArrayClass::Quads: - return GL_QUADS; - } - throw std::runtime_error{"bad value for vboClass"}; -} - void PartRenderer::paintGL() { glEnable(GL_DEPTH_TEST); @@ -178,9 +163,9 @@ glLineWidth(this->renderPreferences.lineThickness); const auto renderAllArrays = [this](){ // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. - this->renderVao(gl::ArrayClass::Triangles); - this->renderVao(gl::ArrayClass::Quads); - this->renderVao(gl::ArrayClass::Lines); + this->renderVao(); + this->renderVao(); + this->renderVao(); }; if (this->renderPreferences.wireframe and this->renderPreferences.style != gl::RenderStyle::PickScene) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -195,15 +180,15 @@ glEnable(GL_CULL_FACE); glCullFace(GL_BACK); this->setFragmentStyle(gl::FragmentStyle::BfcGreen); - renderVao(gl::ArrayClass::Triangles); - renderVao(gl::ArrayClass::Quads); + renderVao(); + renderVao(); glCullFace(GL_FRONT); this->setFragmentStyle(gl::FragmentStyle::BfcRed); - renderVao(gl::ArrayClass::Triangles); - renderVao(gl::ArrayClass::Quads); + renderVao(); + renderVao(); glDisable(GL_CULL_FACE); this->setFragmentStyle(gl::FragmentStyle::Normal); - renderVao(gl::ArrayClass::Lines); + renderVao(); break; case gl::RenderStyle::RandomColors: this->setFragmentStyle(gl::FragmentStyle::RandomColors); @@ -248,12 +233,12 @@ this->needBuild = true; } -void PartRenderer::renderVao(const gl::ArrayClass arrayClass) +void PartRenderer::renderVao(const gl::ArrayClass arrayClass, const GLenum glType) { gl::bindModelShaderVertexArray(&this->shaders, arrayClass); const std::size_t vertexCount = gl::vertexCount(&this->shaders, arrayClass); this->checkForGLErrors(); - glDrawArrays(getGlTypeForArrayClass(arrayClass), 0, static_cast(vertexCount)); + glDrawArrays(glType, 0, static_cast(vertexCount)); this->checkForGLErrors(); gl::releaseModelShaderVertexArray(&this->shaders, arrayClass); this->checkForGLErrors(); diff -r 73b6c478378e -r 41b38b9e05a2 src/gl/partrenderer.h --- a/src/gl/partrenderer.h Sun Apr 09 01:12:00 2023 +0300 +++ b/src/gl/partrenderer.h Sun Apr 09 12:23:32 2023 +0300 @@ -71,10 +71,35 @@ void updateViewMatrix(); void updateModelMatrix(); Q_SLOT void build(); - void renderVao(const gl::ArrayClass arrayClass); + void renderVao(const gl::ArrayClass arrayClass, const GLenum glType); + template + void renderVao(); void checkForGLErrors(); }; +inline constexpr opt getGlTypeForArrayClass(const gl::ArrayClass vboClass) +{ + switch (vboClass) + { + case gl::ArrayClass::Lines: + case gl::ArrayClass::ConditionalLines: + return GL_LINES; + case gl::ArrayClass::Triangles: + return GL_TRIANGLES; + case gl::ArrayClass::Quads: + return GL_QUADS; + } + return {}; +} + +template +void PartRenderer::renderVao() +{ + constexpr opt glType = getGlTypeForArrayClass(arrayClass); + static_assert(glType.has_value()); + this->renderVao(arrayClass, *glType); +} + inline QVector convertWorldPointsToScreenPoints( const std::vector &worldPoints, const PartRenderer* renderer)