@ringozz/godot 4.7.2-641 → 4.7.2-643

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/web-image.ts +47 -29
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ringozz/godot",
3
3
  "author": "Vladimir Davidovich",
4
- "version": "4.7.2-641",
4
+ "version": "4.7.2-643",
5
5
  "description": "Node-API bindings for Godot Engine — call Godot classes from JavaScript",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -65,9 +65,9 @@
65
65
  "precision": "single"
66
66
  },
67
67
  "optionalDependencies": {
68
- "@ringozz/godot-macos-arm64": "^4.7.2-641",
69
- "@ringozz/godot-windows-x86_64": "^4.7.2-641",
70
- "@ringozz/godot-web-wasm32": "^4.7.2-641"
68
+ "@ringozz/godot-macos-arm64": "^4.7.2-643",
69
+ "@ringozz/godot-windows-x86_64": "^4.7.2-643",
70
+ "@ringozz/godot-web-wasm32": "^4.7.2-643"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "@types/bun": "*"
package/src/web-image.ts CHANGED
@@ -12,8 +12,8 @@
12
12
  // a single parse/allocate pair covers everything — a container is just a list of
13
13
  // layers.
14
14
  //
15
- // Exposes the container/format helpers, `pickGodotFormats` (probing the WebGL2
16
- // extensions GLES3 checks) and `decodeCtex` — the default staging path, which
15
+ // Exposes the container/format helpers, `pickGodotFormats` (the driver's
16
+ // compressed-format list) and `decodeCtex` — the default staging path, which
17
17
  // decodes the PNG/WebP payloads with the browser and rebuilds a raw RGBA8
18
18
  // container so no image codec runs in wasm. The optional compressed-transcode
19
19
  // hook lives in load.ts.
@@ -209,16 +209,50 @@ export function allocateCtex(
209
209
  }
210
210
 
211
211
  // ---------------------------------------------------------------------------
212
- // Capability probing. Godot's Compatibility (GLES3) renderer is what the web
213
- // wasm build uses, and it only uploads a compressed format natively when the
214
- // matching GL extension is present; this build compiles in NO decompressors, so
215
- // a format the device can't upload breaks the texture rather than degrading.
216
- // It selects formats for layered/3D textures exactly as for 2D — the
217
- // `astc_layered_supported`/`astc_3d_supported` flags it computes are only used
218
- // to derive `astc_supported`/`astc_hdr_supported` — so this probe covers texture
219
- // arrays and cubemaps too.
212
+ // Capability probing. GLES3 uploads a compressed format only when its config
213
+ // reports it supported, and this build compiles in NO decompressors, so a format
214
+ // the device can't upload breaks the texture rather than degrading. Ask the
215
+ // driver (`COMPRESSED_TEXTURE_FORMATS`) rather than reading extension names:
216
+ // Chrome on Windows lists no ETC2/EAC and rejects those uploads, while
217
+ // `config.cpp` would still route one to it. RGTC arrays are the one place 2D and
218
+ // layered differ — `_texture_set_data` force-decompresses them for
219
+ // `TEXTURE_2D_ARRAY`, gated here on `Image::can_decompress("s3tc")`.
220
220
  // ---------------------------------------------------------------------------
221
221
 
222
+ // `CompressedTexture` GL enums -> Godot `Image::Format`, for the targets the
223
+ // encoder can emit; only the unsigned-normal variants (their siblings share it).
224
+ const GL_TO_GODOT_FORMAT: Record<number, number> = {
225
+ 0x83f0: FORMAT_DXT1, // COMPRESSED_RGB_S3TC_DXT1_EXT
226
+ 0x8dbb: FORMAT_RGTC_R, // COMPRESSED_RED_RGTC1_EXT
227
+ 0x8dbd: FORMAT_RGTC_RG, // COMPRESSED_RED_GREEN_RGTC2_EXT
228
+ 0x8e8c: FORMAT_BPTC_RGBA, // COMPRESSED_RGBA_BPTC_UNORM_EXT
229
+ 0x9270: FORMAT_ETC2_R11, // COMPRESSED_R11_EAC
230
+ 0x9272: FORMAT_ETC2_RG11, // COMPRESSED_RG11_EAC
231
+ 0x9274: FORMAT_ETC2_RGB8, // COMPRESSED_RGB8_ETC2
232
+ 0x93b0: FORMAT_ASTC_4x4, // COMPRESSED_RGBA_ASTC_4x4_KHR
233
+ };
234
+
235
+ /** Enabled before reading the list — a browser may only list a format once its extension is enabled. */
236
+ const PROBED_EXTENSIONS = [
237
+ 'EXT_texture_compression_bptc',
238
+ 'EXT_texture_compression_rgtc',
239
+ 'WEBGL_compressed_texture_s3tc',
240
+ 'WEBGL_compressed_texture_astc',
241
+ 'WEBGL_compressed_texture_etc',
242
+ ];
243
+
244
+ /** The Godot targets among a driver's `COMPRESSED_TEXTURE_FORMATS` list, in list order and deduplicated (pure). */
245
+ export function godotFormatsFor(glFormats: ArrayLike<number>): number[] {
246
+ const formats = new Set<number>();
247
+ for (let i = 0; i < glFormats.length; i++) {
248
+ const godot = GL_TO_GODOT_FORMAT[glFormats[i]!];
249
+ if (godot !== undefined) {
250
+ formats.add(godot);
251
+ }
252
+ }
253
+ return [...formats];
254
+ }
255
+
222
256
  /**
223
257
  * Compressed `Image::Format` targets the running device can upload. A list
224
258
  * because the encoder may also reject a format the browser exposes (e.g. spark
@@ -248,31 +282,15 @@ export function pickGodotFormats(): number[] {
248
282
  if (!gl) {
249
283
  return [];
250
284
  }
251
- const formats: number[] = [];
252
285
  try {
253
- const exts = new Set(gl.getSupportedExtensions() ?? []);
254
- if (exts.has('EXT_texture_compression_bptc')) {
255
- formats.push(FORMAT_BPTC_RGBA);
256
- }
257
- if (exts.has('EXT_texture_compression_rgtc')) {
258
- formats.push(FORMAT_RGTC_RG);
259
- formats.push(FORMAT_RGTC_R);
260
- }
261
- if (exts.has('WEBGL_compressed_texture_astc')) {
262
- formats.push(FORMAT_ASTC_4x4);
263
- }
264
- if (exts.has('WEBGL_compressed_texture_s3tc')) {
265
- formats.push(FORMAT_DXT1);
286
+ for (const name of PROBED_EXTENSIONS) {
287
+ gl.getExtension(name);
266
288
  }
267
- // ETC2/EAC is core WebGL2 (ES 3.0), which is how Godot's web config
268
- // reports it (`etc2_supported = true` for non-GLES-over-GL) — so these
269
- // are always uploadable, independent of any extension.
270
- formats.push(FORMAT_ETC2_RGB8, FORMAT_ETC2_RG11, FORMAT_ETC2_R11);
289
+ return godotFormatsFor(gl.getParameter(gl.COMPRESSED_TEXTURE_FORMATS) as ArrayLike<number>);
271
290
  } finally {
272
291
  // Don't retain the probe context for the page's lifetime.
273
292
  gl.getExtension('WEBGL_lose_context')?.loseContext();
274
293
  }
275
- return formats;
276
294
  }
277
295
 
278
296
  /**