Strange (or expected?) behavior when blocking alpha writes

Take the following directives:


gl.colorMask(1, 1, 1, 0);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUES_SRC_ALPHA);

When I put the above into my app, the first frame renders as if alpha weren’t a factor at all, but the second frame turns completely white.

I can understand the first frame rendering properly, if there’s nothing to blend it with. However, I don’t understand why the second frame would turn white. Do the mathematics support this, or is it more likely a bug in the GL driver?

My understanding of the blend function is that it looks like:

Red = Rs * As + Rd * (1 - As)

Obviously, that only applies to the Red channel, but the other channels should be calculated similarly. In any case, the blend function shouldn’t be affected by the destination alpha at all (according to the above formula), so mathematically speaking, I can’t see why it would produce white.

Also, it’s worth taking note that the transition to white happens in a single frame. There’s no incremental “step” towards white as you’d see with additive blending over time. Even with very low alpha values, it is always exactly the second frame that the rendered polygons turn completely white.

That’s all the detail I can think to provide on this issue. Very curious to hear an explanation, if any.

Don’t know if you copy and pasted, but it’s ONE_MINUS, not ONE_MINUES. It could also be your setup, which varies a bit by browser. Here’s what I use…

var thisCanvas;
thisCanvas = document.createElement ( “canvas” );
gl = thisCanvas.getContext ( “experimental-webgl”, {
alpha : true,
antialias : false,
depth : true,
stencil : false,
premultipliedAlpha : true
} );

Don’t know if you copy and pasted, but it’s ONE_MINUS, not ONE_MINUES.

Sorry, that’s a typo. (I was not copying and pasting.)

Thanks for the response. The context was initialized with no options:

canvas.getContext("experimental-webgl");

I’ve tested this in both Chrome and Firefox: rendering is perfectly normal, but if I set the color mask to (1, 1, 1, 0), then the second frame turns completely white. The first frame renders as if there were no mask.

Though now that I think about it, if the mask is blocking alpha writes and the clear color is (0, 0, 0, 1), then shouldn’t the entire canvas remain black, including on the first frame?

At this point I’m totally confused: can anyone explain what the correct output should be with blending enabled, when blocking all writes to the alpha channel?

For what it’s worth, I’m on a MacBook Pro / GeForce 320M still running Snow Leopard.