diff -r cd6704009eb9 -r 3c10f0e2fbe0 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Thu Feb 06 23:41:20 2020 +0200 +++ b/src/gl/compiler.cpp Fri Feb 07 01:58:34 2020 +0200 @@ -31,7 +31,8 @@ layout(location=0) in vec3 position; layout(location=1) in vec4 color; layout(location=2) in vec3 normal; -layout(location=3) in vec3 id; +layout(location=3) in vec3 idColor; +layout(location=4) in int id; out vec4 vColor; out vec3 vFragPos; out vec3 vNormal; @@ -39,6 +40,8 @@ uniform mat4 viewMatrix; uniform mat4 projectionMatrix; uniform int fragmentStyle; +uniform vec3 selectedColor; +uniform int highlighted; const int FRAGSTYLE_Normal = 0; const int FRAGSTYLE_BfcGreen = 1; @@ -50,22 +53,30 @@ { mat3 normalMatrix = transpose(inverse(mat3(modelMatrix))); vNormal = normalize(normalMatrix * normal); - if (fragmentStyle == FRAGSTYLE_BfcGreen) - { - vColor = vec4(0.2, 0.9, 0.2, 1.0); - } - else if (fragmentStyle == FRAGSTYLE_BfcRed) + if (fragmentStyle == FRAGSTYLE_Id) { - vColor = vec4(0.9, 0.2, 0.2, 1.0); - } - else if (fragmentStyle == FRAGSTYLE_Id) - { - vColor = vec4(id, 1.0); + vColor = vec4(idColor, 1.0); } else { - vColor = color; + if (fragmentStyle == FRAGSTYLE_BfcGreen) + { + vColor = vec4(0.2, 0.9, 0.2, 1.0); + } + else if (fragmentStyle == FRAGSTYLE_BfcRed) + { + vColor = vec4(0.9, 0.2, 0.2, 1.0); + } + else + { + vColor = color; + } + if (highlighted == id) + { + vColor = (vColor + vec4(selectedColor, 1.0) * 0.6) / 1.6; + } } + vFragPos = vec3(modelMatrix * vec4(position, 1.0)); gl_Position = projectionMatrix * viewMatrix * vec4(vFragPos, 1.0); } @@ -142,15 +153,16 @@ object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); object.vertexArray.create(); object.vertexArray.bind(); - object.program->enableAttributeArray(0); - object.program->enableAttributeArray(1); - object.program->enableAttributeArray(2); - object.program->enableAttributeArray(3); + for (int k : {0, 1, 2, 3, 4}) + { + 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); - object.program->setAttributeBuffer(3, GL_FLOAT, offsetof(gl::Vertex, id), 3, stride); + object.program->setAttributeBuffer(3, GL_FLOAT, offsetof(gl::Vertex, idColor), 3, stride); + glVertexAttribIPointer(4, 1, GL_INT, stride, (void*)offsetof(gl::Vertex, id)); object.vertexArray.release(); object.buffer.release(); object.program->release(); @@ -230,7 +242,8 @@ 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()}; - vertex.id = colorFromId(polygon.id); + vertex.idColor = colorFromId(polygon.id); + vertex.id = polygon.id.value; } }