Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Vertex Buffers: Can I go without an index buffer?

Tags:

opengl

I got code working which uses a VBO and an IBO: as I parse my geometry I build vertex and index arrays for triangles and then call glDrawElements with GL_TRIANGLES.

I read about being able to signal primitive restart in the index buffer, here, about halfway down the page. This is good, but I'm wondering if it's possible to forego the index buffer entirely, and just signal a primitive restart by sending in a specific vertex value (like have the first attribute zero value be infinity)?

Then I'd only need to send one buffer to the GPU before I draw with GL_TRIANGLE_FAN for instance to draw a set of convex polygons.

like image 418
Steven Lu Avatar asked Jan 28 '12 05:01

Steven Lu


People also ask

What is an index buffer?

An index buffer is essentially an array of pointers into the vertex buffer. It allows you to reorder the vertex data, and reuse existing data for multiple vertices.

What is a vertex buffer in OpenGL?

A vertex buffer object (VBO) is an OpenGL feature that provides methods for uploading vertex data (position, normal vector, color, etc.) to the video device for non-immediate-mode rendering.

What are OpenGL indices?

Indices is defined as a GLubyte array of 48 elements; GLubyte is the OpenGL data type for an unsigned byte ( unsigned char ). You could use any of the following unsigned integral OpenGL data types: GLubyte , GLushort , and GLuint , since indices are never negative (signed) or fractional (float/double).

What is a buffer in OpenGL?

Buffer Objects are OpenGL Objects that store an array of unformatted memory allocated by the OpenGL context (AKA the GPU). These can be used to store vertex data, pixel data retrieved from images or the framebuffer, and a variety of other things.


Video Answer


2 Answers

If you don't want to use index buffer then you can use glDrawArrays. It will render primitive from just the vertex buffer. Combine that with instancing and you'll be able to draw multiple triangle fans without index buffer.

But for performance reasons if your mesh triangles share vertices you should be using index buffer.

like image 147
Mārtiņš Možeiko Avatar answered Nov 15 '22 13:11

Mārtiņš Možeiko


As clearly stated on that page:

It is technically legal to use this with non-indexed rendering. You should not do this, as it will not give you a useful result.

Primitive restart is for indexed rendering. There is no way to restart a primitive based on the value of a vertex attribute.

like image 23
Nicol Bolas Avatar answered Nov 15 '22 12:11

Nicol Bolas