I know that I can calculate vertices in vertex shader. But how can I specify indices in the vertex shader. Outside of vertex shader I create GL_ELEMENT_ARRAY_BUFFER buffer for indices and GL_ARRAY_BUFFER buffer for vertices. But what when I calculate those in vertex shader, how do I specify what are vertices and what are indices?
There is a built-in read-only integer variable available in vertex shader called “gl_VertexID” which stores an index of the vertex for the current shader’s execution. All input attributes (which are read-only as well) that the shader receives - all those correspond to that particular vertex. So normally you do not need to calculate anything - it is all given as input.
I will check this. My problem is that I want to draw thick lines. To do so I take from user points and those points I want to send to the vertex shader using buffers. Thing is when zoom is small I want to draw those points using GL_POINTS, but when zoom is big enough I want to draw thick lines which vertices are computed inside the vertex shader. I need to use the indices since some vertices are repeated. Is this possible?
Well, I personally draw regular grids without using attribute inputs at all: to get the y coordinate of the point I divide gl_VertexID by the width of the grid, and to get x coordinate I take a modulo gl_VertexID % Width. The height of the point I fetch from the texture at the resulting coordinates. Therefore it is possible to use just an index buffer to feed vertex shader with indices if you know how to calculate attributes based on those numbers. Must mention that even if all attributes are disabled you still need to have a non-zero VAO bound to make a successful draw call.