cocos2d-x  3.0-alpha0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TextureCache 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 TextureCache:
Object TextureCacheEmscripten

Classes

struct  AsyncStruct
 

Public Member Functions

 TextureCache ()
virtual ~TextureCache ()
const char * description (void) const
Texture2DaddImage (const std::string &filepath)
 Returns a Texture2D object given an filename. More...
 
local addImage ( local filepath)
 Returns a Texture2D object given an filename. More...
 
virtual void addImageAsync (const std::string &filepath, Object *target, SEL_CallFuncO selector)
local addImageAsync ( local filepath, local target, local selector)
Texture2DaddImage (Image *image, const std::string &key)
 Returns a Texture2D object given an Image. More...
 
local addImage ( local image, local key)
 Returns a Texture2D object given an Image. More...
 
CC_DEPRECATED_ATTRIBUTE Texture2DaddUIImage (Image *image, const char *key)
local addUIImage ( local image, local key)
Texture2DgetTextureForKey (const std::string &key) const
 Returns an already created texture. More...
 
var getTextureForKey ( var key)
 Returns an already created texture. More...
 
local getTextureForKey ( local key)
 Returns an already created texture. More...
 
CC_DEPRECATED_ATTRIBUTE Texture2DtextureForKey (const char *key) const
local textureForKey ( local key)
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 (Texture2D *texture)
 Deletes a texture from the cache given a texture. More...
 
void removeTextureForKey (const std::string &key)
 Deletes a texture from the cache given a its key name. More...
 
void dumpCachedTextureInfo () const
 Output to CCLOG the current contents of this TextureCache This will attempt to calculate the size of each texture, and the total texture memory in use. More...
 
- Public Member Functions inherited from Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
void release ()
 Release the ownership immediately. More...
 
void retain ()
 Retains the ownership. More...
 
Objectautorelease ()
 Release the ownership sometime soon automatically. More...
 
bool isSingleReference () const
 Returns a boolean value that indicates whether there is only one reference to the object. More...
 
unsigned int retainCount () const
 Returns the object's current reference count. More...
 
virtual bool isEqual (const Object *object)
 Returns a boolean value that indicates whether this object and a given object are equal. More...
 
virtual void acceptVisitor (DataVisitor &visitor)
virtual void update (float dt)

Static Public Member Functions

static TextureCachegetInstance ()
 Returns the shared instance of the cache. More...
 
var getInstance ()
 Returns the shared instance of the cache. More...
 
local getInstance ()
 Returns the shared instance of the cache. More...
 
static CC_DEPRECATED_ATTRIBUTE
TextureCache
sharedTextureCache ()
local sharedTextureCache ()
static void destroyInstance ()
 purges the cache. More...
 
var destroyInstance ()
 purges the cache. More...
 
local destroyInstance ()
 purges the cache. More...
 
static CC_DEPRECATED_ATTRIBUTE void purgeSharedTextureCache ()
local purgeSharedTextureCache ()
static void reloadAllTextures ()
 Reload all textures It's only useful when the value of CC_ENABLE_CACHE_TEXTURE_DATA is 1. More...
 

Protected Attributes

std::thread * _loadingThread
var _loadingThread
local _loadingThread
std::queue< AsyncStruct * > * _asyncStructQueue
var _asyncStructQueue
local _asyncStructQueue
std::queue< ImageInfo * > * _imageInfoQueue
var _imageInfoQueue
local _imageInfoQueue
std::mutex _asyncStructQueueMutex
std::mutex _imageInfoMutex
std::mutex _sleepMutex
var _sleepMutex
local _sleepMutex
std::condition_variable _sleepCondition
var _sleepCondition
local _sleepCondition
bool _needQuit
int _asyncRefCount
var _asyncRefCount
local _asyncRefCount
std::unordered_map
< std::string, Texture2D * > 
_textures
- Protected Attributes inherited from Object
unsigned int _reference
 count of references More...
 
var _reference
 count of references More...
 
local _reference
 count of references More...
 
unsigned int _autoReleaseCount
 count of autorelease More...
 
var _autoReleaseCount
 count of autorelease More...
 
local _autoReleaseCount
 count of autorelease More...
 

Static Protected Attributes

static TextureCache_sharedTextureCache
var _sharedTextureCache
local _sharedTextureCache

Additional Inherited Members

- Public Attributes inherited from Object
unsigned int _ID
 object id, ScriptSupport need public _ID More...
 
int _luaID
 Lua reference id. More...
 

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

var ctor ( )
local TextureCache ( )
virtual ~TextureCache ( )
virtual

Member Function Documentation

Texture2D* addImage ( const std::string &  filepath)

Returns a Texture2D object given an filename.

If the filename was not previously loaded, it will create a new Texture2D 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

var addImage ( var  filepath)

Returns a Texture2D object given an filename.

If the filename was not previously loaded, it will create a new Texture2D 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

local addImage ( local  filepath)

Returns a Texture2D object given an filename.

If the filename was not previously loaded, it will create a new Texture2D 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

Texture2D* addImage ( Image image,
const std::string &  key 
)

Returns a Texture2D object given an Image.

If the image was not previously loaded, it will create a new Texture2D 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.

var addImage ( var  image,
var  key 
)

Returns a Texture2D object given an Image.

If the image was not previously loaded, it will create a new Texture2D 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.

local addImage ( local  image,
local  key 
)

Returns a Texture2D object given an Image.

If the image was not previously loaded, it will create a new Texture2D 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.

virtual void addImageAsync ( const std::string &  filepath,
Object target,
SEL_CallFuncO  selector 
)
virtual
var addImageAsync ( var  filepath,
var  target,
var  selector 
)
virtual
local addImageAsync ( local  filepath,
local  target,
local  selector 
)
virtual
CC_DEPRECATED_ATTRIBUTE
Texture2D* addUIImage
( Image image,
const char *  key 
)
inline
var addUIImage ( var  image,
var  key 
)
inline
local addUIImage ( local  image,
local  key 
)
inline
const char* description ( void  ) const
static void destroyInstance ( )
static

purges the cache.

It releases the retained instance.

Since
v0.99.0
var destroyInstance ( )
static

purges the cache.

It releases the retained instance.

Since
v0.99.0
local destroyInstance ( )
static

purges the cache.

It releases the retained instance.

Since
v0.99.0
void dumpCachedTextureInfo ( ) const

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

Since
v1.0
var dumpCachedTextureInfo ( )

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

Since
v1.0
local dumpCachedTextureInfo ( )

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

Since
v1.0
static TextureCache* getInstance ( )
static

Returns the shared instance of the cache.

var getInstance ( )
static

Returns the shared instance of the cache.

local getInstance ( )
static

Returns the shared instance of the cache.

Texture2D* getTextureForKey ( const std::string &  key) const

Returns an already created texture.

Returns nil if the texture doesn't exist.

Since
v0.99.5
var getTextureForKey ( var  key)

Returns an already created texture.

Returns nil if the texture doesn't exist.

Since
v0.99.5
local getTextureForKey ( local  key)

Returns an already created texture.

Returns nil if the texture doesn't exist.

Since
v0.99.5
static CC_DEPRECATED_ATTRIBUTE
void purgeSharedTextureCache
( )
inlinestatic
var purgeSharedTextureCache ( )
inlinestatic
local purgeSharedTextureCache ( )
inlinestatic
static void reloadAllTextures ( )
static

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

var reloadAllTextures ( )
static

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

local reloadAllTextures ( )
static

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

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

var 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

local 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

void removeTexture ( Texture2D texture)

Deletes a texture from the cache given a texture.

var removeTexture ( var  texture)

Deletes a texture from the cache given a texture.

local removeTexture ( local  texture)

Deletes a texture from the cache given a texture.

void removeTextureForKey ( const std::string &  key)

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

Since
v0.99.4
var removeTextureForKey ( var  key)

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

Since
v0.99.4
local removeTextureForKey ( local  key)

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

Since
v0.99.4
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
var 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
local 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
static CC_DEPRECATED_ATTRIBUTE
TextureCache*
sharedTextureCache
( )
inlinestatic
var sharedTextureCache ( )
inlinestatic
local sharedTextureCache ( )
inlinestatic
CC_DEPRECATED_ATTRIBUTE
Texture2D* textureForKey
( const char *  key) const
inline
var textureForKey ( var  key)
inline
local textureForKey ( local  key)
inline

Member Data Documentation

int _asyncRefCount
protected
var _asyncRefCount
protected
local _asyncRefCount
protected
std::queue<AsyncStruct*>
* _asyncStructQueue
protected
var _asyncStructQueue
protected
local _asyncStructQueue
protected
std::mutex _asyncStructQueueMutex
protected
var _asyncStructQueueMutex
protected
local _asyncStructQueueMutex
protected
std::mutex _imageInfoMutex
protected
var _imageInfoMutex
protected
local _imageInfoMutex
protected
std::queue<ImageInfo*>
* _imageInfoQueue
protected
var _imageInfoQueue
protected
local _imageInfoQueue
protected
std::thread* _loadingThread
protected
var _loadingThread
protected
local _loadingThread
protected
bool _needQuit
protected
var _needQuit
protected
local _needQuit
protected
TextureCache* _sharedTextureCache
staticprotected
var _sharedTextureCache
staticprotected
local _sharedTextureCache
staticprotected
std::condition_variable
_sleepCondition
protected
var _sleepCondition
protected
local _sleepCondition
protected
std::mutex _sleepMutex
protected
var _sleepMutex
protected
local _sleepMutex
protected
std::unordered_map<std::string,
Texture2D*> _textures
protected
var _textures
protected
local _textures
protected

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