fix color channel byte order in gfx/primitives.rs#1522
fix color channel byte order in gfx/primitives.rs#1522antonilol merged 2 commits intoRust-SDL2:masterfrom
Conversation
|
I will report back. I need to remember how I was running rust on my BE system! I think it must have been from Linux (normal OS is MorphOS which doesn't have a rust port). If it was Linux then I still have the disk and can test. |
|
Unfortunately, on my PPC system, I can no longer build the SDL2 dependency. I get lots and lots of errors that I haven't dug into yet but look a lot like 32bit is now failing (or no longer supported), lots of instances of "attempt to compute If I try to cross-compile from my M4 Mac to PPC then I can build for ppc64, just not ppc32. However, I don't have PPC linkers on my Mac so I wouldn't be able to complete that build anyway, I just know the build step doesn't throw those same errors, which is what makes me think it's a PPC32 vs PPC64 issue. My PPC system (the Big Endian system) is technically a PPC64 CPU (e5500), but I don't believe PPC64 linux has been run successfully on it at this point so we run plain PPC instead. Anyway, this all means that at this point, I can only confirm that the colours look correct now on M4 Mac, I cannot confirm on BE as yet. When I get some more time I will continue to see if I can get this built on PPC32, both native and via a Linux system that I can build. |
This has been introduced by bindgen running layout checks at compile time instead of runtime since an update, adding the |
|
Thank you - that got it compiled. Now I need to strip everything back to a simple example that just renders a blank screen of a background colour because currently my answer would be that the colours do not look right on BE, no. If I clear the screen using a colour of Colour::RGB(0, 0, 0) for example, my output screen is red, where clearly I would expect black. So I need to make sure I'm not doing anything stupid even though my Mac and my PPC systems are using the same code. |
|
That is consistent with #1502 and would mean it did not work correctly before #1470 on BE systems.
|
|
Could you check if it works now with this new commit? |
|
For circles ( That code for example - the circles are in the correct colour, but the background is Yellow, not blue. I also have another example where lines are not the correct colour. |
|
Using clear instead of fill_rect gives the correct result. Your code above for example - perfect. |
This is not related to sdl gfx but to sdl renderer, and this actually surprises me because I don't see colors being handled like ints or bytes there. Surely SDL2 works correctly on big endian platforms, right? Does an example using only C code work? Like this (chatgpt slop): #include <SDL2/SDL.h>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow(
"SDL2 Example",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_SHOWN
);
SDL_Renderer* renderer = SDL_CreateRenderer(
window,
-1,
SDL_RENDERER_ACCELERATED
);
// Equivalent to canvas.set_draw_color(Color::BLUE);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
// Equivalent to canvas.fill_rect(None)?;
// Passing NULL fills the entire rendering target
SDL_RenderFillRect(renderer, NULL);
SDL_RenderPresent(renderer);
SDL_Delay(3000);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}(compile: This correctly gives a completely blue screen for me |
|
Please leave this with me and I will test ASAP, hopefully this evening. In short, yes, SDL2 works generally on BE systems. I have 2 (unfinished) games in C/SDL2 render correctly on MorphOS and Amiga OS4. Neither of those OS's have a Rust port (I wish I knew how to do that!). The 3rd system which is Linux Mint PPC (an unofficial distro) is where I am testing this Rust Big Endian stuff and I don't recall if I've run my games on there or not. I will test the supplied code, and my games and report back. The reality is that I'm unlikely to actually use Rust directly on these systems as the build process is a bit slow on them. But it would certainly be nice to be able to cross-compile for them on my main systems (MacOS). I think I hit a further problem with SDL2 compilation following an apt-upgrade as well so I also need to investigate that. ( [edit] The hardware: https://mirari.vitasys.nl ) |
|
In short, the colours are messed up in SDL2 on Linux Mint PPC32. Instead of RGBA you need to specify ABGR to get the right colours. This affects the plain C example code and my games. It could be the reason for the issue in Rust as well unfortunately. The problem is not there in alternative OS's. I'm not familiar with the inner workings of it all enough to know if this is normal and I need to adjust for a different pixel format, or if the code should just run on any platform. I would have thought as such a basic level it should just run? I am trying to get another distro to run so I can determine if it is SDL2-devel on PPC32 Linux in general, or just the version on Mint. Alternative distro's aren't easy for this platform but hopefully I'll get one running over the weekend so I can get to the bottom of this. |
The SDL C function
Good luck! This problem does not seem rust-sdl2 related so I will merge this PR. |
This restores the intended behavior from before #1470 without reintroducing the UB that PR removed.
Tested on my machine (little endian)
@Guddler could you test this on your big endian platform?
I used this code:
should fix #1502