Set Framework texture filter to NEAREST once at upload.
Use the engine default-filter API instead of reapplying texParameteri on every getTexture call.
@@ -1 +1 @@
1
Subproject commit 98c7509bdb0ac1f5221272460b554faf7656e59f
1
Subproject commit 089bb8ab9faab473c4a594f2b0236fd41b71ae90
@@ -1 +1 @@1
Subproject commit 98c7509bdb0ac1f5221272460b554faf7656e59f1
Subproject commit 089bb8ab9faab473c4a594f2b0236fd41b71ae90@@ -152,18 +152,30 @@ function setGlNearest (gl, texture)
152
152
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
153
153
}
154
154
155
/** Framework defaults to LINEAR; patch uploads so pixel art stays crisp when scaled. */
155
/** Framework defaults to LINEAR; set NEAREST once at upload for pixel-art games. */
156
156
export function patchNearestNeighbourTextures (scene)
157
157
{
158
158
const glContext = scene?.glContext;
159
159
if (!glContext || glContext._nearestPatched)
160
160
{ return; }
161
const gl = glContext.gl;
162
if (typeof glContext.setDefaultTextureFilter === "function")
163
{
164
glContext.setDefaultTextureFilter(gl.NEAREST, gl.NEAREST);
165
glContext._nearestPatched = true;
166
return;
167
}
168
// Legacy Framework: apply NEAREST once per texture object, not every getTexture hit.
161
169
const original = glContext.getTexture.bind(glContext);
170
const nearestOnce = new WeakSet();
162
171
glContext.getTexture = (htmlImage) =>
163
172
{
164
173
const texture = original(htmlImage);
165
if (texture)
166
{ setGlNearest(glContext.gl, texture); }
174
if (texture && !nearestOnce.has(texture))
175
{
176
setGlNearest(gl, texture);
177
nearestOnce.add(texture);
178
}
167
179
return texture;
168
180
};
169
181
glContext._nearestPatched = true;
@@ -180,6 +192,7 @@ export function setNearestFilter (scene, source)
180
192
{ return; }
181
193
const htmlImage = source.g_image ?? source;
182
194
const texture = glContext.getTexture(htmlImage);
195
// Text-assert for textures uploaded before NEAREST was the default.
183
196
if (texture)
184
197
{ setGlNearest(glContext.gl, texture); }
185
198
}
@@ -152,18 +152,30 @@ function setGlNearest (gl, texture)152
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);152
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);153
}153
}154
154
155
/** Framework defaults to LINEAR; patch uploads so pixel art stays crisp when scaled. */155
/** Framework defaults to LINEAR; set NEAREST once at upload for pixel-art games. */156
export function patchNearestNeighbourTextures (scene)156
export function patchNearestNeighbourTextures (scene)157
{157
{158
const glContext = scene?.glContext;158
const glContext = scene?.glContext;159
if (!glContext || glContext._nearestPatched)159
if (!glContext || glContext._nearestPatched)160
{ return; }160
{ return; }161
const gl = glContext.gl;162
if (typeof glContext.setDefaultTextureFilter === "function")163
{164
glContext.setDefaultTextureFilter(gl.NEAREST, gl.NEAREST);165
glContext._nearestPatched = true;166
return;167
}168
// Legacy Framework: apply NEAREST once per texture object, not every getTexture hit.161
const original = glContext.getTexture.bind(glContext);169
const original = glContext.getTexture.bind(glContext);170
const nearestOnce = new WeakSet();162
glContext.getTexture = (htmlImage) =>171
glContext.getTexture = (htmlImage) =>163
{172
{164
const texture = original(htmlImage);173
const texture = original(htmlImage);165
if (texture)174
if (texture && !nearestOnce.has(texture))166
{ setGlNearest(glContext.gl, texture); }175
{176
setGlNearest(gl, texture);177
nearestOnce.add(texture);178
}167
return texture;179
return texture;168
};180
};169
glContext._nearestPatched = true;181
glContext._nearestPatched = true;@@ -180,6 +192,7 @@ export function setNearestFilter (scene, source)180
{ return; }192
{ return; }181
const htmlImage = source.g_image ?? source;193
const htmlImage = source.g_image ?? source;182
const texture = glContext.getTexture(htmlImage);194
const texture = glContext.getTexture(htmlImage);195
// Text-assert for textures uploaded before NEAREST was the default.183
if (texture)196
if (texture)184
{ setGlNearest(glContext.gl, texture); }197
{ setGlNearest(glContext.gl, texture); }185
}198
}