Loop color data?

So I have 10,000 lines and I’m trying to reduce the amount of color data I have on my card.

So right now I have 20,000 vertexs for the 10,000 lines, * 4, so 80,000 color floats. Is this really necessary? I use the same colors on all 10,000 lines. If it was a single color, I would just use a glColor4f(), but it’s two colors - one for each vertex. Can I do this with 8 floats? I have this all in a VBO. Is there any way I can tell the color pointer to use the same two vertex colors on all 10,000 lines? Or can I put this in my shader and have it toggle a bool or something between the two colors? Seems like a big waste of video card memory.

gl.glLineWidth(thinline);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, highlines_vbo[0]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glEnableClientState(GL.GL_COLOR_ARRAY);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, highlines_vbo[1]);
gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
gl.glDrawArrays(GL.GL_LINES, 0, highlines);
gl.glDisableClientState(GL.GL_COLOR_ARRAY);

Well, it seems that an easy solution is to use different indices for different attributes. But it is not possible with OpenGL.

What kind of hardware you are running on?
10k color attributes is a piece of cake for most graphics hardware today.

10k could be much higher… depends on the data. Could be 1,000,000. Wasn’t aware of a way with the color pointer, but thought perhaps there was some trick or that a varying could be toggled by the vertex shader, so each vertex would flip between 1 & 0. In doing so, I could use a simple if statement to assign the color in the shader. But I’m not that familiar on what is writable in the shader that could be passed to the next vertex. I know a varying can pass to the fragment shader, but wasn’t sure about it being passed to the next vertex.

You can create a 1D texture.
Provide 1D texcoord for each vertex and there you go. You save 3 floats per vertex.

Thanks - That would surely save on memory. :slight_smile:

You could also use unsigned bytes for the colours instead of floats; that would reduce the overhead to one quarter of what it was. An equal saving to V-man’s proposal.