Skip to content

Commit

Permalink
Merge pull request #1294 from actnwit/fix/generate-mipmap
Browse files Browse the repository at this point in the history
fix: generate mipmap
  • Loading branch information
emadurandal authored Sep 18, 2023
2 parents 7c47e85 + 1709805 commit e8e3cc6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/webgl/WebGLResourceRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ export class WebGLResourceRepository
const textureHandle = this.__registerResource(texture);

this.__glw!.bindTexture2D(0, texture);
const levels = generateMipmap ? Math.max(Math.log2(width), Math.log2(height)) : 1;
const levels = Math.floor(Math.log2(Math.max(width, height))) + 1;
gl.texStorage2D(GL_TEXTURE_2D, levels, internalFormat.index, width, height);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, format.index, type.index, imageData);

Expand All @@ -1167,18 +1167,15 @@ export class WebGLResourceRepository
// } else {
// // gl.texParameteri(gl.TEXTURE_2D, gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
// }
if (MathUtil.isPowerOfTwoTexture(width, height)) {
// if (MathUtil.isPowerOfTwoTexture(width, height)) {
// if (anisotropy) {
// if (this.__glw!.webgl2ExtTFA) {
// gl.texParameteri(gl.TEXTURE_2D, this.__glw!.webgl2ExtTFA!.TEXTURE_MAX_ANISOTROPY_EXT, 4);
// }
// }

const isGenerateMipmap = generateMipmap && height !== 1 && width !== 1;
if (isGenerateMipmap) {
gl.generateMipmap(gl.TEXTURE_2D);
}
}
gl.generateMipmap(gl.TEXTURE_2D);

this.__glw!.unbindTexture2D(0);
}

Expand Down

0 comments on commit e8e3cc6

Please sign in to comment.