Browse Source

WebGLTextures: Fix FramebufferTexture's allocation. (#23854)

There were two bugs in the allocation code:

1. Didn't check if memory needs to be allocated and always used null pixels.
2. Didn't allocate the memory needed for mipmap.
chubei-oppen 3 years ago
parent
commit
80fd48c16d
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/renderers/webgl/WebGLTextures.js

+ 11 - 2
src/renderers/webgl/WebGLTextures.js

@@ -928,9 +928,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 					state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );
 
-				} else {
+				} else if ( allocateMemory ) {
 
-					state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
+					let width = image.width, height = image.height;
+
+					for ( let i = 0; i < levels; i ++ ) {
+
+						state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null );
+
+						width >>= 1;
+						height >>= 1;
+
+					}
 
 				}