|
@@ -6569,7 +6569,7 @@ function LensFlarePlugin( renderer, flares ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- gl.useProgram( program );
|
|
|
+ state.useProgram( program );
|
|
|
|
|
|
state.initAttributes();
|
|
|
state.enableAttribute( attributes.vertex );
|
|
@@ -6716,7 +6716,7 @@ function LensFlarePlugin( renderer, flares ) {
|
|
|
state.enable( gl.DEPTH_TEST );
|
|
|
state.buffers.depth.setMask( true );
|
|
|
|
|
|
- renderer.resetGLState();
|
|
|
+ state.reset();
|
|
|
|
|
|
};
|
|
|
|
|
@@ -6746,6 +6746,21 @@ function LensFlarePlugin( renderer, flares ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @author mrdoob / http://mrdoob.com/
|
|
|
+ */
|
|
|
+
|
|
|
+function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
|
|
|
+
|
|
|
+ Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
|
|
|
+
|
|
|
+ this.needsUpdate = true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CanvasTexture.prototype = Object.create( Texture.prototype );
|
|
|
+CanvasTexture.prototype.constructor = CanvasTexture;
|
|
|
+
|
|
|
/**
|
|
|
* @author mikael emtinger / http://gomo.se/
|
|
|
* @author alteredq / http://alteredqualia.com/
|
|
@@ -6828,8 +6843,7 @@ function SpritePlugin( renderer, sprites ) {
|
|
|
context.fillStyle = 'white';
|
|
|
context.fillRect( 0, 0, 8, 8 );
|
|
|
|
|
|
- texture = new Texture( canvas );
|
|
|
- texture.needsUpdate = true;
|
|
|
+ texture = new CanvasTexture( canvas );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -6845,7 +6859,7 @@ function SpritePlugin( renderer, sprites ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- gl.useProgram( program );
|
|
|
+ state.useProgram( program );
|
|
|
|
|
|
state.initAttributes();
|
|
|
state.enableAttribute( attributes.position );
|
|
@@ -6993,7 +7007,7 @@ function SpritePlugin( renderer, sprites ) {
|
|
|
|
|
|
state.enable( gl.CULL_FACE );
|
|
|
|
|
|
- renderer.resetGLState();
|
|
|
+ state.reset();
|
|
|
|
|
|
};
|
|
|
|
|
@@ -19125,6 +19139,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
var compressedTextureFormats = null;
|
|
|
|
|
|
+ var currentProgram = null;
|
|
|
+
|
|
|
var currentBlending = null;
|
|
|
var currentBlendEquation = null;
|
|
|
var currentBlendSrc = null;
|
|
@@ -19178,25 +19194,23 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
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 );
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
- function init() {
|
|
|
+ // init
|
|
|
|
|
|
- colorBuffer.setClear( 0, 0, 0, 1 );
|
|
|
- depthBuffer.setClear( 1 );
|
|
|
- stencilBuffer.setClear( 0 );
|
|
|
+ colorBuffer.setClear( 0, 0, 0, 1 );
|
|
|
+ depthBuffer.setClear( 1 );
|
|
|
+ stencilBuffer.setClear( 0 );
|
|
|
|
|
|
- enable( gl.DEPTH_TEST );
|
|
|
- depthBuffer.setFunc( LessEqualDepth );
|
|
|
+ enable( gl.DEPTH_TEST );
|
|
|
+ depthBuffer.setFunc( LessEqualDepth );
|
|
|
|
|
|
- setFlipSided( false );
|
|
|
- setCullFace( CullFaceBack );
|
|
|
- enable( gl.CULL_FACE );
|
|
|
+ setFlipSided( false );
|
|
|
+ setCullFace( CullFaceBack );
|
|
|
+ enable( gl.CULL_FACE );
|
|
|
|
|
|
- enable( gl.BLEND );
|
|
|
- setBlending( NormalBlending );
|
|
|
+ enable( gl.BLEND );
|
|
|
+ setBlending( NormalBlending );
|
|
|
|
|
|
- }
|
|
|
+ //
|
|
|
|
|
|
function initAttributes() {
|
|
|
|
|
@@ -19315,6 +19329,22 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function useProgram( program ) {
|
|
|
+
|
|
|
+ if ( currentProgram !== program ) {
|
|
|
+
|
|
|
+ gl.useProgram( program );
|
|
|
+
|
|
|
+ currentProgram = program;
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
|
|
|
|
if ( blending !== NoBlending ) {
|
|
@@ -19682,6 +19712,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
currentTextureSlot = null;
|
|
|
currentBoundTextures = {};
|
|
|
|
|
|
+ currentProgram = null;
|
|
|
+
|
|
|
currentBlending = null;
|
|
|
|
|
|
currentFlipSided = null;
|
|
@@ -19701,7 +19733,6 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
stencil: stencilBuffer
|
|
|
},
|
|
|
|
|
|
- init: init,
|
|
|
initAttributes: initAttributes,
|
|
|
enableAttribute: enableAttribute,
|
|
|
enableAttributeAndDivisor: enableAttributeAndDivisor,
|
|
@@ -19710,6 +19741,8 @@ function WebGLState( gl, extensions, paramThreeToGL ) {
|
|
|
disable: disable,
|
|
|
getCompressedTextureFormats: getCompressedTextureFormats,
|
|
|
|
|
|
+ useProgram: useProgram,
|
|
|
+
|
|
|
setBlending: setBlending,
|
|
|
setMaterial: setMaterial,
|
|
|
|
|
@@ -20371,9 +20404,10 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
var _this = this,
|
|
|
|
|
|
+ _isContextLost = false,
|
|
|
+
|
|
|
// internal state cache
|
|
|
|
|
|
- _currentProgram = null,
|
|
|
_currentRenderTarget = null,
|
|
|
_currentFramebuffer = null,
|
|
|
_currentMaterialId = - 1,
|
|
@@ -20514,6 +20548,7 @@ function WebGLRenderer( parameters ) {
|
|
|
}
|
|
|
|
|
|
_canvas.addEventListener( 'webglcontextlost', onContextLost, false );
|
|
|
+ _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
|
|
|
|
|
|
} catch ( error ) {
|
|
|
|
|
@@ -20521,74 +20556,65 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var extensions = new WebGLExtensions( _gl );
|
|
|
+ var extensions, capabilities, state;
|
|
|
+ var properties, textures, attributes, geometries, objects;
|
|
|
+ var programCache, lightCache, renderLists;
|
|
|
|
|
|
- extensions.get( 'WEBGL_depth_texture' );
|
|
|
- extensions.get( 'OES_texture_float' );
|
|
|
- extensions.get( 'OES_texture_float_linear' );
|
|
|
- extensions.get( 'OES_texture_half_float' );
|
|
|
- extensions.get( 'OES_texture_half_float_linear' );
|
|
|
- extensions.get( 'OES_standard_derivatives' );
|
|
|
- extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+ var background, bufferRenderer, indexedBufferRenderer;
|
|
|
|
|
|
- if ( extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
+ function initGLContext() {
|
|
|
|
|
|
- BufferGeometry.MaxIndex = 4294967296;
|
|
|
+ extensions = new WebGLExtensions( _gl );
|
|
|
+ extensions.get( 'WEBGL_depth_texture' );
|
|
|
+ extensions.get( 'OES_texture_float' );
|
|
|
+ extensions.get( 'OES_texture_float_linear' );
|
|
|
+ extensions.get( 'OES_texture_half_float' );
|
|
|
+ extensions.get( 'OES_texture_half_float_linear' );
|
|
|
+ extensions.get( 'OES_standard_derivatives' );
|
|
|
+ extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- var capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
+ if ( extensions.get( 'OES_element_index_uint' ) ) {
|
|
|
|
|
|
- var state = new WebGLState( _gl, extensions, paramThreeToGL );
|
|
|
+ BufferGeometry.MaxIndex = 4294967296;
|
|
|
|
|
|
- var properties = new WebGLProperties();
|
|
|
- var textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
|
|
|
- var attributes = new WebGLAttributes( _gl );
|
|
|
- var geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
|
|
|
- var objects = new WebGLObjects( _gl, geometries, _infoRender );
|
|
|
- var programCache = new WebGLPrograms( this, capabilities );
|
|
|
- var lightCache = new WebGLLights();
|
|
|
- var renderLists = new WebGLRenderLists();
|
|
|
+ }
|
|
|
|
|
|
- var background = new WebGLBackground( this, state, objects, _premultipliedAlpha );
|
|
|
- var vr = new WebVRManager( this );
|
|
|
+ capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
|
|
|
- this.info.programs = programCache.programs;
|
|
|
+ state = new WebGLState( _gl, extensions, paramThreeToGL );
|
|
|
+ state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
|
+ state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
|
|
|
- var bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
|
|
|
- var indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
|
|
|
+ properties = new WebGLProperties();
|
|
|
+ textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
|
|
|
+ attributes = new WebGLAttributes( _gl );
|
|
|
+ geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
|
|
|
+ objects = new WebGLObjects( _gl, geometries, _infoRender );
|
|
|
+ programCache = new WebGLPrograms( _this, capabilities );
|
|
|
+ lightCache = new WebGLLights();
|
|
|
+ renderLists = new WebGLRenderLists();
|
|
|
|
|
|
- //
|
|
|
+ background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
|
|
|
|
|
|
- function getTargetPixelRatio() {
|
|
|
+ bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
|
|
|
+ indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
|
|
|
|
|
|
- return _currentRenderTarget === null ? _pixelRatio : 1;
|
|
|
+ _this.info.programs = programCache.programs;
|
|
|
|
|
|
}
|
|
|
|
|
|
- function setDefaultGLState() {
|
|
|
-
|
|
|
- state.init();
|
|
|
-
|
|
|
- state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
|
- state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
-
|
|
|
- }
|
|
|
+ initGLContext();
|
|
|
|
|
|
- function resetGLState() {
|
|
|
+ var vr = new WebVRManager( _this );
|
|
|
|
|
|
- _currentProgram = null;
|
|
|
- _currentCamera = null;
|
|
|
+ //
|
|
|
|
|
|
- _currentGeometryProgram = '';
|
|
|
- _currentMaterialId = - 1;
|
|
|
+ function getTargetPixelRatio() {
|
|
|
|
|
|
- state.reset();
|
|
|
+ return _currentRenderTarget === null ? _pixelRatio : 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
- setDefaultGLState();
|
|
|
-
|
|
|
this.context = _gl;
|
|
|
this.capabilities = capabilities;
|
|
|
this.extensions = extensions;
|
|
@@ -20630,6 +20656,13 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ this.forceContextRestore = function () {
|
|
|
+
|
|
|
+ var extension = extensions.get( 'WEBGL_lose_context' );
|
|
|
+ if ( extension ) extension.restoreContext();
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
this.getMaxAnisotropy = function () {
|
|
|
|
|
|
return capabilities.getMaxAnisotropy();
|
|
@@ -20782,13 +20815,12 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- // Reset
|
|
|
-
|
|
|
- this.resetGLState = resetGLState;
|
|
|
+ //
|
|
|
|
|
|
this.dispose = function () {
|
|
|
|
|
|
_canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
|
|
|
+ _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
|
|
|
|
|
|
renderLists.dispose();
|
|
|
|
|
@@ -20800,11 +20832,15 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
- resetGLState();
|
|
|
- setDefaultGLState();
|
|
|
+ _isContextLost = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function onContextRestore( event ) {
|
|
|
+
|
|
|
+ initGLContext();
|
|
|
|
|
|
- properties.clear();
|
|
|
- objects.clear();
|
|
|
+ _isContextLost = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -21363,6 +21399,8 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if ( _isContextLost ) return;
|
|
|
+
|
|
|
// reset caching for this frame
|
|
|
|
|
|
_currentGeometryProgram = '';
|
|
@@ -21937,10 +21975,7 @@ function WebGLRenderer( parameters ) {
|
|
|
p_uniforms = program.getUniforms(),
|
|
|
m_uniforms = materialProperties.shader.uniforms;
|
|
|
|
|
|
- if ( program.id !== _currentProgram ) {
|
|
|
-
|
|
|
- _gl.useProgram( program.program );
|
|
|
- _currentProgram = program.id;
|
|
|
+ if ( state.useProgram( program.program ) ) {
|
|
|
|
|
|
refreshProgram = true;
|
|
|
refreshMaterial = true;
|
|
@@ -24529,21 +24564,6 @@ CompressedTexture.prototype.constructor = CompressedTexture;
|
|
|
|
|
|
CompressedTexture.prototype.isCompressedTexture = true;
|
|
|
|
|
|
-/**
|
|
|
- * @author mrdoob / http://mrdoob.com/
|
|
|
- */
|
|
|
-
|
|
|
-function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
|
|
|
-
|
|
|
- Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
|
|
|
-
|
|
|
- this.needsUpdate = true;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-CanvasTexture.prototype = Object.create( Texture.prototype );
|
|
|
-CanvasTexture.prototype.constructor = CanvasTexture;
|
|
|
-
|
|
|
/**
|
|
|
* @author Matt DesLauriers / @mattdesl
|
|
|
* @author atix / arthursilber.de
|
|
@@ -40831,7 +40851,7 @@ function SpotLightHelper( light, color ) {
|
|
|
|
|
|
geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
|
|
|
|
|
- var material = new LineBasicMaterial( { fog: false, color: this.color } );
|
|
|
+ var material = new LineBasicMaterial( { fog: false } );
|
|
|
|
|
|
this.cone = new LineSegments( geometry, material );
|
|
|
this.add( this.cone );
|
|
@@ -41013,7 +41033,7 @@ function PointLightHelper( light, sphereSize, color ) {
|
|
|
this.color = color;
|
|
|
|
|
|
var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
|
|
|
- var material = new MeshBasicMaterial( { wireframe: true, fog: false, color: this.color } );
|
|
|
+ var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
|
|
|
|
|
|
Mesh.call( this, geometry, material );
|
|
|
|
|
@@ -41104,7 +41124,7 @@ function RectAreaLightHelper( light, color ) {
|
|
|
|
|
|
this.color = color;
|
|
|
|
|
|
- var material = new LineBasicMaterial( { fog: false, color: this.color } );
|
|
|
+ var material = new LineBasicMaterial( { fog: false } );
|
|
|
|
|
|
var geometry = new BufferGeometry();
|
|
|
|
|
@@ -41181,7 +41201,7 @@ function HemisphereLightHelper( light, size, color ) {
|
|
|
var geometry = new OctahedronBufferGeometry( size );
|
|
|
geometry.rotateY( Math.PI * 0.5 );
|
|
|
|
|
|
- this.material = new MeshBasicMaterial( { wireframe: true, fog: false, color: this.color } );
|
|
|
+ this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
|
|
|
if ( this.color === undefined ) this.material.vertexColors = VertexColors;
|
|
|
|
|
|
var position = geometry.getAttribute( 'position' );
|
|
@@ -41514,7 +41534,7 @@ function DirectionalLightHelper( light, size, color ) {
|
|
|
- size, size, 0
|
|
|
], 3 ) );
|
|
|
|
|
|
- var material = new LineBasicMaterial( { fog: false, color: this.color } );
|
|
|
+ var material = new LineBasicMaterial( { fog: false } );
|
|
|
|
|
|
this.lightPlane = new Line( geometry, material );
|
|
|
this.add( this.lightPlane );
|