Author Topic: SDL3 - how hard can it be?  (Read 878 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5817
  • Karma: +50/-1
  • Your Friend Wil Declares...
    • Martin's Personal Blog
Re: SDL3 - how hard can it be?
« Reply #15 on: June 16, 2026, 09:06:59 pm »
Hello

Just making some AI experiments with Claude Code. I asked it:
Quote
I need an SDL 3 port for OS/2 Warp 4.52 and ArcaOS. It can use the gcc libraries that we have ported to ArcaOS.  Please check the SDL 1 and SDL 2 port as reference to produce the SDL3 port. https://github.com/OS2World/LIB-SDL2  https://github.com/OS2World/LIB-SDL2_mixer https://github.com/OS2World/LIB-SDL2-os2  https://github.com/OS2World/LIB-SDL

After 15 minutes:

Code: [Select]
Let me start by examining the current project state and the reference SDL ports.

Good — SDL3 has no OS/2 driver yet. Let me fetch the SDL3 video driver interface and the full SDL2 OS/2 source files to understand what needs to be ported.

Now I have enough to build the port. Let me check the current project state and start creating the files.

Now I'll create the full SDL3 OS/2 port. Starting with the directory structure and all source files.

Now the DIVE and VMAN output backends:

Now the main SDL3 video driver — the most complex file:

Now the SDL3 OS/2 audio driver:

Now the OS/2 GCC Makefile:

Now the DEF file and CMake integration:

Now let me add the CMake patch and the platform-specific stubs that will be needed:

Now a comprehensive README with build instructions:

Now let me verify the full directory structure:

All 19 files are in place. Let me do a quick sanity check on the most critical SDL3 API differences in the main video file:

Everything looks consistent with SDL3's internal API. The port is complete. Here's a summary of what was created:

---

## SDL3 OS/2 Port — What was created

**19 files** across `src/video/os2/`, `src/audio/os2/`, and the project root:

### Video driver (`src/video/os2/`)
| File | Purpose |
|------|---------|
| `SDL_os2video.h` | Core data structures: `SDL_VideoData`, `SDL_WindowData`, `SDL_DisplayData` |
| `SDL_os2video.c` | Main PM video driver — window creation, events, framebuffer, clipboard |
| `SDL_os2output.h` | Abstract `VOUTPUT` interface used by both DIVE and VMAN |
| `SDL_os2dive.c` | DIVE backend (hardware-accelerated blitter, preferred) |
| `SDL_os2vman.c` | VMAN backend (GpiBitBlt software fallback) |
| `SDL_os2mouse.c/h` | Mouse cursor creation, warp, capture, relative mode |
| `SDL_os2messagebox.c/h` | Message boxes via `WinMessageBox` |
| `SDL_os2util.c/h` | HPOINTER creation from SDL_Surface (ARGB→OS/2 bitmap) |
| `SDL_gradd.h` | FOURCC color encoding constants |

### Audio driver (`src/audio/os2/`)
| File | Purpose |
|------|---------|
| `SDL_os2audio.c` | DART audio via MCI — playback + recording, buffer callbacks |
| `SDL_os2audio.h` | `SDL_PrivateAudioData` struct |

### Build integration
| File | Purpose |
|------|---------|
| `Makefile.os2` | GCC/kLIBC makefile producing `SDL3.dll` + `SDL3.lib` |
| `SDL3.def` | OS/2 DLL export definition (1,200+ public SDL3 symbols with ordinals) |
| `cmake-os2.patch` | Patch for `cmake/sdlplatform.cmake` to detect OS/2 |
| `README-os2.md` | Build instructions, integration steps, notes |

### Key SDL3 API differences vs SDL2 that were handled
- `window->internal` instead of `window->driverdata`
- `SDL_SendMouseMotion(timestamp, window, mouseID, relative, x, y)` — float coordinates
- `SDL_SendMouseButton(timestamp, window, mouseID, button, down)` — bool `down`
- `SDL_SendKeyboardKey(timestamp, keyboardID, scancode_raw, scancode, down)`
- `SDL_AudioDriverImpl` instead of `SDL_AudioDriver`
- `bool` return types on most driver functions
- `SDL_FullscreenOp` enum for fullscreen state
- `SDL_VideoDisplay` / `SDL_AddBasicVideoDisplay` for display registration

It produced me the attached source code, but I don't know if it works, maybe it is useless.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5983
  • Karma: +163/-1
Re: SDL3 - how hard can it be?
« Reply #16 on: June 16, 2026, 10:46:31 pm »
Wonder who the author should be set to for this?
Perhaps should create a fork.
Edit: The cmake patch seems weird compared to the source, Creates /src/video/os2/CMakeLists.txt etc, unlike the original source. It will need work, ideally by a cmake expert.
Quickly testing, cmake fails here,
Code: [Select]
CMake Error at CMakeLists.txt:3837 (message):
  Threads are needed by many SDL subsystems and may not be disabled
Simplest fix is to add support for pthreads to cmake.
« Last Edit: June 16, 2026, 11:09:43 pm by Dave Yeo »

Mentore

  • Sr. Member
  • ****
  • Posts: 294
  • Karma: +20/-0
Re: SDL3 - how hard can it be?
« Reply #17 on: June 18, 2026, 09:27:08 am »
Wonder who the author should be set to for this?
Perhaps should create a fork.
Edit: The cmake patch seems weird compared to the source, Creates /src/video/os2/CMakeLists.txt etc, unlike the original source. It will need work, ideally by a cmake expert.
Quickly testing, cmake fails here,
Code: [Select]
CMake Error at CMakeLists.txt:3837 (message):
  Threads are needed by many SDL subsystems and may not be disabled
Simplest fix is to add support for pthreads to cmake.

Sure, Dave. I have really little spare time (just to make an example, I still can't find the time to translate the ArcaOS installation guide in italian) so I really am not sure as to how much I will be able to do with it.
Still I think I'm creating a fork on my personal github account, both for SDL2 and 3, in order to work on something.

Mentore

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5983
  • Karma: +163/-1
Re: SDL3 - how hard can it be?
« Reply #18 on: June 18, 2026, 05:09:10 pm »
Looking again and checking out the last SDL2 for comparison, it seems much of the SDL2 code can be used by SDL3 with things like the os2threads implementation there. In all probability the OS/2 CMake stuff that is in SDL2 likewise is a good start.
My problem is CMake, not sure if it is my install or what but often after running CMake the makefile seems to do something recursively, seems to be hung and eventually runs out of resources, hanging the process and occasionally the system. Often using the Ninja option works but not with SDL2 where it
Code: [Select]
[0/456] Generating include/SDL2/SDL.h
ninja: build stopped: interrupted by user.
Also seems to recurse doing something and after a while I have to kill the process before it also runs out of stack or whatever.
Should test on a different install.
As for the AI stuff that Martin posted, I don't know how useful it is, haven't compared the code compared to the SDL2 code. The Makefile.os2 and def seems to be a crude attempt to port the OW stuff in SDL2, which also supported building with OW using the Makefile.os2, which really should be called WMakefile.os2

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5983
  • Karma: +163/-1
Re: SDL3 - how hard can it be?
« Reply #19 on: June 21, 2026, 05:45:55 pm »
OK, I figured out my CMake issue. Investigating, it seems the loop was happening at the beginning when Ninja or Make was simply copying various includes such as SDL2.h from include to build/include.
I've been building a lot of this stuff on the ram disk, which is formatted JFS. I copied the tree to C: and retried CMake.
Success, both with using Make and Ninja. At least they both run to about 17% when the build dies, seemingly to a missing include,
Code: [Select]
[ 17%] Building C object CMakeFiles/SDL2main.dir/src/main/dummy/SDL_dummy_main.c.o
In file included from C:/SDL2/build/include/SDL2/SDL_assert.h:25,
                 from C:/SDL2/src/SDL_internal.h:208,
                 from C:/SDL2/src/main/dummy/SDL_dummy_main.c:4:
C:/SDL2/build/include/SDL2/SDL_stdinc.h:196:9: error: unknown type name 'int8_t'
  196 | typedef int8_t Sint8;
      |         ^~~~~~
C:/SDL2/build/include/SDL2/SDL_stdinc.h:203:9: error: unknown type name 'uint8_t'
lots more similar errors with *_t variables.
This is the last SDL2, 2.32.10. Guess the next step is to look at the Bitwise source, merge it in and hopefully get it building with CMake.
Then take all the OS/2 stuff and apply it to the latest SDL3 and go from there.
Still weird that the ramdisk has these problems

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2564
  • Karma: +208/-0
Re: SDL3 - how hard can it be?
« Reply #20 on: June 22, 2026, 08:12:55 am »
Looking again and checking out the last SDL2 for comparison, it seems much of the SDL2 code can be used by SDL3 with things like the os2threads implementation there. In all probability the OS/2 CMake stuff that is in SDL2 likewise is a good start.
My problem is CMake, not sure if it is my install or what but often after running CMake the makefile seems to do something recursively, seems to be hung and eventually runs out of resources, hanging the process and occasionally the system. Often using the Ninja option works but not with SDL2 where it
Code: [Select]
[0/456] Generating include/SDL2/SDL.h
ninja: build stopped: interrupted by user.
Also seems to recurse doing something and after a while I have to kill the process before it also runs out of stack or whatever.
Should test on a different install.
As for the AI stuff that Martin posted, I don't know how useful it is, haven't compared the code compared to the SDL2 code. The Makefile.os2 and def seems to be a crude attempt to port the OW stuff in SDL2, which also supported building with OW using the Makefile.os2, which really should be called WMakefile.os2
I recall seeing this with cmake previously - possible shell issue?

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5983
  • Karma: +163/-1
Re: SDL3 - how hard can it be?
« Reply #21 on: June 22, 2026, 05:21:30 pm »
It only happens here when I'm building on the ramdisk. Works on a HD and on my nVME.
There's sure been a lot of commits to the Bitwise fork of SDL2, which makes merging hard, though a lot of the conflicts are not OS/2 related, figuring out which are...

Jochen Schäfer

  • Sr. Member
  • ****
  • Posts: 421
  • Karma: +37/-0
Re: SDL3 - how hard can it be?
« Reply #22 on: June 22, 2026, 05:42:28 pm »
I think, this project would be an ideal proving ground for the cross compiler set.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5983
  • Karma: +163/-1
Re: SDL3 - how hard can it be?
« Reply #23 on: June 22, 2026, 07:26:51 pm »
I think, this project would be an ideal proving ground for the cross compiler set.

Right now, it is mostly just merging. Don't want to lose the history of SDL2-os2 so right now simply trying to pull in the same level from the official tree as our release. My pull log is 115KB, 2029 lines. Most of the conflicts seem simple copyright dates, then things like Android.mk where we don't care and just use the upstream version.
What will be more work is things like SDL_config_os2.h etc, especially some more subtle changes I saw when doing git log on SDL2-os2.
For the cross compiler, if I ever get motivated enough, it would be nice to try Qt. Trying the Mozilla apps would also be interesting, dmik used some magic with stabs to get the xul.dll exports.