delve-framework icon indicating copy to clipboard operation
delve-framework copied to clipboard

SDL3 Platform Support

Open photex opened this issue 1 year ago • 14 comments

As discussed in #40, this PR is the WIP for having SDL3 support.

My expectation is that this will get a bit messy, but ultimately a squash before merging will trim any of the missteps and so on.

Current Goals:

  • [ ] Build SDL3
    • [x] Windows
    • [x] Linux
    • [ ] MacOS
    • [x] Emscripten
  • [ ] Implement the App backend
    • [x] Windows
    • [x] Input
      • [ ] Gamepads
    • [x] Graphics context creation
    • [x] ImGUI
    • [x] Display scale query
    • [ ] Correctly initialize sokol_gfx
      • [ ] Windows
      • [ ] MacOS
      • [x] Linux
      • [x] Emscripten
    • [x] Emscripten main loop
  • [x] Sokol App backend behavior preserved
  • [ ] CI for each platform to ensure everything builds
  • [x] Allow applications to select a backend at build time
    • [ ] Sources only fetched when SDL platform selected
    • [x] SDL only built when that platform is selected

photex avatar Sep 24 '24 07:09 photex

SDL Window ahoy... It's looking kinda messy behind the scenes, but it was just to get to this point. Now I can walk some stuff back or clean some things up.

https://github.com/user-attachments/assets/e73c9ea4-cd63-4791-b97c-0e426f3b8c0d

photex avatar Sep 30 '24 14:09 photex

Whoah, that is great progress!

Interrupt avatar Oct 01 '24 15:10 Interrupt

Ok, so now you can freely use either backend:

zig build -Dplatform_backend=sokol (which is also just the default) or zig build -Dplatform_backend=sdl

Please excuse the wide overreach in the current diff. I tried something, and didn't want to push something that didn't build. I'll reverse a lot of the platform module restructure.

I found the platform/app.zig situation to be pretty confusing. I thought that the platform module itself already provided the public api so there was no need for delve.platform.app.

It also made things a bit easier to reckon with in terms of the build time selection of the backend and simplified some of the imports else where in the platform files.

I still think that there can be a better name for platform/app.zig, but I think perhaps the build time selected backend could become the platform.app instead. That would mean that perhaps the platform apis that work as a facade aren't needed?

I'll noodle a bit and start reverting the changes to the examples. :D

photex avatar Oct 01 '24 16:10 photex

Yeah, is a bit confusing right now. The top level framework/app.zig is really the client application config setup, which maybe could be renamed to delve_framework_app or something, and the thinking was the common backend logic for windowing and rendering would live in the framework/platform layer, hence the app there.

I like the idea of the platform layer holding the common code, and then the actual backends just needing to implement a small set of functions instead of there being a bunch of copy+paste between backends, but this is the first time this has been tried so I'm sure some changes will shake out of it.

Interrupt avatar Oct 02 '24 20:10 Interrupt

Yep, that's the right way to go. I've reverted things so the diff is readable again. Next I need to get the ImGUI events hooked up, and I can figure out builds for other platforms.

photex avatar Oct 03 '24 15:10 photex

I added github actions that build things with both backends. Windows and Linux are working (I haven't tested windows binaries yet... need to find a machine to set windows up on) and I've fixed the build so that SDL is only actually built when you select that backend.

I'm going to base the imgui event handling on what I see with sokol app, I believe another keyboard map will be needed, but I think otherwise it's fairly simple.

That will mean there needs to be more considerations for swapping out the RHI (if this is the right way to think of sokol vs SDL_gpu vs ). But this definitely makes it clear that working on the platform stuff first while maintaining sokol was the right idea. :D

I believe emscripten could be supported with SDL3. Unfortunately it's not part of the emsdk yet so I'll try to build it. It would be sweet to have gamepads for that target.

Also, I plan to rebase and squash all my garbage commits soon.

photex avatar Oct 06 '24 07:10 photex

Ok, ImGUI hooked back up. Need to try and seal the deal on building for each platform now. trying to line up some way to actually test them

photex avatar Oct 08 '24 14:10 photex

This is some serious progress! Making the builds only include SDL3 when needed is huge, that's exactly the kind of thing I've been thinking about as it makes cross platform builds way easier when the dependency list is smaller. This seems really close to having a new app layer backend.

Interrupt avatar Oct 08 '24 16:10 Interrupt

:face_exhaling: realized I was running sokol_app unintentionally lol

photex avatar Oct 09 '24 10:10 photex

Ok, build of SDL for emscripten is working. The mainloop is still not set up correctly though. This is more what I expected originally.

I also just realized that even for the sokol backend, the windows builds aren't initializing sokol_gfx correctly. So I'll figure out what I broke. :D Obviously there shouldn't be any change in behavior or results for that backend!

photex avatar Oct 10 '24 06:10 photex

Alright, so SDL builds and runs under emscripten, but I'm learning that sokol_app definitely handles a lot of details regarding the viewport and surface under emscripten.

photex avatar Oct 12 '24 19:10 photex

I'd believe that, looking through the Sokol source they seem to have a lot of checks for the web build case.

Interrupt avatar Oct 13 '24 06:10 Interrupt

In this case the window resizes but not the viewport being rendered into. It maintains the initially requested dimensions. flooh explained some things to me and pointed at examples of what sokol_app does in these cases.

If I make the window resizeable for a desktop build everything is working as expected. But for the web you end up needing to manage some things for the webgl surface to stay in sync with the canvas.

On the desktop front, for windows, the combination of sokol_gfx and SDL isn’t quite done because at the beginning of the frame we need to provide a pointer to a directx device which the glue lib uses sokol_app to do.

Either way, slowly getting there. :)

photex avatar Oct 13 '24 07:10 photex

Resizing isn't handled yet by the Delve Framework, so that behavior at least matches the current Sokol implementation. This is on my radar to flesh out though

Interrupt avatar Oct 16 '24 15:10 Interrupt