Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
volcoma opened this issue Feb 23, 2017 · 5 comments
Open

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

volcoma opened this issue Feb 23, 2017 · 5 comments
Labels

Comments

@volcoma
Copy link

volcoma commented Feb 23, 2017

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

@john-chapman
Copy link
Owner

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
Copy link
Author

volcoma commented Feb 23, 2017

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
Copy link
Owner

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
Copy link
Author

volcoma commented Feb 26, 2017

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
Copy link
Owner

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:

  • The example has to contend with the OpenGL uniform buffer size limit; it splits up the vertex data into 64kb blocks. In your case you probably don't need to do this if you can allocate and bind arbitrarily large constant buffers.
  • In order to be able to upload the Im3d vertex data directly to the GPU you have to ensure that it is aligned correctly (e.g. 16 byte alignment for an OpenGL uniform buffer). This can be done by setting IM3D_VERTEX_ALIGNMENT in im3d_config.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants