Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glTF sampler filters and wrap modes enums #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthew-rister
Copy link

@matthew-rister matthew-rister commented Nov 15, 2024

Problem

cgltf_sampler defines filter and wrap modes using cgltf_int, which requires referencing the glTF specification to interpret those integers.

Solution

To fix this, enumerations representing valid glTF sampler filter and wrap modes are introduced. For backward compatibility, these enumerations retain their original integer values to allow implicit conversion to cgltf_int.

Testing

Project tests were run using tests/test_all.py on Windows (MSVC 19.41.34123) and Ubuntu (GCC 13.2) which passed without any errors.

Notes

  • cgltf_filter_type includes cgltf_filter_type_undefined = 0 because the glTF specification indicates, "Client implementations SHOULD follow specified filtering modes. When the latter are undefined, client implementations MAY set their own default texture filtering settings." This will always be the default value when not specified because samplers are allocated with calloc.
  • cgltf_wrap_mode omits the suffix _type because there is precedent with a similar enum: cgltf_alpha_mode.

Closes #256

@zeux
Copy link
Contributor

zeux commented Nov 30, 2024

fwiw I've tested this in gltfpack and it works correctly (no app code changes required). It would probably be more consistent with the rest of the code to omit the _default enum value for wrap mode (and just use _repeat explicitly) but it works either way.

@matthew-rister
Copy link
Author

matthew-rister commented Dec 1, 2024

fwiw I've tested this in gltfpack and it works correctly (no app code changes required). It would probably be more consistent with the rest of the code to omit the _default enum value for wrap mode (and just use _repeat explicitly) but it works either way.

Thank you for confirming this change works in gltfpack without further modification. The motivation for cgltf_wrap_mode_default came from the glTF specification which explicitly indicates a default value for wrap modes so it felt appropriate to represent that as part of the API. However, I see this convention isn't used elsewhere in the library so I'm happy to remove it to maintain consistency.

cgltf_sampler defines filter and wrap modes using cgltf_int, which
requires referencing the glTF specification to interpret those integers.
To resolve this, enumerations representing valid glTF sampler filter and
wrap modes are introduced. For backward compatibility, these
enumerations retain their original integer values to allow implicit
conversion to cgltf_int.
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.

[Feature Request] Consider adding enumerations for glTF sampler filters and wrap modes
2 participants