Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace devIL with SDL2_image #344

Merged
merged 10 commits into from
Sep 29, 2023
Merged

Replace devIL with SDL2_image #344

merged 10 commits into from
Sep 29, 2023

Conversation

mlauss2
Copy link
Contributor

@mlauss2 mlauss2 commented Sep 28, 2023

First draft of replacing use of devIL with SDL-image.
Again, main motivation is that SDL-image is much more common, while devIL is more niche (TFE is the only user I know of so far).

This first draft just tries to replace devIL. However, I'd like to replace the TFE_Image::Image struct with SDL_Surface: SDL2 uses it extensively, and it has all the info in "struct Image" plus more.
@luciusDXL: what do you think?

This snapshot already works, only minor issue so far is that the image in a savegame made after this patch is upside down.

@maxz
Copy link
Contributor

maxz commented Sep 29, 2023

I also began working on this, the day before yesterday. But you are faster. I'm heavily in favour of this change.

It makes #120 obsolete.

OpenGL's origin is the lower left corner, while the rest of the world
places it in the upper left.  Need to flip the captured
framebuffer vertically for a savegame screenshot.
Didn't check the editor code though..
@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

Ok, now it's in a state where it works just fine, the "Image*" structure is gone and has been replaced with an "SDL_Surface*" everywhere.
Tested on Linux only.

@mlauss2 mlauss2 changed the title Use SDL_Image instead of devIL Replace devIL with SDL2_image Sep 29, 2023
@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

I also began working on this, the day before yesterday. But you are faster. I'm heavily in favour of this change.

It makes #120 obsolete.

#120 at least has the advantage of being completely built-in, i.e. no external library required.

not build-tested though.
@maxz
Copy link
Contributor

maxz commented Sep 29, 2023

#120 at least has the advantage of being completely built-in, i.e. no external library required.

Well, it is still an external library. Just one moved into the tree. So not linked at runtime, but still by a third party. And most likely once it's added nobody would keep track of problems in the original one.

I can see a certain appeal for such a solution regarding the software renderer, but is SDL2 not pretty much a hard dependency anyways now for input handling and sound?

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

SDL image is not core SDL2, but an additional (they call it "satellite") library. But unlike devIL, it's available as default on most distros, including the steamdeck. In this state building a flatpak should be no different than building a flatpak for e.g. xonotic.

@luciusDXL
Copy link
Owner

luciusDXL commented Sep 29, 2023

This seems fine, I mainly used DeviL because I had used it successfully in the past for a variety of image formats. I will have to patch this in to make sure it compiles and works on Windows.
Edit: Ok, I should be able to set up the Windows side easily enough.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

normally, I wouldn't care, but I'd like to get TFE working on my steamdeck and devIL is kind of niche.
I tried to find a windows .lib version of sdl2-image but failed. the official releases only have dlls.

Out of curiosity: did you remove the screenshot functionality, or was it never fully present? I must admit I never tried to make one until now :)

@luciusDXL
Copy link
Owner

luciusDXL commented Sep 29, 2023

Screenshot functionality still works on Windows - screenshots get saved to /Documents/TheForceEngine/Screenshots. As for the lib, I took care of that. So you don't need to worry about Windows.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

Ok stupid question which keypress ? Eh nevermind, I just saw it...

@luciusDXL
Copy link
Owner

Ok stupid question which keypress ?

PrintScreen. Search for TFE_RenderBackend::queueScreenshot(screenshotPath);

@luciusDXL
Copy link
Owner

luciusDXL commented Sep 29, 2023

Anyway, once you get Linux working I will merge the PR and then fix up Windows (remove Windows DeviL libs/DLLs, add sdl_image lib/dll, etc.).

@luciusDXL luciusDXL marked this pull request as ready for review September 29, 2023 18:52
@luciusDXL luciusDXL merged commit 7dbb7cb into luciusDXL:master Sep 29, 2023
@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

too soon there's a compile error in saveSystem now, please apply this on top

--- a/TheForceEngine/TFE_Game/saveSystem.cpp
+++ b/TheForceEngine/TFE_Game/saveSystem.cpp
@@ -50,14 +50,15 @@ namespace TFE_SaveSystem
                TFE_RenderBackend::captureScreenToMemory(s_imageBuffer[0]);
                // Save to memory.
                u8* png = (u8*)malloc(SAVE_IMAGE_WIDTH * SAVE_IMAGE_HEIGHT * 4);
+               u32 pngSize;
                if (png)
                {
-                       u32 pngSize = (u32)TFE_Image::writeImageToMemory(png, displayInfo.width, displayInfo.height,
+                       pngSize = (u32)TFE_Image::writeImageToMemory(png, displayInfo.width, displayInfo.height,
                                                                 SAVE_IMAGE_WIDTH, SAVE_IMAGE_HEIGHT,
                                                                 s_imageBuffer[0]);
                } else {
                        pngSize = 0;
-                       png = s_imageBuffer[0];
+                       png = (u8 *)s_imageBuffer[0];
                }

@luciusDXL
Copy link
Owner

Got it.

@luciusDXL
Copy link
Owner

I was expecting to fix Windows errors anyway.

@luciusDXL
Copy link
Owner

Got it working on Windows, will push the results shortly.

@luciusDXL
Copy link
Owner

luciusDXL commented Sep 29, 2023

Thanks @mlauss2 - the change now works on Windows and is submitted. The only issue I ran into is that screenshots are upside down, though save game images are fine. I added some code to flip them on save, but will probably want to clean it up in the future. I have tested from a fresh clone/compile on Windows and everything works fine now.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

Thanks @mlauss2 - the change now works on Windows and is submitted. The only issue I ran into is that screenshots are upside down, though save game images are fine. I added some code to flip them on save, but will probably want to clean it up in the future.

What about the screengrabs in new saves?

@luciusDXL
Copy link
Owner

Thanks @mlauss2 - the change now works on Windows and is submitted. The only issue I ran into is that screenshots are upside down, though save game images are fine. I added some code to flip them on save, but will probably want to clean it up in the future.

What about the screengrabs in new saves?

That actually works fine as-is.

@luciusDXL
Copy link
Owner

image

@luciusDXL
Copy link
Owner

@mlauss2 Anyway, if you can test screenshots on Linux and let me know if they are upside down or not. If they are, I will just remove the #ifdef _WIN32 block around the code.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

@mlauss2 Anyway, if you can test screenshots on Linux and let me know if they are upside down or not. If they are, I will just remove the #ifdef _WIN32 block around the code.

Will do.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

With my local branch, the screenshots are fine.
I pulled your master branch, now my screenshots are also flipped. Strange...

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

Looks like this issue is OS independent, please enable the screenshot flip unconditionally.
I'll dig deeper, because this is unacceptable.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 29, 2023

Ohhh... it's due to the different paths:
Screenshots do a GPU-accelerated copy if PBOs are available, while for the screenshots glReadPixels() is used. The flip is only done in ScreenCapture::captureFrontBufferToMemory(), while screenshots are taken with ScreenCapture::captureFrame(), where no flip occurs.

@luciusDXL
Copy link
Owner

luciusDXL commented Sep 29, 2023

@mlauss2 Ah ok - thanks for checking. I will make the flip unconditional for now and then dig into it deeper at a later date. It sounds like I should just modify the PBO/capture code instead.

@luciusDXL
Copy link
Owner

@mlauss2 Linux fix pushed, added a TODO to fix it properly later.

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 30, 2023

@luciusDXL I think you can close PR #117 and #120 as supersesed.

@BielBdeLuna
Copy link

BielBdeLuna commented Sep 30, 2023

made an issue: #351

@mlauss2
Copy link
Contributor Author

mlauss2 commented Sep 30, 2023

on linux: git pull --recurse-submodules didn't pull libsdl2-image-dev from the net, maybe it should be added as an external library in the git repo. after installing it. passing all the cmake checks ok, when I

install libsdl2-image from your distros package manager; I think your build didn't place the headers in the correct spot.

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.

4 participants