webgl-2d icon indicating copy to clipboard operation
webgl-2d copied to clipboard

Implement globalCompositeOperation/globalAlpha; don't fail when WebGL is unavailable; use premultiplied alpha

Open kg opened this issue 13 years ago • 0 comments

As we discussed earlier, here's a pull request with the changes I made to webgl-2d for my own uses. I tested it out in my samples and it works great, but there might be a bug or two hiding in there since I stripped out some custom stuff I added for my own uses.

A summary of the stuff I changed:

Asking for a webgl-2d context will return a normal 2d context if WebGL is unavailable. You can detect this by checking the result context for 'isWebGL'. This simplifies integrating webgl-2d.

globalCompositeOperation works for 'copy', 'source-over' and 'lighter'. Other blend modes will log a warning.

globalAlpha works.

If drawImage is passed a canvas instead of an image, it uses a fast path to call getImageData directly on the canvas.

You can invalidate the cached texture for an image/canvas by setting 'isDirty=true' on the source image/canvas.

Premultiplied alpha is now used for textures. This makes Texture creation slower, but eliminates color bleeding/ringing artifacts when scaling images, and makes the 'lighter' blend mode render more accurately.

kg avatar Apr 13 '12 21:04 kg