|
@@ -14716,7 +14716,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
-function WebGLBufferRenderer( gl, extensions, info ) {
|
|
|
+function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
|
|
|
|
|
|
var mode;
|
|
|
|
|
@@ -14738,7 +14738,7 @@ function WebGLBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
var extension;
|
|
|
|
|
|
- if ( gl.isWebGL2 ) {
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
extension = gl;
|
|
|
|
|
@@ -14755,7 +14755,7 @@ function WebGLBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- extension[ gl.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
|
|
|
+ extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
|
|
|
|
|
|
info.update( count, mode, geometry.maxInstancedCount );
|
|
|
|
|
@@ -14827,6 +14827,8 @@ function WebGLCapabilities( gl, extensions, parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
|
|
|
+
|
|
|
var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
|
|
|
var maxPrecision = getMaxPrecision( precision );
|
|
|
|
|
@@ -14850,11 +14852,13 @@ function WebGLCapabilities( gl, extensions, parameters ) {
|
|
|
var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
|
|
|
|
|
|
var vertexTextures = maxVertexTextures > 0;
|
|
|
- var floatFragmentTextures = gl.isWebGL2 || !! extensions.get( 'OES_texture_float' );
|
|
|
+ var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
|
|
|
var floatVertexTextures = vertexTextures && floatFragmentTextures;
|
|
|
|
|
|
return {
|
|
|
|
|
|
+ isWebGL2: isWebGL2,
|
|
|
+
|
|
|
getMaxAnisotropy: getMaxAnisotropy,
|
|
|
getMaxPrecision: getMaxPrecision,
|
|
|
|
|
@@ -15290,7 +15294,7 @@ function WebGLGeometries( gl, attributes, info ) {
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
-function WebGLIndexedBufferRenderer( gl, extensions, info ) {
|
|
|
+function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
|
|
|
|
|
|
var mode;
|
|
|
|
|
@@ -15321,7 +15325,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
var extension;
|
|
|
|
|
|
- if ( gl.isWebGL2 ) {
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
extension = gl;
|
|
|
|
|
@@ -15338,7 +15342,7 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- extension[ gl.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
|
|
|
+ extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
|
|
|
|
|
|
info.update( count, mode, geometry.maxInstancedCount );
|
|
|
|
|
@@ -16728,7 +16732,7 @@ function unrollLoops( string ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
|
|
|
+function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
|
|
|
|
|
|
var gl = renderer.context;
|
|
|
|
|
@@ -16811,7 +16815,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
|
|
|
//
|
|
|
|
|
|
- var customExtensions = gl.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
|
|
|
+ var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
|
|
|
|
|
|
var customDefines = generateDefines( defines );
|
|
|
|
|
@@ -16899,7 +16903,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
|
|
|
|
|
|
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
|
|
|
- parameters.logarithmicDepthBuffer && ( gl.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
+ parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
|
|
|
'uniform mat4 modelMatrix;',
|
|
|
'uniform mat4 modelViewMatrix;',
|
|
@@ -17004,9 +17008,9 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
|
|
|
|
|
|
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
|
|
|
- parameters.logarithmicDepthBuffer && ( gl.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
+ parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
|
|
|
- parameters.envMap && ( gl.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
|
|
|
+ parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
|
|
|
|
|
|
'uniform mat4 viewMatrix;',
|
|
|
'uniform vec3 cameraPosition;',
|
|
@@ -17042,7 +17046,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
vertexShader = unrollLoops( vertexShader );
|
|
|
fragmentShader = unrollLoops( fragmentShader );
|
|
|
|
|
|
- if ( gl.isWebGL2 && ! material.isRawShaderMaterial ) {
|
|
|
+ if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
|
|
|
|
|
|
var isGLSL3ShaderMaterial = false;
|
|
|
|
|
@@ -17523,7 +17527,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
|
|
|
|
|
|
if ( program === undefined ) {
|
|
|
|
|
|
- program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
|
|
|
+ program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
|
|
|
programs.push( program );
|
|
|
|
|
|
}
|
|
@@ -18785,7 +18789,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
-function WebGLState( gl, extensions, utils ) {
|
|
|
+function WebGLState( gl, extensions, utils, capabilities ) {
|
|
|
|
|
|
function ColorBuffer() {
|
|
|
|
|
@@ -19097,7 +19101,7 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
var enabledAttributes = new Uint8Array( maxVertexAttributes );
|
|
|
var attributeDivisors = new Uint8Array( maxVertexAttributes );
|
|
|
|
|
|
- var capabilities = {};
|
|
|
+ var enabledCapabilities = {};
|
|
|
|
|
|
var compressedTextureFormats = null;
|
|
|
|
|
@@ -19214,9 +19218,9 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
|
|
|
|
|
|
- var extension = gl.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+ var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
- extension[ gl.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
|
|
|
+ extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
|
|
|
attributeDivisors[ attribute ] = meshPerAttribute;
|
|
|
|
|
|
}
|
|
@@ -19240,10 +19244,10 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
function enable( id ) {
|
|
|
|
|
|
- if ( capabilities[ id ] !== true ) {
|
|
|
+ if ( enabledCapabilities[ id ] !== true ) {
|
|
|
|
|
|
gl.enable( id );
|
|
|
- capabilities[ id ] = true;
|
|
|
+ enabledCapabilities[ id ] = true;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -19251,10 +19255,10 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
function disable( id ) {
|
|
|
|
|
|
- if ( capabilities[ id ] !== false ) {
|
|
|
+ if ( enabledCapabilities[ id ] !== false ) {
|
|
|
|
|
|
gl.disable( id );
|
|
|
- capabilities[ id ] = false;
|
|
|
+ enabledCapabilities[ id ] = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -19663,7 +19667,7 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- capabilities = {};
|
|
|
+ enabledCapabilities = {};
|
|
|
|
|
|
compressedTextureFormats = null;
|
|
|
|
|
@@ -19800,7 +19804,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function textureNeedsPowerOfTwo( texture ) {
|
|
|
|
|
|
- if ( _gl.isWebGL2 ) return false;
|
|
|
+ if ( capabilities.isWebGL2 ) return false;
|
|
|
|
|
|
return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
|
|
|
( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
|
|
@@ -19827,7 +19831,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function getInternalFormat( glFormat, glType ) {
|
|
|
|
|
|
- if ( ! _gl.isWebGL2 ) return glFormat;
|
|
|
+ if ( ! capabilities.isWebGL2 ) return glFormat;
|
|
|
|
|
|
if ( glFormat === _gl.RGB ) {
|
|
|
|
|
@@ -20172,7 +20176,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
if ( extension ) {
|
|
|
|
|
|
if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
|
|
|
- if ( texture.type === HalfFloatType && ( _gl.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
|
|
|
+ if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
|
|
|
|
|
|
if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
|
|
|
|
|
@@ -20231,10 +20235,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( texture.type === FloatType ) {
|
|
|
|
|
|
- if ( ! _gl.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
+ if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
|
|
|
- } else if ( _gl.isWebGL2 ) {
|
|
|
+ } else if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
// WebGL 2.0 requires signed internalformat for glTexImage2D
|
|
|
glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
@@ -20626,7 +20630,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
* @author thespite / http://www.twitter.com/thespite
|
|
|
*/
|
|
|
|
|
|
-function WebGLUtils( gl, extensions ) {
|
|
|
+function WebGLUtils( gl, extensions, capabilities ) {
|
|
|
|
|
|
function convert( p ) {
|
|
|
|
|
@@ -20658,7 +20662,7 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === HalfFloatType ) {
|
|
|
|
|
|
- if ( gl.isWebGL2 ) return gl.HALF_FLOAT;
|
|
|
+ if ( capabilities.isWebGL2 ) return gl.HALF_FLOAT;
|
|
|
|
|
|
extension = extensions.get( 'OES_texture_half_float' );
|
|
|
|
|
@@ -20749,7 +20753,7 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === MinEquation || p === MaxEquation ) {
|
|
|
|
|
|
- if ( gl.isWebGL2 ) {
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
if ( p === MinEquation ) return gl.MIN;
|
|
|
if ( p === MaxEquation ) return gl.MAX;
|
|
@@ -20769,7 +20773,7 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === UnsignedInt248Type ) {
|
|
|
|
|
|
- if ( gl.isWebGL2 ) return gl.UNSIGNED_INT_24_8;
|
|
|
+ if ( capabilities.isWebGL2 ) return gl.UNSIGNED_INT_24_8;
|
|
|
|
|
|
extension = extensions.get( 'WEBGL_depth_texture' );
|
|
|
|
|
@@ -21873,8 +21877,6 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _gl.isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext;
|
|
|
-
|
|
|
// Some experimental-webgl implementations do not have getShaderPrecisionFormat
|
|
|
|
|
|
if ( _gl.getShaderPrecisionFormat === undefined ) {
|
|
@@ -21905,7 +21907,9 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
extensions = new WebGLExtensions( _gl );
|
|
|
|
|
|
- if ( ! _gl.isWebGL2 ) {
|
|
|
+ capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
+
|
|
|
+ if ( ! capabilities.isWebGL2 ) {
|
|
|
|
|
|
extensions.get( 'WEBGL_depth_texture' );
|
|
|
extensions.get( 'OES_texture_float' );
|
|
@@ -21919,11 +21923,9 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
extensions.get( 'OES_texture_float_linear' );
|
|
|
|
|
|
- utils = new WebGLUtils( _gl, extensions );
|
|
|
+ utils = new WebGLUtils( _gl, extensions, capabilities );
|
|
|
|
|
|
- capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
-
|
|
|
- state = new WebGLState( _gl, extensions, utils );
|
|
|
+ state = new WebGLState( _gl, extensions, utils, capabilities );
|
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
|
|
@@ -21940,8 +21942,8 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
|
|
|
|
|
|
- bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info );
|
|
|
- indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info );
|
|
|
+ bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
|
|
|
+ indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
|
|
|
|
|
|
info.programs = programCache.programs;
|
|
|
|
|
@@ -22478,7 +22480,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
function setupVertexAttributes( material, program, geometry ) {
|
|
|
|
|
|
- if ( geometry && geometry.isInstancedBufferGeometry & ! _gl.isWebGL2 ) {
|
|
|
+ if ( geometry && geometry.isInstancedBufferGeometry & ! capabilities.isWebGL2 ) {
|
|
|
|
|
|
if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
|
|
|
|
|
@@ -22907,8 +22909,6 @@ function WebGLRenderer( parameters ) {
|
|
|
_vector3.setFromMatrixPosition( object.matrixWorld )
|
|
|
.applyMatrix4( _projScreenMatrix );
|
|
|
|
|
|
- var material = object.material;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
var geometry = objects.update( object );
|
|
@@ -23143,6 +23143,9 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
material.onBeforeCompile( materialProperties.shader, _this );
|
|
|
|
|
|
+ // Computing code again as onBeforeCompile may have changed the shaders
|
|
|
+ code = programCache.getProgramCode( material, parameters );
|
|
|
+
|
|
|
program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
|
|
|
|
|
|
materialProperties.program = program;
|
|
@@ -24191,8 +24194,8 @@ function WebGLRenderer( parameters ) {
|
|
|
}
|
|
|
|
|
|
if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
|
|
|
- ! ( textureType === FloatType && ( _gl.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
|
|
|
- ! ( textureType === HalfFloatType && ( _gl.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
|
|
|
+ ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
|
|
|
+ ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
|
|
|
|
|
|
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
|
|
|
return;
|