I'm trying to visualise a graph with OpenGL. I have vertex buffer with points in 3D space, and an index buffer that specifies lines between vertices. I use glDrawElements to draw the graph. Everything works. Problem is that I need to visualise the edge weights. My problem is that edge weights are pairwise attributes and I have no idea how to put this information into my shader. Only solutions I can think of is drawing each edge individually with DrawRangeElements and setting the edge weight between every call. Is there a better way of doing this?
Asked
Active
Viewed 176 times
0
-
What is a "pairwise attribute"? – Nicol Bolas Oct 15 '12 at 21:06
-
Given vertex A and B, I'd like some way to access an attribute that describes the edge/line between them. In this case the weight. I'd basically like to access an attribute in a buffer for every line that I draw (while still using an index buffer). I'm hoping there is some way I can do this in a geometry shader. – circlingthesun Oct 15 '12 at 21:29
-
Would an adjacency matrix in a 2D texture work? The pixel value at each x/y point would be the edge weight weight between node x and node y. – genpfault Oct 15 '12 at 21:39
-
It would if my graphs were smallish. Unfortunately the graphs I construct can have up to 7 million vertices. :| Thanks for the suggestion :) – circlingthesun Oct 15 '12 at 21:46
1 Answers
1
There's no need to employ a geometry shader. Just render them as GL_LINES
, duplicating the positions as needed as well as providing the same "weight" attribute for each pair of verts on a line. This is ultimately no different from rendering a cube, where each face needs its own normals.
If (and only if) you absolutely must have that memory back, and you can't simply compress your vertex data (using normalized shorts, unnormalized shorts, or whatever), here are some techniques you can use. Be warned: this is a memory-vs-performance tradeoff. So unless you have real memory pressures, just duplicate your vertex data and get it over with.

Community
- 1
- 1

Nicol Bolas
- 449,505
- 63
- 781
- 982
-
Yes. There's no point in using glDrawElements, since each line will use independent vertex indices. – Nicol Bolas Oct 15 '12 at 22:15
-
Is there no way I could somehow avoid the extra memory overhead? – circlingthesun Oct 15 '12 at 22:19