diff -r 5fe2dd4e161a -r 764381756899 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Wed Mar 11 17:19:38 2020 +0200 +++ b/src/gl/compiler.cpp Wed Mar 11 19:05:34 2020 +0200 @@ -171,9 +171,8 @@ if (not this->initialized) { this->initializeOpenGLFunctions(); - for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1) + for (auto& object : this->glObjects) { - auto& object = this->glObjects[i]; object.program = new QOpenGLShaderProgram; gl::buildShaders(object.program, ::vertexShaderSource, ::fragmentShaderSource); object.program->bind(); @@ -186,12 +185,12 @@ { object.program->enableAttributeArray(k); } - constexpr int stride = sizeof(gl::Vertex); - object.program->setAttributeBuffer(0, GL_FLOAT, offsetof(gl::Vertex, position), 3, stride); - object.program->setAttributeBuffer(1, GL_FLOAT, offsetof(gl::Vertex, color), 4, stride); - object.program->setAttributeBuffer(2, GL_FLOAT, offsetof(gl::Vertex, normal), 3, stride); - glVertexAttribIPointer(3, 1, GL_INT, stride, reinterpret_cast(offsetof(gl::Vertex, id))); - glVertexAttribIPointer(4, 1, GL_INT, stride, reinterpret_cast(offsetof(gl::Vertex, selected))); + constexpr int stride = sizeof(Vertex); + object.program->setAttributeBuffer(0, GL_FLOAT, offsetof(Vertex, position), 3, stride); + object.program->setAttributeBuffer(1, GL_FLOAT, offsetof(Vertex, color), 4, stride); + object.program->setAttributeBuffer(2, GL_FLOAT, offsetof(Vertex, normal), 3, stride); + glVertexAttribIPointer(3, 1, GL_INT, stride, reinterpret_cast(offsetof(Vertex, id))); + glVertexAttribIPointer(4, 1, GL_INT, stride, reinterpret_cast(offsetof(Vertex, selected))); object.vertexArray.release(); object.buffer.release(); object.program->release(); @@ -203,13 +202,13 @@ void gl::Compiler::build(Model* model, DocumentManager* context, const gl::RenderPreferences& preferences) { this->boundingBox = {}; - std::vector vboData[gl::NUM_ARRAY_CLASSES]; + std::vector vboData[gl::NUM_POLYGON_TYPES]; const std::vector polygons = model->getPolygons(context); for (const gl::Polygon& polygon : polygons) { this->buildPolygon(polygon, vboData, preferences); } - for (int arrayId = 0; arrayId < gl::NUM_ARRAY_CLASSES; arrayId += 1) + for (int arrayId = 0; arrayId < gl::NUM_POLYGON_TYPES; arrayId += 1) { auto& buffer = this->glObjects[arrayId].buffer; auto& vector = vboData[arrayId]; @@ -244,11 +243,11 @@ void gl::Compiler::buildPolygon( gl::Polygon polygon, - std::vector* vboData, + std::vector* vboData, const gl::RenderPreferences& preferences) { const gl::ArrayClass vboClass = classifyPolygon(polygon); - std::vector& vertexBuffer = vboData[static_cast(vboClass)]; + std::vector& vertexBuffer = vboData[static_cast(vboClass)]; auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); reserveMore(vertexBuffer, polygon.numPolygonVertices()); const QColor color = this->getColorForPolygon(polygon, preferences); @@ -258,7 +257,7 @@ const glm::vec3& v2 = vertexRing[i]; const glm::vec3& v3 = vertexRing[i + 1]; this->boundingBox.consider(polygon.vertices[i]); - gl::Vertex& vertex = vertexBuffer.emplace_back(); + Vertex& vertex = vertexBuffer.emplace_back(); vertex.position = polygon.vertices[i]; vertex.normal = glm::normalize(glm::cross(v1 - v2, v3 - v2)); vertex.color = glm::vec4{color.redF(), color.greenF(), color.blueF(), color.alphaF()}; @@ -313,16 +312,17 @@ void gl::Compiler::setSelectedObjects(const QSet ids) { - for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1) + for (auto& object : this->glObjects) { - auto& vector = this->glObjects[i].cachedData; - for (gl::Vertex& vertex : vector) + std::vector& vector = object.cachedData; + for (Vertex& vertex : vector) { vertex.selected = (ids.contains({vertex.id})) ? 1 : 0; } const GLsizeiptr size = static_cast(vector.size() * sizeof vector[0]); - this->glObjects[i].buffer.bind(); + object.buffer.bind(); glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data()); + object.buffer.release(); } }