Made texture size and format public in the API

Also added refcount to textures so they can be retained by application code.
This commit is contained in:
Sam Lantinga
2024-09-30 20:40:54 -07:00
parent 5136b30652
commit 1f3a0d12e6
8 changed files with 76 additions and 66 deletions

View File

@@ -1362,6 +1362,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
if (!texture) {
return NULL;
}
texture->refcount = 1;
SDL_SetObjectValid(texture, SDL_OBJECT_TYPE_TEXTURE, true);
texture->colorspace = (SDL_Colorspace)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, default_colorspace);
texture->format = format;
@@ -4990,12 +4991,10 @@ bool SDL_RenderPresent(SDL_Renderer *renderer)
return true;
}
static bool SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying)
static void SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying)
{
SDL_Renderer *renderer;
CHECK_TEXTURE_MAGIC(texture, false);
SDL_DestroyProperties(texture->props);
renderer = texture->renderer;
@@ -5036,11 +5035,16 @@ static bool SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying)
texture->locked_surface = NULL;
SDL_free(texture);
return true;
}
void SDL_DestroyTexture(SDL_Texture *texture)
{
CHECK_TEXTURE_MAGIC(texture, );
if (--texture->refcount > 0) {
return;
}
SDL_DestroyTextureInternal(texture, false /* is_destroying */);
}

View File

@@ -71,17 +71,22 @@ typedef struct SDL_RenderViewState
// Define the SDL texture structure
struct SDL_Texture
{
SDL_Colorspace colorspace; /**< The colorspace of the texture */
float SDR_white_point; /**< The SDR white point for this content */
float HDR_headroom; /**< The HDR headroom needed by this content */
SDL_PixelFormat format; /**< The pixel format of the texture */
SDL_TextureAccess access; /**< The texture access mode */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
SDL_BlendMode blendMode; /**< The texture blend mode */
SDL_ScaleMode scaleMode; /**< The texture scale mode */
SDL_FColor color; /**< Texture modulation values */
SDL_RenderViewState view; /**< Target texture view state */
// Public API definition
SDL_PixelFormat format; /**< The format of the texture, read-only */
int w; /**< The width of the texture, read-only. */
int h; /**< The height of the texture, read-only. */
int refcount; /**< Application reference count, used when freeing texture */
// Private API definition
SDL_Colorspace colorspace; // The colorspace of the texture
float SDR_white_point; // The SDR white point for this content
float HDR_headroom; // The HDR headroom needed by this content
SDL_TextureAccess access; // The texture access mode
SDL_BlendMode blendMode; // The texture blend mode
SDL_ScaleMode scaleMode; // The texture scale mode
SDL_FColor color; // Texture modulation values
SDL_RenderViewState view; // Target texture view state
SDL_Renderer *renderer;
@@ -91,13 +96,13 @@ struct SDL_Texture
void *pixels;
int pitch;
SDL_Rect locked_rect;
SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
SDL_Surface *locked_surface; // Locked region exposed as a SDL surface
Uint32 last_command_generation; // last command queue generation this texture was in.
SDL_PropertiesID props;
void *internal; /**< Driver specific texture representation */
void *internal; // Driver specific texture representation
SDL_Texture *prev;
SDL_Texture *next;