未验证 提交 fad652cb 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #19504 from Mugen87/dev49

Core: More usage of let/const.
...@@ -37,9 +37,9 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer ...@@ -37,9 +37,9 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
this.texture.format = texture.format; this.texture.format = texture.format;
this.texture.encoding = texture.encoding; this.texture.encoding = texture.encoding;
var scene = new Scene(); const scene = new Scene();
var shader = { const shader = {
uniforms: { uniforms: {
tEquirect: { value: null }, tEquirect: { value: null },
...@@ -87,7 +87,7 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer ...@@ -87,7 +87,7 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
].join( '\n' ), ].join( '\n' ),
}; };
var material = new ShaderMaterial( { const material = new ShaderMaterial( {
type: 'CubemapFromEquirect', type: 'CubemapFromEquirect',
...@@ -101,11 +101,11 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer ...@@ -101,11 +101,11 @@ WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer
material.uniforms.tEquirect.value = texture; material.uniforms.tEquirect.value = texture;
var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material ); const mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
scene.add( mesh ); scene.add( mesh );
var camera = new CubeCamera( 1, 10, this ); const camera = new CubeCamera( 1, 10, this );
camera.update( renderer, scene ); camera.update( renderer, scene );
mesh.geometry.dispose(); mesh.geometry.dispose();
......
...@@ -51,7 +51,7 @@ function WebGLRenderer( parameters ) { ...@@ -51,7 +51,7 @@ function WebGLRenderer( parameters ) {
parameters = parameters || {}; parameters = parameters || {};
var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ), const _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
_context = parameters.context !== undefined ? parameters.context : null, _context = parameters.context !== undefined ? parameters.context : null,
_alpha = parameters.alpha !== undefined ? parameters.alpha : false, _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
...@@ -63,8 +63,8 @@ function WebGLRenderer( parameters ) { ...@@ -63,8 +63,8 @@ function WebGLRenderer( parameters ) {
_powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default', _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
_failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false; _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
var currentRenderList = null; let currentRenderList = null;
var currentRenderState = null; let currentRenderState = null;
// public properties // public properties
...@@ -118,7 +118,7 @@ function WebGLRenderer( parameters ) { ...@@ -118,7 +118,7 @@ function WebGLRenderer( parameters ) {
// internal properties // internal properties
var _this = this, let _this = this,
_isContextLost = false, _isContextLost = false,
...@@ -184,11 +184,11 @@ function WebGLRenderer( parameters ) { ...@@ -184,11 +184,11 @@ function WebGLRenderer( parameters ) {
// initialize // initialize
var _gl; let _gl;
try { try {
var contextAttributes = { const contextAttributes = {
alpha: _alpha, alpha: _alpha,
depth: _depth, depth: _depth,
stencil: _stencil, stencil: _stencil,
...@@ -239,13 +239,13 @@ function WebGLRenderer( parameters ) { ...@@ -239,13 +239,13 @@ function WebGLRenderer( parameters ) {
} }
var extensions, capabilities, state, info; let extensions, capabilities, state, info;
var properties, textures, attributes, geometries, objects; let properties, textures, attributes, geometries, objects;
var programCache, materials, renderLists, renderStates; let programCache, materials, renderLists, renderStates;
var background, morphtargets, bufferRenderer, indexedBufferRenderer; let background, morphtargets, bufferRenderer, indexedBufferRenderer;
var utils; let utils;
function initGLContext() { function initGLContext() {
...@@ -305,13 +305,13 @@ function WebGLRenderer( parameters ) { ...@@ -305,13 +305,13 @@ function WebGLRenderer( parameters ) {
// xr // xr
var xr = new WebXRManager( _this, _gl ); const xr = new WebXRManager( _this, _gl );
this.xr = xr; this.xr = xr;
// shadow map // shadow map
var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); const shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
this.shadowMap = shadowMap; this.shadowMap = shadowMap;
...@@ -331,14 +331,14 @@ function WebGLRenderer( parameters ) { ...@@ -331,14 +331,14 @@ function WebGLRenderer( parameters ) {
this.forceContextLoss = function () { this.forceContextLoss = function () {
var extension = extensions.get( 'WEBGL_lose_context' ); const extension = extensions.get( 'WEBGL_lose_context' );
if ( extension ) extension.loseContext(); if ( extension ) extension.loseContext();
}; };
this.forceContextRestore = function () { this.forceContextRestore = function () {
var extension = extensions.get( 'WEBGL_lose_context' ); const extension = extensions.get( 'WEBGL_lose_context' );
if ( extension ) extension.restoreContext(); if ( extension ) extension.restoreContext();
}; };
...@@ -537,7 +537,7 @@ function WebGLRenderer( parameters ) { ...@@ -537,7 +537,7 @@ function WebGLRenderer( parameters ) {
this.clear = function ( color, depth, stencil ) { this.clear = function ( color, depth, stencil ) {
var bits = 0; let bits = 0;
if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT; if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT; if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
...@@ -607,7 +607,7 @@ function WebGLRenderer( parameters ) { ...@@ -607,7 +607,7 @@ function WebGLRenderer( parameters ) {
function onMaterialDispose( event ) { function onMaterialDispose( event ) {
var material = event.target; const material = event.target;
material.removeEventListener( 'dispose', onMaterialDispose ); material.removeEventListener( 'dispose', onMaterialDispose );
...@@ -628,7 +628,7 @@ function WebGLRenderer( parameters ) { ...@@ -628,7 +628,7 @@ function WebGLRenderer( parameters ) {
function releaseMaterialProgramReference( material ) { function releaseMaterialProgramReference( material ) {
var programInfo = properties.get( material ).program; const programInfo = properties.get( material ).program;
material.program = undefined; material.program = undefined;
...@@ -656,14 +656,14 @@ function WebGLRenderer( parameters ) { ...@@ -656,14 +656,14 @@ function WebGLRenderer( parameters ) {
state.initAttributes(); state.initAttributes();
var buffers = properties.get( object ); const buffers = properties.get( object );
if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer(); if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer(); if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer(); if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer(); if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
var programAttributes = program.getAttributes(); const programAttributes = program.getAttributes();
if ( object.hasPositions ) { if ( object.hasPositions ) {
...@@ -713,19 +713,19 @@ function WebGLRenderer( parameters ) { ...@@ -713,19 +713,19 @@ function WebGLRenderer( parameters ) {
}; };
var tempScene = new Scene(); const tempScene = new Scene();
this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) { this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
if ( scene === null ) scene = tempScene; // renderBufferDirect second parameter used to be fog (could be null) if ( scene === null ) scene = tempScene; // renderBufferDirect second parameter used to be fog (could be null)
var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 ); const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
var program = setProgram( camera, scene, material, object ); const program = setProgram( camera, scene, material, object );
state.setMaterial( material, frontFaceCW ); state.setMaterial( material, frontFaceCW );
var updateBuffers = false; let updateBuffers = false;
if ( _currentGeometryProgram.geometry !== geometry.id || if ( _currentGeometryProgram.geometry !== geometry.id ||
_currentGeometryProgram.program !== program.id || _currentGeometryProgram.program !== program.id ||
...@@ -754,8 +754,8 @@ function WebGLRenderer( parameters ) { ...@@ -754,8 +754,8 @@ function WebGLRenderer( parameters ) {
// //
var index = geometry.index; let index = geometry.index;
var position = geometry.attributes.position; const position = geometry.attributes.position;
// //
...@@ -771,7 +771,7 @@ function WebGLRenderer( parameters ) { ...@@ -771,7 +771,7 @@ function WebGLRenderer( parameters ) {
// //
var rangeFactor = 1; let rangeFactor = 1;
if ( material.wireframe === true ) { if ( material.wireframe === true ) {
...@@ -780,8 +780,8 @@ function WebGLRenderer( parameters ) { ...@@ -780,8 +780,8 @@ function WebGLRenderer( parameters ) {
} }
var attribute; let attribute;
var renderer = bufferRenderer; let renderer = bufferRenderer;
if ( index !== null ) { if ( index !== null ) {
...@@ -806,18 +806,18 @@ function WebGLRenderer( parameters ) { ...@@ -806,18 +806,18 @@ function WebGLRenderer( parameters ) {
// //
var dataCount = ( index !== null ) ? index.count : position.count; const dataCount = ( index !== null ) ? index.count : position.count;
var rangeStart = geometry.drawRange.start * rangeFactor; const rangeStart = geometry.drawRange.start * rangeFactor;
var rangeCount = geometry.drawRange.count * rangeFactor; const rangeCount = geometry.drawRange.count * rangeFactor;
var groupStart = group !== null ? group.start * rangeFactor : 0; const groupStart = group !== null ? group.start * rangeFactor : 0;
var groupCount = group !== null ? group.count * rangeFactor : Infinity; const groupCount = group !== null ? group.count * rangeFactor : Infinity;
var drawStart = Math.max( rangeStart, groupStart ); const drawStart = Math.max( rangeStart, groupStart );
var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1; const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
var drawCount = Math.max( 0, drawEnd - drawStart + 1 ); const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
if ( drawCount === 0 ) return; if ( drawCount === 0 ) return;
...@@ -838,7 +838,7 @@ function WebGLRenderer( parameters ) { ...@@ -838,7 +838,7 @@ function WebGLRenderer( parameters ) {
} else if ( object.isLine ) { } else if ( object.isLine ) {
var lineWidth = material.linewidth; let lineWidth = material.linewidth;
if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
...@@ -874,7 +874,7 @@ function WebGLRenderer( parameters ) { ...@@ -874,7 +874,7 @@ function WebGLRenderer( parameters ) {
} else if ( geometry.isInstancedBufferGeometry ) { } else if ( geometry.isInstancedBufferGeometry ) {
var instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount ); const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
renderer.renderInstances( geometry, drawStart, drawCount, instanceCount ); renderer.renderInstances( geometry, drawStart, drawCount, instanceCount );
...@@ -896,40 +896,40 @@ function WebGLRenderer( parameters ) { ...@@ -896,40 +896,40 @@ function WebGLRenderer( parameters ) {
state.initAttributes(); state.initAttributes();
var geometryAttributes = geometry.attributes; const geometryAttributes = geometry.attributes;
var programAttributes = program.getAttributes(); const programAttributes = program.getAttributes();
var materialDefaultAttributeValues = material.defaultAttributeValues; const materialDefaultAttributeValues = material.defaultAttributeValues;
for ( var name in programAttributes ) { for ( const name in programAttributes ) {
var programAttribute = programAttributes[ name ]; const programAttribute = programAttributes[ name ];
if ( programAttribute >= 0 ) { if ( programAttribute >= 0 ) {
var geometryAttribute = geometryAttributes[ name ]; const geometryAttribute = geometryAttributes[ name ];
if ( geometryAttribute !== undefined ) { if ( geometryAttribute !== undefined ) {
var normalized = geometryAttribute.normalized; const normalized = geometryAttribute.normalized;
var size = geometryAttribute.itemSize; const size = geometryAttribute.itemSize;
var attribute = attributes.get( geometryAttribute ); const attribute = attributes.get( geometryAttribute );
// TODO Attribute may not be available on context restore // TODO Attribute may not be available on context restore
if ( attribute === undefined ) continue; if ( attribute === undefined ) continue;
var buffer = attribute.buffer; const buffer = attribute.buffer;
var type = attribute.type; const type = attribute.type;
var bytesPerElement = attribute.bytesPerElement; const bytesPerElement = attribute.bytesPerElement;
if ( geometryAttribute.isInterleavedBufferAttribute ) { if ( geometryAttribute.isInterleavedBufferAttribute ) {
var data = geometryAttribute.data; const data = geometryAttribute.data;
var stride = data.stride; const stride = data.stride;
var offset = geometryAttribute.offset; const offset = geometryAttribute.offset;
if ( data && data.isInstancedInterleavedBuffer ) { if ( data && data.isInstancedInterleavedBuffer ) {
...@@ -975,14 +975,14 @@ function WebGLRenderer( parameters ) { ...@@ -975,14 +975,14 @@ function WebGLRenderer( parameters ) {
} else if ( name === 'instanceMatrix' ) { } else if ( name === 'instanceMatrix' ) {
var attribute = attributes.get( object.instanceMatrix ); const attribute = attributes.get( object.instanceMatrix );
// TODO Attribute may not be available on context restore // TODO Attribute may not be available on context restore
if ( attribute === undefined ) continue; if ( attribute === undefined ) continue;
var buffer = attribute.buffer; const buffer = attribute.buffer;
var type = attribute.type; const type = attribute.type;
state.enableAttributeAndDivisor( programAttribute + 0, 1 ); state.enableAttributeAndDivisor( programAttribute + 0, 1 );
state.enableAttributeAndDivisor( programAttribute + 1, 1 ); state.enableAttributeAndDivisor( programAttribute + 1, 1 );
...@@ -998,7 +998,7 @@ function WebGLRenderer( parameters ) { ...@@ -998,7 +998,7 @@ function WebGLRenderer( parameters ) {
} else if ( materialDefaultAttributeValues !== undefined ) { } else if ( materialDefaultAttributeValues !== undefined ) {
var value = materialDefaultAttributeValues[ name ]; const value = materialDefaultAttributeValues[ name ];
if ( value !== undefined ) { if ( value !== undefined ) {
...@@ -1096,7 +1096,7 @@ function WebGLRenderer( parameters ) { ...@@ -1096,7 +1096,7 @@ function WebGLRenderer( parameters ) {
// Animation Loop // Animation Loop
var onAnimationFrameCallback = null; let onAnimationFrameCallback = null;
function onAnimationFrame( time ) { function onAnimationFrame( time ) {
...@@ -1105,7 +1105,7 @@ function WebGLRenderer( parameters ) { ...@@ -1105,7 +1105,7 @@ function WebGLRenderer( parameters ) {
} }
var animation = new WebGLAnimation(); const animation = new WebGLAnimation();
animation.setAnimationLoop( onAnimationFrame ); animation.setAnimationLoop( onAnimationFrame );
if ( typeof window !== 'undefined' ) animation.setContext( window ); if ( typeof window !== 'undefined' ) animation.setContext( window );
...@@ -1123,7 +1123,7 @@ function WebGLRenderer( parameters ) { ...@@ -1123,7 +1123,7 @@ function WebGLRenderer( parameters ) {
this.render = function ( scene, camera ) { this.render = function ( scene, camera ) {
var renderTarget, forceClear; let renderTarget, forceClear;
if ( arguments[ 2 ] !== undefined ) { if ( arguments[ 2 ] !== undefined ) {
...@@ -1199,7 +1199,7 @@ function WebGLRenderer( parameters ) { ...@@ -1199,7 +1199,7 @@ function WebGLRenderer( parameters ) {
if ( _clippingEnabled ) _clipping.beginShadows(); if ( _clippingEnabled ) _clipping.beginShadows();
var shadowsArray = currentRenderState.state.shadowsArray; const shadowsArray = currentRenderState.state.shadowsArray;
shadowMap.render( shadowsArray, scene, camera ); shadowMap.render( shadowsArray, scene, camera );
...@@ -1223,12 +1223,12 @@ function WebGLRenderer( parameters ) { ...@@ -1223,12 +1223,12 @@ function WebGLRenderer( parameters ) {
// render scene // render scene
var opaqueObjects = currentRenderList.opaque; const opaqueObjects = currentRenderList.opaque;
var transparentObjects = currentRenderList.transparent; const transparentObjects = currentRenderList.transparent;
if ( scene.overrideMaterial ) { if ( scene.overrideMaterial ) {
var overrideMaterial = scene.overrideMaterial; const overrideMaterial = scene.overrideMaterial;
if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial ); if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial ); if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
...@@ -1282,7 +1282,7 @@ function WebGLRenderer( parameters ) { ...@@ -1282,7 +1282,7 @@ function WebGLRenderer( parameters ) {
if ( object.visible === false ) return; if ( object.visible === false ) return;
var visible = object.layers.test( camera.layers ); const visible = object.layers.test( camera.layers );
if ( visible ) { if ( visible ) {
...@@ -1315,8 +1315,8 @@ function WebGLRenderer( parameters ) { ...@@ -1315,8 +1315,8 @@ function WebGLRenderer( parameters ) {
} }
var geometry = objects.update( object ); const geometry = objects.update( object );
var material = object.material; const material = object.material;
if ( material.visible ) { if ( material.visible ) {
...@@ -1361,17 +1361,17 @@ function WebGLRenderer( parameters ) { ...@@ -1361,17 +1361,17 @@ function WebGLRenderer( parameters ) {
} }
var geometry = objects.update( object ); const geometry = objects.update( object );
var material = object.material; const material = object.material;
if ( Array.isArray( material ) ) { if ( Array.isArray( material ) ) {
var groups = geometry.groups; const groups = geometry.groups;
for ( var i = 0, l = groups.length; i < l; i ++ ) { for ( let i = 0, l = groups.length; i < l; i ++ ) {
var group = groups[ i ]; const group = groups[ i ];
var groupMaterial = material[ group.materialIndex ]; const groupMaterial = material[ group.materialIndex ];
if ( groupMaterial && groupMaterial.visible ) { if ( groupMaterial && groupMaterial.visible ) {
...@@ -1393,9 +1393,9 @@ function WebGLRenderer( parameters ) { ...@@ -1393,9 +1393,9 @@ function WebGLRenderer( parameters ) {
} }
var children = object.children; const children = object.children;
for ( var i = 0, l = children.length; i < l; i ++ ) { for ( let i = 0, l = children.length; i < l; i ++ ) {
projectObject( children[ i ], camera, groupOrder, sortObjects ); projectObject( children[ i ], camera, groupOrder, sortObjects );
...@@ -1405,24 +1405,24 @@ function WebGLRenderer( parameters ) { ...@@ -1405,24 +1405,24 @@ function WebGLRenderer( parameters ) {
function renderObjects( renderList, scene, camera, overrideMaterial ) { function renderObjects( renderList, scene, camera, overrideMaterial ) {
for ( var i = 0, l = renderList.length; i < l; i ++ ) { for ( let i = 0, l = renderList.length; i < l; i ++ ) {
var renderItem = renderList[ i ]; const renderItem = renderList[ i ];
var object = renderItem.object; const object = renderItem.object;
var geometry = renderItem.geometry; const geometry = renderItem.geometry;
var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial; const material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
var group = renderItem.group; const group = renderItem.group;
if ( camera.isArrayCamera ) { if ( camera.isArrayCamera ) {
_currentArrayCamera = camera; _currentArrayCamera = camera;
var cameras = camera.cameras; const cameras = camera.cameras;
for ( var j = 0, jl = cameras.length; j < jl; j ++ ) { for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
var camera2 = cameras[ j ]; const camera2 = cameras[ j ];
if ( object.layers.test( camera2.layers ) ) { if ( object.layers.test( camera2.layers ) ) {
...@@ -1458,7 +1458,7 @@ function WebGLRenderer( parameters ) { ...@@ -1458,7 +1458,7 @@ function WebGLRenderer( parameters ) {
if ( object.isImmediateRenderObject ) { if ( object.isImmediateRenderObject ) {
var program = setProgram( camera, scene, material, object ); const program = setProgram( camera, scene, material, object );
state.setMaterial( material ); state.setMaterial( material );
...@@ -1481,18 +1481,18 @@ function WebGLRenderer( parameters ) { ...@@ -1481,18 +1481,18 @@ function WebGLRenderer( parameters ) {
function initMaterial( material, scene, object ) { function initMaterial( material, scene, object ) {
var materialProperties = properties.get( material ); const materialProperties = properties.get( material );
var lights = currentRenderState.state.lights; const lights = currentRenderState.state.lights;
var shadowsArray = currentRenderState.state.shadowsArray; const shadowsArray = currentRenderState.state.shadowsArray;
var lightsStateVersion = lights.state.version; const lightsStateVersion = lights.state.version;
var parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object ); const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
var programCacheKey = programCache.getProgramCacheKey( parameters ); const programCacheKey = programCache.getProgramCacheKey( parameters );
var program = materialProperties.program; let program = materialProperties.program;
var programChange = true; let programChange = true;
if ( program === undefined ) { if ( program === undefined ) {
...@@ -1533,13 +1533,13 @@ function WebGLRenderer( parameters ) { ...@@ -1533,13 +1533,13 @@ function WebGLRenderer( parameters ) {
} }
var programAttributes = program.getAttributes(); const programAttributes = program.getAttributes();
if ( material.morphTargets ) { if ( material.morphTargets ) {
material.numSupportedMorphTargets = 0; material.numSupportedMorphTargets = 0;
for ( var i = 0; i < _this.maxMorphTargets; i ++ ) { for ( let i = 0; i < _this.maxMorphTargets; i ++ ) {
if ( programAttributes[ 'morphTarget' + i ] >= 0 ) { if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
...@@ -1555,7 +1555,7 @@ function WebGLRenderer( parameters ) { ...@@ -1555,7 +1555,7 @@ function WebGLRenderer( parameters ) {
material.numSupportedMorphNormals = 0; material.numSupportedMorphNormals = 0;
for ( var i = 0; i < _this.maxMorphNormals; i ++ ) { for ( let i = 0; i < _this.maxMorphNormals; i ++ ) {
if ( programAttributes[ 'morphNormal' + i ] >= 0 ) { if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
...@@ -1567,7 +1567,7 @@ function WebGLRenderer( parameters ) { ...@@ -1567,7 +1567,7 @@ function WebGLRenderer( parameters ) {
} }
var uniforms = materialProperties.uniforms; const uniforms = materialProperties.uniforms;
if ( ! material.isShaderMaterial && if ( ! material.isShaderMaterial &&
! material.isRawShaderMaterial || ! material.isRawShaderMaterial ||
...@@ -1612,7 +1612,7 @@ function WebGLRenderer( parameters ) { ...@@ -1612,7 +1612,7 @@ function WebGLRenderer( parameters ) {
} }
var progUniforms = materialProperties.program.getUniforms(), const progUniforms = materialProperties.program.getUniforms(),
uniformsList = uniformsList =
WebGLUniforms.seqWithValue( progUniforms.seq, uniforms ); WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
...@@ -1624,18 +1624,18 @@ function WebGLRenderer( parameters ) { ...@@ -1624,18 +1624,18 @@ function WebGLRenderer( parameters ) {
textures.resetTextureUnits(); textures.resetTextureUnits();
var fog = scene.fog; const fog = scene.fog;
var environment = material.isMeshStandardMaterial ? scene.environment : null; const environment = material.isMeshStandardMaterial ? scene.environment : null;
var encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding; const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
var materialProperties = properties.get( material ); const materialProperties = properties.get( material );
var lights = currentRenderState.state.lights; const lights = currentRenderState.state.lights;
if ( _clippingEnabled ) { if ( _clippingEnabled ) {
if ( _localClippingEnabled || camera !== _currentCamera ) { if ( _localClippingEnabled || camera !== _currentCamera ) {
var useCache = const useCache =
camera === _currentCamera && camera === _currentCamera &&
material.id === _currentMaterialId; material.id === _currentMaterialId;
...@@ -1687,11 +1687,11 @@ function WebGLRenderer( parameters ) { ...@@ -1687,11 +1687,11 @@ function WebGLRenderer( parameters ) {
} }
var refreshProgram = false; let refreshProgram = false;
var refreshMaterial = false; let refreshMaterial = false;
var refreshLights = false; let refreshLights = false;
var program = materialProperties.program, const program = materialProperties.program,
p_uniforms = program.getUniforms(), p_uniforms = program.getUniforms(),
m_uniforms = materialProperties.uniforms; m_uniforms = materialProperties.uniforms;
...@@ -1744,7 +1744,7 @@ function WebGLRenderer( parameters ) { ...@@ -1744,7 +1744,7 @@ function WebGLRenderer( parameters ) {
material.isMeshStandardMaterial || material.isMeshStandardMaterial ||
material.envMap ) { material.envMap ) {
var uCamPos = p_uniforms.map.cameraPosition; const uCamPos = p_uniforms.map.cameraPosition;
if ( uCamPos !== undefined ) { if ( uCamPos !== undefined ) {
...@@ -1789,11 +1789,11 @@ function WebGLRenderer( parameters ) { ...@@ -1789,11 +1789,11 @@ function WebGLRenderer( parameters ) {
p_uniforms.setOptional( _gl, object, 'bindMatrix' ); p_uniforms.setOptional( _gl, object, 'bindMatrix' );
p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' ); p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
var skeleton = object.skeleton; const skeleton = object.skeleton;
if ( skeleton ) { if ( skeleton ) {
var bones = skeleton.bones; const bones = skeleton.bones;
if ( capabilities.floatVertexTextures ) { if ( capabilities.floatVertexTextures ) {
...@@ -1807,14 +1807,14 @@ function WebGLRenderer( parameters ) { ...@@ -1807,14 +1807,14 @@ function WebGLRenderer( parameters ) {
// 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64) // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix let size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
size = MathUtils.ceilPowerOfTwo( size ); size = MathUtils.ceilPowerOfTwo( size );
size = Math.max( size, 4 ); size = Math.max( size, 4 );
var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
boneMatrices.set( skeleton.boneMatrices ); // copy current values boneMatrices.set( skeleton.boneMatrices ); // copy current values
var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType ); const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
skeleton.boneMatrices = boneMatrices; skeleton.boneMatrices = boneMatrices;
skeleton.boneTexture = boneTexture; skeleton.boneTexture = boneTexture;
...@@ -1970,12 +1970,12 @@ function WebGLRenderer( parameters ) { ...@@ -1970,12 +1970,12 @@ function WebGLRenderer( parameters ) {
} }
var framebuffer = _framebuffer; let framebuffer = _framebuffer;
var isCube = false; let isCube = false;
if ( renderTarget ) { if ( renderTarget ) {
var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer; const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
if ( renderTarget.isWebGLCubeRenderTarget ) { if ( renderTarget.isWebGLCubeRenderTarget ) {
...@@ -2017,7 +2017,7 @@ function WebGLRenderer( parameters ) { ...@@ -2017,7 +2017,7 @@ function WebGLRenderer( parameters ) {
if ( isCube ) { if ( isCube ) {
var textureProperties = properties.get( renderTarget.texture ); const textureProperties = properties.get( renderTarget.texture );
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 ); _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
} }
...@@ -2033,7 +2033,7 @@ function WebGLRenderer( parameters ) { ...@@ -2033,7 +2033,7 @@ function WebGLRenderer( parameters ) {
} }
var framebuffer = properties.get( renderTarget ).__webglFramebuffer; let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) { if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
...@@ -2043,7 +2043,7 @@ function WebGLRenderer( parameters ) { ...@@ -2043,7 +2043,7 @@ function WebGLRenderer( parameters ) {
if ( framebuffer ) { if ( framebuffer ) {
var restore = false; let restore = false;
if ( framebuffer !== _currentFramebuffer ) { if ( framebuffer !== _currentFramebuffer ) {
...@@ -2055,9 +2055,9 @@ function WebGLRenderer( parameters ) { ...@@ -2055,9 +2055,9 @@ function WebGLRenderer( parameters ) {
try { try {
var texture = renderTarget.texture; const texture = renderTarget.texture;
var textureFormat = texture.format; const textureFormat = texture.format;
var textureType = texture.type; const textureType = texture.type;
if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) { if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
...@@ -2109,10 +2109,10 @@ function WebGLRenderer( parameters ) { ...@@ -2109,10 +2109,10 @@ function WebGLRenderer( parameters ) {
if ( level === undefined ) level = 0; if ( level === undefined ) level = 0;
var levelScale = Math.pow( 2, - level ); const levelScale = Math.pow( 2, - level );
var width = Math.floor( texture.image.width * levelScale ); const width = Math.floor( texture.image.width * levelScale );
var height = Math.floor( texture.image.height * levelScale ); const height = Math.floor( texture.image.height * levelScale );
var glFormat = utils.convert( texture.format ); const glFormat = utils.convert( texture.format );
textures.setTexture2D( texture, 0 ); textures.setTexture2D( texture, 0 );
...@@ -2126,10 +2126,10 @@ function WebGLRenderer( parameters ) { ...@@ -2126,10 +2126,10 @@ function WebGLRenderer( parameters ) {
if ( level === undefined ) level = 0; if ( level === undefined ) level = 0;
var width = srcTexture.image.width; const width = srcTexture.image.width;
var height = srcTexture.image.height; const height = srcTexture.image.height;
var glFormat = utils.convert( dstTexture.format ); const glFormat = utils.convert( dstTexture.format );
var glType = utils.convert( dstTexture.type ); const glType = utils.convert( dstTexture.type );
textures.setTexture2D( dstTexture, 0 ); textures.setTexture2D( dstTexture, 0 );
......
...@@ -127,7 +127,7 @@ import shadow_vert from './ShaderLib/shadow_vert.glsl.js'; ...@@ -127,7 +127,7 @@ import shadow_vert from './ShaderLib/shadow_vert.glsl.js';
import sprite_frag from './ShaderLib/sprite_frag.glsl.js'; import sprite_frag from './ShaderLib/sprite_frag.glsl.js';
import sprite_vert from './ShaderLib/sprite_vert.glsl.js'; import sprite_vert from './ShaderLib/sprite_vert.glsl.js';
export var ShaderChunk = { export const ShaderChunk = {
alphamap_fragment: alphamap_fragment, alphamap_fragment: alphamap_fragment,
alphamap_pars_fragment: alphamap_pars_fragment, alphamap_pars_fragment: alphamap_pars_fragment,
alphatest_fragment: alphatest_fragment, alphatest_fragment: alphatest_fragment,
......
...@@ -12,7 +12,7 @@ import { Matrix3 } from '../../math/Matrix3.js'; ...@@ -12,7 +12,7 @@ import { Matrix3 } from '../../math/Matrix3.js';
* @author mikael emtinger / http://gomo.se/ * @author mikael emtinger / http://gomo.se/
*/ */
var ShaderLib = { const ShaderLib = {
basic: { basic: {
......
...@@ -6,7 +6,7 @@ import { Matrix3 } from '../../math/Matrix3.js'; ...@@ -6,7 +6,7 @@ import { Matrix3 } from '../../math/Matrix3.js';
* Uniforms library for shared webgl shaders * Uniforms library for shared webgl shaders
*/ */
var UniformsLib = { const UniformsLib = {
common: { common: {
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
export function cloneUniforms( src ) { export function cloneUniforms( src ) {
var dst = {}; const dst = {};
for ( var u in src ) { for ( const u in src ) {
dst[ u ] = {}; dst[ u ] = {};
for ( var p in src[ u ] ) { for ( const p in src[ u ] ) {
var property = src[ u ][ p ]; const property = src[ u ][ p ];
if ( property && ( property.isColor || if ( property && ( property.isColor ||
property.isMatrix3 || property.isMatrix4 || property.isMatrix3 || property.isMatrix4 ||
...@@ -41,13 +41,13 @@ export function cloneUniforms( src ) { ...@@ -41,13 +41,13 @@ export function cloneUniforms( src ) {
export function mergeUniforms( uniforms ) { export function mergeUniforms( uniforms ) {
var merged = {}; const merged = {};
for ( var u = 0; u < uniforms.length; u ++ ) { for ( let u = 0; u < uniforms.length; u ++ ) {
var tmp = cloneUniforms( uniforms[ u ] ); const tmp = cloneUniforms( uniforms[ u ] );
for ( var p in tmp ) { for ( const p in tmp ) {
merged[ p ] = tmp[ p ]; merged[ p ] = tmp[ p ];
...@@ -61,6 +61,6 @@ export function mergeUniforms( uniforms ) { ...@@ -61,6 +61,6 @@ export function mergeUniforms( uniforms ) {
// Legacy // Legacy
var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms }; const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
export { UniformsUtils }; export { UniformsUtils };
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
function WebGLAnimation() { function WebGLAnimation() {
var context = null; let context = null;
var isAnimating = false; let isAnimating = false;
var animationLoop = null; let animationLoop = null;
function onAnimationFrame( time, frame ) { function onAnimationFrame( time, frame ) {
......
...@@ -4,23 +4,23 @@ ...@@ -4,23 +4,23 @@
function WebGLAttributes( gl, capabilities ) { function WebGLAttributes( gl, capabilities ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
var buffers = new WeakMap(); const buffers = new WeakMap();
function createBuffer( attribute, bufferType ) { function createBuffer( attribute, bufferType ) {
var array = attribute.array; const array = attribute.array;
var usage = attribute.usage; const usage = attribute.usage;
var buffer = gl.createBuffer(); const buffer = gl.createBuffer();
gl.bindBuffer( bufferType, buffer ); gl.bindBuffer( bufferType, buffer );
gl.bufferData( bufferType, array, usage ); gl.bufferData( bufferType, array, usage );
attribute.onUploadCallback(); attribute.onUploadCallback();
var type = gl.FLOAT; let type = gl.FLOAT;
if ( array instanceof Float32Array ) { if ( array instanceof Float32Array ) {
...@@ -67,8 +67,8 @@ function WebGLAttributes( gl, capabilities ) { ...@@ -67,8 +67,8 @@ function WebGLAttributes( gl, capabilities ) {
function updateBuffer( buffer, attribute, bufferType ) { function updateBuffer( buffer, attribute, bufferType ) {
var array = attribute.array; const array = attribute.array;
var updateRange = attribute.updateRange; const updateRange = attribute.updateRange;
gl.bindBuffer( bufferType, buffer ); gl.bindBuffer( bufferType, buffer );
...@@ -112,7 +112,7 @@ function WebGLAttributes( gl, capabilities ) { ...@@ -112,7 +112,7 @@ function WebGLAttributes( gl, capabilities ) {
if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
var data = buffers.get( attribute ); const data = buffers.get( attribute );
if ( data ) { if ( data ) {
...@@ -128,7 +128,7 @@ function WebGLAttributes( gl, capabilities ) { ...@@ -128,7 +128,7 @@ function WebGLAttributes( gl, capabilities ) {
if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
var data = buffers.get( attribute ); const data = buffers.get( attribute );
if ( data === undefined ) { if ( data === undefined ) {
......
...@@ -13,25 +13,25 @@ import { cloneUniforms } from '../shaders/UniformsUtils.js'; ...@@ -13,25 +13,25 @@ import { cloneUniforms } from '../shaders/UniformsUtils.js';
function WebGLBackground( renderer, state, objects, premultipliedAlpha ) { function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
var clearColor = new Color( 0x000000 ); const clearColor = new Color( 0x000000 );
var clearAlpha = 0; let clearAlpha = 0;
var planeMesh; let planeMesh;
var boxMesh; let boxMesh;
var currentBackground = null; let currentBackground = null;
var currentBackgroundVersion = 0; let currentBackgroundVersion = 0;
var currentTonemapping = null; let currentTonemapping = null;
function render( renderList, scene, camera, forceClear ) { function render( renderList, scene, camera, forceClear ) {
var background = scene.background; let background = scene.background;
// Ignore background in AR // Ignore background in AR
// TODO: Reconsider this. // TODO: Reconsider this.
var xr = renderer.xr; const xr = renderer.xr;
var session = xr.getSession && xr.getSession(); const session = xr.getSession && xr.getSession();
if ( session && session.environmentBlendMode === 'additive' ) { if ( session && session.environmentBlendMode === 'additive' ) {
...@@ -98,7 +98,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) { ...@@ -98,7 +98,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
} }
var texture = background.isWebGLCubeRenderTarget ? background.texture : background; const texture = background.isWebGLCubeRenderTarget ? background.texture : background;
boxMesh.material.uniforms.envMap.value = texture; boxMesh.material.uniforms.envMap.value = texture;
boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1; boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1;
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
function WebGLBufferRenderer( gl, extensions, info, capabilities ) { function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
var mode; let mode;
function setMode( value ) { function setMode( value ) {
...@@ -26,7 +26,7 @@ function WebGLBufferRenderer( gl, extensions, info, capabilities ) { ...@@ -26,7 +26,7 @@ function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
if ( primcount === 0 ) return; if ( primcount === 0 ) return;
var extension, methodName; let extension, methodName;
if ( isWebGL2 ) { if ( isWebGL2 ) {
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
function WebGLCapabilities( gl, extensions, parameters ) { function WebGLCapabilities( gl, extensions, parameters ) {
var maxAnisotropy; let maxAnisotropy;
function getMaxAnisotropy() { function getMaxAnisotropy() {
if ( maxAnisotropy !== undefined ) return maxAnisotropy; if ( maxAnisotropy !== undefined ) return maxAnisotropy;
var extension = extensions.get( 'EXT_texture_filter_anisotropic' ); const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
if ( extension !== null ) { if ( extension !== null ) {
...@@ -57,12 +57,12 @@ function WebGLCapabilities( gl, extensions, parameters ) { ...@@ -57,12 +57,12 @@ function WebGLCapabilities( gl, extensions, parameters ) {
} }
/* eslint-disable no-undef */ /* eslint-disable no-undef */
var isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) || const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext ); ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
/* eslint-enable no-undef */ /* eslint-enable no-undef */
var precision = parameters.precision !== undefined ? parameters.precision : 'highp'; let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
var maxPrecision = getMaxPrecision( precision ); const maxPrecision = getMaxPrecision( precision );
if ( maxPrecision !== precision ) { if ( maxPrecision !== precision ) {
...@@ -71,23 +71,23 @@ function WebGLCapabilities( gl, extensions, parameters ) { ...@@ -71,23 +71,23 @@ function WebGLCapabilities( gl, extensions, parameters ) {
} }
var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true; const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS ); const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ); const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE ); const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE ); const maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS ); const maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS ); const maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS ); const maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS ); const maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
var vertexTextures = maxVertexTextures > 0; const vertexTextures = maxVertexTextures > 0;
var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' ); const floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
var floatVertexTextures = vertexTextures && floatFragmentTextures; const floatVertexTextures = vertexTextures && floatFragmentTextures;
var maxSamples = isWebGL2 ? gl.getParameter( gl.MAX_SAMPLES ) : 0; const maxSamples = isWebGL2 ? gl.getParameter( gl.MAX_SAMPLES ) : 0;
return { return {
......
...@@ -7,14 +7,14 @@ import { Plane } from '../../math/Plane.js'; ...@@ -7,14 +7,14 @@ import { Plane } from '../../math/Plane.js';
function WebGLClipping() { function WebGLClipping() {
var scope = this, const scope = this;
globalState = null, let globalState = null,
numGlobalPlanes = 0, numGlobalPlanes = 0,
localClippingEnabled = false, localClippingEnabled = false,
renderingShadows = false, renderingShadows = false;
plane = new Plane(), const plane = new Plane(),
viewNormalMatrix = new Matrix3(), viewNormalMatrix = new Matrix3(),
uniform = { value: null, needsUpdate: false }; uniform = { value: null, needsUpdate: false };
...@@ -25,7 +25,7 @@ function WebGLClipping() { ...@@ -25,7 +25,7 @@ function WebGLClipping() {
this.init = function ( planes, enableLocalClipping, camera ) { this.init = function ( planes, enableLocalClipping, camera ) {
var enabled = const enabled =
planes.length !== 0 || planes.length !== 0 ||
enableLocalClipping || enableLocalClipping ||
// enable state of previous frame - the clipping code has to // enable state of previous frame - the clipping code has to
...@@ -76,16 +76,16 @@ function WebGLClipping() { ...@@ -76,16 +76,16 @@ function WebGLClipping() {
} else { } else {
var nGlobal = renderingShadows ? 0 : numGlobalPlanes, const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
lGlobal = nGlobal * 4, lGlobal = nGlobal * 4;
dstArray = cache.clippingState || null; let dstArray = cache.clippingState || null;
uniform.value = dstArray; // ensure unique state uniform.value = dstArray; // ensure unique state
dstArray = projectPlanes( planes, camera, lGlobal, fromCache ); dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
for ( var i = 0; i !== lGlobal; ++ i ) { for ( let i = 0; i !== lGlobal; ++ i ) {
dstArray[ i ] = globalState[ i ]; dstArray[ i ] = globalState[ i ];
...@@ -116,7 +116,7 @@ function WebGLClipping() { ...@@ -116,7 +116,7 @@ function WebGLClipping() {
function projectPlanes( planes, camera, dstOffset, skipTransform ) { function projectPlanes( planes, camera, dstOffset, skipTransform ) {
var nPlanes = planes !== null ? planes.length : 0, let nPlanes = planes !== null ? planes.length : 0,
dstArray = null; dstArray = null;
if ( nPlanes !== 0 ) { if ( nPlanes !== 0 ) {
...@@ -125,7 +125,7 @@ function WebGLClipping() { ...@@ -125,7 +125,7 @@ function WebGLClipping() {
if ( skipTransform !== true || dstArray === null ) { if ( skipTransform !== true || dstArray === null ) {
var flatSize = dstOffset + nPlanes * 4, const flatSize = dstOffset + nPlanes * 4,
viewMatrix = camera.matrixWorldInverse; viewMatrix = camera.matrixWorldInverse;
viewNormalMatrix.getNormalMatrix( viewMatrix ); viewNormalMatrix.getNormalMatrix( viewMatrix );
...@@ -136,7 +136,7 @@ function WebGLClipping() { ...@@ -136,7 +136,7 @@ function WebGLClipping() {
} }
for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) { for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix ); plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
function WebGLExtensions( gl ) { function WebGLExtensions( gl ) {
var extensions = {}; const extensions = {};
return { return {
...@@ -16,7 +16,7 @@ function WebGLExtensions( gl ) { ...@@ -16,7 +16,7 @@ function WebGLExtensions( gl ) {
} }
var extension; let extension;
switch ( name ) { switch ( name ) {
......
...@@ -8,13 +8,13 @@ import { arrayMax } from '../../utils.js'; ...@@ -8,13 +8,13 @@ import { arrayMax } from '../../utils.js';
function WebGLGeometries( gl, attributes, info ) { function WebGLGeometries( gl, attributes, info ) {
var geometries = new WeakMap(); const geometries = new WeakMap();
var wireframeAttributes = new WeakMap(); const wireframeAttributes = new WeakMap();
function onGeometryDispose( event ) { function onGeometryDispose( event ) {
var geometry = event.target; const geometry = event.target;
var buffergeometry = geometries.get( geometry ); const buffergeometry = geometries.get( geometry );
if ( buffergeometry.index !== null ) { if ( buffergeometry.index !== null ) {
...@@ -22,7 +22,7 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -22,7 +22,7 @@ function WebGLGeometries( gl, attributes, info ) {
} }
for ( var name in buffergeometry.attributes ) { for ( const name in buffergeometry.attributes ) {
attributes.remove( buffergeometry.attributes[ name ] ); attributes.remove( buffergeometry.attributes[ name ] );
...@@ -32,7 +32,7 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -32,7 +32,7 @@ function WebGLGeometries( gl, attributes, info ) {
geometries.delete( geometry ); geometries.delete( geometry );
var attribute = wireframeAttributes.get( buffergeometry ); const attribute = wireframeAttributes.get( buffergeometry );
if ( attribute ) { if ( attribute ) {
...@@ -49,7 +49,7 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -49,7 +49,7 @@ function WebGLGeometries( gl, attributes, info ) {
function get( object, geometry ) { function get( object, geometry ) {
var buffergeometry = geometries.get( geometry ); let buffergeometry = geometries.get( geometry );
if ( buffergeometry ) return buffergeometry; if ( buffergeometry ) return buffergeometry;
...@@ -81,8 +81,8 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -81,8 +81,8 @@ function WebGLGeometries( gl, attributes, info ) {
function update( geometry ) { function update( geometry ) {
var index = geometry.index; const index = geometry.index;
var geometryAttributes = geometry.attributes; const geometryAttributes = geometry.attributes;
if ( index !== null ) { if ( index !== null ) {
...@@ -90,7 +90,7 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -90,7 +90,7 @@ function WebGLGeometries( gl, attributes, info ) {
} }
for ( var name in geometryAttributes ) { for ( const name in geometryAttributes ) {
attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER ); attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
...@@ -98,13 +98,13 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -98,13 +98,13 @@ function WebGLGeometries( gl, attributes, info ) {
// morph targets // morph targets
var morphAttributes = geometry.morphAttributes; const morphAttributes = geometry.morphAttributes;
for ( var name in morphAttributes ) { for ( const name in morphAttributes ) {
var array = morphAttributes[ name ]; const array = morphAttributes[ name ];
for ( var i = 0, l = array.length; i < l; i ++ ) { for ( let i = 0, l = array.length; i < l; i ++ ) {
attributes.update( array[ i ], gl.ARRAY_BUFFER ); attributes.update( array[ i ], gl.ARRAY_BUFFER );
...@@ -116,22 +116,22 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -116,22 +116,22 @@ function WebGLGeometries( gl, attributes, info ) {
function updateWireframeAttribute( geometry ) { function updateWireframeAttribute( geometry ) {
var indices = []; const indices = [];
var geometryIndex = geometry.index; const geometryIndex = geometry.index;
var geometryPosition = geometry.attributes.position; const geometryPosition = geometry.attributes.position;
var version = 0; let version = 0;
if ( geometryIndex !== null ) { if ( geometryIndex !== null ) {
var array = geometryIndex.array; const array = geometryIndex.array;
version = geometryIndex.version; version = geometryIndex.version;
for ( var i = 0, l = array.length; i < l; i += 3 ) { for ( let i = 0, l = array.length; i < l; i += 3 ) {
var a = array[ i + 0 ]; const a = array[ i + 0 ];
var b = array[ i + 1 ]; const b = array[ i + 1 ];
var c = array[ i + 2 ]; const c = array[ i + 2 ];
indices.push( a, b, b, c, c, a ); indices.push( a, b, b, c, c, a );
...@@ -139,14 +139,14 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -139,14 +139,14 @@ function WebGLGeometries( gl, attributes, info ) {
} else { } else {
var array = geometryPosition.array; const array = geometryPosition.array;
version = geometryPosition.version; version = geometryPosition.version;
for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) { for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
var a = i + 0; const a = i + 0;
var b = i + 1; const b = i + 1;
var c = i + 2; const c = i + 2;
indices.push( a, b, b, c, c, a ); indices.push( a, b, b, c, c, a );
...@@ -154,14 +154,14 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -154,14 +154,14 @@ function WebGLGeometries( gl, attributes, info ) {
} }
var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
attribute.version = version; attribute.version = version;
attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER ); attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
// //
var previousAttribute = wireframeAttributes.get( geometry ); const previousAttribute = wireframeAttributes.get( geometry );
if ( previousAttribute ) attributes.remove( previousAttribute ); if ( previousAttribute ) attributes.remove( previousAttribute );
...@@ -173,11 +173,11 @@ function WebGLGeometries( gl, attributes, info ) { ...@@ -173,11 +173,11 @@ function WebGLGeometries( gl, attributes, info ) {
function getWireframeAttribute( geometry ) { function getWireframeAttribute( geometry ) {
var currentAttribute = wireframeAttributes.get( geometry ); const currentAttribute = wireframeAttributes.get( geometry );
if ( currentAttribute ) { if ( currentAttribute ) {
var geometryIndex = geometry.index; const geometryIndex = geometry.index;
if ( geometryIndex !== null ) { if ( geometryIndex !== null ) {
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) { function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
var mode; let mode;
function setMode( value ) { function setMode( value ) {
...@@ -14,7 +14,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) { ...@@ -14,7 +14,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
} }
var type, bytesPerElement; let type, bytesPerElement;
function setIndex( value ) { function setIndex( value ) {
...@@ -35,7 +35,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) { ...@@ -35,7 +35,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
if ( primcount === 0 ) return; if ( primcount === 0 ) return;
var extension, methodName; let extension, methodName;
if ( isWebGL2 ) { if ( isWebGL2 ) {
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
function WebGLInfo( gl ) { function WebGLInfo( gl ) {
var memory = { const memory = {
geometries: 0, geometries: 0,
textures: 0 textures: 0
}; };
var render = { const render = {
frame: 0, frame: 0,
calls: 0, calls: 0,
triangles: 0, triangles: 0,
......
...@@ -9,7 +9,7 @@ import { Vector3 } from '../../math/Vector3.js'; ...@@ -9,7 +9,7 @@ import { Vector3 } from '../../math/Vector3.js';
function UniformsCache() { function UniformsCache() {
var lights = {}; const lights = {};
return { return {
...@@ -21,7 +21,7 @@ function UniformsCache() { ...@@ -21,7 +21,7 @@ function UniformsCache() {
} }
var uniforms; let uniforms;
switch ( light.type ) { switch ( light.type ) {
...@@ -84,7 +84,7 @@ function UniformsCache() { ...@@ -84,7 +84,7 @@ function UniformsCache() {
function ShadowUniformsCache() { function ShadowUniformsCache() {
var lights = {}; const lights = {};
return { return {
...@@ -96,7 +96,7 @@ function ShadowUniformsCache() { ...@@ -96,7 +96,7 @@ function ShadowUniformsCache() {
} }
var uniforms; let uniforms;
switch ( light.type ) { switch ( light.type ) {
...@@ -142,7 +142,7 @@ function ShadowUniformsCache() { ...@@ -142,7 +142,7 @@ function ShadowUniformsCache() {
var nextVersion = 0; let nextVersion = 0;
function shadowCastingLightsFirst( lightA, lightB ) { function shadowCastingLightsFirst( lightA, lightB ) {
...@@ -152,11 +152,11 @@ function shadowCastingLightsFirst( lightA, lightB ) { ...@@ -152,11 +152,11 @@ function shadowCastingLightsFirst( lightA, lightB ) {
function WebGLLights() { function WebGLLights() {
var cache = new UniformsCache(); const cache = new UniformsCache();
var shadowCache = ShadowUniformsCache(); const shadowCache = ShadowUniformsCache();
var state = { const state = {
version: 0, version: 0,
...@@ -191,41 +191,41 @@ function WebGLLights() { ...@@ -191,41 +191,41 @@ function WebGLLights() {
}; };
for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() ); for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
var vector3 = new Vector3(); const vector3 = new Vector3();
var matrix4 = new Matrix4(); const matrix4 = new Matrix4();
var matrix42 = new Matrix4(); const matrix42 = new Matrix4();
function setup( lights, shadows, camera ) { function setup( lights, shadows, camera ) {
var r = 0, g = 0, b = 0; let r = 0, g = 0, b = 0;
for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 ); for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
var directionalLength = 0; let directionalLength = 0;
var pointLength = 0; let pointLength = 0;
var spotLength = 0; let spotLength = 0;
var rectAreaLength = 0; let rectAreaLength = 0;
var hemiLength = 0; let hemiLength = 0;
var numDirectionalShadows = 0; let numDirectionalShadows = 0;
var numPointShadows = 0; let numPointShadows = 0;
var numSpotShadows = 0; let numSpotShadows = 0;
var viewMatrix = camera.matrixWorldInverse; const viewMatrix = camera.matrixWorldInverse;
lights.sort( shadowCastingLightsFirst ); lights.sort( shadowCastingLightsFirst );
for ( var i = 0, l = lights.length; i < l; i ++ ) { for ( let i = 0, l = lights.length; i < l; i ++ ) {
var light = lights[ i ]; const light = lights[ i ];
var color = light.color; const color = light.color;
var intensity = light.intensity; const intensity = light.intensity;
var distance = light.distance; const distance = light.distance;
var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null; const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
if ( light.isAmbientLight ) { if ( light.isAmbientLight ) {
...@@ -235,7 +235,7 @@ function WebGLLights() { ...@@ -235,7 +235,7 @@ function WebGLLights() {
} else if ( light.isLightProbe ) { } else if ( light.isLightProbe ) {
for ( var j = 0; j < 9; j ++ ) { for ( let j = 0; j < 9; j ++ ) {
state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity ); state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
...@@ -243,7 +243,7 @@ function WebGLLights() { ...@@ -243,7 +243,7 @@ function WebGLLights() {
} else if ( light.isDirectionalLight ) { } else if ( light.isDirectionalLight ) {
var uniforms = cache.get( light ); const uniforms = cache.get( light );
uniforms.color.copy( light.color ).multiplyScalar( light.intensity ); uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.direction.setFromMatrixPosition( light.matrixWorld ); uniforms.direction.setFromMatrixPosition( light.matrixWorld );
...@@ -253,9 +253,9 @@ function WebGLLights() { ...@@ -253,9 +253,9 @@ function WebGLLights() {
if ( light.castShadow ) { if ( light.castShadow ) {
var shadow = light.shadow; const shadow = light.shadow;
var shadowUniforms = shadowCache.get( light ); const shadowUniforms = shadowCache.get( light );
shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowRadius = shadow.radius;
...@@ -275,7 +275,7 @@ function WebGLLights() { ...@@ -275,7 +275,7 @@ function WebGLLights() {
} else if ( light.isSpotLight ) { } else if ( light.isSpotLight ) {
var uniforms = cache.get( light ); const uniforms = cache.get( light );
uniforms.position.setFromMatrixPosition( light.matrixWorld ); uniforms.position.setFromMatrixPosition( light.matrixWorld );
uniforms.position.applyMatrix4( viewMatrix ); uniforms.position.applyMatrix4( viewMatrix );
...@@ -294,9 +294,9 @@ function WebGLLights() { ...@@ -294,9 +294,9 @@ function WebGLLights() {
if ( light.castShadow ) { if ( light.castShadow ) {
var shadow = light.shadow; const shadow = light.shadow;
var shadowUniforms = shadowCache.get( light ); const shadowUniforms = shadowCache.get( light );
shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowRadius = shadow.radius;
...@@ -316,7 +316,7 @@ function WebGLLights() { ...@@ -316,7 +316,7 @@ function WebGLLights() {
} else if ( light.isRectAreaLight ) { } else if ( light.isRectAreaLight ) {
var uniforms = cache.get( light ); const uniforms = cache.get( light );
// (a) intensity is the total visible light emitted // (a) intensity is the total visible light emitted
//uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) ); //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
...@@ -348,7 +348,7 @@ function WebGLLights() { ...@@ -348,7 +348,7 @@ function WebGLLights() {
} else if ( light.isPointLight ) { } else if ( light.isPointLight ) {
var uniforms = cache.get( light ); const uniforms = cache.get( light );
uniforms.position.setFromMatrixPosition( light.matrixWorld ); uniforms.position.setFromMatrixPosition( light.matrixWorld );
uniforms.position.applyMatrix4( viewMatrix ); uniforms.position.applyMatrix4( viewMatrix );
...@@ -359,9 +359,9 @@ function WebGLLights() { ...@@ -359,9 +359,9 @@ function WebGLLights() {
if ( light.castShadow ) { if ( light.castShadow ) {
var shadow = light.shadow; const shadow = light.shadow;
var shadowUniforms = shadowCache.get( light ); const shadowUniforms = shadowCache.get( light );
shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowRadius = shadow.radius;
...@@ -383,7 +383,7 @@ function WebGLLights() { ...@@ -383,7 +383,7 @@ function WebGLLights() {
} else if ( light.isHemisphereLight ) { } else if ( light.isHemisphereLight ) {
var uniforms = cache.get( light ); const uniforms = cache.get( light );
uniforms.direction.setFromMatrixPosition( light.matrixWorld ); uniforms.direction.setFromMatrixPosition( light.matrixWorld );
uniforms.direction.transformDirection( viewMatrix ); uniforms.direction.transformDirection( viewMatrix );
...@@ -404,7 +404,7 @@ function WebGLLights() { ...@@ -404,7 +404,7 @@ function WebGLLights() {
state.ambient[ 1 ] = g; state.ambient[ 1 ] = g;
state.ambient[ 2 ] = b; state.ambient[ 2 ] = b;
var hash = state.hash; const hash = state.hash;
if ( hash.directionalLength !== directionalLength || if ( hash.directionalLength !== directionalLength ||
hash.pointLength !== pointLength || hash.pointLength !== pointLength ||
......
...@@ -143,7 +143,7 @@ function WebGLMaterials( properties ) { ...@@ -143,7 +143,7 @@ function WebGLMaterials( properties ) {
} }
var envMap = material.envMap || environment; const envMap = material.envMap || environment;
if ( envMap ) { if ( envMap ) {
...@@ -180,7 +180,7 @@ function WebGLMaterials( properties ) { ...@@ -180,7 +180,7 @@ function WebGLMaterials( properties ) {
// 5. alpha map // 5. alpha map
// 6. emissive map // 6. emissive map
var uvScaleMap; let uvScaleMap;
if ( material.map ) { if ( material.map ) {
...@@ -243,7 +243,7 @@ function WebGLMaterials( properties ) { ...@@ -243,7 +243,7 @@ function WebGLMaterials( properties ) {
// 1. ao map // 1. ao map
// 2. light map // 2. light map
var uv2ScaleMap; let uv2ScaleMap;
if ( material.aoMap ) { if ( material.aoMap ) {
...@@ -314,7 +314,7 @@ function WebGLMaterials( properties ) { ...@@ -314,7 +314,7 @@ function WebGLMaterials( properties ) {
// 1. color map // 1. color map
// 2. alpha map // 2. alpha map
var uvScaleMap; let uvScaleMap;
if ( material.map ) { if ( material.map ) {
...@@ -362,7 +362,7 @@ function WebGLMaterials( properties ) { ...@@ -362,7 +362,7 @@ function WebGLMaterials( properties ) {
// 1. color map // 1. color map
// 2. alpha map // 2. alpha map
var uvScaleMap; let uvScaleMap;
if ( material.map ) { if ( material.map ) {
......
...@@ -10,19 +10,19 @@ function absNumericalSort( a, b ) { ...@@ -10,19 +10,19 @@ function absNumericalSort( a, b ) {
function WebGLMorphtargets( gl ) { function WebGLMorphtargets( gl ) {
var influencesList = {}; const influencesList = {};
var morphInfluences = new Float32Array( 8 ); const morphInfluences = new Float32Array( 8 );
function update( object, geometry, material, program ) { function update( object, geometry, material, program ) {
var objectInfluences = object.morphTargetInfluences; const objectInfluences = object.morphTargetInfluences;
// When object doesn't have morph target influences defined, we treat it as a 0-length array // When object doesn't have morph target influences defined, we treat it as a 0-length array
// This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
var length = objectInfluences === undefined ? 0 : objectInfluences.length; const length = objectInfluences === undefined ? 0 : objectInfluences.length;
var influences = influencesList[ geometry.id ]; let influences = influencesList[ geometry.id ];
if ( influences === undefined ) { if ( influences === undefined ) {
...@@ -30,7 +30,7 @@ function WebGLMorphtargets( gl ) { ...@@ -30,7 +30,7 @@ function WebGLMorphtargets( gl ) {
influences = []; influences = [];
for ( var i = 0; i < length; i ++ ) { for ( let i = 0; i < length; i ++ ) {
influences[ i ] = [ i, 0 ]; influences[ i ] = [ i, 0 ];
...@@ -40,14 +40,14 @@ function WebGLMorphtargets( gl ) { ...@@ -40,14 +40,14 @@ function WebGLMorphtargets( gl ) {
} }
var morphTargets = material.morphTargets && geometry.morphAttributes.position; const morphTargets = material.morphTargets && geometry.morphAttributes.position;
var morphNormals = material.morphNormals && geometry.morphAttributes.normal; const morphNormals = material.morphNormals && geometry.morphAttributes.normal;
// Remove current morphAttributes // Remove current morphAttributes
for ( var i = 0; i < length; i ++ ) { for ( let i = 0; i < length; i ++ ) {
var influence = influences[ i ]; const influence = influences[ i ];
if ( influence[ 1 ] !== 0 ) { if ( influence[ 1 ] !== 0 ) {
...@@ -60,9 +60,9 @@ function WebGLMorphtargets( gl ) { ...@@ -60,9 +60,9 @@ function WebGLMorphtargets( gl ) {
// Collect influences // Collect influences
for ( var i = 0; i < length; i ++ ) { for ( let i = 0; i < length; i ++ ) {
var influence = influences[ i ]; const influence = influences[ i ];
influence[ 0 ] = i; influence[ 0 ] = i;
influence[ 1 ] = objectInfluences[ i ]; influence[ 1 ] = objectInfluences[ i ];
...@@ -73,16 +73,16 @@ function WebGLMorphtargets( gl ) { ...@@ -73,16 +73,16 @@ function WebGLMorphtargets( gl ) {
// Add morphAttributes // Add morphAttributes
var morphInfluencesSum = 0; let morphInfluencesSum = 0;
for ( var i = 0; i < 8; i ++ ) { for ( let i = 0; i < 8; i ++ ) {
var influence = influences[ i ]; const influence = influences[ i ];
if ( influence ) { if ( influence ) {
var index = influence[ 0 ]; const index = influence[ 0 ];
var value = influence[ 1 ]; const value = influence[ 1 ];
if ( value ) { if ( value ) {
...@@ -104,7 +104,7 @@ function WebGLMorphtargets( gl ) { ...@@ -104,7 +104,7 @@ function WebGLMorphtargets( gl ) {
// GLSL shader uses formula baseinfluence * base + sum(target * influence) // GLSL shader uses formula baseinfluence * base + sum(target * influence)
// This allows us to switch between absolute morphs and relative morphs without changing shader code // This allows us to switch between absolute morphs and relative morphs without changing shader code
// When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence) // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence ); program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences ); program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
......
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
function WebGLObjects( gl, geometries, attributes, info ) { function WebGLObjects( gl, geometries, attributes, info ) {
var updateMap = new WeakMap(); let updateMap = new WeakMap();
function update( object ) { function update( object ) {
var frame = info.render.frame; const frame = info.render.frame;
var geometry = object.geometry; const geometry = object.geometry;
var buffergeometry = geometries.get( object, geometry ); const buffergeometry = geometries.get( object, geometry );
// Update once per frame // Update once per frame
......
...@@ -7,13 +7,13 @@ import { WebGLShader } from './WebGLShader.js'; ...@@ -7,13 +7,13 @@ import { WebGLShader } from './WebGLShader.js';
import { ShaderChunk } from '../shaders/ShaderChunk.js'; import { ShaderChunk } from '../shaders/ShaderChunk.js';
import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, EquirectangularRefractionMapping, CubeRefractionMapping, SphericalReflectionMapping, EquirectangularReflectionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, Uncharted2ToneMapping, ReinhardToneMapping, LinearToneMapping, GammaEncoding, RGBDEncoding, RGBM16Encoding, RGBM7Encoding, RGBEEncoding, sRGBEncoding, LinearEncoding, LogLuvEncoding } from '../../constants.js'; import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, EquirectangularRefractionMapping, CubeRefractionMapping, SphericalReflectionMapping, EquirectangularReflectionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, Uncharted2ToneMapping, ReinhardToneMapping, LinearToneMapping, GammaEncoding, RGBDEncoding, RGBM16Encoding, RGBM7Encoding, RGBEEncoding, sRGBEncoding, LinearEncoding, LogLuvEncoding } from '../../constants.js';
var programIdCount = 0; let programIdCount = 0;
function addLineNumbers( string ) { function addLineNumbers( string ) {
var lines = string.split( '\n' ); const lines = string.split( '\n' );
for ( var i = 0; i < lines.length; i ++ ) { for ( let i = 0; i < lines.length; i ++ ) {
lines[ i ] = ( i + 1 ) + ': ' + lines[ i ]; lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
...@@ -52,15 +52,15 @@ function getEncodingComponents( encoding ) { ...@@ -52,15 +52,15 @@ function getEncodingComponents( encoding ) {
function getShaderErrors( gl, shader, type ) { function getShaderErrors( gl, shader, type ) {
var status = gl.getShaderParameter( shader, gl.COMPILE_STATUS ); const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS );
var log = gl.getShaderInfoLog( shader ).trim(); const log = gl.getShaderInfoLog( shader ).trim();
if ( status && log === '' ) return ''; if ( status && log === '' ) return '';
// --enable-privileged-webgl-extension // --enable-privileged-webgl-extension
// console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) ); // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
var source = gl.getShaderSource( shader ); const source = gl.getShaderSource( shader );
return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source ); return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
...@@ -68,21 +68,21 @@ function getShaderErrors( gl, shader, type ) { ...@@ -68,21 +68,21 @@ function getShaderErrors( gl, shader, type ) {
function getTexelDecodingFunction( functionName, encoding ) { function getTexelDecodingFunction( functionName, encoding ) {
var components = getEncodingComponents( encoding ); const components = getEncodingComponents( encoding );
return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }'; return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
} }
function getTexelEncodingFunction( functionName, encoding ) { function getTexelEncodingFunction( functionName, encoding ) {
var components = getEncodingComponents( encoding ); const components = getEncodingComponents( encoding );
return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }'; return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
} }
function getToneMappingFunction( functionName, toneMapping ) { function getToneMappingFunction( functionName, toneMapping ) {
var toneMappingName; let toneMappingName;
switch ( toneMapping ) { switch ( toneMapping ) {
...@@ -117,7 +117,7 @@ function getToneMappingFunction( functionName, toneMapping ) { ...@@ -117,7 +117,7 @@ function getToneMappingFunction( functionName, toneMapping ) {
function generateExtensions( parameters ) { function generateExtensions( parameters ) {
var chunks = [ const chunks = [
( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '', ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '', ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '', ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
...@@ -130,11 +130,11 @@ function generateExtensions( parameters ) { ...@@ -130,11 +130,11 @@ function generateExtensions( parameters ) {
function generateDefines( defines ) { function generateDefines( defines ) {
var chunks = []; const chunks = [];
for ( var name in defines ) { for ( const name in defines ) {
var value = defines[ name ]; const value = defines[ name ];
if ( value === false ) continue; if ( value === false ) continue;
...@@ -148,14 +148,14 @@ function generateDefines( defines ) { ...@@ -148,14 +148,14 @@ function generateDefines( defines ) {
function fetchAttributeLocations( gl, program ) { function fetchAttributeLocations( gl, program ) {
var attributes = {}; const attributes = {};
var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES ); const n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
for ( var i = 0; i < n; i ++ ) { for ( let i = 0; i < n; i ++ ) {
var info = gl.getActiveAttrib( program, i ); const info = gl.getActiveAttrib( program, i );
var name = info.name; const name = info.name;
// console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i ); // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
...@@ -197,7 +197,7 @@ function replaceClippingPlaneNums( string, parameters ) { ...@@ -197,7 +197,7 @@ function replaceClippingPlaneNums( string, parameters ) {
// Resolve Includes // Resolve Includes
var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm; const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
function resolveIncludes( string ) { function resolveIncludes( string ) {
...@@ -207,7 +207,7 @@ function resolveIncludes( string ) { ...@@ -207,7 +207,7 @@ function resolveIncludes( string ) {
function includeReplacer( match, include ) { function includeReplacer( match, include ) {
var string = ShaderChunk[ include ]; const string = ShaderChunk[ include ];
if ( string === undefined ) { if ( string === undefined ) {
...@@ -221,8 +221,8 @@ function includeReplacer( match, include ) { ...@@ -221,8 +221,8 @@ function includeReplacer( match, include ) {
// Unroll Loops // Unroll Loops
var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g; const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
var unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g; const unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;
function unrollLoops( string ) { function unrollLoops( string ) {
...@@ -241,9 +241,9 @@ function deprecatedLoopReplacer( match, start, end, snippet ) { ...@@ -241,9 +241,9 @@ function deprecatedLoopReplacer( match, start, end, snippet ) {
function loopReplacer( match, start, end, snippet ) { function loopReplacer( match, start, end, snippet ) {
var string = ''; let string = '';
for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) { for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
string += snippet string += snippet
.replace( /\[ i \]/g, '[ ' + i + ' ]' ) .replace( /\[ i \]/g, '[ ' + i + ' ]' )
...@@ -259,7 +259,7 @@ function loopReplacer( match, start, end, snippet ) { ...@@ -259,7 +259,7 @@ function loopReplacer( match, start, end, snippet ) {
function generatePrecision( parameters ) { function generatePrecision( parameters ) {
var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;"; let precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
if ( parameters.precision === "highp" ) { if ( parameters.precision === "highp" ) {
...@@ -281,7 +281,7 @@ function generatePrecision( parameters ) { ...@@ -281,7 +281,7 @@ function generatePrecision( parameters ) {
function generateShadowMapTypeDefine( parameters ) { function generateShadowMapTypeDefine( parameters ) {
var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC'; let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
if ( parameters.shadowMapType === PCFShadowMap ) { if ( parameters.shadowMapType === PCFShadowMap ) {
...@@ -303,7 +303,7 @@ function generateShadowMapTypeDefine( parameters ) { ...@@ -303,7 +303,7 @@ function generateShadowMapTypeDefine( parameters ) {
function generateEnvMapTypeDefine( parameters ) { function generateEnvMapTypeDefine( parameters ) {
var envMapTypeDefine = 'ENVMAP_TYPE_CUBE'; let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
if ( parameters.envMap ) { if ( parameters.envMap ) {
...@@ -338,7 +338,7 @@ function generateEnvMapTypeDefine( parameters ) { ...@@ -338,7 +338,7 @@ function generateEnvMapTypeDefine( parameters ) {
function generateEnvMapModeDefine( parameters ) { function generateEnvMapModeDefine( parameters ) {
var envMapModeDefine = 'ENVMAP_MODE_REFLECTION'; let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
if ( parameters.envMap ) { if ( parameters.envMap ) {
...@@ -359,7 +359,7 @@ function generateEnvMapModeDefine( parameters ) { ...@@ -359,7 +359,7 @@ function generateEnvMapModeDefine( parameters ) {
function generateEnvMapBlendingDefine( parameters ) { function generateEnvMapBlendingDefine( parameters ) {
var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE'; let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
if ( parameters.envMap ) { if ( parameters.envMap ) {
...@@ -387,27 +387,28 @@ function generateEnvMapBlendingDefine( parameters ) { ...@@ -387,27 +387,28 @@ function generateEnvMapBlendingDefine( parameters ) {
function WebGLProgram( renderer, cacheKey, parameters ) { function WebGLProgram( renderer, cacheKey, parameters ) {
var gl = renderer.getContext(); const gl = renderer.getContext();
var defines = parameters.defines; const defines = parameters.defines;
var vertexShader = parameters.vertexShader; let vertexShader = parameters.vertexShader;
var fragmentShader = parameters.fragmentShader; let fragmentShader = parameters.fragmentShader;
var shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
var envMapTypeDefine = generateEnvMapTypeDefine( parameters );
var envMapModeDefine = generateEnvMapModeDefine( parameters );
var envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
const envMapModeDefine = generateEnvMapModeDefine( parameters );
const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
var customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters ); const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
var customDefines = generateDefines( defines ); const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
var program = gl.createProgram(); const customDefines = generateDefines( defines );
var prefixVertex, prefixFragment; const program = gl.createProgram();
let prefixVertex, prefixFragment;
if ( parameters.isRawShaderMaterial ) { if ( parameters.isRawShaderMaterial ) {
...@@ -668,9 +669,9 @@ function WebGLProgram( renderer, cacheKey, parameters ) { ...@@ -668,9 +669,9 @@ function WebGLProgram( renderer, cacheKey, parameters ) {
if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) { if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) {
var isGLSL3ShaderMaterial = false; let isGLSL3ShaderMaterial = false;
var versionRegex = /^\s*#version\s+300\s+es\s*\n/; const versionRegex = /^\s*#version\s+300\s+es\s*\n/;
if ( parameters.isShaderMaterial && if ( parameters.isShaderMaterial &&
vertexShader.match( versionRegex ) !== null && vertexShader.match( versionRegex ) !== null &&
...@@ -711,14 +712,14 @@ function WebGLProgram( renderer, cacheKey, parameters ) { ...@@ -711,14 +712,14 @@ function WebGLProgram( renderer, cacheKey, parameters ) {
} }
var vertexGlsl = prefixVertex + vertexShader; const vertexGlsl = prefixVertex + vertexShader;
var fragmentGlsl = prefixFragment + fragmentShader; const fragmentGlsl = prefixFragment + fragmentShader;
// console.log( '*VERTEX*', vertexGlsl ); // console.log( '*VERTEX*', vertexGlsl );
// console.log( '*FRAGMENT*', fragmentGlsl ); // console.log( '*FRAGMENT*', fragmentGlsl );
var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl ); const glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl ); const glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
gl.attachShader( program, glVertexShader ); gl.attachShader( program, glVertexShader );
gl.attachShader( program, glFragmentShader ); gl.attachShader( program, glFragmentShader );
...@@ -741,19 +742,19 @@ function WebGLProgram( renderer, cacheKey, parameters ) { ...@@ -741,19 +742,19 @@ function WebGLProgram( renderer, cacheKey, parameters ) {
// check for link errors // check for link errors
if ( renderer.debug.checkShaderErrors ) { if ( renderer.debug.checkShaderErrors ) {
var programLog = gl.getProgramInfoLog( program ).trim(); const programLog = gl.getProgramInfoLog( program ).trim();
var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim(); const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim(); const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
var runnable = true; let runnable = true;
var haveDiagnostics = true; let haveDiagnostics = true;
if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) { if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
runnable = false; runnable = false;
var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' ); const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' ); const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors ); console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
...@@ -806,7 +807,7 @@ function WebGLProgram( renderer, cacheKey, parameters ) { ...@@ -806,7 +807,7 @@ function WebGLProgram( renderer, cacheKey, parameters ) {
// set up caching for uniform locations // set up caching for uniform locations
var cachedUniforms; let cachedUniforms;
this.getUniforms = function () { this.getUniforms = function () {
...@@ -822,7 +823,7 @@ function WebGLProgram( renderer, cacheKey, parameters ) { ...@@ -822,7 +823,7 @@ function WebGLProgram( renderer, cacheKey, parameters ) {
// set up caching for attribute locations // set up caching for attribute locations
var cachedAttributes; let cachedAttributes;
this.getAttributes = function () { this.getAttributes = function () {
......
...@@ -9,16 +9,17 @@ import { UniformsUtils } from '../shaders/UniformsUtils.js'; ...@@ -9,16 +9,17 @@ import { UniformsUtils } from '../shaders/UniformsUtils.js';
function WebGLPrograms( renderer, extensions, capabilities ) { function WebGLPrograms( renderer, extensions, capabilities ) {
var programs = []; const programs = [];
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
var floatVertexTextures = capabilities.floatVertexTextures; const floatVertexTextures = capabilities.floatVertexTextures;
var precision = capabilities.precision; const maxVertexUniforms = capabilities.maxVertexUniforms;
var maxVertexUniforms = capabilities.maxVertexUniforms; const vertexTextures = capabilities.vertexTextures;
var vertexTextures = capabilities.vertexTextures;
var shaderIDs = { let precision = capabilities.precision;
const shaderIDs = {
MeshDepthMaterial: 'depth', MeshDepthMaterial: 'depth',
MeshDistanceMaterial: 'distanceRGBA', MeshDistanceMaterial: 'distanceRGBA',
MeshNormalMaterial: 'normal', MeshNormalMaterial: 'normal',
...@@ -36,7 +37,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -36,7 +37,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
SpriteMaterial: 'sprite' SpriteMaterial: 'sprite'
}; };
var parameterNames = [ const parameterNames = [
"precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing", "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing",
"map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV",
"lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap", "lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap",
...@@ -54,11 +55,11 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -54,11 +55,11 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
function getShaderObject( material, shaderID ) { function getShaderObject( material, shaderID ) {
var shaderobject; let shaderobject;
if ( shaderID ) { if ( shaderID ) {
var shader = ShaderLib[ shaderID ]; const shader = ShaderLib[ shaderID ];
shaderobject = { shaderobject = {
name: material.type, name: material.type,
...@@ -84,8 +85,8 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -84,8 +85,8 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
function allocateBones( object ) { function allocateBones( object ) {
var skeleton = object.skeleton; const skeleton = object.skeleton;
var bones = skeleton.bones; const bones = skeleton.bones;
if ( floatVertexTextures ) { if ( floatVertexTextures ) {
...@@ -100,10 +101,10 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -100,10 +101,10 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
// - limit here is ANGLE's 254 max uniform vectors // - limit here is ANGLE's 254 max uniform vectors
// (up to 54 should be safe) // (up to 54 should be safe)
var nVertexUniforms = maxVertexUniforms; const nVertexUniforms = maxVertexUniforms;
var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 ); const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
var maxBones = Math.min( nVertexMatrices, bones.length ); const maxBones = Math.min( nVertexMatrices, bones.length );
if ( maxBones < bones.length ) { if ( maxBones < bones.length ) {
...@@ -120,7 +121,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -120,7 +121,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
function getTextureEncodingFromMap( map ) { function getTextureEncodingFromMap( map ) {
var encoding; let encoding;
if ( ! map ) { if ( ! map ) {
...@@ -143,17 +144,17 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -143,17 +144,17 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
this.getParameters = function ( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) { this.getParameters = function ( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
var fog = scene.fog; const fog = scene.fog;
var environment = material.isMeshStandardMaterial ? scene.environment : null; const environment = material.isMeshStandardMaterial ? scene.environment : null;
var envMap = material.envMap || environment; const envMap = material.envMap || environment;
var shaderID = shaderIDs[ material.type ]; const shaderID = shaderIDs[ material.type ];
// heuristics to create shader parameters according to lights in the scene // heuristics to create shader parameters according to lights in the scene
// (not to blow over maxLights budget) // (not to blow over maxLights budget)
var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0; const maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
if ( material.precision !== null ) { if ( material.precision !== null ) {
...@@ -167,12 +168,12 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -167,12 +168,12 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
} }
var shaderobject = getShaderObject( material, shaderID ); const shaderobject = getShaderObject( material, shaderID );
material.onBeforeCompile( shaderobject, renderer ); material.onBeforeCompile( shaderobject, renderer );
var currentRenderTarget = renderer.getRenderTarget(); const currentRenderTarget = renderer.getRenderTarget();
var parameters = { const parameters = {
isWebGL2: isWebGL2, isWebGL2: isWebGL2,
...@@ -298,7 +299,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -298,7 +299,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
this.getProgramCacheKey = function ( parameters ) { this.getProgramCacheKey = function ( parameters ) {
var array = []; const array = [];
if ( parameters.shaderID ) { if ( parameters.shaderID ) {
...@@ -313,7 +314,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -313,7 +314,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
if ( parameters.defines !== undefined ) { if ( parameters.defines !== undefined ) {
for ( var name in parameters.defines ) { for ( const name in parameters.defines ) {
array.push( name ); array.push( name );
array.push( parameters.defines[ name ] ); array.push( parameters.defines[ name ] );
...@@ -324,7 +325,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -324,7 +325,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
if ( parameters.isRawShaderMaterial === undefined ) { if ( parameters.isRawShaderMaterial === undefined ) {
for ( var i = 0; i < parameterNames.length; i ++ ) { for ( let i = 0; i < parameterNames.length; i ++ ) {
array.push( parameters[ parameterNames[ i ] ] ); array.push( parameters[ parameterNames[ i ] ] );
...@@ -343,12 +344,12 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -343,12 +344,12 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
this.acquireProgram = function ( parameters, cacheKey ) { this.acquireProgram = function ( parameters, cacheKey ) {
var program; let program;
// Check if code has been already compiled // Check if code has been already compiled
for ( var p = 0, pl = programs.length; p < pl; p ++ ) { for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
var preexistingProgram = programs[ p ]; const preexistingProgram = programs[ p ];
if ( preexistingProgram.cacheKey === cacheKey ) { if ( preexistingProgram.cacheKey === cacheKey ) {
...@@ -377,7 +378,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) { ...@@ -377,7 +378,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
if ( -- program.usedTimes === 0 ) { if ( -- program.usedTimes === 0 ) {
// Remove from unordered set // Remove from unordered set
var i = programs.indexOf( program ); const i = programs.indexOf( program );
programs[ i ] = programs[ programs.length - 1 ]; programs[ i ] = programs[ programs.length - 1 ];
programs.pop(); programs.pop();
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
function WebGLProperties() { function WebGLProperties() {
var properties = new WeakMap(); let properties = new WeakMap();
function get( object ) { function get( object ) {
var map = properties.get( object ); let map = properties.get( object );
if ( map === undefined ) { if ( map === undefined ) {
......
...@@ -57,13 +57,13 @@ function reversePainterSortStable( a, b ) { ...@@ -57,13 +57,13 @@ function reversePainterSortStable( a, b ) {
function WebGLRenderList() { function WebGLRenderList() {
var renderItems = []; const renderItems = [];
var renderItemsIndex = 0; let renderItemsIndex = 0;
var opaque = []; const opaque = [];
var transparent = []; const transparent = [];
var defaultProgram = { id: - 1 }; const defaultProgram = { id: - 1 };
function init() { function init() {
...@@ -76,7 +76,7 @@ function WebGLRenderList() { ...@@ -76,7 +76,7 @@ function WebGLRenderList() {
function getNextRenderItem( object, geometry, material, groupOrder, z, group ) { function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
var renderItem = renderItems[ renderItemsIndex ]; let renderItem = renderItems[ renderItemsIndex ];
if ( renderItem === undefined ) { if ( renderItem === undefined ) {
...@@ -116,7 +116,7 @@ function WebGLRenderList() { ...@@ -116,7 +116,7 @@ function WebGLRenderList() {
function push( object, geometry, material, groupOrder, z, group ) { function push( object, geometry, material, groupOrder, z, group ) {
var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
( material.transparent === true ? transparent : opaque ).push( renderItem ); ( material.transparent === true ? transparent : opaque ).push( renderItem );
...@@ -124,7 +124,7 @@ function WebGLRenderList() { ...@@ -124,7 +124,7 @@ function WebGLRenderList() {
function unshift( object, geometry, material, groupOrder, z, group ) { function unshift( object, geometry, material, groupOrder, z, group ) {
var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
( material.transparent === true ? transparent : opaque ).unshift( renderItem ); ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
...@@ -141,9 +141,9 @@ function WebGLRenderList() { ...@@ -141,9 +141,9 @@ function WebGLRenderList() {
// Clear references from inactive renderItems in the list // Clear references from inactive renderItems in the list
for ( var i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) { for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
var renderItem = renderItems[ i ]; const renderItem = renderItems[ i ];
if ( renderItem.id === null ) break; if ( renderItem.id === null ) break;
...@@ -174,11 +174,11 @@ function WebGLRenderList() { ...@@ -174,11 +174,11 @@ function WebGLRenderList() {
function WebGLRenderLists() { function WebGLRenderLists() {
var lists = new WeakMap(); let lists = new WeakMap();
function onSceneDispose( event ) { function onSceneDispose( event ) {
var scene = event.target; const scene = event.target;
scene.removeEventListener( 'dispose', onSceneDispose ); scene.removeEventListener( 'dispose', onSceneDispose );
...@@ -188,8 +188,9 @@ function WebGLRenderLists() { ...@@ -188,8 +188,9 @@ function WebGLRenderLists() {
function get( scene, camera ) { function get( scene, camera ) {
var cameras = lists.get( scene ); const cameras = lists.get( scene );
var list; let list;
if ( cameras === undefined ) { if ( cameras === undefined ) {
list = new WebGLRenderList(); list = new WebGLRenderList();
......
...@@ -6,10 +6,10 @@ import { WebGLLights } from './WebGLLights.js'; ...@@ -6,10 +6,10 @@ import { WebGLLights } from './WebGLLights.js';
function WebGLRenderState() { function WebGLRenderState() {
var lights = new WebGLLights(); const lights = new WebGLLights();
var lightsArray = []; const lightsArray = [];
var shadowsArray = []; const shadowsArray = [];
function init() { function init() {
...@@ -36,7 +36,7 @@ function WebGLRenderState() { ...@@ -36,7 +36,7 @@ function WebGLRenderState() {
} }
var state = { const state = {
lightsArray: lightsArray, lightsArray: lightsArray,
shadowsArray: shadowsArray, shadowsArray: shadowsArray,
...@@ -56,11 +56,11 @@ function WebGLRenderState() { ...@@ -56,11 +56,11 @@ function WebGLRenderState() {
function WebGLRenderStates() { function WebGLRenderStates() {
var renderStates = new WeakMap(); let renderStates = new WeakMap();
function onSceneDispose( event ) { function onSceneDispose( event ) {
var scene = event.target; const scene = event.target;
scene.removeEventListener( 'dispose', onSceneDispose ); scene.removeEventListener( 'dispose', onSceneDispose );
...@@ -70,7 +70,7 @@ function WebGLRenderStates() { ...@@ -70,7 +70,7 @@ function WebGLRenderStates() {
function get( scene, camera ) { function get( scene, camera ) {
var renderState; let renderState;
if ( renderStates.has( scene ) === false ) { if ( renderStates.has( scene ) === false ) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
function WebGLShader( gl, type, string ) { function WebGLShader( gl, type, string ) {
var shader = gl.createShader( type ); const shader = gl.createShader( type );
gl.shaderSource( shader, string ); gl.shaderSource( shader, string );
gl.compileShader( shader ); gl.compileShader( shader );
......
...@@ -20,9 +20,9 @@ import vsm_vert from '../shaders/ShaderLib/vsm_vert.glsl.js'; ...@@ -20,9 +20,9 @@ import vsm_vert from '../shaders/ShaderLib/vsm_vert.glsl.js';
function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
var _frustum = new Frustum(), let _frustum = new Frustum();
_shadowMapSize = new Vector2(), const _shadowMapSize = new Vector2(),
_viewportSize = new Vector2(), _viewportSize = new Vector2(),
_viewport = new Vector4(), _viewport = new Vector4(),
...@@ -32,9 +32,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -32,9 +32,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
_materialCache = {}; _materialCache = {};
var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide }; const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
var shadowMaterialVertical = new ShaderMaterial( { const shadowMaterialVertical = new ShaderMaterial( {
defines: { defines: {
SAMPLE_RATE: 2.0 / 8.0, SAMPLE_RATE: 2.0 / 8.0,
...@@ -53,10 +53,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -53,10 +53,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} ); } );
var shadowMaterialHorizonal = shadowMaterialVertical.clone(); const shadowMaterialHorizonal = shadowMaterialVertical.clone();
shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1; shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
var fullScreenTri = new BufferGeometry(); const fullScreenTri = new BufferGeometry();
fullScreenTri.setAttribute( fullScreenTri.setAttribute(
"position", "position",
new BufferAttribute( new BufferAttribute(
...@@ -65,9 +65,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -65,9 +65,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
) )
); );
var fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical ); const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
var scope = this; const scope = this;
this.enabled = false; this.enabled = false;
...@@ -83,11 +83,11 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -83,11 +83,11 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( lights.length === 0 ) return; if ( lights.length === 0 ) return;
var currentRenderTarget = _renderer.getRenderTarget(); const currentRenderTarget = _renderer.getRenderTarget();
var activeCubeFace = _renderer.getActiveCubeFace(); const activeCubeFace = _renderer.getActiveCubeFace();
var activeMipmapLevel = _renderer.getActiveMipmapLevel(); const activeMipmapLevel = _renderer.getActiveMipmapLevel();
var _state = _renderer.state; const _state = _renderer.state;
// Set GL state for depth map. // Set GL state for depth map.
_state.setBlending( NoBlending ); _state.setBlending( NoBlending );
...@@ -97,10 +97,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -97,10 +97,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
// render depth map // render depth map
for ( var i = 0, il = lights.length; i < il; i ++ ) { for ( let i = 0, il = lights.length; i < il; i ++ ) {
var light = lights[ i ]; const light = lights[ i ];
var shadow = light.shadow; const shadow = light.shadow;
if ( shadow === undefined ) { if ( shadow === undefined ) {
...@@ -111,7 +111,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -111,7 +111,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
_shadowMapSize.copy( shadow.mapSize ); _shadowMapSize.copy( shadow.mapSize );
var shadowFrameExtents = shadow.getFrameExtents(); const shadowFrameExtents = shadow.getFrameExtents();
_shadowMapSize.multiply( shadowFrameExtents ); _shadowMapSize.multiply( shadowFrameExtents );
...@@ -139,7 +139,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -139,7 +139,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) { if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat }; const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars ); shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap"; shadow.map.texture.name = light.name + ".shadowMap";
...@@ -152,7 +152,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -152,7 +152,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( shadow.map === null ) { if ( shadow.map === null ) {
var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat }; const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars ); shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap"; shadow.map.texture.name = light.name + ".shadowMap";
...@@ -164,11 +164,11 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -164,11 +164,11 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
_renderer.setRenderTarget( shadow.map ); _renderer.setRenderTarget( shadow.map );
_renderer.clear(); _renderer.clear();
var viewportCount = shadow.getViewportCount(); const viewportCount = shadow.getViewportCount();
for ( var vp = 0; vp < viewportCount; vp ++ ) { for ( let vp = 0; vp < viewportCount; vp ++ ) {
var viewport = shadow.getViewport( vp ); const viewport = shadow.getViewport( vp );
_viewport.set( _viewport.set(
_viewportSize.x * viewport.x, _viewportSize.x * viewport.x,
...@@ -205,7 +205,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -205,7 +205,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
function VSMPass( shadow, camera ) { function VSMPass( shadow, camera ) {
var geometry = _objects.update( fullScreenMesh ); const geometry = _objects.update( fullScreenMesh );
// vertical pass // vertical pass
...@@ -229,9 +229,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -229,9 +229,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) { function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2; const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
var material = _depthMaterials[ index ]; let material = _depthMaterials[ index ];
if ( material === undefined ) { if ( material === undefined ) {
...@@ -254,9 +254,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -254,9 +254,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) { function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2; const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
var material = _distanceMaterials[ index ]; let material = _distanceMaterials[ index ];
if ( material === undefined ) { if ( material === undefined ) {
...@@ -277,10 +277,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -277,10 +277,10 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) { function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
var result = null; let result = null;
var getMaterialVariant = getDepthMaterialVariant; let getMaterialVariant = getDepthMaterialVariant;
var customMaterial = object.customDepthMaterial; let customMaterial = object.customDepthMaterial;
if ( light.isPointLight === true ) { if ( light.isPointLight === true ) {
...@@ -291,7 +291,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -291,7 +291,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( customMaterial === undefined ) { if ( customMaterial === undefined ) {
var useMorphing = false; let useMorphing = false;
if ( material.morphTargets === true ) { if ( material.morphTargets === true ) {
...@@ -299,7 +299,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -299,7 +299,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} }
var useSkinning = false; let useSkinning = false;
if ( object.isSkinnedMesh === true ) { if ( object.isSkinnedMesh === true ) {
...@@ -315,7 +315,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -315,7 +315,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} }
var useInstancing = object.isInstancedMesh === true; const useInstancing = object.isInstancedMesh === true;
result = getMaterialVariant( useMorphing, useSkinning, useInstancing ); result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
...@@ -332,9 +332,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -332,9 +332,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
// in this case we need a unique material instance reflecting the // in this case we need a unique material instance reflecting the
// appropriate state // appropriate state
var keyA = result.uuid, keyB = material.uuid; const keyA = result.uuid, keyB = material.uuid;
var materialsForVariant = _materialCache[ keyA ]; let materialsForVariant = _materialCache[ keyA ];
if ( materialsForVariant === undefined ) { if ( materialsForVariant === undefined ) {
...@@ -343,7 +343,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -343,7 +343,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} }
var cachedMaterial = materialsForVariant[ keyB ]; let cachedMaterial = materialsForVariant[ keyB ];
if ( cachedMaterial === undefined ) { if ( cachedMaterial === undefined ) {
...@@ -392,7 +392,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -392,7 +392,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
if ( object.visible === false ) return; if ( object.visible === false ) return;
var visible = object.layers.test( camera.layers ); const visible = object.layers.test( camera.layers );
if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) { if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
...@@ -400,21 +400,21 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -400,21 +400,21 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld ); object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
var geometry = _objects.update( object ); const geometry = _objects.update( object );
var material = object.material; const material = object.material;
if ( Array.isArray( material ) ) { if ( Array.isArray( material ) ) {
var groups = geometry.groups; const groups = geometry.groups;
for ( var k = 0, kl = groups.length; k < kl; k ++ ) { for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
var group = groups[ k ]; const group = groups[ k ];
var groupMaterial = material[ group.materialIndex ]; const groupMaterial = material[ group.materialIndex ];
if ( groupMaterial && groupMaterial.visible ) { if ( groupMaterial && groupMaterial.visible ) {
var depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type ); const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group ); _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
...@@ -424,7 +424,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -424,7 +424,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} else if ( material.visible ) { } else if ( material.visible ) {
var depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type ); const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
_renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null ); _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
...@@ -434,9 +434,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { ...@@ -434,9 +434,9 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
} }
var children = object.children; const children = object.children;
for ( var i = 0, l = children.length; i < l; i ++ ) { for ( let i = 0, l = children.length; i < l; i ++ ) {
renderObject( children[ i ], camera, shadowCamera, light, type ); renderObject( children[ i ], camera, shadowCamera, light, type );
......
...@@ -7,15 +7,15 @@ import { Vector4 } from '../../math/Vector4.js'; ...@@ -7,15 +7,15 @@ import { Vector4 } from '../../math/Vector4.js';
function WebGLState( gl, extensions, capabilities ) { function WebGLState( gl, extensions, capabilities ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
function ColorBuffer() { function ColorBuffer() {
var locked = false; let locked = false;
var color = new Vector4(); const color = new Vector4();
var currentColorMask = null; let currentColorMask = null;
var currentColorClear = new Vector4( 0, 0, 0, 0 ); const currentColorClear = new Vector4( 0, 0, 0, 0 );
return { return {
...@@ -70,11 +70,11 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -70,11 +70,11 @@ function WebGLState( gl, extensions, capabilities ) {
function DepthBuffer() { function DepthBuffer() {
var locked = false; let locked = false;
var currentDepthMask = null; let currentDepthMask = null;
var currentDepthFunc = null; let currentDepthFunc = null;
var currentDepthClear = null; let currentDepthClear = null;
return { return {
...@@ -202,16 +202,16 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -202,16 +202,16 @@ function WebGLState( gl, extensions, capabilities ) {
function StencilBuffer() { function StencilBuffer() {
var locked = false; let locked = false;
var currentStencilMask = null; let currentStencilMask = null;
var currentStencilFunc = null; let currentStencilFunc = null;
var currentStencilRef = null; let currentStencilRef = null;
var currentStencilFuncMask = null; let currentStencilFuncMask = null;
var currentStencilFail = null; let currentStencilFail = null;
var currentStencilZFail = null; let currentStencilZFail = null;
var currentStencilZPass = null; let currentStencilZPass = null;
var currentStencilClear = null; let currentStencilClear = null;
return { return {
...@@ -314,42 +314,42 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -314,42 +314,42 @@ function WebGLState( gl, extensions, capabilities ) {
// //
var colorBuffer = new ColorBuffer(); const colorBuffer = new ColorBuffer();
var depthBuffer = new DepthBuffer(); const depthBuffer = new DepthBuffer();
var stencilBuffer = new StencilBuffer(); const stencilBuffer = new StencilBuffer();
var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS ); const maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
var newAttributes = new Uint8Array( maxVertexAttributes ); const newAttributes = new Uint8Array( maxVertexAttributes );
var enabledAttributes = new Uint8Array( maxVertexAttributes ); const enabledAttributes = new Uint8Array( maxVertexAttributes );
var attributeDivisors = new Uint8Array( maxVertexAttributes ); const attributeDivisors = new Uint8Array( maxVertexAttributes );
var enabledCapabilities = {}; let enabledCapabilities = {};
var currentProgram = null; let currentProgram = null;
var currentBlendingEnabled = null; let currentBlendingEnabled = null;
var currentBlending = null; let currentBlending = null;
var currentBlendEquation = null; let currentBlendEquation = null;
var currentBlendSrc = null; let currentBlendSrc = null;
var currentBlendDst = null; let currentBlendDst = null;
var currentBlendEquationAlpha = null; let currentBlendEquationAlpha = null;
var currentBlendSrcAlpha = null; let currentBlendSrcAlpha = null;
var currentBlendDstAlpha = null; let currentBlendDstAlpha = null;
var currentPremultipledAlpha = false; let currentPremultipledAlpha = false;
var currentFlipSided = null; let currentFlipSided = null;
var currentCullFace = null; let currentCullFace = null;
var currentLineWidth = null; let currentLineWidth = null;
var currentPolygonOffsetFactor = null; let currentPolygonOffsetFactor = null;
var currentPolygonOffsetUnits = null; let currentPolygonOffsetUnits = null;
var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS ); const maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
var lineWidthAvailable = false; let lineWidthAvailable = false;
var version = 0; let version = 0;
var glVersion = gl.getParameter( gl.VERSION ); const glVersion = gl.getParameter( gl.VERSION );
if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) { if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
...@@ -363,22 +363,22 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -363,22 +363,22 @@ function WebGLState( gl, extensions, capabilities ) {
} }
var currentTextureSlot = null; let currentTextureSlot = null;
var currentBoundTextures = {}; let currentBoundTextures = {};
var currentScissor = new Vector4(); const currentScissor = new Vector4();
var currentViewport = new Vector4(); const currentViewport = new Vector4();
function createTexture( type, target, count ) { function createTexture( type, target, count ) {
var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
var texture = gl.createTexture(); const texture = gl.createTexture();
gl.bindTexture( type, texture ); gl.bindTexture( type, texture );
gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST ); gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST ); gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
for ( var i = 0; i < count; i ++ ) { for ( let i = 0; i < count; i ++ ) {
gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data ); gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
...@@ -388,7 +388,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -388,7 +388,7 @@ function WebGLState( gl, extensions, capabilities ) {
} }
var emptyTextures = {}; const emptyTextures = {};
emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 ); emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 ); emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
...@@ -411,7 +411,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -411,7 +411,7 @@ function WebGLState( gl, extensions, capabilities ) {
function initAttributes() { function initAttributes() {
for ( var i = 0, l = newAttributes.length; i < l; i ++ ) { for ( let i = 0, l = newAttributes.length; i < l; i ++ ) {
newAttributes[ i ] = 0; newAttributes[ i ] = 0;
...@@ -438,7 +438,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -438,7 +438,7 @@ function WebGLState( gl, extensions, capabilities ) {
if ( attributeDivisors[ attribute ] !== meshPerAttribute ) { if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
var extension = isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' ); const extension = isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
extension[ isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute ); extension[ isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
attributeDivisors[ attribute ] = meshPerAttribute; attributeDivisors[ attribute ] = meshPerAttribute;
...@@ -449,7 +449,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -449,7 +449,7 @@ function WebGLState( gl, extensions, capabilities ) {
function disableUnusedAttributes() { function disableUnusedAttributes() {
for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) { for ( let i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
if ( enabledAttributes[ i ] !== newAttributes[ i ] ) { if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
...@@ -514,7 +514,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -514,7 +514,7 @@ function WebGLState( gl, extensions, capabilities ) {
} }
var equationToGL = { const equationToGL = {
[ AddEquation ]: gl.FUNC_ADD, [ AddEquation ]: gl.FUNC_ADD,
[ SubtractEquation ]: gl.FUNC_SUBTRACT, [ SubtractEquation ]: gl.FUNC_SUBTRACT,
[ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT [ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT
...@@ -527,7 +527,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -527,7 +527,7 @@ function WebGLState( gl, extensions, capabilities ) {
} else { } else {
var extension = extensions.get( 'EXT_blend_minmax' ); const extension = extensions.get( 'EXT_blend_minmax' );
if ( extension !== null ) { if ( extension !== null ) {
...@@ -538,7 +538,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -538,7 +538,7 @@ function WebGLState( gl, extensions, capabilities ) {
} }
var factorToGL = { const factorToGL = {
[ ZeroFactor ]: gl.ZERO, [ ZeroFactor ]: gl.ZERO,
[ OneFactor ]: gl.ONE, [ OneFactor ]: gl.ONE,
[ SrcColorFactor ]: gl.SRC_COLOR, [ SrcColorFactor ]: gl.SRC_COLOR,
...@@ -692,7 +692,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -692,7 +692,7 @@ function WebGLState( gl, extensions, capabilities ) {
? disable( gl.CULL_FACE ) ? disable( gl.CULL_FACE )
: enable( gl.CULL_FACE ); : enable( gl.CULL_FACE );
var flipSided = ( material.side === BackSide ); let flipSided = ( material.side === BackSide );
if ( frontFaceCW ) flipSided = ! flipSided; if ( frontFaceCW ) flipSided = ! flipSided;
setFlipSided( flipSided ); setFlipSided( flipSided );
...@@ -706,7 +706,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -706,7 +706,7 @@ function WebGLState( gl, extensions, capabilities ) {
depthBuffer.setMask( material.depthWrite ); depthBuffer.setMask( material.depthWrite );
colorBuffer.setMask( material.colorWrite ); colorBuffer.setMask( material.colorWrite );
var stencilWrite = material.stencilWrite; const stencilWrite = material.stencilWrite;
stencilBuffer.setTest( stencilWrite ); stencilBuffer.setTest( stencilWrite );
if ( stencilWrite ) { if ( stencilWrite ) {
...@@ -848,7 +848,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -848,7 +848,7 @@ function WebGLState( gl, extensions, capabilities ) {
} }
var boundTexture = currentBoundTextures[ currentTextureSlot ]; let boundTexture = currentBoundTextures[ currentTextureSlot ];
if ( boundTexture === undefined ) { if ( boundTexture === undefined ) {
...@@ -870,7 +870,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -870,7 +870,7 @@ function WebGLState( gl, extensions, capabilities ) {
function unbindTexture() { function unbindTexture() {
var boundTexture = currentBoundTextures[ currentTextureSlot ]; const boundTexture = currentBoundTextures[ currentTextureSlot ];
if ( boundTexture !== undefined && boundTexture.type !== undefined ) { if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
...@@ -953,7 +953,7 @@ function WebGLState( gl, extensions, capabilities ) { ...@@ -953,7 +953,7 @@ function WebGLState( gl, extensions, capabilities ) {
function reset() { function reset() {
for ( var i = 0; i < enabledAttributes.length; i ++ ) { for ( let i = 0; i < enabledAttributes.length; i ++ ) {
if ( enabledAttributes[ i ] === 1 ) { if ( enabledAttributes[ i ] === 1 ) {
......
...@@ -7,20 +7,20 @@ import { MathUtils } from '../../math/MathUtils.js'; ...@@ -7,20 +7,20 @@ import { MathUtils } from '../../math/MathUtils.js';
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) { function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
var maxTextures = capabilities.maxTextures; const maxTextures = capabilities.maxTextures;
var maxCubemapSize = capabilities.maxCubemapSize; const maxCubemapSize = capabilities.maxCubemapSize;
var maxTextureSize = capabilities.maxTextureSize; const maxTextureSize = capabilities.maxTextureSize;
var maxSamples = capabilities.maxSamples; const maxSamples = capabilities.maxSamples;
var _videoTextures = new WeakMap(); const _videoTextures = new WeakMap();
var _canvas; let _canvas;
// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas, // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
// also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")! // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
// Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d). // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
var useOffscreenCanvas = false; let useOffscreenCanvas = false;
try { try {
...@@ -45,7 +45,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -45,7 +45,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) { function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
var scale = 1; let scale = 1;
// handle case if texture exceeds max size // handle case if texture exceeds max size
...@@ -65,21 +65,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -65,21 +65,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) { ( 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 ); const width = floor( scale * image.width );
var height = floor( scale * image.height ); const height = floor( scale * image.height );
if ( _canvas === undefined ) _canvas = createCanvas( width, height ); if ( _canvas === undefined ) _canvas = createCanvas( width, height );
// cube textures can't reuse the same canvas // 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.width = width;
canvas.height = height; canvas.height = height;
var context = canvas.getContext( '2d' ); const context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0, width, height ); 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 + ').' ); 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, ...@@ -130,7 +130,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.generateMipmap( target ); _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 // 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; textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
...@@ -149,7 +149,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -149,7 +149,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
var internalFormat = glFormat; let internalFormat = glFormat;
if ( glFormat === _gl.RED ) { if ( glFormat === _gl.RED ) {
...@@ -204,7 +204,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -204,7 +204,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function onTextureDispose( event ) { function onTextureDispose( event ) {
var texture = event.target; const texture = event.target;
texture.removeEventListener( 'dispose', onTextureDispose ); texture.removeEventListener( 'dispose', onTextureDispose );
...@@ -222,7 +222,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -222,7 +222,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function onRenderTargetDispose( event ) { function onRenderTargetDispose( event ) {
var renderTarget = event.target; const renderTarget = event.target;
renderTarget.removeEventListener( 'dispose', onRenderTargetDispose ); renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
...@@ -236,7 +236,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -236,7 +236,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function deallocateTexture( texture ) { function deallocateTexture( texture ) {
var textureProperties = properties.get( texture ); const textureProperties = properties.get( texture );
if ( textureProperties.__webglInit === undefined ) return; if ( textureProperties.__webglInit === undefined ) return;
...@@ -248,8 +248,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -248,8 +248,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function deallocateRenderTarget( renderTarget ) { function deallocateRenderTarget( renderTarget ) {
var renderTargetProperties = properties.get( renderTarget ); const renderTargetProperties = properties.get( renderTarget );
var textureProperties = properties.get( renderTarget.texture ); const textureProperties = properties.get( renderTarget.texture );
if ( ! renderTarget ) return; if ( ! renderTarget ) return;
...@@ -267,7 +267,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -267,7 +267,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( renderTarget.isWebGLCubeRenderTarget ) { if ( renderTarget.isWebGLCubeRenderTarget ) {
for ( var i = 0; i < 6; i ++ ) { for ( let i = 0; i < 6; i ++ ) {
_gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] ); _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] ); if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
...@@ -291,7 +291,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -291,7 +291,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// //
var textureUnits = 0; let textureUnits = 0;
function resetTextureUnits() { function resetTextureUnits() {
...@@ -301,7 +301,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -301,7 +301,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function allocateTextureUnit() { function allocateTextureUnit() {
var textureUnit = textureUnits; const textureUnit = textureUnits;
if ( textureUnit >= maxTextures ) { if ( textureUnit >= maxTextures ) {
...@@ -319,13 +319,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -319,13 +319,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function setTexture2D( texture, slot ) { function setTexture2D( texture, slot ) {
var textureProperties = properties.get( texture ); const textureProperties = properties.get( texture );
if ( texture.isVideoTexture ) updateVideoTexture( texture ); if ( texture.isVideoTexture ) updateVideoTexture( texture );
if ( texture.version > 0 && textureProperties.__version !== texture.version ) { if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
var image = texture.image; const image = texture.image;
if ( image === undefined ) { if ( image === undefined ) {
...@@ -351,7 +351,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -351,7 +351,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function setTexture2DArray( texture, slot ) { function setTexture2DArray( texture, slot ) {
var textureProperties = properties.get( texture ); const textureProperties = properties.get( texture );
if ( texture.version > 0 && textureProperties.__version !== texture.version ) { if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
...@@ -367,7 +367,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -367,7 +367,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function setTexture3D( texture, slot ) { function setTexture3D( texture, slot ) {
var textureProperties = properties.get( texture ); const textureProperties = properties.get( texture );
if ( texture.version > 0 && textureProperties.__version !== texture.version ) { if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
...@@ -385,7 +385,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -385,7 +385,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( texture.image.length !== 6 ) return; if ( texture.image.length !== 6 ) return;
var textureProperties = properties.get( texture ); const textureProperties = properties.get( texture );
if ( texture.version > 0 && textureProperties.__version !== texture.version ) { if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
...@@ -396,12 +396,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -396,12 +396,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
var isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) ); const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture ); 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 ) { if ( ! isCompressed && ! isDataTexture ) {
...@@ -415,7 +415,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -415,7 +415,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
var image = cubeImage[ 0 ], const image = cubeImage[ 0 ],
supportsMips = isPowerOfTwo( image ) || isWebGL2, supportsMips = isPowerOfTwo( image ) || isWebGL2,
glFormat = utils.convert( texture.format ), glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ), glType = utils.convert( texture.type ),
...@@ -423,17 +423,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -423,17 +423,17 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips ); setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
var mipmaps; let mipmaps;
if ( isCompressed ) { if ( isCompressed ) {
for ( var i = 0; i < 6; i ++ ) { for ( let i = 0; i < 6; i ++ ) {
mipmaps = cubeImage[ i ].mipmaps; 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 ) { if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
...@@ -463,16 +463,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -463,16 +463,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
mipmaps = texture.mipmaps; mipmaps = texture.mipmaps;
for ( var i = 0; i < 6; i ++ ) { for ( let i = 0; i < 6; i ++ ) {
if ( isDataTexture ) { 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 ); 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 ]; const mipmap = mipmaps[ j ];
var mipmapImage = mipmap.image[ i ].image; 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 ); 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, ...@@ -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 ] ); 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 ] ); 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, ...@@ -525,13 +525,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
var wrappingToGL = { const wrappingToGL = {
[ RepeatWrapping ]: _gl.REPEAT, [ RepeatWrapping ]: _gl.REPEAT,
[ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE, [ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE,
[ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT [ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT
}; };
var filterToGL = { const filterToGL = {
[ NearestFilter ]: _gl.NEAREST, [ NearestFilter ]: _gl.NEAREST,
[ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST, [ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST,
[ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR, [ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR,
...@@ -585,7 +585,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -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 ) { if ( extension ) {
...@@ -621,7 +621,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -621,7 +621,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function uploadTexture( textureProperties, texture, slot ) { 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.isDataTexture2DArray ) textureType = _gl.TEXTURE_2D_ARRAY;
if ( texture.isDataTexture3D ) textureType = _gl.TEXTURE_3D; if ( texture.isDataTexture3D ) textureType = _gl.TEXTURE_3D;
...@@ -635,17 +635,19 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -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_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false; const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize ); const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
var supportsMips = isPowerOfTwo( image ) || isWebGL2, const supportsMips = isPowerOfTwo( image ) || isWebGL2,
glFormat = utils.convert( texture.format ), glFormat = utils.convert( texture.format );
glType = utils.convert( texture.type ),
let glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType ); glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
setTextureParameters( textureType, texture, supportsMips ); setTextureParameters( textureType, texture, supportsMips );
var mipmap, mipmaps = texture.mipmaps; let mipmap;
const mipmaps = texture.mipmaps;
if ( texture.isDepthTexture ) { if ( texture.isDepthTexture ) {
...@@ -733,7 +735,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -733,7 +735,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( mipmaps.length > 0 && supportsMips ) { 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 ]; mipmap = mipmaps[ i ];
state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); 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, ...@@ -752,7 +754,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} else if ( texture.isCompressedTexture ) { } 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 ]; mipmap = mipmaps[ i ];
...@@ -798,7 +800,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -798,7 +800,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( mipmaps.length > 0 && supportsMips ) { 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 ]; mipmap = mipmaps[ i ];
state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap ); state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );
...@@ -834,9 +836,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -834,9 +836,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// Setup storage for target texture and bind it to correct framebuffer // Setup storage for target texture and bind it to correct framebuffer
function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) { function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
var glFormat = utils.convert( renderTarget.texture.format ); const glFormat = utils.convert( renderTarget.texture.format );
var glType = utils.convert( renderTarget.texture.type ); const glType = utils.convert( renderTarget.texture.type );
var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null ); state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 ); _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
...@@ -851,11 +853,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -851,11 +853,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) { if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
var glInternalFormat = _gl.DEPTH_COMPONENT16; let glInternalFormat = _gl.DEPTH_COMPONENT16;
if ( isMultisample ) { if ( isMultisample ) {
var depthTexture = renderTarget.depthTexture; const depthTexture = renderTarget.depthTexture;
if ( depthTexture && depthTexture.isDepthTexture ) { if ( depthTexture && depthTexture.isDepthTexture ) {
...@@ -871,7 +873,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -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 ); _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
...@@ -887,7 +889,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -887,7 +889,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( isMultisample ) { if ( isMultisample ) {
var samples = getRenderTargetSamples( renderTarget ); const samples = getRenderTargetSamples( renderTarget );
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height ); _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
...@@ -902,13 +904,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -902,13 +904,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} else { } else {
var glFormat = utils.convert( renderTarget.texture.format ); const glFormat = utils.convert( renderTarget.texture.format );
var glType = utils.convert( renderTarget.texture.type ); const glType = utils.convert( renderTarget.texture.type );
var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
if ( isMultisample ) { if ( isMultisample ) {
var samples = getRenderTargetSamples( renderTarget ); const samples = getRenderTargetSamples( renderTarget );
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
...@@ -927,7 +929,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -927,7 +929,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// Setup resources for a Depth Texture for a FBO (needs an extension) // Setup resources for a Depth Texture for a FBO (needs an extension)
function setupDepthTexture( framebuffer, renderTarget ) { 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' ); if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
...@@ -951,7 +953,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -951,7 +953,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
setTexture2D( renderTarget.depthTexture, 0 ); setTexture2D( renderTarget.depthTexture, 0 );
var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture; const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
if ( renderTarget.depthTexture.format === DepthFormat ) { if ( renderTarget.depthTexture.format === DepthFormat ) {
...@@ -972,9 +974,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -972,9 +974,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// Setup GL resources for a non-texture depth buffer // Setup GL resources for a non-texture depth buffer
function setupDepthRenderbuffer( renderTarget ) { 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 ) { if ( renderTarget.depthTexture ) {
...@@ -988,7 +990,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -988,7 +990,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
renderTargetProperties.__webglDepthbuffer = []; renderTargetProperties.__webglDepthbuffer = [];
for ( var i = 0; i < 6; i ++ ) { for ( let i = 0; i < 6; i ++ ) {
_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer(); renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
...@@ -1013,8 +1015,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1013,8 +1015,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// Set up GL resources for the render target // Set up GL resources for the render target
function setupRenderTarget( renderTarget ) { function setupRenderTarget( renderTarget ) {
var renderTargetProperties = properties.get( renderTarget ); const renderTargetProperties = properties.get( renderTarget );
var textureProperties = properties.get( renderTarget.texture ); const textureProperties = properties.get( renderTarget.texture );
renderTarget.addEventListener( 'dispose', onRenderTargetDispose ); renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
...@@ -1022,9 +1024,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1022,9 +1024,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
info.memory.textures ++; info.memory.textures ++;
var isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true ); const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2; const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
// Handles WebGL2 RGBFormat fallback - #18858 // Handles WebGL2 RGBFormat fallback - #18858
...@@ -1042,7 +1044,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1042,7 +1044,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
renderTargetProperties.__webglFramebuffer = []; renderTargetProperties.__webglFramebuffer = [];
for ( var i = 0; i < 6; i ++ ) { for ( let i = 0; i < 6; i ++ ) {
renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer(); renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
...@@ -1061,10 +1063,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1061,10 +1063,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer ); _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
var glFormat = utils.convert( renderTarget.texture.format ); const glFormat = utils.convert( renderTarget.texture.format );
var glType = utils.convert( renderTarget.texture.type ); const glType = utils.convert( renderTarget.texture.type );
var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
var samples = getRenderTargetSamples( renderTarget ); const samples = getRenderTargetSamples( renderTarget );
_gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
...@@ -1098,7 +1100,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1098,7 +1100,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture ); state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, supportsMips ); 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 ); 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, ...@@ -1140,13 +1142,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateRenderTargetMipmap( renderTarget ) { function updateRenderTargetMipmap( renderTarget ) {
var texture = renderTarget.texture; const texture = renderTarget.texture;
var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2; const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) { if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
var target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D; const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
var webglTexture = properties.get( texture ).__webglTexture; const webglTexture = properties.get( texture ).__webglTexture;
state.bindTexture( target, webglTexture ); state.bindTexture( target, webglTexture );
generateMipmap( target, texture, renderTarget.width, renderTarget.height ); generateMipmap( target, texture, renderTarget.width, renderTarget.height );
...@@ -1162,14 +1164,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1162,14 +1164,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( isWebGL2 ) { if ( isWebGL2 ) {
var renderTargetProperties = properties.get( renderTarget ); const renderTargetProperties = properties.get( renderTarget );
_gl.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); _gl.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
_gl.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); _gl.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
var width = renderTarget.width; const width = renderTarget.width;
var height = renderTarget.height; const height = renderTarget.height;
var mask = _gl.COLOR_BUFFER_BIT; let mask = _gl.COLOR_BUFFER_BIT;
if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT; if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT;
if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT; if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT;
...@@ -1197,7 +1199,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1197,7 +1199,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateVideoTexture( texture ) { function updateVideoTexture( texture ) {
var frame = info.render.frame; const frame = info.render.frame;
// Check the last frame we updated the VideoTexture // Check the last frame we updated the VideoTexture
...@@ -1212,8 +1214,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1212,8 +1214,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// backwards compatibility // backwards compatibility
var warnedTexture2D = false; let warnedTexture2D = false;
var warnedTextureCube = false; let warnedTextureCube = false;
function safeSetTexture2D( texture, slot ) { function safeSetTexture2D( texture, slot ) {
......
...@@ -50,35 +50,35 @@ import { Texture } from '../../textures/Texture.js'; ...@@ -50,35 +50,35 @@ import { Texture } from '../../textures/Texture.js';
import { DataTexture2DArray } from '../../textures/DataTexture2DArray.js'; import { DataTexture2DArray } from '../../textures/DataTexture2DArray.js';
import { DataTexture3D } from '../../textures/DataTexture3D.js'; import { DataTexture3D } from '../../textures/DataTexture3D.js';
var emptyTexture = new Texture(); const emptyTexture = new Texture();
var emptyTexture2dArray = new DataTexture2DArray(); const emptyTexture2dArray = new DataTexture2DArray();
var emptyTexture3d = new DataTexture3D(); const emptyTexture3d = new DataTexture3D();
var emptyCubeTexture = new CubeTexture(); const emptyCubeTexture = new CubeTexture();
// --- Utilities --- // --- Utilities ---
// Array Caches (provide typed arrays for temporary by size) // Array Caches (provide typed arrays for temporary by size)
var arrayCacheF32 = []; const arrayCacheF32 = [];
var arrayCacheI32 = []; const arrayCacheI32 = [];
// Float32Array caches used for uploading Matrix uniforms // Float32Array caches used for uploading Matrix uniforms
var mat4array = new Float32Array( 16 ); const mat4array = new Float32Array( 16 );
var mat3array = new Float32Array( 9 ); const mat3array = new Float32Array( 9 );
var mat2array = new Float32Array( 4 ); const mat2array = new Float32Array( 4 );
// Flattening for arrays of vectors and matrices // Flattening for arrays of vectors and matrices
function flatten( array, nBlocks, blockSize ) { function flatten( array, nBlocks, blockSize ) {
var firstElem = array[ 0 ]; const firstElem = array[ 0 ];
if ( firstElem <= 0 || firstElem > 0 ) return array; if ( firstElem <= 0 || firstElem > 0 ) return array;
// unoptimized: ! isNaN( firstElem ) // unoptimized: ! isNaN( firstElem )
// see http://jacksondunstan.com/articles/983 // see http://jacksondunstan.com/articles/983
var n = nBlocks * blockSize, let n = nBlocks * blockSize,
r = arrayCacheF32[ n ]; r = arrayCacheF32[ n ];
if ( r === undefined ) { if ( r === undefined ) {
...@@ -92,7 +92,7 @@ function flatten( array, nBlocks, blockSize ) { ...@@ -92,7 +92,7 @@ function flatten( array, nBlocks, blockSize ) {
firstElem.toArray( r, 0 ); firstElem.toArray( r, 0 );
for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) { for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
offset += blockSize; offset += blockSize;
array[ i ].toArray( r, offset ); array[ i ].toArray( r, offset );
...@@ -109,7 +109,7 @@ function arraysEqual( a, b ) { ...@@ -109,7 +109,7 @@ function arraysEqual( a, b ) {
if ( a.length !== b.length ) return false; if ( a.length !== b.length ) return false;
for ( var i = 0, l = a.length; i < l; i ++ ) { for ( let i = 0, l = a.length; i < l; i ++ ) {
if ( a[ i ] !== b[ i ] ) return false; if ( a[ i ] !== b[ i ] ) return false;
...@@ -121,7 +121,7 @@ function arraysEqual( a, b ) { ...@@ -121,7 +121,7 @@ function arraysEqual( a, b ) {
function copyArray( a, b ) { function copyArray( a, b ) {
for ( var i = 0, l = b.length; i < l; i ++ ) { for ( let i = 0, l = b.length; i < l; i ++ ) {
a[ i ] = b[ i ]; a[ i ] = b[ i ];
...@@ -133,7 +133,7 @@ function copyArray( a, b ) { ...@@ -133,7 +133,7 @@ function copyArray( a, b ) {
function allocTexUnits( textures, n ) { function allocTexUnits( textures, n ) {
var r = arrayCacheI32[ n ]; let r = arrayCacheI32[ n ];
if ( r === undefined ) { if ( r === undefined ) {
...@@ -142,9 +142,12 @@ function allocTexUnits( textures, n ) { ...@@ -142,9 +142,12 @@ function allocTexUnits( textures, n ) {
} }
for ( var i = 0; i !== n; ++ i ) for ( let i = 0; i !== n; ++ i ) {
r[ i ] = textures.allocateTextureUnit(); r[ i ] = textures.allocateTextureUnit();
}
return r; return r;
} }
...@@ -158,7 +161,7 @@ function allocTexUnits( textures, n ) { ...@@ -158,7 +161,7 @@ function allocTexUnits( textures, n ) {
function setValueV1f( gl, v ) { function setValueV1f( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( cache[ 0 ] === v ) return; if ( cache[ 0 ] === v ) return;
...@@ -172,7 +175,7 @@ function setValueV1f( gl, v ) { ...@@ -172,7 +175,7 @@ function setValueV1f( gl, v ) {
function setValueV2f( gl, v ) { function setValueV2f( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( v.x !== undefined ) { if ( v.x !== undefined ) {
...@@ -199,7 +202,7 @@ function setValueV2f( gl, v ) { ...@@ -199,7 +202,7 @@ function setValueV2f( gl, v ) {
function setValueV3f( gl, v ) { function setValueV3f( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( v.x !== undefined ) { if ( v.x !== undefined ) {
...@@ -239,7 +242,7 @@ function setValueV3f( gl, v ) { ...@@ -239,7 +242,7 @@ function setValueV3f( gl, v ) {
function setValueV4f( gl, v ) { function setValueV4f( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( v.x !== undefined ) { if ( v.x !== undefined ) {
...@@ -270,8 +273,8 @@ function setValueV4f( gl, v ) { ...@@ -270,8 +273,8 @@ function setValueV4f( gl, v ) {
function setValueM2( gl, v ) { function setValueM2( gl, v ) {
var cache = this.cache; const cache = this.cache;
var elements = v.elements; const elements = v.elements;
if ( elements === undefined ) { if ( elements === undefined ) {
...@@ -297,8 +300,8 @@ function setValueM2( gl, v ) { ...@@ -297,8 +300,8 @@ function setValueM2( gl, v ) {
function setValueM3( gl, v ) { function setValueM3( gl, v ) {
var cache = this.cache; const cache = this.cache;
var elements = v.elements; const elements = v.elements;
if ( elements === undefined ) { if ( elements === undefined ) {
...@@ -324,8 +327,8 @@ function setValueM3( gl, v ) { ...@@ -324,8 +327,8 @@ function setValueM3( gl, v ) {
function setValueM4( gl, v ) { function setValueM4( gl, v ) {
var cache = this.cache; const cache = this.cache;
var elements = v.elements; const elements = v.elements;
if ( elements === undefined ) { if ( elements === undefined ) {
...@@ -353,8 +356,8 @@ function setValueM4( gl, v ) { ...@@ -353,8 +356,8 @@ function setValueM4( gl, v ) {
function setValueT1( gl, v, textures ) { function setValueT1( gl, v, textures ) {
var cache = this.cache; const cache = this.cache;
var unit = textures.allocateTextureUnit(); const unit = textures.allocateTextureUnit();
if ( cache[ 0 ] !== unit ) { if ( cache[ 0 ] !== unit ) {
...@@ -369,8 +372,8 @@ function setValueT1( gl, v, textures ) { ...@@ -369,8 +372,8 @@ function setValueT1( gl, v, textures ) {
function setValueT2DArray1( gl, v, textures ) { function setValueT2DArray1( gl, v, textures ) {
var cache = this.cache; const cache = this.cache;
var unit = textures.allocateTextureUnit(); const unit = textures.allocateTextureUnit();
if ( cache[ 0 ] !== unit ) { if ( cache[ 0 ] !== unit ) {
...@@ -385,8 +388,8 @@ function setValueT2DArray1( gl, v, textures ) { ...@@ -385,8 +388,8 @@ function setValueT2DArray1( gl, v, textures ) {
function setValueT3D1( gl, v, textures ) { function setValueT3D1( gl, v, textures ) {
var cache = this.cache; const cache = this.cache;
var unit = textures.allocateTextureUnit(); const unit = textures.allocateTextureUnit();
if ( cache[ 0 ] !== unit ) { if ( cache[ 0 ] !== unit ) {
...@@ -401,8 +404,8 @@ function setValueT3D1( gl, v, textures ) { ...@@ -401,8 +404,8 @@ function setValueT3D1( gl, v, textures ) {
function setValueT6( gl, v, textures ) { function setValueT6( gl, v, textures ) {
var cache = this.cache; const cache = this.cache;
var unit = textures.allocateTextureUnit(); const unit = textures.allocateTextureUnit();
if ( cache[ 0 ] !== unit ) { if ( cache[ 0 ] !== unit ) {
...@@ -419,7 +422,7 @@ function setValueT6( gl, v, textures ) { ...@@ -419,7 +422,7 @@ function setValueT6( gl, v, textures ) {
function setValueV1i( gl, v ) { function setValueV1i( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( cache[ 0 ] === v ) return; if ( cache[ 0 ] === v ) return;
...@@ -431,7 +434,7 @@ function setValueV1i( gl, v ) { ...@@ -431,7 +434,7 @@ function setValueV1i( gl, v ) {
function setValueV2i( gl, v ) { function setValueV2i( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( arraysEqual( cache, v ) ) return; if ( arraysEqual( cache, v ) ) return;
...@@ -443,7 +446,7 @@ function setValueV2i( gl, v ) { ...@@ -443,7 +446,7 @@ function setValueV2i( gl, v ) {
function setValueV3i( gl, v ) { function setValueV3i( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( arraysEqual( cache, v ) ) return; if ( arraysEqual( cache, v ) ) return;
...@@ -455,7 +458,7 @@ function setValueV3i( gl, v ) { ...@@ -455,7 +458,7 @@ function setValueV3i( gl, v ) {
function setValueV4i( gl, v ) { function setValueV4i( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( arraysEqual( cache, v ) ) return; if ( arraysEqual( cache, v ) ) return;
...@@ -469,7 +472,7 @@ function setValueV4i( gl, v ) { ...@@ -469,7 +472,7 @@ function setValueV4i( gl, v ) {
function setValueV1ui( gl, v ) { function setValueV1ui( gl, v ) {
var cache = this.cache; const cache = this.cache;
if ( cache[ 0 ] === v ) return; if ( cache[ 0 ] === v ) return;
...@@ -566,7 +569,7 @@ function setValueV4iArray( gl, v ) { ...@@ -566,7 +569,7 @@ function setValueV4iArray( gl, v ) {
function setValueV2fArray( gl, v ) { function setValueV2fArray( gl, v ) {
var data = flatten( v, this.size, 2 ); const data = flatten( v, this.size, 2 );
gl.uniform2fv( this.addr, data ); gl.uniform2fv( this.addr, data );
...@@ -574,7 +577,7 @@ function setValueV2fArray( gl, v ) { ...@@ -574,7 +577,7 @@ function setValueV2fArray( gl, v ) {
function setValueV3fArray( gl, v ) { function setValueV3fArray( gl, v ) {
var data = flatten( v, this.size, 3 ); const data = flatten( v, this.size, 3 );
gl.uniform3fv( this.addr, data ); gl.uniform3fv( this.addr, data );
...@@ -582,7 +585,7 @@ function setValueV3fArray( gl, v ) { ...@@ -582,7 +585,7 @@ function setValueV3fArray( gl, v ) {
function setValueV4fArray( gl, v ) { function setValueV4fArray( gl, v ) {
var data = flatten( v, this.size, 4 ); const data = flatten( v, this.size, 4 );
gl.uniform4fv( this.addr, data ); gl.uniform4fv( this.addr, data );
...@@ -592,7 +595,7 @@ function setValueV4fArray( gl, v ) { ...@@ -592,7 +595,7 @@ function setValueV4fArray( gl, v ) {
function setValueM2Array( gl, v ) { function setValueM2Array( gl, v ) {
var data = flatten( v, this.size, 4 ); const data = flatten( v, this.size, 4 );
gl.uniformMatrix2fv( this.addr, false, data ); gl.uniformMatrix2fv( this.addr, false, data );
...@@ -600,7 +603,7 @@ function setValueM2Array( gl, v ) { ...@@ -600,7 +603,7 @@ function setValueM2Array( gl, v ) {
function setValueM3Array( gl, v ) { function setValueM3Array( gl, v ) {
var data = flatten( v, this.size, 9 ); const data = flatten( v, this.size, 9 );
gl.uniformMatrix3fv( this.addr, false, data ); gl.uniformMatrix3fv( this.addr, false, data );
...@@ -608,7 +611,7 @@ function setValueM3Array( gl, v ) { ...@@ -608,7 +611,7 @@ function setValueM3Array( gl, v ) {
function setValueM4Array( gl, v ) { function setValueM4Array( gl, v ) {
var data = flatten( v, this.size, 16 ); const data = flatten( v, this.size, 16 );
gl.uniformMatrix4fv( this.addr, false, data ); gl.uniformMatrix4fv( this.addr, false, data );
...@@ -618,13 +621,13 @@ function setValueM4Array( gl, v ) { ...@@ -618,13 +621,13 @@ function setValueM4Array( gl, v ) {
function setValueT1Array( gl, v, textures ) { function setValueT1Array( gl, v, textures ) {
var n = v.length; const n = v.length;
var units = allocTexUnits( textures, n ); const units = allocTexUnits( textures, n );
gl.uniform1iv( this.addr, units ); gl.uniform1iv( this.addr, units );
for ( var i = 0; i !== n; ++ i ) { for ( let i = 0; i !== n; ++ i ) {
textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] ); textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
...@@ -634,13 +637,13 @@ function setValueT1Array( gl, v, textures ) { ...@@ -634,13 +637,13 @@ function setValueT1Array( gl, v, textures ) {
function setValueT6Array( gl, v, textures ) { function setValueT6Array( gl, v, textures ) {
var n = v.length; const n = v.length;
var units = allocTexUnits( textures, n ); const units = allocTexUnits( textures, n );
gl.uniform1iv( this.addr, units ); gl.uniform1iv( this.addr, units );
for ( var i = 0; i !== n; ++ i ) { for ( let i = 0; i !== n; ++ i ) {
textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] ); textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
...@@ -712,7 +715,7 @@ function PureArrayUniform( id, activeInfo, addr ) { ...@@ -712,7 +715,7 @@ function PureArrayUniform( id, activeInfo, addr ) {
PureArrayUniform.prototype.updateCache = function ( data ) { PureArrayUniform.prototype.updateCache = function ( data ) {
var cache = this.cache; let cache = this.cache;
if ( data instanceof Float32Array && cache.length !== data.length ) { if ( data instanceof Float32Array && cache.length !== data.length ) {
...@@ -735,11 +738,11 @@ function StructuredUniform( id ) { ...@@ -735,11 +738,11 @@ function StructuredUniform( id ) {
StructuredUniform.prototype.setValue = function ( gl, value, textures ) { StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
var seq = this.seq; const seq = this.seq;
for ( var i = 0, n = seq.length; i !== n; ++ i ) { for ( let i = 0, n = seq.length; i !== n; ++ i ) {
var u = seq[ i ]; const u = seq[ i ];
u.setValue( gl, value[ u.id ], textures ); u.setValue( gl, value[ u.id ], textures );
} }
...@@ -750,7 +753,7 @@ StructuredUniform.prototype.setValue = function ( gl, value, textures ) { ...@@ -750,7 +753,7 @@ StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
// Parser - builds up the property tree from the path strings // Parser - builds up the property tree from the path strings
var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; const RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
// extracts // extracts
// - the identifier (member name or array index) // - the identifier (member name or array index)
...@@ -770,7 +773,7 @@ function addUniform( container, uniformObject ) { ...@@ -770,7 +773,7 @@ function addUniform( container, uniformObject ) {
function parseUniform( activeInfo, addr, container ) { function parseUniform( activeInfo, addr, container ) {
var path = activeInfo.name, const path = activeInfo.name,
pathLength = path.length; pathLength = path.length;
// reset RegExp object, because of the early exit of a previous run // reset RegExp object, because of the early exit of a previous run
...@@ -778,10 +781,10 @@ function parseUniform( activeInfo, addr, container ) { ...@@ -778,10 +781,10 @@ function parseUniform( activeInfo, addr, container ) {
while ( true ) { while ( true ) {
var match = RePathPart.exec( path ), const match = RePathPart.exec( path ),
matchEnd = RePathPart.lastIndex, matchEnd = RePathPart.lastIndex;
id = match[ 1 ], let id = match[ 1 ],
idIsIndex = match[ 2 ] === ']', idIsIndex = match[ 2 ] === ']',
subscript = match[ 3 ]; subscript = match[ 3 ];
...@@ -801,7 +804,8 @@ function parseUniform( activeInfo, addr, container ) { ...@@ -801,7 +804,8 @@ function parseUniform( activeInfo, addr, container ) {
// step into inner node / create it in case it doesn't exist // step into inner node / create it in case it doesn't exist
var map = container.map, next = map[ id ]; const map = container.map;
let next = map[ id ];
if ( next === undefined ) { if ( next === undefined ) {
...@@ -825,11 +829,11 @@ function WebGLUniforms( gl, program ) { ...@@ -825,11 +829,11 @@ function WebGLUniforms( gl, program ) {
this.seq = []; this.seq = [];
this.map = {}; this.map = {};
var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS ); const n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
for ( var i = 0; i < n; ++ i ) { for ( let i = 0; i < n; ++ i ) {
var info = gl.getActiveUniform( program, i ), const info = gl.getActiveUniform( program, i ),
addr = gl.getUniformLocation( program, info.name ); addr = gl.getUniformLocation( program, info.name );
parseUniform( info, addr, this ); parseUniform( info, addr, this );
...@@ -840,7 +844,7 @@ function WebGLUniforms( gl, program ) { ...@@ -840,7 +844,7 @@ function WebGLUniforms( gl, program ) {
WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) { WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
var u = this.map[ name ]; const u = this.map[ name ];
if ( u !== undefined ) u.setValue( gl, value, textures ); if ( u !== undefined ) u.setValue( gl, value, textures );
...@@ -848,7 +852,7 @@ WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) { ...@@ -848,7 +852,7 @@ WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
WebGLUniforms.prototype.setOptional = function ( gl, object, name ) { WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
var v = object[ name ]; const v = object[ name ];
if ( v !== undefined ) this.setValue( gl, name, v ); if ( v !== undefined ) this.setValue( gl, name, v );
...@@ -859,9 +863,9 @@ WebGLUniforms.prototype.setOptional = function ( gl, object, name ) { ...@@ -859,9 +863,9 @@ WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
WebGLUniforms.upload = function ( gl, seq, values, textures ) { WebGLUniforms.upload = function ( gl, seq, values, textures ) {
for ( var i = 0, n = seq.length; i !== n; ++ i ) { for ( let i = 0, n = seq.length; i !== n; ++ i ) {
var u = seq[ i ], const u = seq[ i ],
v = values[ u.id ]; v = values[ u.id ];
if ( v.needsUpdate !== false ) { if ( v.needsUpdate !== false ) {
...@@ -877,11 +881,11 @@ WebGLUniforms.upload = function ( gl, seq, values, textures ) { ...@@ -877,11 +881,11 @@ WebGLUniforms.upload = function ( gl, seq, values, textures ) {
WebGLUniforms.seqWithValue = function ( seq, values ) { WebGLUniforms.seqWithValue = function ( seq, values ) {
var r = []; const r = [];
for ( var i = 0, n = seq.length; i !== n; ++ i ) { for ( let i = 0, n = seq.length; i !== n; ++ i ) {
var u = seq[ i ]; const u = seq[ i ];
if ( u.id in values ) r.push( u ); if ( u.id in values ) r.push( u );
} }
......
...@@ -6,11 +6,11 @@ import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ ...@@ -6,11 +6,11 @@ import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_
function WebGLUtils( gl, extensions, capabilities ) { function WebGLUtils( gl, extensions, capabilities ) {
var isWebGL2 = capabilities.isWebGL2; const isWebGL2 = capabilities.isWebGL2;
function convert( p ) { function convert( p ) {
var extension; let extension;
if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE; if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4; if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
......
...@@ -83,11 +83,11 @@ Object.assign( WebXRController.prototype, { ...@@ -83,11 +83,11 @@ Object.assign( WebXRController.prototype, {
update: function ( inputSource, frame, referenceSpace ) { update: function ( inputSource, frame, referenceSpace ) {
var inputPose = null; let inputPose = null;
var gripPose = null; let gripPose = null;
var targetRay = this._targetRay; const targetRay = this._targetRay;
var grip = this._grip; const grip = this._grip;
if ( inputSource ) { if ( inputSource ) {
......
...@@ -12,38 +12,38 @@ import { WebXRController } from './WebXRController.js'; ...@@ -12,38 +12,38 @@ import { WebXRController } from './WebXRController.js';
function WebXRManager( renderer, gl ) { function WebXRManager( renderer, gl ) {
var scope = this; const scope = this;
var session = null; let session = null;
var framebufferScaleFactor = 1.0; let framebufferScaleFactor = 1.0;
var referenceSpace = null; let referenceSpace = null;
var referenceSpaceType = 'local-floor'; let referenceSpaceType = 'local-floor';
var pose = null; let pose = null;
var controllers = []; const controllers = [];
var inputSourcesMap = new Map(); const inputSourcesMap = new Map();
// //
var cameraL = new PerspectiveCamera(); const cameraL = new PerspectiveCamera();
cameraL.layers.enable( 1 ); cameraL.layers.enable( 1 );
cameraL.viewport = new Vector4(); cameraL.viewport = new Vector4();
var cameraR = new PerspectiveCamera(); const cameraR = new PerspectiveCamera();
cameraR.layers.enable( 2 ); cameraR.layers.enable( 2 );
cameraR.viewport = new Vector4(); cameraR.viewport = new Vector4();
var cameras = [ cameraL, cameraR ]; const cameras = [ cameraL, cameraR ];
var cameraVR = new ArrayCamera(); const cameraVR = new ArrayCamera();
cameraVR.layers.enable( 1 ); cameraVR.layers.enable( 1 );
cameraVR.layers.enable( 2 ); cameraVR.layers.enable( 2 );
var _currentDepthNear = null; let _currentDepthNear = null;
var _currentDepthFar = null; let _currentDepthFar = null;
// //
...@@ -53,7 +53,7 @@ function WebXRManager( renderer, gl ) { ...@@ -53,7 +53,7 @@ function WebXRManager( renderer, gl ) {
this.getController = function ( index ) { this.getController = function ( index ) {
var controller = controllers[ index ]; let controller = controllers[ index ];
if ( controller === undefined ) { if ( controller === undefined ) {
...@@ -68,7 +68,7 @@ function WebXRManager( renderer, gl ) { ...@@ -68,7 +68,7 @@ function WebXRManager( renderer, gl ) {
this.getControllerGrip = function ( index ) { this.getControllerGrip = function ( index ) {
var controller = controllers[ index ]; let controller = controllers[ index ];
if ( controller === undefined ) { if ( controller === undefined ) {
...@@ -85,7 +85,7 @@ function WebXRManager( renderer, gl ) { ...@@ -85,7 +85,7 @@ function WebXRManager( renderer, gl ) {
function onSessionEvent( event ) { function onSessionEvent( event ) {
var controller = inputSourcesMap.get( event.inputSource ); const controller = inputSourcesMap.get( event.inputSource );
if ( controller ) { if ( controller ) {
...@@ -180,7 +180,7 @@ function WebXRManager( renderer, gl ) { ...@@ -180,7 +180,7 @@ function WebXRManager( renderer, gl ) {
session.addEventListener( 'squeezeend', onSessionEvent ); session.addEventListener( 'squeezeend', onSessionEvent );
session.addEventListener( 'end', onSessionEnd ); session.addEventListener( 'end', onSessionEnd );
var attributes = gl.getContextAttributes(); const attributes = gl.getContextAttributes();
if ( attributes.xrCompatible !== true ) { if ( attributes.xrCompatible !== true ) {
...@@ -188,7 +188,7 @@ function WebXRManager( renderer, gl ) { ...@@ -188,7 +188,7 @@ function WebXRManager( renderer, gl ) {
} }
var layerInit = { const layerInit = {
antialias: attributes.antialias, antialias: attributes.antialias,
alpha: attributes.alpha, alpha: attributes.alpha,
depth: attributes.depth, depth: attributes.depth,
...@@ -197,7 +197,7 @@ function WebXRManager( renderer, gl ) { ...@@ -197,7 +197,7 @@ function WebXRManager( renderer, gl ) {
}; };
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
var baseLayer = new XRWebGLLayer( session, gl, layerInit ); const baseLayer = new XRWebGLLayer( session, gl, layerInit );
session.updateRenderState( { baseLayer: baseLayer } ); session.updateRenderState( { baseLayer: baseLayer } );
...@@ -213,11 +213,11 @@ function WebXRManager( renderer, gl ) { ...@@ -213,11 +213,11 @@ function WebXRManager( renderer, gl ) {
function updateInputSources( event ) { function updateInputSources( event ) {
var inputSources = session.inputSources; const inputSources = session.inputSources;
// Assign inputSources to available controllers // Assign inputSources to available controllers
for ( var i = 0; i < controllers.length; i ++ ) { for ( let i = 0; i < controllers.length; i ++ ) {
inputSourcesMap.set( inputSources[ i ], controllers[ i ] ); inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
...@@ -225,10 +225,10 @@ function WebXRManager( renderer, gl ) { ...@@ -225,10 +225,10 @@ function WebXRManager( renderer, gl ) {
// Notify disconnected // Notify disconnected
for ( var i = 0; i < event.removed.length; i ++ ) { for ( let i = 0; i < event.removed.length; i ++ ) {
var inputSource = event.removed[ i ]; const inputSource = event.removed[ i ];
var controller = inputSourcesMap.get( inputSource ); const controller = inputSourcesMap.get( inputSource );
if ( controller ) { if ( controller ) {
...@@ -241,10 +241,10 @@ function WebXRManager( renderer, gl ) { ...@@ -241,10 +241,10 @@ function WebXRManager( renderer, gl ) {
// Notify connected // Notify connected
for ( var i = 0; i < event.added.length; i ++ ) { for ( let i = 0; i < event.added.length; i ++ ) {
var inputSource = event.added[ i ]; const inputSource = event.added[ i ];
var controller = inputSourcesMap.get( inputSource ); const controller = inputSourcesMap.get( inputSource );
if ( controller ) { if ( controller ) {
...@@ -258,8 +258,8 @@ function WebXRManager( renderer, gl ) { ...@@ -258,8 +258,8 @@ function WebXRManager( renderer, gl ) {
// //
var cameraLPos = new Vector3(); const cameraLPos = new Vector3();
var cameraRPos = new Vector3(); const cameraRPos = new Vector3();
/** /**
* @author jsantell / https://www.jsantell.com/ * @author jsantell / https://www.jsantell.com/
...@@ -274,28 +274,28 @@ function WebXRManager( renderer, gl ) { ...@@ -274,28 +274,28 @@ function WebXRManager( renderer, gl ) {
cameraLPos.setFromMatrixPosition( cameraL.matrixWorld ); cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
cameraRPos.setFromMatrixPosition( cameraR.matrixWorld ); cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
var ipd = cameraLPos.distanceTo( cameraRPos ); const ipd = cameraLPos.distanceTo( cameraRPos );
var projL = cameraL.projectionMatrix.elements; const projL = cameraL.projectionMatrix.elements;
var projR = cameraR.projectionMatrix.elements; const projR = cameraR.projectionMatrix.elements;
// VR systems will have identical far and near planes, and // VR systems will have identical far and near planes, and
// most likely identical top and bottom frustum extents. // most likely identical top and bottom frustum extents.
// Use the left camera for these values. // Use the left camera for these values.
var near = projL[ 14 ] / ( projL[ 10 ] - 1 ); const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
var far = projL[ 14 ] / ( projL[ 10 ] + 1 ); const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ]; const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ]; const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ]; const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ]; const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
var left = near * leftFov; const left = near * leftFov;
var right = near * rightFov; const right = near * rightFov;
// Calculate the new camera's position offset from the // Calculate the new camera's position offset from the
// left camera. xOffset should be roughly half `ipd`. // left camera. xOffset should be roughly half `ipd`.
var zOffset = ipd / ( - leftFov + rightFov ); const zOffset = ipd / ( - leftFov + rightFov );
var xOffset = zOffset * - leftFov; const xOffset = zOffset * - leftFov;
// TODO: Better way to apply this offset? // TODO: Better way to apply this offset?
cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale ); cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
...@@ -307,12 +307,12 @@ function WebXRManager( renderer, gl ) { ...@@ -307,12 +307,12 @@ function WebXRManager( renderer, gl ) {
// Find the union of the frustum values of the cameras and scale // Find the union of the frustum values of the cameras and scale
// the values so that the near plane's position does not change in world space, // the values so that the near plane's position does not change in world space,
// although must now be relative to the new union camera. // although must now be relative to the new union camera.
var near2 = near + zOffset; const near2 = near + zOffset;
var far2 = far + zOffset; const far2 = far + zOffset;
var left2 = left - xOffset; const left2 = left - xOffset;
var right2 = right + ( ipd - xOffset ); const right2 = right + ( ipd - xOffset );
var top2 = topFov * far / far2 * near2; const top2 = topFov * far / far2 * near2;
var bottom2 = bottomFov * far / far2 * near2; const bottom2 = bottomFov * far / far2 * near2;
camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 ); camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
...@@ -353,12 +353,12 @@ function WebXRManager( renderer, gl ) { ...@@ -353,12 +353,12 @@ function WebXRManager( renderer, gl ) {
} }
var parent = camera.parent; const parent = camera.parent;
var cameras = cameraVR.cameras; const cameras = cameraVR.cameras;
updateCamera( cameraVR, parent ); updateCamera( cameraVR, parent );
for ( var i = 0; i < cameras.length; i ++ ) { for ( let i = 0; i < cameras.length; i ++ ) {
updateCamera( cameras[ i ], parent ); updateCamera( cameras[ i ], parent );
...@@ -368,9 +368,9 @@ function WebXRManager( renderer, gl ) { ...@@ -368,9 +368,9 @@ function WebXRManager( renderer, gl ) {
camera.matrixWorld.copy( cameraVR.matrixWorld ); camera.matrixWorld.copy( cameraVR.matrixWorld );
var children = camera.children; const children = camera.children;
for ( var i = 0, l = children.length; i < l; i ++ ) { for ( let i = 0, l = children.length; i < l; i ++ ) {
children[ i ].updateMatrixWorld( true ); children[ i ].updateMatrixWorld( true );
...@@ -396,7 +396,7 @@ function WebXRManager( renderer, gl ) { ...@@ -396,7 +396,7 @@ function WebXRManager( renderer, gl ) {
// Animation Loop // Animation Loop
var onAnimationFrameCallback = null; let onAnimationFrameCallback = null;
function onAnimationFrame( time, frame ) { function onAnimationFrame( time, frame ) {
...@@ -404,12 +404,12 @@ function WebXRManager( renderer, gl ) { ...@@ -404,12 +404,12 @@ function WebXRManager( renderer, gl ) {
if ( pose !== null ) { if ( pose !== null ) {
var views = pose.views; const views = pose.views;
var baseLayer = session.renderState.baseLayer; const baseLayer = session.renderState.baseLayer;
renderer.setFramebuffer( baseLayer.framebuffer ); renderer.setFramebuffer( baseLayer.framebuffer );
var cameraVRNeedsUpdate = false; let cameraVRNeedsUpdate = false;
// check if it's necessary to rebuild cameraVR's camera list // check if it's necessary to rebuild cameraVR's camera list
...@@ -420,12 +420,12 @@ function WebXRManager( renderer, gl ) { ...@@ -420,12 +420,12 @@ function WebXRManager( renderer, gl ) {
} }
for ( var i = 0; i < views.length; i ++ ) { for ( let i = 0; i < views.length; i ++ ) {
var view = views[ i ]; const view = views[ i ];
var viewport = baseLayer.getViewport( view ); const viewport = baseLayer.getViewport( view );
var camera = cameras[ i ]; const camera = cameras[ i ];
camera.matrix.fromArray( view.transform.matrix ); camera.matrix.fromArray( view.transform.matrix );
camera.projectionMatrix.fromArray( view.projectionMatrix ); camera.projectionMatrix.fromArray( view.projectionMatrix );
camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height ); camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
...@@ -448,12 +448,12 @@ function WebXRManager( renderer, gl ) { ...@@ -448,12 +448,12 @@ function WebXRManager( renderer, gl ) {
// //
var inputSources = session.inputSources; const inputSources = session.inputSources;
for ( var i = 0; i < controllers.length; i ++ ) { for ( let i = 0; i < controllers.length; i ++ ) {
var controller = controllers[ i ]; const controller = controllers[ i ];
var inputSource = inputSources[ i ]; const inputSource = inputSources[ i ];
controller.update( inputSource, frame, referenceSpace ); controller.update( inputSource, frame, referenceSpace );
...@@ -463,7 +463,7 @@ function WebXRManager( renderer, gl ) { ...@@ -463,7 +463,7 @@ function WebXRManager( renderer, gl ) {
} }
var animation = new WebGLAnimation(); const animation = new WebGLAnimation();
animation.setAnimationLoop( onAnimationFrame ); animation.setAnimationLoop( onAnimationFrame );
this.setAnimationLoop = function ( callback ) { this.setAnimationLoop = function ( callback ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册