PDA

View Full Version : use a custom color paletted texture



mireazma
04-01-2015, 11:38 PM
Hello.
Is there a built-in feature of OpenGL 3.3+ to draw a paletted texture?
From Google I found an old page specifying an extension.
Ideally I'd draw a custom palette (arbitrary number of bits, i.e. colors) texture. I looked at
www.opengl.org/sdk/docs/man3/xhtml/glTexImage2D.xml
for a way with glTexParameter for glTexImage2D but didn't find anything for paletted textures.
Do I have to enable an EXT?
Can someone please tell me what code do I need for a paletted texture draw?

Agent D
04-02-2015, 07:19 AM
AFAIK older versions (and compatibillity profile) did support color index mode and color index textures, but current, core profile GL
does not support that anymore.

But it can be easily emulated in a shader by reading integer indices from the indexed texture and reading the actual color values from
a 1D color map texture.

Is there a particular reason why you cannot convert your color indexed textures at load time, or offline and use 24bpp RGB images instead?

Alfonse Reinheart
04-02-2015, 08:09 AM
But it can be easily emulated in a shader by reading integer indices from the indexed texture and reading the actual color values from

It should also be noted that emulating paletted textures in a shader requires you to do your own filtering.

mireazma
04-03-2015, 02:28 AM
Thank you both for help.

It should also be noted that emulating paletted textures in a shader requires you to do your own filtering.
and this wraps it up.

I did the math on several images both photos and gradients and using paletted textures turns out to be an efficient kind of compression (~1.4:1) depending on the texture, taking note of its biggest pro: it's lossless. Of course, it's not fit for cases when lossless = useless.
What I don't know is the efficiency of looking up the index in the table but I think it must be fast.
BTW did you see the artifacts of DXT on gradients? Unacceptable :)