'How to specify color for each vertex if i have duplicates?

I have a plane with 4 points. I wrote a subdivision algorithm. I can subdivide my plane and get all needed vertices for subdivided plane. But what Is the problem? I have some duplicated vertices in my array but i want to specify different color for each of them. I draw with VBO and EBO, color will sended with vertexAttribPointer. So, can you give me some recommendations to solve this problem? My Plane

using Vector3D = QVector3D;
std::array<Vector3D, 4> plane
            {   // +Z SIDE
                   Vector3D(-0.5f, -0.5f, 0.5f),
                   Vector3D( 0.5f, -0.5f, 0.5f),
                   Vector3D( 0.5f,  0.5f, 0.5f),
                   Vector3D(-0.5f,  0.5f, 0.5f)
            };

My subdivision algorithm

void subdivisionSurface(std::vector<Vector3D>& vertices, std::array<Vector3D, 4> plane, unsigned int iterations = 1)
{
    if (iterations == 0)
    {
            return;
    }
    else
    {

        Vector3D e1 = plane[1] - plane[0];
        Vector3D e2 = plane[2] - plane[3];
        Vector3D e3 = plane[3] - plane[0];
        Vector3D e4 = plane[2] - plane[1];

        Vector3D p1 = (e1 * 0.5) + plane[0];
        Vector3D p2 = (e2 * 0.5) + plane[3];
        Vector3D p3 = (e3 * 0.5) + plane[0];
        Vector3D p4 = (e4 * 0.5) + plane[1];
        Vector3D e5 = p2 - p1;
        Vector3D p5 = (e5 * 0.5) + p1;

        if(!(std::find(vertices.begin(), vertices.end(), p1) != vertices.end()))
            vertices.push_back(p1);
        if(!(std::find(vertices.begin(), vertices.end(), p2) != vertices.end()))
            vertices.push_back(p2);
        if(!(std::find(vertices.begin(), vertices.end(), p3) != vertices.end()))
            vertices.push_back(p3);
        if(!(std::find(vertices.begin(), vertices.end(), p4) != vertices.end()))
            vertices.push_back(p4);
        if(!(std::find(vertices.begin(), vertices.end(), p5) != vertices.end()))
            vertices.push_back(p5);

        std::vector< std::array<Vector3D, 4>> subPlanes
        {
                    { plane[0], p1, p5, p3 },
                    { p1, plane[1], p4, p5 },
                    { p5, p4, plane[2], p2 },
                    { p3, p5, p2, plane[3] }
        };

        if (iterations == 1)
           return;
        else
        {
            for(auto& splane : subPlanes)
                  subdivisionSurface(vertices, splane, iterations - 1);
            return;
        }

    }


}

Honestly, it is not my algorithm, i just a little bit refactored what i founded under another question on StackOverflow. But i clearly understand what it does.

You can see that i didn't add duplicated vertices now, then for this data i will generate IBO and draw my subdivided plane with different color for each vertex. I see that check for each new vertex isn't efficient way. Do you know how to fix this? How to fix my algorithm or how to specify the same color for repeated vertices. I belive that QVector3D make exact comparison of float number.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source