X Tutup
Skip to content

BACKENDS: Add SDL3 backend + update imgui#6312

Merged
sev- merged 1 commit intoscummvm:masterfrom
scemino:master
Feb 18, 2025
Merged

BACKENDS: Add SDL3 backend + update imgui#6312
sev- merged 1 commit intoscummvm:masterfrom
scemino:master

Conversation

@scemino
Copy link
Contributor

@scemino scemino commented Dec 14, 2024

This PR modifies the current SDL backend to add SDL3 support.
There are a lot of combinations so don't hesitate to read it carefully and/or test it.
I didn't test the SDL3_net library.
This is the first time I modify the configure file, so have a look and tell me if I need to do some changes (I'm sure you will ;)).
And maybe the way I handled all the #ifdef are not at your taste, so feel free to give some advice.

To do this PR I used these recommendations: https://github.com/libsdl-org/SDL/blob/main/docs/README-migration.md and of course https://wiki.libsdl.org/SDL3/CategoryAPI

@ccawley2011
Copy link
Member

Since there are a lot of repeated ifdefs relates to functions that have simply been renamed or only have minor changes to the parameters, I'd recommend using wrapper functions where possible to make the changes easier to read and less fragile to maintain.

@scemino
Copy link
Contributor Author

scemino commented Dec 15, 2024

Since there are a lot of repeated ifdefs relates to functions that have simply been renamed or only have minor changes to the parameters, I'd recommend using wrapper functions where possible to make the changes easier to read and less fragile to maintain.

Thanks for your advice.
Do you prefer #define, static functions or member functions?

Here is an example with static functions:

Before:

#if SDL_VERSION_ATLEAST(3, 0, 0)
    if (!SDL_AddGamepadMappingsFromFile(file.getPath().toString(Common::Path::kNativeSeparator).c_str()))
#else
    if (SDL_GameControllerAddMappingsFromFile(file.getPath().toString(Common::Path::kNativeSeparator).c_str()) < 0)
#endif
        error("File %s not valid: %s", file.getPath().toString(Common::Path::kNativeSeparator).c_str(), SDL_GetError());

After with static functions:

static bool gameControllerAddMappingsFromFile(const char *file) {
#if SDL_VERSION_ATLEAST(3, 0, 0)
	return SDL_AddGamepadMappingsFromFile(file);
#else
	return SDL_GameControllerAddMappingsFromFile(file) >= 0;
#endif
}

...

if (!gameControllerAddMappingsFromFile(file.getPath().toString(Common::Path::kNativeSeparator).c_str()))
        error("File %s not valid: %s", file.getPath().toString(Common::Path::kNativeSeparator).c_str(), SDL_GetError());
    

@sev-
Copy link
Member

sev- commented Dec 15, 2024

Regarding the imgui update, did you add the files from the matching git commit as rest of the code?

@scemino
Copy link
Contributor Author

scemino commented Dec 16, 2024

Regarding the imgui update, did you add the files from the matching git commit as rest of the code?

Yes I used the commit ocornut/imgui@cb16568 corresponding to the tag https://github.com/ocornut/imgui/releases/tag/v1.91.3

About this, I see that there is a backends/imgui/scummvm.patch file, I should update this file too, no?

@scemino
Copy link
Contributor Author

scemino commented Dec 16, 2024

Since there are a lot of repeated ifdefs relates to functions that have simply been renamed or only have minor changes to the parameters, I'd recommend using wrapper functions where possible to make the changes easier to read and less fragile to maintain.

Tell me if it's OK now or did you think something different?

@scemino scemino force-pushed the master branch 4 times, most recently from 26a395e to 117ab44 Compare December 16, 2024 21:48
@sev-
Copy link
Member

sev- commented Dec 16, 2024

About this, I see that there is a backends/imgui/scummvm.patch file, I should update this file too, no?
Yes. I use it for updating imgui from time to time. Just make a diff against the imgui git commit.

@scemino scemino force-pushed the master branch 2 times, most recently from d0f76eb to fbd5a5a Compare December 17, 2024 20:37
@scemino
Copy link
Contributor Author

scemino commented Dec 17, 2024

About this, I see that there is a backends/imgui/scummvm.patch file, I should update this file too, no?
Yes. I use it for updating imgui from time to time. Just make a diff against the imgui git commit.

I updated the patch file, but I have a lot more changes than the previous one, can you have a look @sev- please?

@bluegr
Copy link
Member

bluegr commented Dec 18, 2024

Since there are a lot of repeated ifdefs relates to functions that have simply been renamed or only have minor changes to the parameters, I'd recommend using wrapper functions where possible to make the changes easier to read and less fragile to maintain.

Tell me if it's OK now or did you think something different?

There is no definite answer here... use whatever makes the code easier to read and maintain.

From the three options you provided:

  • static wrapper functions would be a very straightforward way
  • defines are a bit uglier than function wrappers, IMHO
  • member functions are also a nice idea, we could keep all of these functions neatly placed inside classes, and instantiate a different class per SDL version

So, from the options above, we could either use a C-style implementation (static wrapper functions) or a C++-style implementation (different class per SDL version, inherited from a common parent class, with member functions). I personally like the C++ approach better, but function wrappers would also work just fine :)

@scemino
Copy link
Contributor Author

scemino commented Dec 18, 2024

Since there are a lot of repeated ifdefs relates to functions that have simply been renamed or only have minor changes to the parameters, I'd recommend using wrapper functions where possible to make the changes easier to read and less fragile to maintain.

Tell me if it's OK now or did you think something different?

There is no definite answer here... use whatever makes the code easier to read and maintain.

From the three options you provided:

  • static wrapper functions would be a very straightforward way
  • defines are a bit uglier than function wrappers, IMHO
  • member functions are also a nice idea, we could keep all of these functions neatly placed inside classes, and instantiate a different class per SDL version

So, from the options above, we could either use a C-style implementation (static wrapper functions) or a C++-style implementation (different class per SDL version, inherited from a common parent class, with member functions). I personally like the C++ approach better, but function wrappers would also work just fine :)

I made my choice already, sorry I'm not a huge fan of inheritance and I don't see the benefit of creating 1 class by version.

@bluegr
Copy link
Member

bluegr commented Dec 19, 2024

I made my choice already, sorry I'm not a huge fan of inheritance and I don't see the benefit of creating 1 class by version.

That's fine :) Nice implementation!

@lotharsm
Copy link
Member

Thank you for looking into this!

I wanted to give it a try on Mingw64, and currently it seems that Win32 isn't fully supported yet:

In file included from backends/platform/sdl/win32/win32-window.cpp:27:
./backends/platform/sdl/win32/win32-window.h:32:9: error: 'HWND' does not name a type
   32 |         HWND getHwnd();
      |         ^~~~
backends/platform/sdl/win32/win32-main.cpp: In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':
backends/platform/sdl/win32/win32-main.cpp:54:16: error: 'main' was not declared in this scope
   54 |         return main(__argc, __argv);
      |                ^~~~
make: *** [Makefile.common:176: backends/platform/sdl/win32/win32-main.o] Error 1
make: *** Waiting for unfinished jobs....
    C++      engines/scumm/boxes.o
    C++      engines/scumm/camera.o
backends/platform/sdl/win32/win32-window.cpp: In member function 'virtual void SdlWindow_Win32::setupIcon()':
backends/platform/sdl/win32/win32-window.cpp:36:29: error: 'getHwnd' was not declared in this scope; did you mean 'getwc'?
   36 |                 HWND hwnd = getHwnd();
      |                             ^~~~~~~
      |                             getwc
backends/platform/sdl/win32/win32-window.cpp: At global scope:
backends/platform/sdl/win32/win32-window.cpp:53:6: error: no declaration matches 'HWND__* SdlWindow_Win32::getHwnd()'
   53 | HWND SdlWindow_Win32::getHwnd() {
      |      ^~~~~~~~~~~~~~~
backends/platform/sdl/win32/win32-window.cpp:53:6: note: no functions named 'HWND__* SdlWindow_Win32::getHwnd()'
./backends/platform/sdl/win32/win32-window.h:29:7: note: 'class SdlWindow_Win32' defined here
   29 | class SdlWindow_Win32 final : public SdlWindow {
      |       ^~~~~~~~~~~~~~~
make: *** [Makefile.common:176: backends/platform/sdl/win32/win32-window.o] Error 1

I quickly went through the release notes and indeed it looks like backends/platform/sdl/win32/win32-window.cpp is missing something - I'll check if I can adapt it from the other changes.

@scemino
Copy link
Contributor Author

scemino commented Dec 26, 2024

I quickly went through the release notes and indeed it looks like backends/platform/sdl/win32/win32-window.cpp is missing something - I'll check if I can adapt it from the other changes.

That's nice of you, thank you.

Copy link
Member

@sev- sev- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colossal work, thank you!

Have number of comments, mainly on formatting and suggestion to add more wrappers.

I am concerned that the code now becomes much harder to maintain with this amount of ifdefs, so maybe splitting files/adding more wrappers could make it easier to read and less fragile?

@scemino
Copy link
Contributor Author

scemino commented Dec 30, 2024

Colossal work, thank you!

Have number of comments, mainly on formatting and suggestion to add more wrappers.

I am concerned that the code now becomes much harder to maintain with this amount of ifdefs, so maybe splitting files/adding more wrappers could make it easier to read and less fragile?

Sorry I've been sick for a few days, as soon as I feel better I'll take care of it.

@sev-
Copy link
Member

sev- commented Jan 24, 2025

@scemino for generating patch, please use the same command as outlined in cff87d8

diff -rbu . ../scummvm/scummvm/backends/imgui/|grep -v ^Only >../scummvm/scummvm/backends/imgui/scummvm.patch

This will remove those whitespace and file path changes.

Copy link
Member

@sev- sev- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is much cleaner now, thank you for the split of sdl-events.cpp file.

My recommendation to add a configure key --use-sdl3, so then you give preference/try to it, otherwise, put it at the end of the detection list until we perform a thorough testing.

I like the sdl-events.cpp splut, the code looks much much cleaner, though, of course, somebody has to modify it in three places if any enhancements are added (relatively unlikely).

I wonder, does it make sense to do[sdl-graphics.cpp file? or it will be way too much?

I left a few small comments here and there, mostly on the formatting. as the code is pretty clean.

Also, did you test the backend with testbed? And also, perhaps testbed needs to be enhanced with test for the multifinger taps?

@ccawley2011
Copy link
Member

I like the sdl-events.cpp splut, the code looks much much cleaner, though, of course, somebody has to modify it in three places if any enhancements are added (relatively unlikely).

I feel that the code is less clean after the split because of the amount of duplication that could be avoided by simply using defines for the renamed functions, similarly to what we did when we first moved to SDL2 in commit 8530997.

@scemino scemino force-pushed the master branch 2 times, most recently from c61c064 to 199537a Compare January 26, 2025 08:39
@scemino
Copy link
Contributor Author

scemino commented Jan 26, 2025

Also, did you test the backend with testbed?

I need to do the test with SDL1, then SDL2, then SDL3, right ?
That's a good idea, I found some bugs already with SDL3: SDL_BlitSurface failed: The surface is not indexed format!.
This means I need to check every function where a test is done like thisif (SDL_... != 0)
I will fix this ASAP.
There are 2 places, I don't know if I need to make the changes in backends/platform/openpandora/op-backend.cpp and backends/platform/sdl/amigaos/amigaos.cpp, what do you recommend ?

Another bug: the ImGui window can't be moved outside the main window.

And also, perhaps testbed needs to be enhanced with test for the multifinger taps?

I'm not sure I'm the best person to do that, but I can give a try if you want.

@raziel-
Copy link
Contributor

raziel- commented Jan 26, 2025

amigaos4 has just gotten an sdl3 rc
https://www.amigans.net/modules/newbb/viewtopic.php?post_id=152728#forumpost152728

not tested and i won't be able to do it anymore, but i guess sdl3 support will be possible

@scemino scemino force-pushed the master branch 2 times, most recently from 500cff7 to d365f34 Compare January 27, 2025 16:09
@scemino
Copy link
Contributor Author

scemino commented Jan 27, 2025

amigaos4 has just gotten an sdl3 rc https://www.amigans.net/modules/newbb/viewtopic.php?post_id=152728#forumpost152728

not tested and i won't be able to do it anymore, but i guess sdl3 support will be possible

So it could be useful to do these changes for amigaos, I did the changes, I have no way to test it ;)

@raziel-
Copy link
Contributor

raziel- commented Jan 27, 2025

thank you very much
someone will be happy I'm sure 😀

@scemino
Copy link
Contributor Author

scemino commented Jan 31, 2025

Another bug: the ImGui window can't be moved outside the main window.

This one is fixed now!

@scemino scemino requested a review from sev- January 31, 2025 19:51
@sev-
Copy link
Member

sev- commented Feb 7, 2025

@scemino any plans to regenerate the patch so it shows less diff?

@sev-
Copy link
Member

sev- commented Feb 7, 2025

I would like to merge it, so I could subsequently update ImGui, and the patch stays in the way.

@scemino
Copy link
Contributor Author

scemino commented Feb 9, 2025

@scemino any plans to regenerate the patch so it shows less diff?

For me it seems correct, the only big differences is the addition of imgui_impl_sdlrenderer3.cpp and imgui_impl_sdlrenderer3.h, can you point me out what's wrong?

@scemino
Copy link
Contributor Author

scemino commented Feb 9, 2025

I would like to merge it, so I could subsequently update ImGui, and the patch stays in the way.

I can drop my modifications on the patch, you want me to do that?

@sev-
Copy link
Member

sev- commented Feb 16, 2025

@scemino any plans to regenerate the patch so it shows less diff?

For me it seems correct, the only big differences is the addition of imgui_impl_sdlrenderer3.cpp and imgui_impl_sdlrenderer3.h, can you point me out what's wrong?

No, it is not correct. You did not provide the paths exactly as it was before, as a result, we have a lot of noise like:

- diff --color -rbu ./backends/imgui_impl_opengl3.cpp - ../scummvm/scummvm/backends/imgui/backends/imgui_impl_opengl3.cpp
- --- ./backends/imgui_impl_opengl3.cpp	2024-10-07 18:21:01
- +++ ../scummvm/scummvm/backends/imgui/backends/imgui_impl_opengl3.cpp	2024-10-07 18:30:56
+ diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp
+ index 770f85f4..b363ba07 100644
+ --- a/backends/imgui_impl_opengl3.cpp
+ +++ b/backends/imgui_impl_opengl3.cpp
@@ -114,7 +114,7 @@
 #define _CRT_SECURE_NO_WARNINGS
 #endif
-  
+

I am asking to do this for conistency, otherwise we end up with changing it every time.

@scemino
Copy link
Contributor Author

scemino commented Feb 17, 2025

@scemino any plans to regenerate the patch so it shows less diff?

For me it seems correct, the only big differences is the addition of imgui_impl_sdlrenderer3.cpp and imgui_impl_sdlrenderer3.h, can you point me out what's wrong?

No, it is not correct. You did not provide the paths exactly as it was before, as a result, we have a lot of noise like:

- diff --color -rbu ./backends/imgui_impl_opengl3.cpp - ../scummvm/scummvm/backends/imgui/backends/imgui_impl_opengl3.cpp
- --- ./backends/imgui_impl_opengl3.cpp	2024-10-07 18:21:01
- +++ ../scummvm/scummvm/backends/imgui/backends/imgui_impl_opengl3.cpp	2024-10-07 18:30:56
+ diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp
+ index 770f85f4..b363ba07 100644
+ --- a/backends/imgui_impl_opengl3.cpp
+ +++ b/backends/imgui_impl_opengl3.cpp
@@ -114,7 +114,7 @@
 #define _CRT_SECURE_NO_WARNINGS
 #endif
-  
+

I am asking to do this for conistency, otherwise we end up with changing it every time.

Sorry I'm not able to do it:

git diff --color -rbu > scummvm.patch
error: invalid option: -rbu

I removed the modifications on the patch.

@sev-
Copy link
Member

sev- commented Feb 17, 2025

git diff --color -rbu > scummvm.patch
error: invalid option: -rbu

because it is NOT git. it is plain diff :D git diff shows you the difference between commits, while here you need to store differences between ScummVM and ImGui repos.

Quoting my early reply:

@scemino for generating patch, please use the same command as outlined in cff87d8

diff -rbu . ../scummvm/scummvm/backends/imgui/|grep -v ^Only >../scummvm/scummvm/backends/imgui/scummvm.patch

This will remove those whitespace and file path changes.

Also, there are conflicts now, so the thing has to be rebased.

@sev-
Copy link
Member

sev- commented Feb 17, 2025

I removed the modifications on the patch.

I am using the patch for applying the changes on the ImGui upgrade. What is your proposed solution to this?

@scemino
Copy link
Contributor Author

scemino commented Feb 18, 2025

git diff --color -rbu > scummvm.patch
error: invalid option: -rbu

because it is NOT git. it is plain diff :D git diff shows you the difference between commits, while here you need to store differences between ScummVM and ImGui repos.

Quoting my early reply:

@scemino for generating patch, please use the same command as outlined in cff87d8

diff -rbu . ../scummvm/scummvm/backends/imgui/|grep -v ^Only >../scummvm/scummvm/backends/imgui/scummvm.patch

This will remove those whitespace and file path changes.

Also, there are conflicts now, so the thing has to be rebased.

OK I understand now, sorry about that.

@sev-
Copy link
Member

sev- commented Feb 18, 2025

Thank you, merging.

@sev- sev- merged commit 8afb2c1 into scummvm:master Feb 18, 2025
8 checks passed
if test -z "$_sdlconfig"; then
echo "none found!"
exit 1
_sdlconfig="pkg-config sdl3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I did not realize, that this breaks completely systems without pkg-config. Like mine....

@orgads
Copy link
Contributor

orgads commented Feb 22, 2025

Thank you! Do you plan to add it also for create_project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup