diff --git a/cocos/gfx/webgl2/webgl2-commands.ts b/cocos/gfx/webgl2/webgl2-commands.ts index 5b3bc74231..0b2de19cf1 100644 --- a/cocos/gfx/webgl2/webgl2-commands.ts +++ b/cocos/gfx/webgl2/webgl2-commands.ts @@ -971,10 +971,10 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture: h = Math.max(1, h >> 1); } } else { - const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 }; for (let i = 0; i < gpuTexture.mipLevel; ++i) { const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1); - gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0); + const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 }; + gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view); w = Math.max(1, w >> 1); h = Math.max(1, h >> 1); } @@ -1034,14 +1034,13 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture: } } } else { - const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 }; - for (let f = 0; f < 6; ++f) { let w = gpuTexture.width; let h = gpuTexture.height; for (let i = 0; i < gpuTexture.mipLevel; ++i) { const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1); - gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0); + const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 }; + gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view); w = Math.max(1, w >> 1); h = Math.max(1, h >> 1); } @@ -1118,10 +1117,10 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2GFXDevice, gpuTexture: h = Math.max(1, h >> 1); } } else { - const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 }; for (let i = 0; i < gpuTexture.mipLevel; ++i) { const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1); - gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0); + const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 }; + gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_2D, i, gpuTexture.glInternelFmt, w, h, 0, view); w = Math.max(1, w >> 1); h = Math.max(1, h >> 1); } @@ -1162,14 +1161,13 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2GFXDevice, gpuTexture: } } } else { - const view: ArrayBufferView = { buffer: new ArrayBuffer(0), byteLength: 0, byteOffset: 0 }; - for (let f = 0; f < 6; ++f) { let w = gpuTexture.width; let h = gpuTexture.height; for (let i = 0; i < gpuTexture.mipLevel; ++i) { const imgSize = GFXFormatSize(gpuTexture.format, w, h, 1); - gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, imgSize, 0); + const view: ArrayBufferView = { buffer: new ArrayBuffer(imgSize), byteLength: imgSize, byteOffset: 0 }; + gl.compressedTexImage2D(WebGL2RenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture.glInternelFmt, w, h, 0, view); w = Math.max(1, w >> 1); h = Math.max(1, h >> 1); }