|
@@ -1,13 +1,10 @@
|
|
-import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, RGB_ETC1_Format, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, SRGBTransfer, LinearTransfer } from '../../constants.js';
|
|
|
|
-import * as MathUtils from '../../math/MathUtils.js';
|
|
|
|
-import { ImageUtils } from '../../extras/ImageUtils.js';
|
|
|
|
|
|
+import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, RGB_ETC1_Format, DepthFormat, DepthStencilFormat, UnsignedIntType, UnsignedInt248Type, FloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, NoColorSpace, LinearSRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, SRGBTransfer, LinearTransfer } from '../../constants.js';
|
|
import { createElementNS } from '../../utils.js';
|
|
import { createElementNS } from '../../utils.js';
|
|
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
import { Vector2 } from '../../math/Vector2.js';
|
|
import { Vector2 } from '../../math/Vector2.js';
|
|
|
|
|
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
|
|
|
|
- const isWebGL2 = capabilities.isWebGL2;
|
|
|
|
const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;
|
|
const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;
|
|
const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );
|
|
const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );
|
|
|
|
|
|
@@ -45,7 +42,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
|
|
|
|
|
|
+ function resizeImage( image, needsNewCanvas, maxSize ) {
|
|
|
|
|
|
let scale = 1;
|
|
let scale = 1;
|
|
|
|
|
|
@@ -61,7 +58,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
// only perform resize if necessary
|
|
// only perform resize if necessary
|
|
|
|
|
|
- if ( scale < 1 || needsPowerOfTwo === true ) {
|
|
|
|
|
|
+ if ( scale < 1 ) {
|
|
|
|
|
|
// only perform resize for certain image types
|
|
// only perform resize for certain image types
|
|
|
|
|
|
@@ -70,10 +67,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ||
|
|
( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ||
|
|
( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) ) {
|
|
( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) ) {
|
|
|
|
|
|
- const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
|
|
|
|
-
|
|
|
|
- const width = floor( scale * dimensions.width );
|
|
|
|
- const height = floor( scale * dimensions.height );
|
|
|
|
|
|
+ const width = Math.floor( scale * dimensions.width );
|
|
|
|
+ const height = Math.floor( scale * dimensions.height );
|
|
|
|
|
|
if ( _canvas === undefined ) _canvas = createCanvas( width, height );
|
|
if ( _canvas === undefined ) _canvas = createCanvas( width, height );
|
|
|
|
|
|
@@ -109,27 +104,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function isPowerOfTwo( image ) {
|
|
|
|
-
|
|
|
|
- const dimensions = getDimensions( image );
|
|
|
|
|
|
+ function textureNeedsGenerateMipmaps( texture ) {
|
|
|
|
|
|
- return MathUtils.isPowerOfTwo( dimensions.width ) && MathUtils.isPowerOfTwo( dimensions.height );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function textureNeedsPowerOfTwo( texture ) {
|
|
|
|
-
|
|
|
|
- if ( isWebGL2 ) return false;
|
|
|
|
-
|
|
|
|
- return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
|
|
|
|
- ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- function textureNeedsGenerateMipmaps( texture, supportsMips ) {
|
|
|
|
-
|
|
|
|
- return texture.generateMipmaps && supportsMips &&
|
|
|
|
- texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
|
|
|
|
|
|
+ return texture.generateMipmaps && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,8 +118,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
|
|
function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
|
|
|
|
|
|
- if ( isWebGL2 === false ) return glFormat;
|
|
|
|
-
|
|
|
|
if ( internalFormatName !== null ) {
|
|
if ( internalFormatName !== null ) {
|
|
|
|
|
|
if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
|
|
if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
|
|
@@ -215,9 +190,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function getMipLevels( texture, image, supportsMips ) {
|
|
|
|
|
|
+ function getMipLevels( texture, image ) {
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
|
|
|
|
|
|
return Math.log2( Math.max( image.width, image.height ) ) + 1;
|
|
return Math.log2( Math.max( image.width, image.height ) ) + 1;
|
|
|
|
|
|
@@ -241,20 +216,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // Fallback filters for non-power-of-2 textures
|
|
|
|
-
|
|
|
|
- function filterFallback( f ) {
|
|
|
|
-
|
|
|
|
- if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
|
|
|
|
-
|
|
|
|
- return _gl.NEAREST;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return _gl.LINEAR;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
|
|
|
|
function onTextureDispose( event ) {
|
|
function onTextureDispose( event ) {
|
|
@@ -569,7 +530,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
[ NotEqualCompare ]: _gl.NOTEQUAL
|
|
[ NotEqualCompare ]: _gl.NOTEQUAL
|
|
};
|
|
};
|
|
|
|
|
|
- function setTextureParameters( textureType, texture, supportsMips ) {
|
|
|
|
|
|
+ function setTextureParameters( textureType, texture ) {
|
|
|
|
|
|
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false &&
|
|
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false &&
|
|
( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
|
|
( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
|
|
@@ -579,48 +540,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( supportsMips ) {
|
|
|
|
-
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
|
|
|
|
-
|
|
|
|
- if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
|
|
|
|
-
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
|
|
|
|
-
|
|
|
|
- if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
|
|
|
|
-
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, _gl.CLAMP_TO_EDGE );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
|
|
|
|
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
|
|
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
|
|
|
|
- _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
|
|
|
|
|
|
+ if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) {
|
|
|
|
|
|
- if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );
|
|
|
|
+ _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );
|
|
|
|
+
|
|
if ( texture.compareFunction ) {
|
|
if ( texture.compareFunction ) {
|
|
|
|
|
|
_gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE );
|
|
_gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE );
|
|
@@ -632,8 +563,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( texture.magFilter === NearestFilter ) return;
|
|
if ( texture.magFilter === NearestFilter ) return;
|
|
if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;
|
|
if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;
|
|
- if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
|
|
|
|
- if ( isWebGL2 === false && ( texture.type === HalfFloatType && extensions.has( 'OES_texture_half_float_linear' ) === false ) ) return; // verify extension for WebGL 1 only
|
|
|
|
|
|
+ if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension
|
|
|
|
|
|
if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
|
|
if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
|
|
|
|
|
|
@@ -754,97 +684,41 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
_gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
|
|
_gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
|
|
|
|
|
|
- const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
|
|
|
|
- let image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
|
|
|
|
|
|
+ let image = resizeImage( texture.image, false, capabilities.maxTextureSize );
|
|
image = verifyColorSpace( texture, image );
|
|
image = verifyColorSpace( texture, image );
|
|
|
|
|
|
- const supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
|
- glFormat = utils.convert( texture.format, texture.colorSpace );
|
|
|
|
|
|
+ const glFormat = utils.convert( texture.format, texture.colorSpace );
|
|
|
|
|
|
- let glType = utils.convert( texture.type ),
|
|
|
|
- glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
|
|
|
|
|
|
+ const glType = utils.convert( texture.type );
|
|
|
|
+ let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
|
|
|
|
|
|
- setTextureParameters( textureType, texture, supportsMips );
|
|
|
|
|
|
+ setTextureParameters( textureType, texture );
|
|
|
|
|
|
let mipmap;
|
|
let mipmap;
|
|
const mipmaps = texture.mipmaps;
|
|
const mipmaps = texture.mipmaps;
|
|
|
|
|
|
- const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true && glInternalFormat !== RGB_ETC1_Format );
|
|
|
|
|
|
+ const useTexStorage = ( texture.isVideoTexture !== true && glInternalFormat !== RGB_ETC1_Format );
|
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
const dataReady = source.dataReady;
|
|
const dataReady = source.dataReady;
|
|
- const levels = getMipLevels( texture, image, supportsMips );
|
|
|
|
|
|
+ const levels = getMipLevels( texture, image );
|
|
|
|
|
|
if ( texture.isDepthTexture ) {
|
|
if ( texture.isDepthTexture ) {
|
|
|
|
|
|
// populate depth texture with dummy data
|
|
// populate depth texture with dummy data
|
|
|
|
|
|
- glInternalFormat = _gl.DEPTH_COMPONENT;
|
|
|
|
-
|
|
|
|
- if ( isWebGL2 ) {
|
|
|
|
-
|
|
|
|
- if ( texture.type === FloatType ) {
|
|
|
|
-
|
|
|
|
- glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
|
-
|
|
|
|
- } else if ( texture.type === UnsignedIntType ) {
|
|
|
|
-
|
|
|
|
- glInternalFormat = _gl.DEPTH_COMPONENT24;
|
|
|
|
-
|
|
|
|
- } else if ( texture.type === UnsignedInt248Type ) {
|
|
|
|
-
|
|
|
|
- glInternalFormat = _gl.DEPTH24_STENCIL8;
|
|
|
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- glInternalFormat = _gl.DEPTH_COMPONENT16; // WebGL2 requires sized internalformat for glTexImage2D
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- if ( texture.type === FloatType ) {
|
|
|
|
-
|
|
|
|
- console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // validation checks for WebGL 1
|
|
|
|
|
|
+ if ( texture.type === FloatType ) {
|
|
|
|
|
|
- if ( texture.format === DepthFormat && glInternalFormat === _gl.DEPTH_COMPONENT ) {
|
|
|
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
|
|
|
- // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
|
|
|
|
- // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
|
|
|
|
- // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
|
|
|
- if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
|
|
|
|
|
|
+ } else if ( texture.type === UnsignedIntType ) {
|
|
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
|
|
|
|
|
|
+ glInternalFormat = _gl.DEPTH_COMPONENT24;
|
|
|
|
|
|
- texture.type = UnsignedIntType;
|
|
|
|
- glType = utils.convert( texture.type );
|
|
|
|
|
|
+ } else if ( texture.type === UnsignedInt248Type ) {
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( texture.format === DepthStencilFormat && glInternalFormat === _gl.DEPTH_COMPONENT ) {
|
|
|
|
-
|
|
|
|
- // Depth stencil textures need the DEPTH_STENCIL internal format
|
|
|
|
- // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
|
|
|
- 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.
|
|
|
|
- // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
|
|
|
- if ( texture.type !== UnsignedInt248Type ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
|
|
|
|
-
|
|
|
|
- texture.type = UnsignedInt248Type;
|
|
|
|
- glType = utils.convert( texture.type );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -870,7 +744,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
// if there are no manual mipmaps
|
|
// if there are no manual mipmaps
|
|
// set 0 level mipmap and then use GL to generate other mipmap levels
|
|
// set 0 level mipmap and then use GL to generate other mipmap levels
|
|
|
|
|
|
- if ( mipmaps.length > 0 && supportsMips ) {
|
|
|
|
|
|
+ if ( mipmaps.length > 0 ) {
|
|
|
|
|
|
if ( useTexStorage && allocateMemory ) {
|
|
if ( useTexStorage && allocateMemory ) {
|
|
|
|
|
|
@@ -1117,7 +991,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
// if there are no manual mipmaps
|
|
// if there are no manual mipmaps
|
|
// set 0 level mipmap and then use GL to generate other mipmap levels
|
|
// set 0 level mipmap and then use GL to generate other mipmap levels
|
|
|
|
|
|
- if ( mipmaps.length > 0 && supportsMips ) {
|
|
|
|
|
|
+ if ( mipmaps.length > 0 ) {
|
|
|
|
|
|
if ( useTexStorage && allocateMemory ) {
|
|
if ( useTexStorage && allocateMemory ) {
|
|
|
|
|
|
@@ -1177,7 +1051,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) ) {
|
|
|
|
|
|
generateMipmap( textureType );
|
|
generateMipmap( textureType );
|
|
|
|
|
|
@@ -1226,7 +1100,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( ! isCompressed && ! isDataTexture ) {
|
|
if ( ! isCompressed && ! isDataTexture ) {
|
|
|
|
|
|
- cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
|
|
|
|
|
|
+ cubeImage[ i ] = resizeImage( texture.image[ i ], true, capabilities.maxCubemapSize );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -1239,17 +1113,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
}
|
|
}
|
|
|
|
|
|
const image = cubeImage[ 0 ],
|
|
const image = cubeImage[ 0 ],
|
|
- supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
|
glFormat = utils.convert( texture.format, texture.colorSpace ),
|
|
glFormat = utils.convert( texture.format, texture.colorSpace ),
|
|
glType = utils.convert( texture.type ),
|
|
glType = utils.convert( texture.type ),
|
|
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
|
|
glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
|
|
|
|
|
|
- const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true );
|
|
|
|
|
|
+ const useTexStorage = ( texture.isVideoTexture !== true );
|
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
|
|
const dataReady = source.dataReady;
|
|
const dataReady = source.dataReady;
|
|
- let levels = getMipLevels( texture, image, supportsMips );
|
|
|
|
|
|
+ let levels = getMipLevels( texture, image );
|
|
|
|
|
|
- setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
|
|
|
|
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture );
|
|
|
|
|
|
let mipmaps;
|
|
let mipmaps;
|
|
|
|
|
|
@@ -1414,7 +1287,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) ) {
|
|
|
|
|
|
// We assume images for cube map have the same size.
|
|
// We assume images for cube map have the same size.
|
|
generateMipmap( _gl.TEXTURE_CUBE_MAP );
|
|
generateMipmap( _gl.TEXTURE_CUBE_MAP );
|
|
@@ -1482,7 +1355,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
|
|
if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
|
|
|
|
|
|
- let glInternalFormat = ( isWebGL2 === true ) ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16;
|
|
|
|
|
|
+ let glInternalFormat = _gl.DEPTH_COMPONENT24;
|
|
|
|
|
|
if ( isMultisample || useMultisampledRTT( renderTarget ) ) {
|
|
if ( isMultisample || useMultisampledRTT( renderTarget ) ) {
|
|
|
|
|
|
@@ -1713,7 +1586,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
const isMultipleRenderTargets = ( textures.length > 1 );
|
|
const isMultipleRenderTargets = ( textures.length > 1 );
|
|
- const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
|
|
if ( ! isMultipleRenderTargets ) {
|
|
if ( ! isMultipleRenderTargets ) {
|
|
|
|
|
|
@@ -1736,7 +1608,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
for ( let i = 0; i < 6; i ++ ) {
|
|
for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- if ( isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
+ if ( texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
renderTargetProperties.__webglFramebuffer[ i ] = [];
|
|
renderTargetProperties.__webglFramebuffer[ i ] = [];
|
|
|
|
|
|
@@ -1756,7 +1628,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- if ( isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
+ if ( texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
renderTargetProperties.__webglFramebuffer = [];
|
|
renderTargetProperties.__webglFramebuffer = [];
|
|
|
|
|
|
@@ -1774,31 +1646,23 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( isMultipleRenderTargets ) {
|
|
if ( isMultipleRenderTargets ) {
|
|
|
|
|
|
- if ( capabilities.drawBuffers ) {
|
|
|
|
|
|
+ for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
|
|
|
|
- for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
|
|
|
|
+ const attachmentProperties = properties.get( textures[ i ] );
|
|
|
|
|
|
- const attachmentProperties = properties.get( textures[ i ] );
|
|
|
|
|
|
+ if ( attachmentProperties.__webglTexture === undefined ) {
|
|
|
|
|
|
- if ( attachmentProperties.__webglTexture === undefined ) {
|
|
|
|
|
|
+ attachmentProperties.__webglTexture = _gl.createTexture();
|
|
|
|
|
|
- attachmentProperties.__webglTexture = _gl.createTexture();
|
|
|
|
-
|
|
|
|
- info.memory.textures ++;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ info.memory.textures ++;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension.' );
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
|
|
|
|
+ if ( ( renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
|
|
|
|
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
|
|
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
|
|
renderTargetProperties.__webglColorRenderbuffer = [];
|
|
renderTargetProperties.__webglColorRenderbuffer = [];
|
|
@@ -1842,11 +1706,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
if ( isCube ) {
|
|
if ( isCube ) {
|
|
|
|
|
|
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
|
|
- setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
|
|
|
|
|
|
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture );
|
|
|
|
|
|
for ( let i = 0; i < 6; i ++ ) {
|
|
for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- if ( isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
+ if ( texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
for ( let level = 0; level < texture.mipmaps.length; level ++ ) {
|
|
for ( let level = 0; level < texture.mipmaps.length; level ++ ) {
|
|
|
|
|
|
@@ -1862,7 +1726,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) ) {
|
|
|
|
|
|
generateMipmap( _gl.TEXTURE_CUBE_MAP );
|
|
generateMipmap( _gl.TEXTURE_CUBE_MAP );
|
|
|
|
|
|
@@ -1878,10 +1742,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
const attachmentProperties = properties.get( attachment );
|
|
const attachmentProperties = properties.get( attachment );
|
|
|
|
|
|
state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture );
|
|
state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture );
|
|
- setTextureParameters( _gl.TEXTURE_2D, attachment, supportsMips );
|
|
|
|
|
|
+ setTextureParameters( _gl.TEXTURE_2D, attachment );
|
|
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0 );
|
|
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0 );
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( attachment, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( attachment ) ) {
|
|
|
|
|
|
generateMipmap( _gl.TEXTURE_2D );
|
|
generateMipmap( _gl.TEXTURE_2D );
|
|
|
|
|
|
@@ -1897,22 +1761,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {
|
|
if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {
|
|
|
|
|
|
- if ( isWebGL2 ) {
|
|
|
|
-
|
|
|
|
- glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- console.error( 'THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2.' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
state.bindTexture( glTextureType, textureProperties.__webglTexture );
|
|
state.bindTexture( glTextureType, textureProperties.__webglTexture );
|
|
- setTextureParameters( glTextureType, texture, supportsMips );
|
|
|
|
|
|
+ setTextureParameters( glTextureType, texture );
|
|
|
|
|
|
- if ( isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
+ if ( texture.mipmaps && texture.mipmaps.length > 0 ) {
|
|
|
|
|
|
for ( let level = 0; level < texture.mipmaps.length; level ++ ) {
|
|
for ( let level = 0; level < texture.mipmaps.length; level ++ ) {
|
|
|
|
|
|
@@ -1926,7 +1782,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) ) {
|
|
|
|
|
|
generateMipmap( glTextureType );
|
|
generateMipmap( glTextureType );
|
|
|
|
|
|
@@ -1948,15 +1804,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function updateRenderTargetMipmap( renderTarget ) {
|
|
function updateRenderTargetMipmap( renderTarget ) {
|
|
|
|
|
|
- const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
-
|
|
|
|
const textures = renderTarget.textures;
|
|
const textures = renderTarget.textures;
|
|
|
|
|
|
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
|
|
|
|
const texture = textures[ i ];
|
|
const texture = textures[ i ];
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture ) ) {
|
|
|
|
|
|
const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
const webglTexture = properties.get( texture ).__webglTexture;
|
|
const webglTexture = properties.get( texture ).__webglTexture;
|
|
@@ -1973,7 +1827,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function updateMultisampleRenderTarget( renderTarget ) {
|
|
function updateMultisampleRenderTarget( renderTarget ) {
|
|
|
|
|
|
- if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
|
|
|
|
+ if ( ( renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) {
|
|
|
|
|
|
const textures = renderTarget.textures;
|
|
const textures = renderTarget.textures;
|
|
const width = renderTarget.width;
|
|
const width = renderTarget.width;
|
|
@@ -2088,7 +1942,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
const renderTargetProperties = properties.get( renderTarget );
|
|
const renderTargetProperties = properties.get( renderTarget );
|
|
|
|
|
|
- return isWebGL2 && renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false;
|
|
|
|
|
|
+ return renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2113,7 +1967,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
const format = texture.format;
|
|
const format = texture.format;
|
|
const type = texture.type;
|
|
const type = texture.type;
|
|
|
|
|
|
- if ( texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat ) return image;
|
|
|
|
|
|
+ if ( texture.isCompressedTexture === true || texture.isVideoTexture === true ) return image;
|
|
|
|
|
|
if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) {
|
|
if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) {
|
|
|
|
|
|
@@ -2121,36 +1975,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( ColorManagement.getTransfer( colorSpace ) === SRGBTransfer ) {
|
|
if ( ColorManagement.getTransfer( colorSpace ) === SRGBTransfer ) {
|
|
|
|
|
|
- if ( isWebGL2 === false ) {
|
|
|
|
-
|
|
|
|
- // in WebGL 1, try to use EXT_sRGB extension and unsized formats
|
|
|
|
-
|
|
|
|
- if ( extensions.has( 'EXT_sRGB' ) === true && format === RGBAFormat ) {
|
|
|
|
-
|
|
|
|
- texture.format = _SRGBAFormat;
|
|
|
|
|
|
+ // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format
|
|
|
|
|
|
- // it's not possible to generate mips in WebGL 1 with this extension
|
|
|
|
|
|
+ if ( format !== RGBAFormat || type !== UnsignedByteType ) {
|
|
|
|
|
|
- texture.minFilter = LinearFilter;
|
|
|
|
- texture.generateMipmaps = false;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- // slow fallback (CPU decode)
|
|
|
|
-
|
|
|
|
- image = ImageUtils.sRGBToLinear( image );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format
|
|
|
|
-
|
|
|
|
- if ( format !== RGBAFormat || type !== UnsignedByteType ) {
|
|
|
|
-
|
|
|
|
- console.warn( 'THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.' );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ console.warn( 'THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.' );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|