Skip to content

Commit 322d9fe

Browse files
committed
refactor: optimize default texture params
1 parent 0a5b05c commit 322d9fe

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/src/core/texture.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export function fillTexture(
129129
? WebGL2RenderingContext.SRGB8_ALPHA8
130130
: WebGL2RenderingContext.RGBA,
131131
type = WebGL2RenderingContext.UNSIGNED_BYTE,
132-
generateMipmaps = true,
133-
anisotropy = navigator.hardwareConcurrency, // in most case between 4 and 12, depending on the hardware range
132+
generateMipmaps = "src" in params, // no mipmap for data textures
133+
anisotropy = 1,
134134
minFilter = generateMipmaps ? "linear-mipmap-linear" : "linear",
135135
magFilter = "linear",
136136
wrapS = "clamp-to-edge",
@@ -152,14 +152,17 @@ export function fillTexture(
152152
gl.generateMipmap(gl.TEXTURE_2D);
153153

154154
// anisotropic filtering
155-
const ext = gl.getExtension("EXT_texture_filter_anisotropic");
156-
if (ext && anisotropy > 1) {
157-
const maxAnisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
158-
gl.texParameterf(
159-
gl.TEXTURE_2D,
160-
ext.TEXTURE_MAX_ANISOTROPY_EXT,
161-
Math.min(maxAnisotropy, anisotropy),
162-
);
155+
if (anisotropy > 1) {
156+
console.log("anisotropy", anisotropy);
157+
const ext = gl.getExtension("EXT_texture_filter_anisotropic");
158+
if (ext) {
159+
const maxAnisotropy = gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
160+
gl.texParameterf(
161+
gl.TEXTURE_2D,
162+
ext.TEXTURE_MAX_ANISOTROPY_EXT,
163+
Math.min(maxAnisotropy, anisotropy),
164+
);
165+
}
163166
}
164167
}
165168

@@ -274,13 +277,10 @@ export function createFloatDataTexture(data: number[] | Float32Array): DataTextu
274277
format: WebGL2RenderingContext.RGBA,
275278
type: WebGL2RenderingContext.FLOAT,
276279
internalFormat: WebGL2RenderingContext.RGBA32F,
277-
generateMipmaps: false,
278280
width: textureWidth,
279281
height: textureHeight,
280282
minFilter: "nearest",
281283
magFilter: "nearest",
282284
flipY: false,
283-
wrapS: "clamp-to-edge",
284-
wrapT: "clamp-to-edge",
285285
};
286286
}

0 commit comments

Comments
 (0)