In SDL2, is there currently any way to create an indexed streaming texture with a custom palette?
Use case: I’m trying to develop a game framework in the form of an 8-bit “fantasy console” – not unlike Pico-8, except powered by a real 8-bit VM with its own architecture and assembly, rather than by Lua.
I know this is how I can create an indexed streaming texture:
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_INDEX8, SDL_TEXTUREACCESS_STREAMING, width, height);
However, because SDL_CreateTexture accepts an SDL_PixelFormatEnum, not an SDL_PixelFormat, there’s no way to specify a palette. There also doesn’t seem to be a way to set a palette after the fact, short of the obviously-named SDL_SetTexturePalette, which doesn’t seem to exist in SDL2.
I’m aware I can create an indexed surface and set a palette for it, using SDL_CreateRGBSurfaceWithFormat[From] and SDL_SetSurfacePalette, and then create a texture with those same properties using SDL_CreateTextureFromSurface. However, per the documentation, SDL_CreateTextureFromSurface will always return a static texture.
My current workaround is to use an RGBA8888 texture, store an 8-bit indexed pixel buffer and palette in static memory, and manually convert every pixel to RGBA8888 in transit every frame. This seems suboptimal. Considering my use case, it’s not as if I need highly optimized graphics code, but if I’m going to do something, I’d like to do it right – if a right way exists.
Thanks and regards,
Jaime