Skip to content

Commit 2a325bc

Browse files
committed
Added support for textures with palettes
Closes #6192
1 parent 137b0b2 commit 2a325bc

File tree

8 files changed

+628
-65
lines changed

8 files changed

+628
-65
lines changed

include/SDL3/SDL_render.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Rende
660660
* pixels, required
661661
* - `SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER`: the height of the texture in
662662
* pixels, required
663+
* - `SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER`: an SDL_Palette to use with the texture, optional.
663664
* - `SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating
664665
* point textures, this defines the value of 100% diffuse white, with higher
665666
* values being displayed in the High Dynamic Range headroom. This defaults
@@ -759,6 +760,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureWithProperties(SDL_Re
759760
#define SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER "SDL.texture.create.access"
760761
#define SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER "SDL.texture.create.width"
761762
#define SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER "SDL.texture.create.height"
763+
#define SDL_PROP_TEXTURE_CREATE_PALETTE_POINTER "SDL.texture.create.palette"
762764
#define SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT "SDL.texture.create.SDR_white_point"
763765
#define SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT "SDL.texture.create.HDR_headroom"
764766
#define SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER "SDL.texture.create.d3d11.texture"
@@ -929,6 +931,40 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRendererFromTexture(SDL_Textur
929931
*/
930932
extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h);
931933

934+
/**
935+
* Set the palette used by a texture.
936+
*
937+
* A single palette can be shared with many textures.
938+
*
939+
* \param texture the texture to update.
940+
* \param palette the SDL_Palette structure to use.
941+
* \returns true on success or false on failure; call SDL_GetError() for more
942+
* information.
943+
*
944+
* \threadsafety This function should only be called on the main thread.
945+
*
946+
* \since This function is available since SDL 3.4.0.
947+
*
948+
* \sa SDL_CreatePalette
949+
* \sa SDL_GetTexturePalette
950+
*/
951+
extern SDL_DECLSPEC bool SDLCALL SDL_SetTexturePalette(SDL_Texture *texture, SDL_Palette *palette);
952+
953+
/**
954+
* Get the palette used by a texture.
955+
*
956+
* \param texture the texture to query.
957+
* \returns a pointer to the palette used by the texture, or NULL if there is
958+
* no palette used.
959+
*
960+
* \threadsafety This function should only be called on the main thread.
961+
*
962+
* \since This function is available since SDL 3.4.0.
963+
*
964+
* \sa SDL_SetTexturePalette
965+
*/
966+
extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetTexturePalette(SDL_Texture *texture);
967+
932968
/**
933969
* Set an additional color value multiplied into render copy operations.
934970
*
@@ -1155,7 +1191,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, S
11551191
/**
11561192
* Set the scale mode used for texture scale operations.
11571193
*
1158-
* The default texture scale mode is SDL_SCALEMODE_LINEAR.
1194+
* The default texture scale mode is SDL_SCALEMODE_LINEAR for RGB and YUV textures and SDL_SCALEMODE_PIXELART for indexed textures.
11591195
*
11601196
* If the scale mode is not supported, the closest supported mode is chosen.
11611197
*

src/dynapi/SDL_dynapi.sym

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,8 @@ SDL3_0.0.0 {
12571257
SDL_hid_get_properties;
12581258
SDL_GetPixelFormatFromGPUTextureFormat;
12591259
SDL_GetGPUTextureFormatFromPixelFormat;
1260+
SDL_SetTexturePalette;
1261+
SDL_GetTexturePalette;
12601262
# extra symbols go here (don't modify this line)
12611263
local: *;
12621264
};

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,3 +1282,5 @@
12821282
#define SDL_hid_get_properties SDL_hid_get_properties_REAL
12831283
#define SDL_GetPixelFormatFromGPUTextureFormat SDL_GetPixelFormatFromGPUTextureFormat_REAL
12841284
#define SDL_GetGPUTextureFormatFromPixelFormat SDL_GetGPUTextureFormatFromPixelFormat_REAL
1285+
#define SDL_SetTexturePalette SDL_SetTexturePalette_REAL
1286+
#define SDL_GetTexturePalette SDL_GetTexturePalette_REAL

src/dynapi/SDL_dynapi_procs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,3 +1290,5 @@ SDL_DYNAPI_PROC(Uint32,SDL_AddAtomicU32,(SDL_AtomicU32 *a,int b),(a,b),return)
12901290
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_hid_get_properties,(SDL_hid_device *a),(a),return)
12911291
SDL_DYNAPI_PROC(SDL_PixelFormat,SDL_GetPixelFormatFromGPUTextureFormat,(SDL_GPUTextureFormat a),(a),return)
12921292
SDL_DYNAPI_PROC(SDL_GPUTextureFormat,SDL_GetGPUTextureFormatFromPixelFormat,(SDL_PixelFormat a),(a),return)
1293+
SDL_DYNAPI_PROC(bool,SDL_SetTexturePalette,(SDL_Texture *a,SDL_Palette *b),(a,b),return)
1294+
SDL_DYNAPI_PROC(SDL_Palette*,SDL_GetTexturePalette,(SDL_Texture *a),(a),return)

0 commit comments

Comments
 (0)