未验证 提交 7fe9a41c 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #15574 from takahirox/SkipNonPOTFallbackWebGL2

Skip non-POT texture fallback on WebGL2
......@@ -83,9 +83,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
function textureNeedsGenerateMipmaps( texture, supportsMips ) {
return texture.generateMipmaps && isPowerOfTwo &&
return texture.generateMipmaps && supportsMips &&
texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
}
......@@ -355,12 +355,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
var image = cubeImage[ 0 ],
isPowerOfTwoImage = isPowerOfTwo( image ),
supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( glFormat, glType );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, supportsMips );
for ( var i = 0; i < 6; i ++ ) {
......@@ -418,7 +418,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
// We assume images for cube map have the same size.
generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
......@@ -447,11 +447,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
function setTextureParameters( textureType, texture, supportsMips ) {
var extension;
if ( isPowerOfTwoImage ) {
if ( supportsMips ) {
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
_gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
......@@ -539,12 +539,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
var isPowerOfTwoImage = isPowerOfTwo( image ),
var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
glFormat = utils.convert( texture.format ),
glType = utils.convert( texture.type ),
glInternalFormat = getInternalFormat( glFormat, glType );
setTextureParameters( textureType, texture, isPowerOfTwoImage );
setTextureParameters( textureType, texture, supportsMips );
var mipmap, mipmaps = texture.mipmaps;
......@@ -610,7 +610,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// if there are no manual mipmaps
// set 0 level mipmap and then use GL to generate other mipmap levels
if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
if ( mipmaps.length > 0 && supportsMips ) {
for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
......@@ -670,7 +670,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
// if there are no manual mipmaps
// set 0 level mipmap and then use GL to generate other mipmap levels
if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
if ( mipmaps.length > 0 && supportsMips ) {
for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
......@@ -691,7 +691,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
generateMipmap( _gl.TEXTURE_2D, texture, image.width, image.height );
......@@ -880,7 +880,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
// Setup framebuffer
......@@ -941,7 +941,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
if ( isCube ) {
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, supportsMips );
for ( var i = 0; i < 6; i ++ ) {
......@@ -949,7 +949,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
generateMipmap( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, renderTarget.width, renderTarget.height );
......@@ -960,10 +960,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
} else {
state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, supportsMips );
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
generateMipmap( _gl.TEXTURE_2D, renderTarget.texture, renderTarget.width, renderTarget.height );
......@@ -986,9 +986,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
function updateRenderTargetMipmap( renderTarget ) {
var texture = renderTarget.texture;
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
var webglTexture = properties.get( texture ).__webglTexture;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册