|
@@ -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;
|
|
|
|
|
@@ -14736,16 +14736,26 @@ function WebGLBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
function renderInstances( geometry, start, count ) {
|
|
|
|
|
|
- var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+ var extension;
|
|
|
|
|
|
- if ( extension === null ) {
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
- console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
- return;
|
|
|
+ extension = gl;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+
|
|
|
+ if ( extension === null ) {
|
|
|
+
|
|
|
+ console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
|
|
|
+ extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
|
|
|
|
|
|
info.update( count, mode, geometry.maxInstancedCount );
|
|
|
|
|
@@ -14817,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 );
|
|
|
|
|
@@ -14840,11 +14852,13 @@ function WebGLCapabilities( gl, extensions, parameters ) {
|
|
|
var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
|
|
|
|
|
|
var vertexTextures = maxVertexTextures > 0;
|
|
|
- var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
|
|
|
+ var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
|
|
|
var floatVertexTextures = vertexTextures && floatFragmentTextures;
|
|
|
|
|
|
return {
|
|
|
|
|
|
+ isWebGL2: isWebGL2,
|
|
|
+
|
|
|
getMaxAnisotropy: getMaxAnisotropy,
|
|
|
getMaxPrecision: getMaxPrecision,
|
|
|
|
|
@@ -15117,18 +15131,7 @@ function WebGLGeometries( gl, attributes, info ) {
|
|
|
|
|
|
delete geometries[ geometry.id ];
|
|
|
|
|
|
- // TODO Remove duplicate code
|
|
|
-
|
|
|
- var attribute = wireframeAttributes[ geometry.id ];
|
|
|
-
|
|
|
- if ( attribute ) {
|
|
|
-
|
|
|
- attributes.remove( attribute );
|
|
|
- delete wireframeAttributes[ geometry.id ];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- attribute = wireframeAttributes[ buffergeometry.id ];
|
|
|
+ var attribute = wireframeAttributes[ buffergeometry.id ];
|
|
|
|
|
|
if ( attribute ) {
|
|
|
|
|
@@ -15280,7 +15283,7 @@ function WebGLGeometries( gl, attributes, info ) {
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
-function WebGLIndexedBufferRenderer( gl, extensions, info ) {
|
|
|
+function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
|
|
|
|
|
|
var mode;
|
|
|
|
|
@@ -15309,16 +15312,26 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
|
|
|
|
|
|
function renderInstances( geometry, start, count ) {
|
|
|
|
|
|
- var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+ var extension;
|
|
|
|
|
|
- if ( extension === null ) {
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
- console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
- return;
|
|
|
+ extension = gl;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+
|
|
|
+ if ( extension === null ) {
|
|
|
+
|
|
|
+ console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- extension.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 );
|
|
|
|
|
@@ -16708,7 +16721,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;
|
|
|
|
|
@@ -16791,7 +16804,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
|
|
|
//
|
|
|
|
|
|
- var customExtensions = generateExtensions( material.extensions, parameters, extensions );
|
|
|
+ var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
|
|
|
|
|
|
var customDefines = generateDefines( defines );
|
|
|
|
|
@@ -16879,7 +16892,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
|
|
|
|
|
|
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
|
|
|
- parameters.logarithmicDepthBuffer && 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;',
|
|
@@ -16984,9 +16997,9 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
|
|
|
|
|
|
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
|
|
|
- parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
+ parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
|
|
|
|
|
|
- parameters.envMap && 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;',
|
|
@@ -17022,6 +17035,50 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
|
|
|
vertexShader = unrollLoops( vertexShader );
|
|
|
fragmentShader = unrollLoops( fragmentShader );
|
|
|
|
|
|
+ if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
|
|
|
+
|
|
|
+ var isGLSL3ShaderMaterial = false;
|
|
|
+
|
|
|
+ var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
|
|
|
+
|
|
|
+ if ( material.isShaderMaterial &&
|
|
|
+ vertexShader.match( versionRegex ) !== null &&
|
|
|
+ fragmentShader.match( versionRegex ) !== null ) {
|
|
|
+
|
|
|
+ isGLSL3ShaderMaterial = true;
|
|
|
+
|
|
|
+ vertexShader = vertexShader.replace( versionRegex, '' );
|
|
|
+ fragmentShader = fragmentShader.replace( versionRegex, '' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // GLSL 3.0 conversion
|
|
|
+ prefixVertex = [
|
|
|
+ '#version 300 es\n',
|
|
|
+ '#define attribute in',
|
|
|
+ '#define varying out',
|
|
|
+ '#define texture2D texture'
|
|
|
+ ].join( '\n' ) + '\n' + prefixVertex;
|
|
|
+
|
|
|
+ prefixFragment = [
|
|
|
+ '#version 300 es\n',
|
|
|
+ '#define varying in',
|
|
|
+ isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
|
|
|
+ isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
|
|
|
+ '#define gl_FragDepthEXT gl_FragDepth',
|
|
|
+ '#define texture2D texture',
|
|
|
+ '#define textureCube texture',
|
|
|
+ '#define texture2DProj textureProj',
|
|
|
+ '#define texture2DLodEXT textureLod',
|
|
|
+ '#define texture2DProjLodEXT textureProjLod',
|
|
|
+ '#define textureCubeLodEXT textureLod',
|
|
|
+ '#define texture2DGradEXT textureGrad',
|
|
|
+ '#define texture2DProjGradEXT textureProjGrad',
|
|
|
+ '#define textureCubeGradEXT textureGrad'
|
|
|
+ ].join( '\n' ) + '\n' + prefixFragment;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
var vertexGlsl = prefixVertex + vertexShader;
|
|
|
var fragmentGlsl = prefixFragment + fragmentShader;
|
|
|
|
|
@@ -17459,7 +17516,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 );
|
|
|
|
|
|
}
|
|
@@ -18721,7 +18778,7 @@ function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
|
|
|
* @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
-function WebGLState( gl, extensions, utils ) {
|
|
|
+function WebGLState( gl, extensions, utils, capabilities ) {
|
|
|
|
|
|
function ColorBuffer() {
|
|
|
|
|
@@ -19033,7 +19090,7 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
var enabledAttributes = new Uint8Array( maxVertexAttributes );
|
|
|
var attributeDivisors = new Uint8Array( maxVertexAttributes );
|
|
|
|
|
|
- var capabilities = {};
|
|
|
+ var enabledCapabilities = {};
|
|
|
|
|
|
var compressedTextureFormats = null;
|
|
|
|
|
@@ -19150,9 +19207,9 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
|
|
|
|
|
|
- var extension = extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+ var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
|
|
|
- extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
|
|
|
+ extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
|
|
|
attributeDivisors[ attribute ] = meshPerAttribute;
|
|
|
|
|
|
}
|
|
@@ -19176,10 +19233,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;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -19187,10 +19244,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;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -19599,7 +19656,7 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- capabilities = {};
|
|
|
+ enabledCapabilities = {};
|
|
|
|
|
|
compressedTextureFormats = null;
|
|
|
|
|
@@ -19668,7 +19725,6 @@ function WebGLState( gl, extensions, utils ) {
|
|
|
|
|
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
|
|
|
|
- var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext ); /* global WebGL2RenderingContext */
|
|
|
var _videoTextures = {};
|
|
|
var _canvas;
|
|
|
|
|
@@ -19737,6 +19793,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function textureNeedsPowerOfTwo( texture ) {
|
|
|
|
|
|
+ if ( capabilities.isWebGL2 ) return false;
|
|
|
+
|
|
|
return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
|
|
|
( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
|
|
|
|
|
@@ -19760,6 +19818,30 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function getInternalFormat( glFormat, glType ) {
|
|
|
+
|
|
|
+ if ( ! capabilities.isWebGL2 ) return glFormat;
|
|
|
+
|
|
|
+ if ( glFormat === _gl.RGB ) {
|
|
|
+
|
|
|
+ if ( glType === _gl.FLOAT ) return _gl.RGB32F;
|
|
|
+ if ( glType === _gl.HALF_FLOAT ) return _gl.RGB16F;
|
|
|
+ if ( glType === _gl.UNSIGNED_BYTE ) return _gl.RGB8;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( glFormat === _gl.RGBA ) {
|
|
|
+
|
|
|
+ if ( glType === _gl.FLOAT ) return _gl.RGBA32F;
|
|
|
+ if ( glType === _gl.HALF_FLOAT ) return _gl.RGBA16F;
|
|
|
+ if ( glType === _gl.UNSIGNED_BYTE ) return _gl.RGBA8;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return glFormat;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// Fallback filters for non-power-of-2 textures
|
|
|
|
|
|
function filterFallback( f ) {
|
|
@@ -19954,7 +20036,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
var image = cubeImage[ 0 ],
|
|
|
isPowerOfTwoImage = isPowerOfTwo( image ),
|
|
|
glFormat = utils.convert( texture.format ),
|
|
|
- glType = utils.convert( texture.type );
|
|
|
+ glType = utils.convert( texture.type ),
|
|
|
+ glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
|
|
|
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
|
|
|
|
|
@@ -19964,11 +20047,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( isDataTexture ) {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, 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 );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -19984,7 +20067,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
|
|
|
|
|
|
- state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
+ state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -19994,7 +20077,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
|
|
|
+ state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -20082,7 +20165,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 && 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 ) {
|
|
|
|
|
@@ -20126,7 +20209,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
var isPowerOfTwoImage = isPowerOfTwo( image ),
|
|
|
glFormat = utils.convert( texture.format ),
|
|
|
- glType = utils.convert( texture.type );
|
|
|
+ glType = utils.convert( texture.type ),
|
|
|
+ glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
|
|
|
setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
|
|
|
|
|
@@ -20136,21 +20220,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
// populate depth texture with dummy data
|
|
|
|
|
|
- var internalFormat = _gl.DEPTH_COMPONENT;
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT;
|
|
|
|
|
|
if ( texture.type === FloatType ) {
|
|
|
|
|
|
- if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
- internalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
+ if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
|
|
|
- } else if ( _isWebGL2 ) {
|
|
|
+ } else if ( capabilities.isWebGL2 ) {
|
|
|
|
|
|
// WebGL 2.0 requires signed internalformat for glTexImage2D
|
|
|
- internalFormat = _gl.DEPTH_COMPONENT16;
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
|
|
|
+ if ( texture.format === DepthFormat && glInternalFormat === _gl.DEPTH_COMPONENT ) {
|
|
|
|
|
|
// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
|
|
|
// DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
|
|
@@ -20170,7 +20254,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
|
|
if ( texture.format === DepthStencilFormat ) {
|
|
|
|
|
|
- internalFormat = _gl.DEPTH_STENCIL;
|
|
|
+ glInternalFormat = _gl.DEPTH_STENCIL;
|
|
|
|
|
|
// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
|
|
|
// DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
|
|
@@ -20186,7 +20270,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
|
|
|
|
|
|
} else if ( texture.isDataTexture ) {
|
|
|
|
|
@@ -20199,7 +20283,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, i, glFormat, 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 );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -20208,7 +20292,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
|
|
|
textureProperties.__maxMipLevel = 0;
|
|
|
|
|
|
}
|
|
@@ -20223,7 +20307,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
|
|
|
|
|
|
- state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
+ state.compressedTexImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -20233,7 +20317,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, i, glFormat, 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 );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -20254,7 +20338,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -20263,7 +20347,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image );
|
|
|
textureProperties.__maxMipLevel = 0;
|
|
|
|
|
|
}
|
|
@@ -20289,7 +20373,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
var glFormat = utils.convert( renderTarget.texture.format );
|
|
|
var glType = utils.convert( renderTarget.texture.type );
|
|
|
- state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
|
|
|
+ var glInternalFormat = getInternalFormat( glFormat, glType );
|
|
|
+ state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
|
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
|
|
|
_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
|
|
@@ -20534,7 +20619,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 ) {
|
|
|
|
|
@@ -20566,6 +20651,8 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === HalfFloatType ) {
|
|
|
|
|
|
+ if ( capabilities.isWebGL2 ) return gl.HALF_FLOAT;
|
|
|
+
|
|
|
extension = extensions.get( 'OES_texture_half_float' );
|
|
|
|
|
|
if ( extension !== null ) return extension.HALF_FLOAT_OES;
|
|
@@ -20655,6 +20742,13 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === MinEquation || p === MaxEquation ) {
|
|
|
|
|
|
+ if ( capabilities.isWebGL2 ) {
|
|
|
+
|
|
|
+ if ( p === MinEquation ) return gl.MIN;
|
|
|
+ if ( p === MaxEquation ) return gl.MAX;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
extension = extensions.get( 'EXT_blend_minmax' );
|
|
|
|
|
|
if ( extension !== null ) {
|
|
@@ -20668,6 +20762,8 @@ function WebGLUtils( gl, extensions ) {
|
|
|
|
|
|
if ( p === UnsignedInt248Type ) {
|
|
|
|
|
|
+ if ( capabilities.isWebGL2 ) return gl.UNSIGNED_INT_24_8;
|
|
|
+
|
|
|
extension = extensions.get( 'WEBGL_depth_texture' );
|
|
|
|
|
|
if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
|
|
@@ -21799,20 +21895,26 @@ function WebGLRenderer( parameters ) {
|
|
|
function initGLContext() {
|
|
|
|
|
|
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( 'OES_element_index_uint' );
|
|
|
- extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
-
|
|
|
- utils = new WebGLUtils( _gl, extensions );
|
|
|
|
|
|
capabilities = new WebGLCapabilities( _gl, extensions, parameters );
|
|
|
|
|
|
- state = new WebGLState( _gl, extensions, utils );
|
|
|
+ if ( ! capabilities.isWebGL2 ) {
|
|
|
+
|
|
|
+ extensions.get( 'WEBGL_depth_texture' );
|
|
|
+ extensions.get( 'OES_texture_float' );
|
|
|
+ extensions.get( 'OES_texture_half_float' );
|
|
|
+ extensions.get( 'OES_texture_half_float_linear' );
|
|
|
+ extensions.get( 'OES_standard_derivatives' );
|
|
|
+ extensions.get( 'OES_element_index_uint' );
|
|
|
+ extensions.get( 'ANGLE_instanced_arrays' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ extensions.get( 'OES_texture_float_linear' );
|
|
|
+
|
|
|
+ utils = new WebGLUtils( _gl, extensions, capabilities );
|
|
|
+
|
|
|
+ state = new WebGLState( _gl, extensions, utils, capabilities );
|
|
|
state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
|
|
|
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
|
|
|
|
|
@@ -21829,8 +21931,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;
|
|
|
|
|
@@ -22367,7 +22469,7 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
function setupVertexAttributes( material, program, geometry ) {
|
|
|
|
|
|
- if ( geometry && geometry.isInstancedBufferGeometry ) {
|
|
|
+ if ( geometry && geometry.isInstancedBufferGeometry & ! capabilities.isWebGL2 ) {
|
|
|
|
|
|
if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
|
|
|
|
|
@@ -22796,8 +22898,6 @@ function WebGLRenderer( parameters ) {
|
|
|
_vector3.setFromMatrixPosition( object.matrixWorld )
|
|
|
.applyMatrix4( _projScreenMatrix );
|
|
|
|
|
|
- var material = object.material;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
var geometry = objects.update( object );
|
|
@@ -23032,6 +23132,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;
|
|
@@ -24080,8 +24183,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 && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
|
|
|
- ! ( textureType === HalfFloatType && 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;
|