Jump to content
  • Advertisement
Sign in to follow this  
SeraphLance

Drawing vertices without actual vertices?

This topic is 2138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

http://www.opengl.org/discussion_boards/showthread.php/182969-Draw-with-fragment-shader-without-vertices

 

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

Share this post


Link to post
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

Share this post


Link to post
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?^^

Share this post


Link to post
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.

Share this post


Link to post
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).

Share this post


Link to post
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^^

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!