which would lead to overdraw. In case you need that very often (for example some tiled surface), you would overdraw a bit too much… (and games really need to be optimized in the view of overdraw, because almost every game is fill-rate limited).
So what I’d do is write a little shader. Simply takes 3 textures: texture 1, texture 2, and the mask.
Wait… here is the kind of shader I thought about:
// R G B A
const vec4 white = vec4(0, 0, 0, 1);
sampler2D texture1;
sampler2D texture2;
sampler2D mask;
void main(void) {
// This is more pseudo-code than shader. It's some time ago the last time I wrote a shader...
// Use this for getting the Idea, not for using this :) (first solve all errors :D )
vec4 mask_color = texture2D(mask, gl_TexCoords);
if (mask_color == white) {
gl_FragColor = texture2D(texture1, gl_TexCoords);
} else {
gl_FragColor = texture2D(texture2, gl_TexCoords);
}
}