Reputation: 6193
Right now I'm creating my OpenGL geometry objects - which all are wireframe models - this way (simplified code):
int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
element.shaderProgram = glCreateProgram();
glAttachShader(element.shaderProgram, m_gl3VertexShader);
glAttachShader(element.shaderProgram, fragmentShader);
glLinkProgram(element.shaderProgram);
glGetProgramiv(element.shaderProgram, GL_LINK_STATUS, &success);
glDeleteShader(m_gl3VertexShader);
glDeleteShader(fragmentShader);
glGenVertexArrays(1, &element.VAO);
glGenBuffers(1, &element.VBO);
glBindVertexArray(element.VAO);
glBindBuffer(GL_ARRAY_BUFFER, element.VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(centerCrossVertices), centerCrossVertices, GL_STATIC_DRAW);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Here centerCrossVertices is one GL_LINE_STRIP with a fixed length.
Later they are drawn this way:
glUseProgram(shaderProgram);
glBindVertexArray(m_gl3ElementList[i].VAO);
glDrawArrays(GL_LINE_STRIP,0,centerCrossVertices_size);
Now I want to display some more complex models which consist of several sets of line-strips but which have different lengths. Means there is one object which itself does not make use of one line strip but of several of them which can have different number of vertices they consist of.
My question: do I have to call the upper sequence for each of these line strips and do I need to create separate VBO/VAOs for each of them? Or is there a way to combine several line strips? If yes: how can this be done?
Upvotes: 1
Views: 105
Reputation: 52083
Now I want to display some more complex models which consist of several sets of line-strips but which have different lengths
If you switch to an indexed draw-call (like glDrawElements()
) and use primitive restart you can render all your strips in a single draw-call.
Upvotes: 2