Replies: 1 comment
-
This idea is only for after the 5.5 release. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been thinking about how to make it easier to maintain and extend various file format loaders for some time, and I have an idea/prototype I'd like to discuss.
The core problem that I'm trying to solve is that all the image loaders are effectively hardcoded into rTextures.c, and detected in a big if/elseif/else test. This has a few issues in my view.
I am proposing that the internals of rTextures be restructured, and instead of a big if/else test in LoadImageFromMemory, we store internal function pointers to the image loaders in an array, with the extension that goes with that loader.
This way the image loaders can be installed into this array in one clean place in the code, and LoadImageFromMemory simply has to walk that array looking for the extension. when it finds it, it calls the loader and gets the image data. This simplifies the loading code and makes each loader modular.
I would not expose this function pointer(callback) to the public API.
I would keep it in an internal header as an extern where other advanced code can use it.
Platforms could use it to register platform specific image formats (like for console development), and libraries could be written to add new formats to the framework as single header libs that just drop into user code. We could even move all the current optional image formats into raygui-like single header libs that are distributed with raylib but not built as part of the default package, allowing users to pick and choose what optional formats they have without needing to rebuild the lib.
My focus is on being able to add an image loader for an engine specific resource format from external code, but I think this can help make the base image loader more modular and reusable, as well as possibly help with maintenance since it becomes easier to split the loaders into separate modules that different people could maintain.
I have prototyped this change in this branch, and it works exactly like the current system, the loop search is processed similar to the nested IF/ELSE statements.
https://github.com/JeffM2501/raylib/tree/modular_image_loaders
Any comments or feedback on the idea are most welcome.
Beta Was this translation helpful? Give feedback.
All reactions