I have a shader that is used to draw a font. I know that people use texture to draw points, but here the point drawing shader is so fast that it does not make a difference to change it to texture. However, the way i implemented takes a lot of memory to hold the pixel values.

Currently i use an array of coordinates to draw the text and an array of ARGB to set the color. But the color is always the same, i just change the A-channel of the color, replicating the RGB in all pixels. The shader is below:

What i have to change in the code above to let i upload just the RGB and pass an array of A-channels? This would save a lot of memory, because instead of passing 4 bytes for each pixel, i would pass just 1 byte for the pixel.

You'll need to change your glVertexAttribPointer call of course (the alpha attribute becomes glVertexAttribPointer (index, 1, GL_UNSIGNED_BYTE, GL_TRUE, stride, pointer)), as well as add a glUniform3fv for setting a_RGB. Not too sure how well your hardware and/or driver is going to like getting a 1-byte normalized attrib array though; the spec says it's possible, even D3D10 and 11 support it (normally a good indication that it is actually supported in hardware with GL too) but it may punt you back to a software emulated path on older hardware (in which case you've certainly saved a lot of memory but are also running a lot slower as a result - a common enough risk).

10-05-2012, 11:32 AM

guihazan

Hi mhagain,

I thought about another solution, but i don't know how to implement it.