john-chapman / im3d

Immediate mode rendering and 3d gizmos.
MIT License
1.21k stars 63 forks source link

Is there a way for this to work without the geometry shaders #12

Open volcoma opened 7 years ago

volcoma commented 7 years ago

The library is pretty cool but is there a way for it to work without the geometry shaders for lower end devices?

john-chapman commented 7 years ago

Yes, you're free to implement the draw callback/shader in any way you like.

Without geometry shaders the only issue you might have is that (depending on the graphics API) you may be unable to change the line thickness/point size per vertex. You could live without this, it just won't render as nicely.

An alternative approach, slightly more involved, would be to build your own application-side vertex list from the data passed to the draw callback. This way you can reformat the vertices however you like - for example you could construct a single large triangle strip, expanding the points/lines as you go, then draw the whole thing in a single draw call after Im3d::Draw() returns.

Which graphics API are you working with? It may be worth adding an example.

volcoma commented 7 years ago

Well I am using BGFX library that wraps everything in one api. Unfortunetely it does not have a support for geometry shaders yet so thats why I am asking :)

john-chapman commented 7 years ago

A third option would be to upload the Im3d vertex data to a constant buffer, then make an instanced draw call with 4 vertices and do the point/line expansion in the vertex shader. This will probably have similar performance to the geometry shader approach.

I'll try and get around to adding a 'no geometry shaders' example soon as a reference for these techniques. In the meantime let me know if you have any success integrating it.

volcoma commented 7 years ago

Well integrating the library is a matter of an hour's work tops. Looks pretty easy. The only thing stopping me to replace my existing stuff with your library is this issue.

john-chapman commented 7 years ago

I've added an example which targets OpenGL 3.1 as a reference for how to integrate Im3d without geometry shaders. I went with the last approach I mentioned above - uploading the vertex data to a constant buffer and manually fetching it in the vertex shader to do point/line expansion. The performance is roughly the same as the geometry shader version.

There are 2 important things to note: