diff -r a0ddbc9a4e77 -r 0fd926ebb03b src/gl/compiler.cpp --- a/src/gl/compiler.cpp Tue Jun 28 14:53:22 2022 +0300 +++ b/src/gl/compiler.cpp Tue Jun 28 17:35:56 2022 +0300 @@ -28,8 +28,8 @@ layout(location=0) in vec3 position; layout(location=1) in vec4 color; layout(location=2) in vec3 normal; -layout(location=3) in int id; -layout(location=4) in int selected; +layout(location=3) in vec3 pickcolor; +layout(location=4) in float selected; out vec4 vColor; out vec3 vFragPos; out vec3 vNormal; @@ -37,7 +37,7 @@ uniform mat4 viewMatrix; uniform mat4 projectionMatrix; uniform int fragmentStyle; -uniform vec3 selectedColor; +uniform vec4 selectedColor; uniform int highlighted; const int FRAGSTYLE_Normal = 0; @@ -53,17 +53,7 @@ vNormal = normalize(normalMatrix * normal); if (fragmentStyle == FRAGSTYLE_Id) { - /* 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 if (selected == 1) - { - vColor = vec4(selectedColor, 1.0); + vColor = vec4(pickcolor, 1.0); } else { @@ -83,12 +73,14 @@ { vColor = color; } +/* if (highlighted == id) { vColor = (vColor + vec4(selectedColor, 1.0) * 0.6) / 1.6; } +*/ + vColor = (1 - selected) * vColor + selected * selectedColor; } - vFragPos = vec3(modelMatrix * vec4(position, 1.0)); gl_Position = projectionMatrix * viewMatrix * vec4(vFragPos, 1.0); } @@ -206,14 +198,12 @@ shader.program->enableAttributeArray(k); } using Vertex = ModelShaders::Vertex; - constexpr int stride = sizeof(Vertex); + constexpr std::size_t stride = sizeof(Vertex); shader.program->setAttributeBuffer(0, GL_FLOAT, offsetof(Vertex, position), 3, stride); shader.program->setAttributeBuffer(1, GL_FLOAT, offsetof(Vertex, color), 4, stride); shader.program->setAttributeBuffer(2, GL_FLOAT, offsetof(Vertex, normal), 3, stride); - const void* vertexptr = reinterpret_cast(offsetof(Vertex, id)); - glfunc().glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, stride, vertexptr); - const void* selectedptr = reinterpret_cast(offsetof(Vertex, selected)); - glfunc().glVertexAttribPointer(4, 1, GL_INT, GL_FALSE, stride, selectedptr); + shader.program->setAttributeBuffer(3, GL_FLOAT, offsetof(Vertex, pickcolor), 3, stride); + shader.program->setAttributeBuffer(4, GL_FLOAT, offsetof(Vertex, selected), 1, stride); shader.vertexArray.release(); shader.buffer.release(); shader.program->release(); @@ -307,6 +297,7 @@ vertex.normal = normal; vertex.color = glm::vec4{color.redF(), color.greenF(), color.blueF(), color.alphaF()}; vertex.id = polygon.id.value; + vertex.pickcolor = idToColor(polygon.id.value); }); }); for (gl::ModelShaders::ShaderObject& shader : shaders->shaderObjects) @@ -319,9 +310,13 @@ } } -ModelId gl::idFromColor(const std::array& data) +ModelId gl::idFromUcharColor(const std::array& data) { - return {data[0] * std::int32_t{0x10000} + data[1] * std::int32_t{0x100} + data[2]}; + return { + static_cast(data[0]) | + static_cast(data[1]) << 8 | + static_cast(data[2]) << 16 + }; } void gl::bindModelShaderVertexArray(gl::ModelShaders* shaders, gl::ArrayClass arrayClass)