I see that SDL2 currently supports using ANGLE for OpenGL ES, which is great for what I want to do. One thing I’d like to do with ANGLE is be able to specify which backend to use (D3D, OpenGL, Vulkan, etc.). ANGLE provides a way of specifying it via an EGL extension for
eglGetPlatformDisplay(EXT), but it’s currently not used for ANGLE support in SDL2.
I already wrote a change for SDL2 that implements this control via an SDL Hint. The hint is set to the number of the
EGL_PLATFORM_ANGLE_TYPE_ANGLE attribute value (eg.
"0x3208" for D3D11,
"0x3450" for Vulkan, etc.) to avoid having to hardcode all the possible attribute values, which also makes it forwards-compatible to any new backends that get added to ANGLE. However, my current implementation is a bit messy currently, and doesn’t have any real error handling. Before I clean it up and submit the patch (somehow), I had some questions about how implementing Hints should work.
The hint for specifying an ANGLE backend is highly correlated with
SDL_HINT_OPENGL_ES_DRIVER, as specifying that you want a specific backend implies that you want to use ANGLE, and therefore
SDL_HINT_OPENGL_ES_DRIVER should be
"1". Because of the valid possible values for the ANGLE attribute, it’s possible to extend the existing hint to also handle specifying the ANGLE backend, but I get the feeling that is not something that the SDL developers / maintainers want. The other option is to keep them separate, but then the question is whether to have the new hint also imply the old hint (i.e. any check for the
SDL_HINT_OPENGL_ES_DRIVER Hint will also check the new hint). What is the best way to go about this?
I’m also not sure how the Hints system should handle failures. Checking whether the hint can be applied is simple, as it’s just a matter of checking if the EGL implementation has the extension
EGL_ANGLE_platform_angle. However, I’m not sure what should be done if the Hint is set, but the extension isn’t available. Should it be a hard failure (i.e. return that a context could not be created) or should it ignore the Hint if it’s not applicable (i.e. continue creating the context as if the Hint was never set)? A soft failure could create confusion, as it wouldn’t be able to indicate if the Hint is actually doing anything, but a hard failure could also be “wrong” for a Hint.
What do you all think about this?