First off: Demos!
Title cards are for wimps!
Title cards are for wimps!
Posted: August 2010
Posted: September 2011
Quake 3 Demo:
WebGL Camp 4, 2011 - Brandon Jones
The rest of this presentation will make artists cry!
Keep your texture sizes reasonable
TF2 Heavy texture map. 1024x512, no alpha channel
HTTP compression is the ultimate no-brainer.
Posted: May 2011
Reuse textures for images of the same size
Match the format to the actual input.
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, ...);
(Note: OpenGL ES 2.0 requires that these values match)
If your textures are opaque or contain premultiplied alpha
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
We all love the following code
var img = new Image(); img.onload = function() { gl.bindTexture(gl.TEXTURE_2D, texture); gl.texImage2D(gl.TEXTURE_2D, ..., img); }; img.src = textureUrl;
But doing that while rendering can cause unpredictable performance hitches
For more predictable behavior, only allow a fixed number of uploads every few frames
var img = new Image(); img.onload = function() { readyTextures.push({img: img, tex: texture}); }; img.src = textureUrl; function requestAnimationFrameCallback() { if(readyTextures.length && frameCount % 2) { var ready = readyTextures.shift(); gl.bindTexture(gl.TEXTURE_2D, ready.tex); gl.texImage2D(gl.TEXTURE_2D, ..., ready.img); } // Draw };
console.time("update"); updateFrame(); console.timeEnd("update"); console.time("draw"); drawFrame(); console.timeEnd("draw");
Calls must be paired, cannot be nested
Posted: December 2011
Compressed Textures!
var ct = gl.getExtension("WEBKIT_WEBGL_compressed_textures"); var texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); ct.compressedTexImage2D(gl.TEXTURE_2D, 0, // Mip level ct.COMPRESSED_RGBA_S3TC_DXT5_EXT, // Internal Format width, height, // Texture Dimensions 0, // Border? 0/1 buffer // Typed Array w/ compressed texture data ); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // and so on...
iOS Rage 1024x1024 texture download size
In memory texture size
Thank you!