Followers 0

# Drawing vertices without actual vertices?

## 9 posts in this topic

Namely, I want to write a vertex shader something akin to this:

in vec3 vertex;

void main()
{
vertex.x = gl_VertexID % vertexWidth;
vertex.y = gl_VertexID / vertexWidth;
//vertex.z = someProceduralFunction(...);
gl_Position = projection * modelview * vec4(vertex, 1.0);
}


Ignoring the question of whether the code even compiles, it's abundantly clear that I don't actually need any VBOs in the theoretical sense, so is it possible to just pump some kind of shadow vertices to this shader?  Or do I need to allocate the space in the buffer regardless?

0

##### Share on other sites

I've never tried this in GL, but yep, this trick is completely valid in D3D! In D3D, you basically just make sure that no VBOs or vertex attributes are bound/exist.

0

##### Share on other sites

you will need at the very least 1 vertex and an index buffer with a length == to the number of vertices you want to generate. I could be wrong, but I'm almost positive that the vertex shader only runs and only runs once per vertex in the VBO.

0

##### Share on other sites

I did ask something very similar on OpenGL.org and got an answer.

You dont have to glEnableVertexAttribArray( 0); the vertex attribute but define a default value with glVertexAttrib1f( 0, 0);

Define the input attribute in the shader: layout(location = 0) in float dummy_attrib;

....and then just use gl_VertexID as you said.

I dont use any VBOs when I do this but if you are afraid of broken drivers then use one.

Edited by Aliii
1

##### Share on other sites

Fancy, though what is the use?

0

##### Share on other sites

you will need at the very least 1 vertex and an index buffer with a length == to the number of vertices you want to generate. I could be wrong, but I'm almost positive that the vertex shader only runs and only runs once per vertex in the VBO.

No, you don't. It is perfectly valid to draw without a single attribute.

Fancy, though what is the use?

Rendering without attributes (not without vertices, since it is impossible) is an awfully powerfully rendering method. In last 3 or 4 years I have almost everything drawn without a single attribute. From screen-aligned quads and 2D charts to some very complex geometries. For simple shapes index buffer is not required, but complex ones need "scheme" for "vertex distribution". For my purposes, attributless rendering is more powerful than tesselation shaders since there is no limitations for patch size.

Edited by Aks9
1

##### Share on other sites

No, you don't. It is perfectly valid to draw without a single attribute.

Ok, then I'm confussed how does the GPU know how many times to call the vertex shader? How does one invoke this black mage?^^

0

##### Share on other sites
The primitive type as well as the number of vertices (or entries in the index buffer) are the parameters of draw calls.
0

##### Share on other sites

No, you don't. It is perfectly valid to draw without a single attribute.

Ok, then I'm confussed how does the GPU know how many times to call the vertex shader? How does one invoke this black mage?^^
Even when you are using VBOs, it's the actual draw call itself that specifies the number of vertices to be drawn (or the number of triangles/etc, but that's the same thing).
0

##### Share on other sites

Even when you are using VBOs, it's the actual draw call itself that specifies the number of vertices to be drawn (or the number of triangles/etc, but that's the same thing).

ooooh...  I aways thought that would lead to an exception because of trying to access a null pointer... interesting^^ Learn something new everyday^^

0

## Create an account

Register a new account