cocos2d-x  2.2.3-gd2.113-rev1ec524e
Loading...
Searching...
No Matches
CCTextureCache Class Reference

Singleton that handles the loading of textures Once the texture is loaded, the next time it will return a reference of the previously loaded texture reducing GPU & CPU memory. More...

#include <CCTextureCache.h>

Inheritance diagram for CCTextureCache:
[legend]
Collaboration diagram for CCTextureCache:
[legend]

Public Member Functions

 CCTextureCache ()
 ctor NA More...
 
virtual ~CCTextureCache ()
 NA NA. More...
 
const char * description (void)
 NA NA. More...
 
CCDictionarysnapshotTextures ()
 NA. More...
 
void addImageAsync (const char *path, CCObject *target, SEL_CallFuncO selector)
 
CCTexture2DaddUIImage (CCImage *image, const char *key)
 Returns a Texture2D object given an UIImage image If the image was not previously loaded, it will create a new CCTexture2D object and it will return it. More...
 
CCTexture2DtextureForKey (const char *key)
 Returns an already created texture. More...
 
bool reloadTexture (const char *fileName)
 Reload texture from the image file If the file image hasn't loaded before, load it. More...
 
void removeAllTextures ()
 Purges the dictionary of loaded textures. More...
 
void removeUnusedTextures ()
 Removes unused textures Textures that have a retain count of 1 will be deleted It is convenient to call this method after when starting a new Scene. More...
 
void removeTexture (CCTexture2D *texture)
 Deletes a texture from the cache given a texture. More...
 
void removeTextureForKey (const char *textureKeyName)
 Deletes a texture from the cache given a its key name. More...
 
void dumpCachedTextureInfo ()
 Output to CCLOG the current contents of this CCTextureCache This will attempt to calculate the size of each texture, and the total texture memory in use. More...
 
CCTexture2DaddPVRImage (const char *filename)
 Returns a Texture2D object given an PVR filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. More...
 
CCTexture2DaddETCImage (const char *filename)
 Returns a Texture2D object given an ETC filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. More...
 
CCTexture2DaddImage (const char *fileimage, bool)
 Returns a Texture2D object given an file image If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it. More...
 
- Public Member Functions inherited from CCObject
 CCObject (void)
 
virtual ~CCObject (void)
 NA. More...
 
void release (void)
 
void retain (void)
 
CCObjectautorelease (void)
 
CCObjectcopy (void)
 
bool isSingleReference (void) const
 
unsigned int retainCount (void) const
 
virtual bool isEqual (const CCObject *pObject)
 
virtual void acceptVisitor (CCDataVisitor &visitor)
 
virtual void update (float dt)
 
 CCObject (const CCObject &)
 
CCObjectoperator= (const CCObject &)
 
virtual void encodeWithCoder (DS_Dictionary *)
 
virtual bool canEncode ()
 
CCObjectType getObjType () const
 
virtual int getTag () const
 
virtual void setTag (int nTag)
 
void setObjType (CCObjectType)
 
- Public Member Functions inherited from CCCopying
virtual CCObjectcopyWithZone (CCZone *pZone)
 

Static Public Member Functions

static CCTextureCachesharedTextureCache ()
 Returns the shared instance of the cache getInstance. More...
 
static void purgeSharedTextureCache ()
 purges the cache. More...
 
static void reloadAllTextures ()
 Reload all textures It's only useful when the value of CC_ENABLE_CACHE_TEXTURE_DATA is 1. More...
 
- Static Public Member Functions inherited from CCObject
static CCObjectcreateWithCoder (DS_Dictionary *)
 

Protected Attributes

CCDictionarym_pTextures
 
- Protected Attributes inherited from CCObject
unsigned int m_uReference
 
unsigned int m_uAutoReleaseCount
 
int m_nTag
 
int m_eObjType
 
unsigned int m_uObjectIdxInArray
 

Additional Inherited Members

- Public Attributes inherited from CCObject
unsigned int m_uID
 
int m_nLuaID
 

Detailed Description

Singleton that handles the loading of textures Once the texture is loaded, the next time it will return a reference of the previously loaded texture reducing GPU & CPU memory.

Constructor & Destructor Documentation

◆ CCTextureCache()

ctor NA

◆ ~CCTextureCache()

virtual ~CCTextureCache ( )
virtual

NA NA.

Member Function Documentation

◆ addETCImage()

CCTexture2D * addETCImage ( const char *  filename)

Returns a Texture2D object given an ETC filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.

Otherwise it will return a reference of a previously loaded image NA

◆ addImage()

CCTexture2D * addImage ( const char *  fileimage,
bool   
)

Returns a Texture2D object given an file image If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.

It will use the filename as a key. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif

Remarks
Added by RobTop. See RT_ADD for more info.

◆ addImageAsync()

void addImageAsync ( const char *  path,
CCObject target,
SEL_CallFuncO  selector 
)

◆ addPVRImage()

CCTexture2D * addPVRImage ( const char *  filename)

Returns a Texture2D object given an PVR filename If the file image was not previously loaded, it will create a new CCTexture2D object and it will return it.

Otherwise it will return a reference of a previously loaded image

◆ addUIImage()

CCTexture2D * addUIImage ( CCImage image,
const char *  key 
)

Returns a Texture2D object given an UIImage image If the image was not previously loaded, it will create a new CCTexture2D object and it will return it.

Otherwise it will return a reference of a previously loaded image The "key" parameter will be used as the "key" for the cache. If "key" is nil, then a new texture will be created each time.

◆ description()

const char * description ( void  )

NA NA.

◆ dumpCachedTextureInfo()

void dumpCachedTextureInfo ( )

Output to CCLOG the current contents of this CCTextureCache This will attempt to calculate the size of each texture, and the total texture memory in use.

Since
v1.0

◆ purgeSharedTextureCache()

static void purgeSharedTextureCache ( )
static

purges the cache.

It releases the retained instance.

Since
v0.99.0

◆ reloadAllTextures()

static void reloadAllTextures ( )
static

Reload all textures It's only useful when the value of CC_ENABLE_CACHE_TEXTURE_DATA is 1.

◆ reloadTexture()

bool reloadTexture ( const char *  fileName)

Reload texture from the image file If the file image hasn't loaded before, load it.

Otherwise the texture will be reloaded from the file image. The "filenName" parameter is the related/absolute path of the file image. Return true if the reloading is succeed, otherwise return false.

◆ removeAllTextures()

void removeAllTextures ( )

Purges the dictionary of loaded textures.

Call this method if you receive the "Memory Warning" In the short term: it will free some resources preventing your app from being killed In the medium term: it will allocate more resources In the long term: it will be the same

◆ removeTexture()

void removeTexture ( CCTexture2D texture)

Deletes a texture from the cache given a texture.

◆ removeTextureForKey()

void removeTextureForKey ( const char *  textureKeyName)

Deletes a texture from the cache given a its key name.

Since
v0.99.4

◆ removeUnusedTextures()

void removeUnusedTextures ( )

Removes unused textures Textures that have a retain count of 1 will be deleted It is convenient to call this method after when starting a new Scene.

Since
v0.8

◆ sharedTextureCache()

static CCTextureCache * sharedTextureCache ( )
static

Returns the shared instance of the cache getInstance.

◆ snapshotTextures()

CCDictionary * snapshotTextures ( )

NA.

◆ textureForKey()

CCTexture2D * textureForKey ( const char *  key)

Returns an already created texture.

Returns nil if the texture doesn't exist.

Since
v0.99.5

Member Data Documentation

◆ m_pTextures

CCDictionary* m_pTextures
protected

The documentation for this class was generated from the following file: