Equivalent of GL_LINE_LOOP in Vulkan

282 views Asked by At

I have started learning Vulkan recently and been working on a project that requires migrating OpenGL code to Vulkan. I have been searching for the equivalent of OpenGL's 'GL_LINE_LOOP' in Vulkan to migrate the following piece of code:

glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
    glVertex2f(m_rCircFit.left(),m_rCircFit.top()); //(x,y)
    glVertex2f(m_rCircFit.right(),m_rCircFit.top()); //(x+width,y)
    glVertex2f(m_rCircFit.right(),m_rCircFit.bottom()); //(x+width,y+height)
    glVertex2f(m_rCircFit.left(),m_rCircFit.bottom()); //(x,y+height)
glEnd();

I am able to draw a rectangle using 'VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP' but the output looks like following:

image

But I don't want the diagonal line connecting between the top-left and bottom-right vertices. Can anyone guide me about what to use in Vulkan to achieve the same functionality as 'GL_LINE_LOOP'?

1

There are 1 answers

2
Blindy On

A line loop is a line strip with an additional line that connects the first and last vertices. So the direct translation flag would be VK_PRIMITIVE_TOPOLOGY_LINE_STRIP.

However note that you're wasting your time if this is the granularity you're working with. Vulkan uses an entirely different methodology than modern OpenGL, and you're not using reference modern OpenGL, you're using the ancient glBegin stuff.

If you have more than ~1-3 draw calls per frame, you can in the most literal sense throw away your code and just keep using OpenGL. Vulkan is all about batching all of your data together and rendering it all at once.