Skip to content

Commit

Permalink
usage of mipmaps is now configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Oct 27, 2023
1 parent 5c62043 commit e8fbc53
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/display/src/displays/webgl/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export type Image =

const isPowerOf2 = (size: number) => (size & (size - 1)) == 0;

export type TextureOptions = {
flipY?: boolean,
format?: GLenum,
halfFloat?: boolean,
premultiplyAlpha?: boolean,
mipMaps?: boolean
}

class Texture {
width: number;
height: number;
Expand All @@ -41,19 +49,16 @@ class Texture {
private flipY: boolean;
private halfFloat: boolean;
private premultiplyAlpha: boolean;
private mipMaps: boolean;

ref?: number; // reference counter for Texture sharing

constructor(gl: WebGLRenderingContext, image?: Image, options: {
flipY?: boolean,
format?: GLenum,
halfFloat?: boolean,
premultiplyAlpha?: boolean
} = {}) {
constructor(gl: WebGLRenderingContext, image?: Image, options: TextureOptions = {}) {
this.gl = gl;
this.format = options.format || gl.RGBA;
this.flipY = options.flipY || false;
this.halfFloat = options.halfFloat || false;
this.mipMaps = options.mipMaps ?? true;
this.premultiplyAlpha = options.premultiplyAlpha == undefined
? true
: options.premultiplyAlpha;
Expand Down Expand Up @@ -105,7 +110,7 @@ class Texture {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x || 0, y || 0, format, gl.UNSIGNED_BYTE, <HTMLCanvasElement | HTMLImageElement>image);
}

if (width == height && isPowerOf2(height)) {
if (this.mipMaps && width == height && isPowerOf2(height)) {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.generateMipmap(gl.TEXTURE_2D);
Expand Down

0 comments on commit e8fbc53

Please sign in to comment.