View Full Version : GlDrawElements without vertex data

06-05-2010, 10:04 AM
I am coding a terrain which doesn't even have an heightmap. It's basically just a grid of quads + an 2dTextureArray which holds the N possible textures for each quad + a 2dTexture which is nothing but an array which stores, for each quad, whose texture should be used from the texture array.

Now, when I think about this in term of vertex shader, I should be able to calculate everything without having to pass real vertex data. Actually, all I'd have to pass is an array of indices to which quads I should render (ex. [1,2,3,5,9,23,40]), because from that single index I am able to derive pretty much everything.

I've tried looking for primitive id in glsl but looks like it's something which is used in geometry shaders only, so I wonder if what I am saying makes sense at all and there's some way to implement it. Any suggestion?


06-05-2010, 03:00 PM

If you don't wan't tesselation or geometry shaders, I see two possible ways:

1. Go with a mesh (VBO) containing a quad for each tile and transmit the texture array index to the fragment shader either through a lookup in the vertex shader or directly storing that info as a vertex attrib (1 lookup in your index texture in the vertex shader and 1 lookup in the texture array in the fragment shader).

2. Just draw one big quad and solve everything in the fragment shader (which means 2 texture lookups / fragment with an array index depending on the outcome of the first texture lookup). Slower execution, much faster to code.

It all depends on your target platform

06-06-2010, 04:27 AM
The VBO with multiple quads definitely is the way to go, infact that's what I am using already.

Now... the problem is that, to specify a per-vertex texture index (thus having a U,V,W mapping coords, so to say) I should make every quad "unique", while now I am sharing vertices.

What I am looking for is a way to derive the Texture Index in the vertex shader and pass it to the pixel shader.