提交 9f4fb2be 编写于 作者: M Mr.doob

WebGLTextures: Cache isWebGL2, maxTexture, maxCubemapSize, maxTextureSize and maxSamples.

上级 9d70acde
...@@ -7,6 +7,12 @@ import { _Math } from '../../math/Math.js'; ...@@ -7,6 +7,12 @@ import { _Math } from '../../math/Math.js';
function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) { 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 _videoTextures = new WeakMap();
var _canvas; var _canvas;
...@@ -95,7 +101,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -95,7 +101,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function textureNeedsPowerOfTwo( texture ) { function textureNeedsPowerOfTwo( texture ) {
if ( capabilities.isWebGL2 ) return false; if ( isWebGL2 ) return false;
return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) || return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ); ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
...@@ -122,7 +128,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -122,7 +128,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function getInternalFormat( glFormat, glType ) { function getInternalFormat( glFormat, glType ) {
if ( ! capabilities.isWebGL2 ) return glFormat; if ( isWebGL2 === false ) return glFormat;
var internalFormat = glFormat; var internalFormat = glFormat;
...@@ -294,9 +300,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -294,9 +300,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var textureUnit = textureUnits; 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, ...@@ -396,7 +402,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 ], false, true, maxCubemapSize );
} else { } else {
...@@ -407,7 +413,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -407,7 +413,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} }
var image = cubeImage[ 0 ], var image = cubeImage[ 0 ],
supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2, supportsMips = isPowerOfTwo( image ) || isWebGL2,
glFormat = utils.convert( texture.format ), glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ), glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( glFormat, glType ); glInternalFormat = getInternalFormat( glFormat, glType );
...@@ -567,7 +573,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -567,7 +573,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( extension ) { if ( extension ) {
if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return; 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 ) { if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
...@@ -613,9 +619,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -613,9 +619,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false; 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 ), glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ), glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( glFormat, glType ); glInternalFormat = getInternalFormat( glFormat, glType );
...@@ -632,10 +638,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -632,10 +638,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( texture.type === FloatType ) { 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; glInternalFormat = _gl.DEPTH_COMPONENT32F;
} else if ( capabilities.isWebGL2 ) { } else if ( isWebGL2 ) {
// WebGL 2.0 requires signed internalformat for glTexImage2D // WebGL 2.0 requires signed internalformat for glTexImage2D
glInternalFormat = _gl.DEPTH_COMPONENT16; glInternalFormat = _gl.DEPTH_COMPONENT16;
...@@ -962,7 +968,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -962,7 +968,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var isCube = ( renderTarget.isWebGLRenderTargetCube === true ); var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true ); var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
var isMultiview = ( renderTarget.isWebGLMultiviewRenderTarget === true ); var isMultiview = ( renderTarget.isWebGLMultiviewRenderTarget === true );
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2; var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
// Setup framebuffer // Setup framebuffer
...@@ -982,7 +988,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -982,7 +988,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( isMultisample ) { if ( isMultisample ) {
if ( capabilities.isWebGL2 ) { if ( isWebGL2 ) {
renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer(); renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
...@@ -1110,7 +1116,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1110,7 +1116,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateRenderTargetMipmap( renderTarget ) { function updateRenderTargetMipmap( renderTarget ) {
var texture = renderTarget.texture; var texture = renderTarget.texture;
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2; var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) { if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
...@@ -1129,7 +1135,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1129,7 +1135,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( renderTarget.isWebGLMultisampleRenderTarget ) { if ( renderTarget.isWebGLMultisampleRenderTarget ) {
if ( capabilities.isWebGL2 ) { if ( isWebGL2 ) {
var renderTargetProperties = properties.get( renderTarget ); var renderTargetProperties = properties.get( renderTarget );
...@@ -1157,8 +1163,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, ...@@ -1157,8 +1163,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function getRenderTargetSamples( renderTarget ) { function getRenderTargetSamples( renderTarget ) {
return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ? return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
Math.min( capabilities.maxSamples, renderTarget.samples ) : 0; Math.min( maxSamples, renderTarget.samples ) : 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册