Added SDL_SetTextureUserData() and SDL_GetTextureUserData() to associate a user-specified pointer with an SDL texture

This commit is contained in:
Sam Lantinga 2021-08-10 15:17:59 -07:00
parent a0af7ce731
commit f5794f9eeb
7 changed files with 46 additions and 2 deletions

View file

@ -52,7 +52,7 @@ include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
set(SDL_MAJOR_VERSION 2)
set(SDL_MINOR_VERSION 0)
set(SDL_MICRO_VERSION 17)
set(SDL_INTERFACE_AGE 1)
set(SDL_INTERFACE_AGE 0)
set(SDL_BINARY_AGE 17)
set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
# the following should match the versions in Xcode project file:

View file

@ -23,7 +23,7 @@ dnl Set various version strings - taken gratefully from the GTk sources
SDL_MAJOR_VERSION=2
SDL_MINOR_VERSION=0
SDL_MICRO_VERSION=17
SDL_INTERFACE_AGE=1
SDL_INTERFACE_AGE=0
SDL_BINARY_AGE=17
SDL_VERSION=$SDL_MAJOR_VERSION.$SDL_MINOR_VERSION.$SDL_MICRO_VERSION

View file

@ -480,6 +480,28 @@ extern DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture * texture,
extern DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture * texture,
SDL_ScaleMode *scaleMode);
/**
* Associate a user-specified pointer with a texture.
*
* \param texture the texture to update.
* \param userdata the pointer to associate with the texture.
* \returns 0 on success, or -1 if the texture is not valid.
*
* \sa SDL_GetTextureUserData
*/
extern DECLSPEC int SDLCALL SDL_SetTextureUserData(SDL_Texture * texture,
void *userdata);
/**
* Get the user-specified pointer associated with a texture
*
* \param texture the texture to query.
* \return the pointer associated with the texture, or NULL if the texture is not valid.
*
* \sa SDL_SetTextureUserData
*/
extern DECLSPEC void * SDLCALL SDL_GetTextureUserData(SDL_Texture * texture);
/**
* Update the given texture rectangle with new pixel data.
*

View file

@ -815,3 +815,5 @@
#define SDL_GameControllerSendEffect SDL_GameControllerSendEffect_REAL
#define SDL_JoystickSendEffect SDL_JoystickSendEffect_REAL
#define SDL_GameControllerGetSensorDataRate SDL_GameControllerGetSensorDataRate_REAL
#define SDL_SetTextureUserData SDL_SetTextureUserData_REAL
#define SDL_GetTextureUserData SDL_GetTextureUserData_REAL

View file

@ -880,3 +880,5 @@ SDL_DYNAPI_PROC(int,SDL_FlashWindow,(SDL_Window *a, SDL_FlashOperation b),(a,b),
SDL_DYNAPI_PROC(int,SDL_GameControllerSendEffect,(SDL_GameController *a, const void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_JoystickSendEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(float,SDL_GameControllerGetSensorDataRate,(SDL_GameController *a, SDL_SensorType b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureUserData,(SDL_Texture *a, void *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_GetTextureUserData,(SDL_Texture *a),(a),return)

View file

@ -1486,6 +1486,23 @@ SDL_GetTextureScaleMode(SDL_Texture * texture, SDL_ScaleMode *scaleMode)
return 0;
}
int
SDL_SetTextureUserData(SDL_Texture * texture, void *userdata)
{
CHECK_TEXTURE_MAGIC(texture, -1);
texture->userdata = userdata;
return 0;
}
void *
SDL_GetTextureUserData(SDL_Texture * texture)
{
CHECK_TEXTURE_MAGIC(texture, NULL);
return texture->userdata;
}
#if SDL_HAVE_YUV
static int
SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,

View file

@ -58,6 +58,7 @@ struct SDL_Texture
Uint32 last_command_generation; /* last command queue generation this texture was in. */
void *driverdata; /**< Driver specific texture representation */
void *userdata;
SDL_Texture *prev;
SDL_Texture *next;