When Nvidia dropped the paletted texture extension, I had to implement this as a dependent texture look-up using the Nvidia texture-shader extensions.
With OpenGL 2.0, is there a vendor-independent way of doing this?
Or, if I use Cg, what vendors could I support?
Use GLSL then… Totally vendor-independent…
If you have access to glslang-capable hardware, that is. If all you have is a Geforce 3/4, then yes, you don’t really have a choice. If you do have access to a GeForce FX or 6, or a Radeon 9500 or better, then you can use ARB_fragment_program or glslang.
Emulating paletted textures using dependent texturing is not as trivial as it initially seems. The problem is filtering. With paletted textures multiple source texels are read, looked up in the palette, then filtered. With dependent texturing, multiple texels are read, filtered, and then used to access another texture (e.g., a palette).
This isn’t to say you won’t be able to achieve whatever effect you’re attempting. I’m just saying that there isn’t a direct mapping from paletted textures to dependent texturing.
Using nearest mapping will only remove the “filtered” step from “With paletted textures multiple source texels are read, looked up in the palette, then filtered”.
The filtering part has to be done by hand.
The filtering part has to be done by hand.
To do the filtering by hand, you also need to read multiple texels. Depending on what wrap mode you have selected, this may not be trivial. For example, if you want to use CLAMP_TO_BORDER, you can’t just sample the original texel biased with (0, 0), (0.5n, 0), (0, 0.5n), (0.5n, 0.5n), where n is 1/texture_size. With that wrap mode, if any sample hits the texture border then the border color is used. You could do it with conditional branching, but…umm…yuck!