How do you keep platform code and RHI code separate?
Hello! I’m currently in the process of re-writing most of my engine. (It kind of just devolved into ai slop due to my own laziness and I wasn’t actually making any design decisions of my own, meaning that not only did I have no idea how anything worked, it didn’t even work the way I wanted it to)
I’ve written a basic platform abstraction layer that polls os events and translates it to my event and input systems, as well as being able to spawn windows.
I’m now at the point where I’d like to consider being able to do something with the screen, so I need to be able to get the window surface.
Now, I’m primarily developing my engine in Vulkan, but I’d like to keep everything outside of Vulkan-specific code as agnostic as possible. So, for example, I could port my engine to Apple’s Metal or whatever PlayStation uses in the future and only have to ADD a new renderer instead of REWRITING all of my code.
Now, as much as I can remember off of the top of my head, in order to make a surface, you need to call a platform-specific function. My current platform is SDL3*, and you need to call SDL_Vulkan_CreateSurface with an instance and the sdl window pointer. In order to create an instance, you have to get your platform-specific extensions, which you need to call SDL for.
So, how do you guys separate the platform (SDL) from the API (Vulkan) effectively and cleanly?
* I know SDL3 already abstracts platforms and stuff, but I’d like to treat it as its own platform. It helps keep SDL code out of everything else and makes porting easier for platforms without SDL support (which is little to none but not 0)