Closed icculus closed 1 month ago
Is there any point in keeping the SDL1/2 surface api past SDL2? Surely old SDL1 apps have been ported by now?
It's still useful (even if lots of things are going to use the GPU)
Sounds good!
I started playing around with this, and ended up wondering whether indexed surfaces should require palettes at all. Currently, every indexed surface has a palette (which, if the user doesn't specify one, is all black, except for 1-bit surfaces, where it has one black colour, and one white).
I have a super-hacky proof of concept which makes the palette NULL by default, and has blits between surfaces with NULL palettes just use the identity map: https://github.com/sulix/SDL/commit/nopalsurface
(It only handles the 8-bit → 8-bit case properly at this point, so is definitely not production ready.)
Does this make sense from an API point of view, either instead of or in addition to a flag for SDL_BlitSurface()? Personally, I quite like how this makes creating and using a surface 'just work' unless palettes are manually specified (though there are some nasty corner cases when, e.g., SDL_LoadBMP() is used).
I started playing around with this, and ended up wondering whether indexed surfaces should require palettes at all. Currently, every indexed surface has a palette (which, if the user doesn't specify one, is all black, except for 1-bit surfaces, where it has one black colour, and one white).
I have a super-hacky proof of concept which makes the palette NULL by default, and has blits between surfaces with NULL palettes just use the identity map: sulix@nopalsurface
(It only handles the 8-bit → 8-bit case properly at this point, so is definitely not production ready.)
Does this make sense from an API point of view, either instead of or in addition to a flag for SDL_BlitSurface()? Personally, I quite like how this makes creating and using a surface 'just work' unless palettes are manually specified (though there are some nasty corner cases when, e.g., SDL_LoadBMP() is used).
This seems totally reasonable for SDL 3.0. When expanding to truecolor we can fail the blit, or have a NULL palette map to black. Feel free to create a PR when you're ready!
Adding flipping into all the various blit combinations would be code and test case explosion. Instead you can just use SDL_FlipSurface() once your blit is complete.
I went ahead and made the palette change in https://github.com/libsdl-org/SDL/pull/10226.
@sulix, I went ahead and merged your change for 8-bit palettes. Could you do the followup work to handle multiple bit-depths appropriately? Are there other corner cases that need tidying up as well?
Feel free to update surface_testPalette() or add additional automated palette tests to cover whatever you need.
Okay, I think this is in a good place now.
Copying between 8-bit indexed surfaces that don't have a palette will just do a memcpy, copying between indexed surfaces that don't have a palette and RGB surfaces will fail, and < 8 bit surfaces aren't supported as copy targets, as always.
Originally posted by @sulix in https://github.com/libsdl-org/SDL/issues/3519#issuecomment-1313630422