|
@@ -179,6 +179,30 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function getMipLevels( texture, image, supportsMips ) {
|
|
|
|
+
|
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true ) {
|
|
|
|
+
|
|
|
|
+ // generated mipmaps via gl.generateMipmap()
|
|
|
|
+
|
|
|
|
+ return Math.log2( Math.max( image.width, image.height ) ) + 1;
|
|
|
|
+
|
|
|
|
+ } else if ( texture.mipmaps.length > 0 ) {
|
|
|
|
+
|
|
|
|
+ // user-defined mipmaps
|
|
|
|
+
|
|
|
|
+ return texture.mipmaps.length;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ // texture without mipmaps (only base level)
|
|
|
|
+
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
// Fallback filters for non-power-of-2 textures
|
|
// Fallback filters for non-power-of-2 textures
|
|
|
|
|
|
function filterFallback( f ) {
|
|
function filterFallback( f ) {
|
|
@@ -680,12 +704,31 @@ 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
|
|
|
|
|
|
|
|
+ const levels = getMipLevels( texture, image, supportsMips );
|
|
|
|
+ const useTexStorage = ( isWebGL2 && texture.isVideoTexture !== true );
|
|
|
|
+ const allocateMemory = ( texture.version === 1 );
|
|
|
|
+
|
|
if ( mipmaps.length > 0 && supportsMips ) {
|
|
if ( mipmaps.length > 0 && supportsMips ) {
|
|
|
|
|
|
|
|
+ if ( useTexStorage && allocateMemory ) {
|
|
|
|
+
|
|
|
|
+ state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
|
|
|
|
mipmap = mipmaps[ i ];
|
|
mipmap = mipmaps[ i ];
|
|
- state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );
|
|
|
|
|
|
+
|
|
|
|
+ if ( useTexStorage ) {
|
|
|
|
+
|
|
|
|
+ state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -693,7 +736,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image );
|
|
|
|
|
|
+ if ( useTexStorage ) {
|
|
|
|
+
|
|
|
|
+ if ( allocateMemory ) {
|
|
|
|
+
|
|
|
|
+ state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|