-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[rmodels] Loading GLB/GLTF fails to parse or render when running on a Big Endian system #4647
Comments
@nbe1233 raylib was not designed considering Big Endian systems so it could fail in multiple points in that regards... Still, lately some changes by @Peter0x44 where merged to add some BE support. The reported issue also involves an external library, it should probably reported to https://github.com/jkuhlmann/cgltf What additional changes are needed to support BE on raylib for gltf loading? |
I didn't make any changes for that, but parts of the gltf loading code look rather suspicious, and probably assume LE byte order. Everything in a glb is LE. |
Currently, we look into Wii/GameCube on the raylib Discord together, which is BE too. Does the PS3 give you the same results, similar to that, when you load a GLTF/GLB file? |
Yeah I had the same issue. I solved it by replacing LOAD_ATTRIBUTE_CAST() in rmodels.c with this
|
Supporting BE could require many changes to raylib and also external libraries... Have you tried with multiple texture formats or other file-formats? |
Please, before submitting a new issue verify and check:
Issue description
glb files fails to load as cgltf.h uses endian-specific code.
gltf files are successfully parsed, but mesh vertices, normals, and indices are incorrectly loaded by rmodels.c
Environment
I've been working on a homebrew PS3 port using the PSL1GHT SDK, using RSXGL which implements Opengl 3.1 core.
Code Example
Here cgltf.h copys bytes from glb data, which is stored as little-endian, but since the system is big-endian it stores GlbMagic as big-endian while interpreting glb bytes as a big-endian number, causing a mismatch.
After fixing cgltf.h with a bunch of __builtin_bswap32(), I could now load glb which behaved the same as gltf files, that is to say still broken. I found that in order for the model to be rendered correctly, I had to swap the bytes of Mesh positions, normals, and indices. I believe the errors comes from the LOAD_ATTRIBUTE_CAST macro function in LoadGLTF.
I've managed to get glb/gltf files to render correctly by passing __builtin_bswap32(), perhaps using le32toh() would be better, though my toolchain lack said function.
The text was updated successfully, but these errors were encountered: