|
@@ -7,20 +7,20 @@ import { MathUtils } from '../../math/MathUtils.js';
|
|
|
|
|
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
|
|
|
|
- var isWebGL2 = capabilities.isWebGL2;
|
|
|
- var maxTextures = capabilities.maxTextures;
|
|
|
- var maxCubemapSize = capabilities.maxCubemapSize;
|
|
|
- var maxTextureSize = capabilities.maxTextureSize;
|
|
|
- var maxSamples = capabilities.maxSamples;
|
|
|
+ const isWebGL2 = capabilities.isWebGL2;
|
|
|
+ const maxTextures = capabilities.maxTextures;
|
|
|
+ const maxCubemapSize = capabilities.maxCubemapSize;
|
|
|
+ const maxTextureSize = capabilities.maxTextureSize;
|
|
|
+ const maxSamples = capabilities.maxSamples;
|
|
|
|
|
|
- var _videoTextures = new WeakMap();
|
|
|
- var _canvas;
|
|
|
+ const _videoTextures = new WeakMap();
|
|
|
+ let _canvas;
|
|
|
|
|
|
// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
|
|
|
// also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
|
|
|
// Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
|
|
|
|
|
|
- var useOffscreenCanvas = false;
|
|
|
+ let useOffscreenCanvas = false;
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -45,7 +45,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
|
|
|
|
|
|
- var scale = 1;
|
|
|
+ let scale = 1;
|
|
|
|
|
|
// handle case if texture exceeds max size
|
|
|
|
|
@@ -65,21 +65,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
|
|
|
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
|
|
|
|
|
|
- var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
|
|
|
+ const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
|
|
|
|
|
|
- var width = floor( scale * image.width );
|
|
|
- var height = floor( scale * image.height );
|
|
|
+ const width = floor( scale * image.width );
|
|
|
+ const height = floor( scale * image.height );
|
|
|
|
|
|
if ( _canvas === undefined ) _canvas = createCanvas( width, height );
|
|
|
|
|
|
// cube textures can't reuse the same canvas
|
|
|
|
|
|
- var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
|
|
|
+ const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
|
|
|
|
|
|
canvas.width = width;
|
|
|
canvas.height = height;
|
|
|
|
|
|
- var context = canvas.getContext( '2d' );
|
|
|
+ const context = canvas.getContext( '2d' );
|
|
|
context.drawImage( image, 0, 0, width, height );
|
|
|
|
|
|
console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
|
|
@@ -130,7 +130,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
_gl.generateMipmap( target );
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
// Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
|
|
|
textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
|
|
@@ -149,7 +149,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- var internalFormat = glFormat;
|
|
|
+ let internalFormat = glFormat;
|
|
|
|
|
|
if ( glFormat === _gl.RED ) {
|
|
|
|
|
@@ -204,7 +204,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function onTextureDispose( event ) {
|
|
|
|
|
|
- var texture = event.target;
|
|
|
+ const texture = event.target;
|
|
|
|
|
|
texture.removeEventListener( 'dispose', onTextureDispose );
|
|
|
|
|
@@ -222,7 +222,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function onRenderTargetDispose( event ) {
|
|
|
|
|
|
- var renderTarget = event.target;
|
|
|
+ const renderTarget = event.target;
|
|
|
|
|
|
renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
|
|
|
|
|
@@ -236,7 +236,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function deallocateTexture( texture ) {
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
if ( textureProperties.__webglInit === undefined ) return;
|
|
|
|
|
@@ -248,8 +248,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function deallocateRenderTarget( renderTarget ) {
|
|
|
|
|
|
- var renderTargetProperties = properties.get( renderTarget );
|
|
|
- var textureProperties = properties.get( renderTarget.texture );
|
|
|
+ const renderTargetProperties = properties.get( renderTarget );
|
|
|
+ const textureProperties = properties.get( renderTarget.texture );
|
|
|
|
|
|
if ( ! renderTarget ) return;
|
|
|
|
|
@@ -267,7 +267,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( renderTarget.isWebGLCubeRenderTarget ) {
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
_gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
|
|
|
if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
|
|
@@ -291,7 +291,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
//
|
|
|
|
|
|
- var textureUnits = 0;
|
|
|
+ let textureUnits = 0;
|
|
|
|
|
|
function resetTextureUnits() {
|
|
|
|
|
@@ -301,7 +301,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function allocateTextureUnit() {
|
|
|
|
|
|
- var textureUnit = textureUnits;
|
|
|
+ const textureUnit = textureUnits;
|
|
|
|
|
|
if ( textureUnit >= maxTextures ) {
|
|
|
|
|
@@ -319,13 +319,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function setTexture2D( texture, slot ) {
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
if ( texture.isVideoTexture ) updateVideoTexture( texture );
|
|
|
|
|
|
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
|
|
- var image = texture.image;
|
|
|
+ const image = texture.image;
|
|
|
|
|
|
if ( image === undefined ) {
|
|
|
|
|
@@ -351,7 +351,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function setTexture2DArray( texture, slot ) {
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
|
@@ -367,7 +367,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function setTexture3D( texture, slot ) {
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
|
@@ -385,7 +385,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( texture.image.length !== 6 ) return;
|
|
|
|
|
|
- var textureProperties = properties.get( texture );
|
|
|
+ const textureProperties = properties.get( texture );
|
|
|
|
|
|
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
|
|
|
|
|
@@ -396,12 +396,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
|
|
|
|
|
|
- var isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
|
|
|
- var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
|
|
|
+ const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
|
|
|
+ const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
|
|
|
|
|
|
- var cubeImage = [];
|
|
|
+ const cubeImage = [];
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
if ( ! isCompressed && ! isDataTexture ) {
|
|
|
|
|
@@ -415,7 +415,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- var image = cubeImage[ 0 ],
|
|
|
+ const image = cubeImage[ 0 ],
|
|
|
supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
glFormat = utils.convert( texture.format ),
|
|
|
glType = utils.convert( texture.type ),
|
|
@@ -423,17 +423,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
|
|
|
|
- var mipmaps;
|
|
|
+ let mipmaps;
|
|
|
|
|
|
if ( isCompressed ) {
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
mipmaps = cubeImage[ i ].mipmaps;
|
|
|
|
|
|
- for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
+ for ( let j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
+ const mipmap = mipmaps[ j ];
|
|
|
|
|
|
if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
|
|
|
|
|
@@ -463,16 +463,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
mipmaps = texture.mipmaps;
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
if ( isDataTexture ) {
|
|
|
|
|
|
state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
|
|
|
|
|
|
- for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
+ for ( let j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
- var mipmapImage = mipmap.image[ i ].image;
|
|
|
+ const mipmap = mipmaps[ j ];
|
|
|
+ const mipmapImage = mipmap.image[ i ].image;
|
|
|
|
|
|
state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
|
|
|
|
|
@@ -482,9 +482,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
|
|
|
|
|
|
- for ( var j = 0; j < mipmaps.length; j ++ ) {
|
|
|
+ for ( let j = 0; j < mipmaps.length; j ++ ) {
|
|
|
|
|
|
- var mipmap = mipmaps[ j ];
|
|
|
+ const mipmap = mipmaps[ j ];
|
|
|
|
|
|
state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
|
|
|
|
|
@@ -525,13 +525,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- var wrappingToGL = {
|
|
|
+ const wrappingToGL = {
|
|
|
[ RepeatWrapping ]: _gl.REPEAT,
|
|
|
[ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE,
|
|
|
[ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT
|
|
|
};
|
|
|
|
|
|
- var filterToGL = {
|
|
|
+ const filterToGL = {
|
|
|
[ NearestFilter ]: _gl.NEAREST,
|
|
|
[ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST,
|
|
|
[ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR,
|
|
@@ -585,7 +585,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
|
+ const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
|
|
|
|
if ( extension ) {
|
|
|
|
|
@@ -621,7 +621,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function uploadTexture( textureProperties, texture, slot ) {
|
|
|
|
|
|
- var textureType = _gl.TEXTURE_2D;
|
|
|
+ let textureType = _gl.TEXTURE_2D;
|
|
|
|
|
|
if ( texture.isDataTexture2DArray ) textureType = _gl.TEXTURE_2D_ARRAY;
|
|
|
if ( texture.isDataTexture3D ) textureType = _gl.TEXTURE_3D;
|
|
@@ -635,17 +635,19 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
|
|
|
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
|
|
|
|
- var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
|
|
|
- var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
|
|
|
+ const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
|
|
|
+ const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
|
|
|
|
|
|
- var supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
- glFormat = utils.convert( texture.format ),
|
|
|
- glType = utils.convert( texture.type ),
|
|
|
+ const supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
+ glFormat = utils.convert( texture.format );
|
|
|
+
|
|
|
+ let glType = utils.convert( texture.type ),
|
|
|
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
|
|
|
|
|
|
setTextureParameters( textureType, texture, supportsMips );
|
|
|
|
|
|
- var mipmap, mipmaps = texture.mipmaps;
|
|
|
+ let mipmap;
|
|
|
+ const mipmaps = texture.mipmaps;
|
|
|
|
|
|
if ( texture.isDepthTexture ) {
|
|
|
|
|
@@ -733,7 +735,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( mipmaps.length > 0 && supportsMips ) {
|
|
|
|
|
|
- for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
|
state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
|
|
@@ -752,7 +754,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else if ( texture.isCompressedTexture ) {
|
|
|
|
|
|
- for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
|
|
|
@@ -798,7 +800,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( mipmaps.length > 0 && supportsMips ) {
|
|
|
|
|
|
- for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
+ for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
|
state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );
|
|
@@ -834,9 +836,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// Setup storage for target texture and bind it to correct framebuffer
|
|
|
function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
|
|
|
|
|
|
- var glFormat = utils.convert( renderTarget.texture.format );
|
|
|
- var glType = utils.convert( renderTarget.texture.type );
|
|
|
- var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
+ const glFormat = utils.convert( renderTarget.texture.format );
|
|
|
+ const glType = utils.convert( renderTarget.texture.type );
|
|
|
+ const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
|
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
|
|
@@ -851,11 +853,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
|
|
|
|
|
|
- var glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
|
+ let glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
|
|
|
|
if ( isMultisample ) {
|
|
|
|
|
|
- var depthTexture = renderTarget.depthTexture;
|
|
|
+ const depthTexture = renderTarget.depthTexture;
|
|
|
|
|
|
if ( depthTexture && depthTexture.isDepthTexture ) {
|
|
|
|
|
@@ -871,7 +873,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- var samples = getRenderTargetSamples( renderTarget );
|
|
|
+ const samples = getRenderTargetSamples( renderTarget );
|
|
|
|
|
|
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
|
|
|
|
|
@@ -887,7 +889,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( isMultisample ) {
|
|
|
|
|
|
- var samples = getRenderTargetSamples( renderTarget );
|
|
|
+ const samples = getRenderTargetSamples( renderTarget );
|
|
|
|
|
|
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
|
|
|
|
|
@@ -902,13 +904,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- var glFormat = utils.convert( renderTarget.texture.format );
|
|
|
- var glType = utils.convert( renderTarget.texture.type );
|
|
|
- var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
+ const glFormat = utils.convert( renderTarget.texture.format );
|
|
|
+ const glType = utils.convert( renderTarget.texture.type );
|
|
|
+ const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
|
|
|
if ( isMultisample ) {
|
|
|
|
|
|
- var samples = getRenderTargetSamples( renderTarget );
|
|
|
+ const samples = getRenderTargetSamples( renderTarget );
|
|
|
|
|
|
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
|
|
|
|
|
@@ -927,7 +929,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// Setup resources for a Depth Texture for a FBO (needs an extension)
|
|
|
function setupDepthTexture( framebuffer, renderTarget ) {
|
|
|
|
|
|
- var isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
|
|
|
+ const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
|
|
|
if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
|
|
|
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
@@ -951,7 +953,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
setTexture2D( renderTarget.depthTexture, 0 );
|
|
|
|
|
|
- var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
|
|
|
+ const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
|
|
|
|
|
|
if ( renderTarget.depthTexture.format === DepthFormat ) {
|
|
|
|
|
@@ -972,9 +974,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// Setup GL resources for a non-texture depth buffer
|
|
|
function setupDepthRenderbuffer( renderTarget ) {
|
|
|
|
|
|
- var renderTargetProperties = properties.get( renderTarget );
|
|
|
+ const renderTargetProperties = properties.get( renderTarget );
|
|
|
|
|
|
- var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
|
+ const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
|
|
|
|
if ( renderTarget.depthTexture ) {
|
|
|
|
|
@@ -988,7 +990,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
renderTargetProperties.__webglDepthbuffer = [];
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
|
|
|
renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
|
|
@@ -1013,8 +1015,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// Set up GL resources for the render target
|
|
|
function setupRenderTarget( renderTarget ) {
|
|
|
|
|
|
- var renderTargetProperties = properties.get( renderTarget );
|
|
|
- var textureProperties = properties.get( renderTarget.texture );
|
|
|
+ const renderTargetProperties = properties.get( renderTarget );
|
|
|
+ const textureProperties = properties.get( renderTarget.texture );
|
|
|
|
|
|
renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
|
|
|
|
|
@@ -1022,9 +1024,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
info.memory.textures ++;
|
|
|
|
|
|
- var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
|
- var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
|
|
|
- var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
+ const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
|
+ const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
|
|
|
+ const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
// Handles WebGL2 RGBFormat fallback - #18858
|
|
|
|
|
@@ -1042,7 +1044,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
renderTargetProperties.__webglFramebuffer = [];
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
|
|
|
|
|
@@ -1061,10 +1063,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
_gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
|
|
|
|
|
|
- var glFormat = utils.convert( renderTarget.texture.format );
|
|
|
- var glType = utils.convert( renderTarget.texture.type );
|
|
|
- var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
- var samples = getRenderTargetSamples( renderTarget );
|
|
|
+ const glFormat = utils.convert( renderTarget.texture.format );
|
|
|
+ const glType = utils.convert( renderTarget.texture.type );
|
|
|
+ const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
|
|
|
+ const samples = getRenderTargetSamples( renderTarget );
|
|
|
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
|
|
|
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
|
|
@@ -1098,7 +1100,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
|
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, supportsMips );
|
|
|
|
|
|
- for ( var i = 0; i < 6; i ++ ) {
|
|
|
+ for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
|
|
|
|
|
@@ -1140,13 +1142,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function updateRenderTargetMipmap( renderTarget ) {
|
|
|
|
|
|
- var texture = renderTarget.texture;
|
|
|
- var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
+ const texture = renderTarget.texture;
|
|
|
+ const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
- var target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
|
- var webglTexture = properties.get( texture ).__webglTexture;
|
|
|
+ const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
|
+ const webglTexture = properties.get( texture ).__webglTexture;
|
|
|
|
|
|
state.bindTexture( target, webglTexture );
|
|
|
generateMipmap( target, texture, renderTarget.width, renderTarget.height );
|
|
@@ -1162,14 +1164,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( isWebGL2 ) {
|
|
|
|
|
|
- var renderTargetProperties = properties.get( renderTarget );
|
|
|
+ const renderTargetProperties = properties.get( renderTarget );
|
|
|
|
|
|
_gl.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
|
|
|
_gl.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
|
|
|
|
|
|
- var width = renderTarget.width;
|
|
|
- var height = renderTarget.height;
|
|
|
- var mask = _gl.COLOR_BUFFER_BIT;
|
|
|
+ const width = renderTarget.width;
|
|
|
+ const height = renderTarget.height;
|
|
|
+ let mask = _gl.COLOR_BUFFER_BIT;
|
|
|
|
|
|
if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;
|
|
|
if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;
|
|
@@ -1197,7 +1199,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function updateVideoTexture( texture ) {
|
|
|
|
|
|
- var frame = info.render.frame;
|
|
|
+ const frame = info.render.frame;
|
|
|
|
|
|
// Check the last frame we updated the VideoTexture
|
|
|
|
|
@@ -1212,8 +1214,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
// backwards compatibility
|
|
|
|
|
|
- var warnedTexture2D = false;
|
|
|
- var warnedTextureCube = false;
|
|
|
+ let warnedTexture2D = false;
|
|
|
+ let warnedTextureCube = false;
|
|
|
|
|
|
function safeSetTexture2D( texture, slot ) {
|
|
|
|