diff -r 3c10f0e2fbe0 -r d56cc7387dad src/gl/compiler.cpp --- a/src/gl/compiler.cpp Fri Feb 07 01:58:34 2020 +0200 +++ b/src/gl/compiler.cpp Fri Feb 07 02:01:21 2020 +0200 @@ -31,8 +31,7 @@ layout(location=0) in vec3 position; layout(location=1) in vec4 color; layout(location=2) in vec3 normal; -layout(location=3) in vec3 idColor; -layout(location=4) in int id; +layout(location=3) in int id; out vec4 vColor; out vec3 vFragPos; out vec3 vNormal; @@ -55,7 +54,13 @@ vNormal = normalize(normalMatrix * normal); if (fragmentStyle == FRAGSTYLE_Id) { - vColor = vec4(idColor, 1.0); + /* Calculate a color based from this index. This method caters for + * 16777216 objects. I don't think that will be exceeded anytime soon. + */ + int r = (id / 0x10000) % 0x100; + int g = (id / 0x100) % 0x100; + int b = id % 0x100; + vColor = vec4(r / 255.0, g / 255.0, b / 255.0, 1.0); } else { @@ -153,7 +158,7 @@ object.buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); object.vertexArray.create(); object.vertexArray.bind(); - for (int k : {0, 1, 2, 3, 4}) + for (int k : {0, 1, 2, 3}) { object.program->enableAttributeArray(k); } @@ -161,8 +166,7 @@ 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, idColor), 3, stride); - glVertexAttribIPointer(4, 1, GL_INT, stride, (void*)offsetof(gl::Vertex, id)); + glVertexAttribIPointer(3, 1, GL_INT, stride, (void*)offsetof(gl::Vertex, id)); object.vertexArray.release(); object.buffer.release(); object.program->release(); @@ -207,16 +211,6 @@ return gl::ArrayClass::Lines; } -static glm::vec3 colorFromId(ldraw::Id id) -{ - // Calculate a color based from this index. This method caters for - // 16777216 objects. I don't think that will be exceeded anytime soon. - const int r = (id.value / 0x10000) % 0x100; - const int g = (id.value / 0x100) % 0x100; - const int b = id.value % 0x100; - return {r / 255.0f, g / 255.0f, b / 255.0f}; -} - ldraw::Id gl::Compiler::idFromColor(const std::array& data) { return {data[0] * std::int32_t{0x10000} + data[1] * std::int32_t{0x100} + data[2]}; @@ -242,7 +236,6 @@ 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.idColor = colorFromId(polygon.id); vertex.id = polygon.id.value; } }