diff -r 0f80a2e5e42b -r 1a9eac27698d src/gl/compiler.cpp --- a/src/gl/compiler.cpp Fri Feb 07 02:02:16 2020 +0200 +++ b/src/gl/compiler.cpp Fri Feb 07 23:59:06 2020 +0200 @@ -32,6 +32,7 @@ layout(location=1) in vec4 color; layout(location=2) in vec3 normal; layout(location=3) in int id; +layout(location=4) in int selected; out vec4 vColor; out vec3 vFragPos; out vec3 vNormal; @@ -62,6 +63,10 @@ int b = id % 0x100; vColor = vec4(r / 255.0, g / 255.0, b / 255.0, 1.0); } + else if (selected == 1) + { + vColor = vec4(selectedColor, 1.0); + } else { if (fragmentStyle == FRAGSTYLE_BfcGreen) @@ -158,7 +163,7 @@ object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); object.vertexArray.create(); object.vertexArray.bind(); - for (int k : {0, 1, 2, 3}) + for (int k : {0, 1, 2, 3, 4}) { object.program->enableAttributeArray(k); } @@ -167,6 +172,7 @@ 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))); object.vertexArray.release(); object.buffer.release(); object.program->release(); @@ -189,6 +195,7 @@ auto& buffer = this->glObjects[arrayId].buffer; auto& vector = vboData[arrayId]; this->storedVertexCounts[arrayId] = vector.size(); + this->glObjects[arrayId].cachedData = vector; // todo: get rid of this copy buffer.bind(); buffer.allocate(vector.data(), static_cast(vector.size() * sizeof vector[0])); buffer.release(); @@ -266,9 +273,9 @@ return boxCenter(this->boundingBox); } -float gl::Compiler::modelDistance() const +double gl::Compiler::modelDistance() const { - return longestMeasure(this->boundingBox); + return static_cast(longestMeasure(this->boundingBox)); } void gl::Compiler::bindVertexArray(gl::ArrayClass arrayClass) @@ -285,6 +292,21 @@ object.vertexArray.release(); } +void gl::Compiler::setSelectedObjects(const QSet ids) +{ + for (int i = 0; i < gl::NUM_ARRAY_CLASSES; i += 1) + { + auto& vector = this->glObjects[i].cachedData; + for (gl::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(); + glBufferSubData(GL_ARRAY_BUFFER, 0, size, vector.data()); + } +} + std::size_t gl::Compiler::vertexCount(const gl::ArrayClass arrayClass) const { return this->storedVertexCounts[static_cast(arrayClass)];