🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Reading glTF, best approach to using the .bin file

Started by
2 comments, last by LorenzoGatti 3 years, 4 months ago

small primer for those who don't yet already know, glTF is a format that comes in a couple different deliverable flavours, and i'm specifically talking about the GLTF_SEPARATED mode, where the .gltf is a JSON file, it comes with one or more .bin files accompanying it. The content of the .bin is effectively the raw buffers you'd pass into a generated buffer, and in the json file is a structure of “accessors” that inform you which datatype is expected, which .bin to use, and the exact byte offset and data length to use to feed your buffer. It's a really neat and very clever file format that if this is your first time hearing about it, worth checking out for your next project.

okay with that all out of the way, this is my first time implementing this file type. And up until now i've really only parsed text based file formats before. The .bin files are the part that has me puzzled over which direction to take with it.

I've been informed I can simply stream in only the data I care about using the offset and length to do so, and spit that wholesale into the buffer as needed.

I've also been informed that another approach is to simply read in the whole bin file(s) into memory, as undoubtably it's all going to get used anyways, and extract the portions out that I need that way.

My question I'm posing here is, because i'm teeter-tottering over it, which approach seems like the better one?

or is there an even better approach than those two?

Thanks!

~Ky.

Advertisement

The goal with binary gltf is that you can basically just load the entire thing into the GPU as is, and render it directly from there. Of course, depending on the specifics of your renderer this may be more or less true - if you don't implement rendering the same way that gltf expects, you may need to preprocess the data before sending it to the GPU.

I'd start by loading the entire file into memory, and the uploading the the ranges you need to the GPU. That's going to be the simplest approach, and unless your gltf files are very large (and you aren't using significant portions of the data), it'll be plenty efficient.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Shouldn't you normally load the whole glTF buffers, without gaps and omissions? You should be able to avoid putting unused data in your own asset files and to align units of loading and units of usage.

Even if there is something to ignore or select in your glTF files and the difference between discarding data between file and memory and between memory and GPU isn't completely irrelevant, the practical difference should be very small. It's more important to avoid repeated, redundant processing of the same data (e.g. reading a file containing mesh A and mesh B, loading mesh A to the GPU, discarding the loaded data structures, and later reloading the whole file to use mesh B).

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement