glColorPointer with monochrome color data.

In this application I have a large array of GLfloats that I need to use to color the vertices in a vertex array. The color data is provided in one of two formats, either interleaved RGB triplets, or single-component monochrome values.

Ideally what I want to do is:

glColorPointer(ismono ? 1 : 3, GL_FLOAT, 0, data);

And when the color has 1 component, it is used as the R, G, and B color component. I can’t do that because glColorPointer only accepts size of 3 or 4, not 1.

I want to avoid having to create a temporary buffer and duplicate each of the monochrome color channels 3 times; I’d really like to use the monochrome array directly.

Is there some way I can do this?


I haven’t tried this yet; but is it possible to tack two “dummy” values onto the end of the monochrome data array, then use a negative stride (like -sizeof(GLfloat)*2)? That gives valid red components but “junk” green and blue for every color; but then I could write a shader or something that copied red to green + blue (or, is there something in ARB_imaging or somewhere else that would let me do that mapping?)?

Edit: Nevermind it says stride can’t be negative in the docs. :-/

Maybe you can just send/use the data as a generic vertex attribute which allows sizes of 1,2,3 and 4…