Class TTexturesVideosCache
Unit
Declaration
type TTexturesVideosCache = class(TVideosCache)
Description
A cache of loaded images for textures.
Load by TextureImage_IncReference, free by TextureImage_DecReference. These replace LoadTextureImage, and manual freeing of Image/Composite.
If you used IncReference that returns Composite, then you should also free using DecReference that takes Composite. If you used IncReference without Composite parameter, then also free using DecReference without Composite parameter.
The idea is that instead of LoadTextureImage(...)
call Cache.TextureImage_IncReference(...)
. Later, instead of freeing this image, call TextureImage_DecReference(Image)
. From your point of view, things will work the same. But if you expect to load many textures from the same URL, then you will get a great speed and memory saving, because image will only be actually loaded once. Notes:
Note that in case of problems with loading, TextureImage_IncReference may raise an exception, just like normal LoadTextureImage. In this case it's guaranteed that no reference will be incremented, of course. If LoadTextureImage_IncReference returns in a normal way, then it will return something non-
Nil
, just like LoadTextureImage does.LoadTextureImage_DecReference alwas sets Image to
Nil
, like FreeAndNil.Since detecting image alpha channel type may be a little time-consuming (iteration over all pixels is needed), we also do it here and save in cache.
Note that before destroying this object you must free all textures, i.e. call LoadTextureImage_DecReference for all images allocated by LoadTextureImage_IncReference. This class is not a lousy way of avoiding memory leaks — it would be a bad idea, because it would cause sloppy programming, where memory is unnecessarily allocated for a long time. In fact, this class asserts in destructor that no images are in cache anymore, so if you compiled with assertions enabled, this class does the job of memory-leak detector.
Hierarchy
- TObject
- TVideosCache
- TTexturesVideosCache
Overview
Methods
constructor Create; |
|
destructor Destroy; override; |
|
function TextureImage_IncReference(const Url: String; out Composite: TCompositeImage; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
function TextureImage_IncReference(const Url: String; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
function TextureImage_IncReference(const Url: String; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
procedure TextureImage_DecReference(var Image: TEncodedImage; var Composite: TCompositeImage); overload; |
|
procedure TextureImage_DecReference(var Image: TEncodedImage); overload; |
|
function Empty: boolean; override; |
Description
Methods
constructor Create; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function TextureImage_IncReference(const Url: String; out Composite: TCompositeImage; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
This item has no description. |
function TextureImage_IncReference(const Url: String; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
This item has no description. |
function TextureImage_IncReference(const Url: String; const LoadOptions: TLoadImageOptions = []): TEncodedImage; overload; |
|
This item has no description. |
procedure TextureImage_DecReference(var Image: TEncodedImage; var Composite: TCompositeImage); overload; |
|
This item has no description. |
procedure TextureImage_DecReference(var Image: TEncodedImage); overload; |
|
This item has no description. |
function Empty: boolean; override; |
|
This item has no description. |
Generated by PasDoc 0.16.0-snapshot.