Skip to content

Conversation

alexchuber
Copy link
Contributor

No description provided.

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 24, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 24, 2025

Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wwww0000tttt good catch !!!

@sebavan sebavan merged commit e04e218 into BabylonJS:master Aug 25, 2025
18 checks passed
@@ -43,7 +43,7 @@ export class KTX2Decoder {

// eslint-disable-next-line @typescript-eslint/naming-convention
public async decode(data: Uint8Array, caps: KTX2.ICompressedFormatCapabilities, options?: KTX2.IKTX2DecoderOptions): Promise<KTX2.IDecodedData> {
const finalOptions = { ...options, ...KTX2Decoder.DefaultDecoderOptions };
const finalOptions = { ...KTX2Decoder.DefaultDecoderOptions, ...options };
Copy link
Contributor

@Popov72 Popov72 Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, ...options, ...KTX2Decoder.DefaultDecoderOptions was done on purpose.

The idea is that if a setting is defined in KTX2Decoder.DefaultDecoderOptions, it should apply no matter what. That's why KTX2Decoder.DefaultDecoderOptions is empty by default, which means that user-defined options will prevail, but if you define something in DefaultDecoderOptions, it will always take precedence (DefaultDecoderOptions is probably poorly worded, and we probably need a comment in the code!).

Copy link
Contributor Author

@alexchuber alexchuber Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting... didn't know this.

My motivation for this change was that even undefined values from KTX2Decoder.DefaultDecoderOptions would override anything set in options.

For example, if I wanted to forceRGBA for a particular texture, the undefined value from KTX2Decoder.DefaultDecoderOptions would take precedence, which I wouldn't expect.

Is this the intended behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an API standpoint, this behavior seems like the opposite of everything else, but maybe that is because of the "default" name. But it seems weird to pass options in with a specific call to the function and those options not take precedence over more broadly scoped options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if I wanted to forceRGBA for a particular texture, the undefined value from KTX2Decoder.DefaultDecoderOptions would take precedence, which I wouldn't expect.

No, it's not expected, but by default KTX2Decoder.DefaultDecoderOptions == {}, there's no undefined values. We could remove undefined values from DefaultDecoderOptions to be extra safe, though.

From an API standpoint, this behavior seems like the opposite of everything else, but maybe that is because of the "default" name. But it seems weird to pass options in with a specific call to the function and those options not take precedence over more broadly scoped options.

Yes, the problem is that the name should be something like ForcedDecoderOptions instead... It allows the user to easily apply some options when decoding KTX textures, something very difficult to do otherwise (these options are passed through the Texture constructor, something the user may not have access to, like when reading a glb file for example).

The comment in KhronosTextureContainer2.DefaultDecoderOptions explains it:

https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Misc/khronosTextureContainer2.ts#L253-L257

alexchuber added a commit to alexchuber/Babylon.js that referenced this pull request Aug 25, 2025
sebavan pushed a commit that referenced this pull request Aug 25, 2025
This reverts #17061.

Will follow-up later, but essentially, the defaults are currently
intended to take precedence over options.
alexchuber added a commit that referenced this pull request Aug 28, 2025
Take 2 of #17061. This function is what eventually sets
KTX2Decoder.DefaultDecoderOptions, so let's stop this from happening:

```typescript
const table = {...{ foo: true }, ...{}}
// result: { foo: true }

const table = {...{ foo: true }, ...{ foo: undefined }}
// result: { foo: undefined }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants