fix copressed texture creation on webgl2

This commit is contained in:
jerrywwl
2019-04-26 11:30:55 +08:00
parent b6f82ad6ff
commit c67b27630d
+8 -10
View File
@@ -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);
}