提交 da0d1c1f 编写于 作者: O Olli Etuaho 提交者: Mr.doob

Save memory by loading JPEGs as RGB by default (#9203)

JPEGs can't have an alpha channel, so it's optimal to load them as RGB
textures instead of RGBA. This saves 25% of texture memory on
OpenGL-based WebGL implementations. The optimization is especially
significant on memory-constrained mobile platforms.
上级 3e6696e1
......@@ -19,6 +19,12 @@ Object.assign( THREE.TextureLoader.prototype, {
loader.setPath( this.path );
loader.load( url, function ( image ) {
// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
var isJPEG = url.search(/\.(jpg|jpeg)$/) > 0;
if (!isJPEG) {
isJPEG = url.search(/^data\:image\/jpeg/) == 0;
}
texture.format = isJPEG ? THREE.RGBFormat : THREE.RGBAFormat;
texture.image = image;
texture.needsUpdate = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册