-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
sdl: Improve pixel fetching api #406
base: master
Are you sure you want to change the base?
Conversation
@veeableful quick question, why are the alias pixel formats not mapped to their c values directly? I'm asking this because, my tests for RGB888 pass, but the tests for RGB24 do not, which is weird. This has me puzzled. EDIT: The documentation and source do not match up. |
That was painful... The tests were very flaky with the default renderer (not actually returning valid pixel data sometimes), had to use a SoftwareRenderer instead. Also avoids complications with init and main. It's working fine now for RGBA formats (except the last one, it's not convertible, gotta figure out what that means still), and it's still missing palette and planar modes. All this trial and error, + the compilation time drove me absolutely mad 😭 |
The PR is looking great @flga. Thanks for the hard work!
I don't remember exactly why 😅 I guess that was done to enable it to compile using older SDL2 (e.g. SDL2 2.0.0). Now that I see it, I think I should have declared the missing alias definitions in go-sdl2 for older SDL2. I have pushed the change (hopefully didn't break anything!).
Hm.. yeah the compilation speed is quite slow. I wonder if it is possible to split the |
Hey @veeableful, I've been looking into the indexed and yuv pixel formats and they work in a slightly different manner. Indexed formats require a palette, which is hard to support unless we accept an actual Format instead of a format enum, and yuv seem to be very "edge casey", I've played around with implementing this, and it kinda works, the basic quadrant tests pass, but the concatenated quadrants do not. I feel like this will lead to re-implementing a lot of sdl logic and it doesn't seem all that worth it. What do you think about reducing this new method into just RGBA (all the formats, although I still need to look into how PIXELFORMAT_ARGB2101010 works)? Users that need more specialized handling can still use the default, no guard rails, method. In regards to code splitting, in principle yes, that would solve it, however I'm not so sure that it is feasible, seems like it would be easy to fall into circular deps. |
Yeah @flga, absolutely. You could add support for the ones you have implemented now and maybe set error for the ones that are not yet implemented. We could always support them in the future =) |
@veeableful sorry, seems like I've missed the notification. I'll update the PR tomorrow. |
@flga Don’t worry about it. Take as much time as you need! |
I think there's two parts to this problem.
1 - do not require the callers to import unsafe in ReadPixels, just take in a slice and assume it's size is correct (easy enough, but I think it would be best to do it separately)
2 - provide a version of this function that does the heavy lifting for the caller (this pr)
I think it's worthwhile keeping the original implementation and just fixing up the unsafe.Pointer.
For one, it's what the actual SDL api looks like, but it also allows the caller to manage his/her buffers.
The basic principle is to take in a rect and a pixel format and fill in the gaps appropriately.
This isn't ready yet, seems to work but it needs more tests, so I'll be marking it as draft for now.
I also need to rethink the testing methodology, this way of creating the expected pixel buffers is unwieldy.