|
@@ -7,6 +7,12 @@ import { _Math } from '../../math/Math.js';
|
|
|
|
|
|
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
|
|
|
|
|
|
+ var isWebGL2 = capabilities.isWebGL2;
|
|
|
+ var maxTextures = capabilities.maxTextures;
|
|
|
+ var maxCubemapSize = capabilities.maxCubemapSize;
|
|
|
+ var maxTextureSize = capabilities.maxTextureSize;
|
|
|
+ var maxSamples = capabilities.maxSamples;
|
|
|
+
|
|
|
var _videoTextures = new WeakMap();
|
|
|
var _canvas;
|
|
|
|
|
@@ -95,7 +101,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function textureNeedsPowerOfTwo( texture ) {
|
|
|
|
|
|
- if ( capabilities.isWebGL2 ) return false;
|
|
|
+ if ( isWebGL2 ) return false;
|
|
|
|
|
|
return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
|
|
|
( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
|
|
@@ -122,7 +128,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function getInternalFormat( glFormat, glType ) {
|
|
|
|
|
|
- if ( ! capabilities.isWebGL2 ) return glFormat;
|
|
|
+ if ( isWebGL2 === false ) return glFormat;
|
|
|
|
|
|
var internalFormat = glFormat;
|
|
|
|
|
@@ -294,9 +300,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
var textureUnit = textureUnits;
|
|
|
|
|
|
- if ( textureUnit >= capabilities.maxTextures ) {
|
|
|
+ if ( textureUnit >= maxTextures ) {
|
|
|
|
|
|
- console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
|
|
|
+ console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -396,7 +402,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( ! isCompressed && ! isDataTexture ) {
|
|
|
|
|
|
- cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
|
|
|
+ cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -407,7 +413,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
}
|
|
|
|
|
|
var image = cubeImage[ 0 ],
|
|
|
- supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
|
|
|
+ supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
glFormat = utils.convert( texture.format ),
|
|
|
glType = utils.convert( texture.type ),
|
|
|
glInternalFormat = getInternalFormat( glFormat, glType );
|
|
@@ -567,7 +573,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 && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
|
|
|
+ if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
|
|
|
|
|
|
if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
|
|
|
|
|
@@ -613,9 +619,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
|
|
|
|
|
|
var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
|
|
|
- var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
|
|
|
+ var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
|
|
|
|
|
|
- var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
|
|
|
+ var supportsMips = isPowerOfTwo( image ) || isWebGL2,
|
|
|
glFormat = utils.convert( texture.format ),
|
|
|
glType = utils.convert( texture.type ),
|
|
|
glInternalFormat = getInternalFormat( glFormat, glType );
|
|
@@ -632,10 +638,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( texture.type === FloatType ) {
|
|
|
|
|
|
- if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
+ if ( isWebGL2 === false ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
|
|
|
glInternalFormat = _gl.DEPTH_COMPONENT32F;
|
|
|
|
|
|
- } else if ( capabilities.isWebGL2 ) {
|
|
|
+ } else if ( isWebGL2 ) {
|
|
|
|
|
|
// WebGL 2.0 requires signed internalformat for glTexImage2D
|
|
|
glInternalFormat = _gl.DEPTH_COMPONENT16;
|
|
@@ -962,7 +968,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
|
|
|
var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
|
|
|
var isMultiview = ( renderTarget.isWebGLMultiviewRenderTarget === true );
|
|
|
- var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
|
|
|
+ var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
// Setup framebuffer
|
|
|
|
|
@@ -982,7 +988,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( isMultisample ) {
|
|
|
|
|
|
- if ( capabilities.isWebGL2 ) {
|
|
|
+ if ( isWebGL2 ) {
|
|
|
|
|
|
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
|
|
|
renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
|
|
@@ -1110,7 +1116,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
function updateRenderTargetMipmap( renderTarget ) {
|
|
|
|
|
|
var texture = renderTarget.texture;
|
|
|
- var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
|
|
|
+ var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
@@ -1129,7 +1135,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
if ( renderTarget.isWebGLMultisampleRenderTarget ) {
|
|
|
|
|
|
- if ( capabilities.isWebGL2 ) {
|
|
|
+ if ( isWebGL2 ) {
|
|
|
|
|
|
var renderTargetProperties = properties.get( renderTarget );
|
|
|
|
|
@@ -1157,8 +1163,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function getRenderTargetSamples( renderTarget ) {
|
|
|
|
|
|
- return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
|
|
|
- Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
|
|
|
+ return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
|
|
|
+ Math.min( maxSamples, renderTarget.samples ) : 0;
|
|
|
|
|
|
}
|
|
|
|