Introduce a way to add a 100% external custom platform #3594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Let me start with a few things (in order to avoid misunderstanding):
external
folder that I added at the root is purely for demonstration purposes and would NOT be included in a final/ready to merge version.With these details out of the way, let's get to the interesting part.
The purpose of this effort is to demonstrate what it could take for raylib to support platforms that are NOT embedded in raylib and as a result not maintained by @raysan5.
Goals (that I have tried to achieve with this PR)
After looking at the source code, I believe there are 2 areas where there needs to be "hooks" for a platform to reside outside raylib:
The overall approach that I took is the following: use conventions as much as possible so that it is easy both from the user of the platform and the developer of the platform to integrate with raylib.
The "only" required pieces of information that raylib needs are:
PLATFORM_CUSTOM_ROOT_DIR
variable.The custom platform looks like this (by convention):
cmake/raylibPlatformCustomProjectConfig.cmake
: optional and contain cmake definitions that needs to happen beforeproject()
is invokedcmake/raylibPlatformCustomLibraryConfig.cmake
: optional and contain cmake definitions of libraries and generic option (like settingCMAKE_STATIC_LIBRARY_SUFFIX
)cmake/raylibPlatformCustomTargetConfig.cmake
: optional and contain cmake definitions that applies on theraylib
target (ex:target_link_options(raylib PRIVATE "-sUSE_GLFW=3")
)src/raylib_platform_custom.c
is the implementation of the platform that gets included inrcore.c
(similar toplatforms/rcore_desktop.c
)src/raylib_platform_custom.h
is a new header file containing several definitions that are used in the codeLet me give an example of the last one: in rlgl.h there is this code:
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
so I changed it to
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_CUSTOM_ENABLE_OPENGL_ES2)
and
PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
is a define that needs to be defined (or not) in thesrc/raylib_platform_custom.h
The name
PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
as well as the other entries in this file have been inferred by what the#if
is supposed to mean but not knowing the code, that was my best bet.I understand this is a lot (to explain, but in the end not a lot of changes!), this is why I decided to include the
external
folder with 2 examples of 2 custom platforms and 2 examples of projects using each. Please check theexternal/README.md
file for details. As you will see the 2 custom platforms are simply clones of 2 built-in ones, but they get used as a custom/external platform, NOT a built-in one (and again, the fact that this folder is checked in with raylib is so that I can provide this examples in the first place)