• Create Account

## Drawing vertices without actual vertices?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1SeraphLance  Members

Posted 09 December 2013 - 10:51 PM

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?

### #2Hodgman  Moderators

Posted 09 December 2013 - 10:55 PM

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.

### #3ryutenchi  Members

Posted 10 December 2013 - 12:06 AM

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.

### #4Aliii  Members

Posted 10 December 2013 - 12:24 AM

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, 10 December 2013 - 12:25 AM.

Posted 12 December 2013 - 12:52 AM

Fancy, though what is the use?

### #6Aks9  Members

Posted 12 December 2013 - 02:42 AM

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, 12 December 2013 - 03:25 PM.

### #7ryutenchi  Members

Posted 13 December 2013 - 04:35 PM

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?^^

### #8Aks9  Members

Posted 13 December 2013 - 05:29 PM

The primitive type as well as the number of vertices (or entries in the index buffer) are the parameters of draw calls.

### #9Hodgman  Moderators

Posted 13 December 2013 - 05:29 PM

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).

### #10ryutenchi  Members

Posted 15 December 2013 - 03:34 PM

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^^

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.