emscripten: Let SDL hints be set by URL parameters.

Any parameters (key/value pairs after the '?' in a URL) that have a keyname
that starts with `SDL_` will be put into Emscripten's environment variable
emulation table at startup, before SDL_main runs.

This lets users set hints the same way they might set them from a shell's
command line on a desktop platform:

For example:

`https://example.com/my_sdl3_application.html?SDL_RENDER_DRIVER=software`

Fixes #10154.
This commit is contained in:
Ryan C. Gordon 2024-07-03 20:05:43 -04:00
parent 9d47daef0a
commit f338fa20dd
3 changed files with 68 additions and 0 deletions

View file

@ -94,6 +94,16 @@
/* We need to export SDL_main so it can be launched from Java */
#define SDLMAIN_DECLSPEC SDL_DECLSPEC
#elif defined(SDL_PLATFORM_EMSCRIPTEN)
/* On Emscripten, SDL provides a main function that converts URL
parameters that start with "SDL_" to environment variables, so
they can be used as SDL hints, etc.
This is 100% optional, so if you don't want this to happen, you may
define SDL_MAIN_HANDLED
*/
#define SDL_MAIN_AVAILABLE
#elif defined(SDL_PLATFORM_PSP)
/* On PSP SDL provides a main function that sets the module info,
activates the GPU and starts the thread required to be able to exit