cocos2d-x  2.2.3
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CCTextureAtlas Class Reference

A class that implements a Texture Atlas. More...

#include <CCTextureAtlas.h>

Inheritance diagram for CCTextureAtlas:
CCObject CCCopying

Public Member Functions

virtual unsigned int getTotalQuads (void)
 getTotalQuads More...
 
virtual unsigned int getCapacity (void)
 getCapacity More...
 
virtual CCTexture2DgetTexture (void)
 getTexture More...
 
virtual void setTexture (CCTexture2D *var)
 setTexture More...
 
virtual ccV3F_C4B_T2F_QuadgetQuads (void)
 getQuads More...
 
virtual void setQuads (ccV3F_C4B_T2F_Quad *var)
 setQuads More...
 
 CCTextureAtlas ()
virtual ~CCTextureAtlas ()
const char * description ()
bool initWithFile (const char *file, unsigned int capacity)
 initializes a TextureAtlas with a filename and with a certain capacity for Quads. More...
 
bool initWithTexture (CCTexture2D *texture, unsigned int capacity)
 initializes a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for Quads. More...
 
void updateQuad (ccV3F_C4B_T2F_Quad *quad, unsigned int index)
 updates a Quad (texture, vertex and color) at a certain index index must be between 0 and the atlas capacity - 1 More...
 
void insertQuad (ccV3F_C4B_T2F_Quad *quad, unsigned int index)
 
Inserts a Quad (texture, vertex and color) at a certain index

index must be between 0 and the atlas capacity - 1 More...

 
void insertQuads (ccV3F_C4B_T2F_Quad *quads, unsigned int index, unsigned int amount)
 Inserts a c array of quads at a given index index must be between 0 and the atlas capacity - 1 this method doesn't enlarge the array when amount + index > totalQuads. More...
 
void insertQuadFromIndex (unsigned int fromIndex, unsigned int newIndex)
 
Removes the quad that is located at a certain index and inserts it at a new index

This operation is faster than removing and inserting in a quad in 2 different steps More...

 
void removeQuadAtIndex (unsigned int index)
 removes a quad at a given index number. More...
 
void removeQuadsAtIndex (unsigned int index, unsigned int amount)
 removes a amount of quads starting from index More...
 
void removeAllQuads ()
 removes all Quads. More...
 
bool resizeCapacity (unsigned int n)
 resize the capacity of the CCTextureAtlas. More...
 
void increaseTotalQuadsWith (unsigned int amount)
 Used internally by CCParticleBatchNode don't use this unless you know what you're doing. More...
 
void moveQuadsFromIndex (unsigned int oldIndex, unsigned int amount, unsigned int newIndex)
 Moves an amount of quads from oldIndex at newIndex. More...
 
void moveQuadsFromIndex (unsigned int index, unsigned int newIndex)
 Moves quads from index till totalQuads to the newIndex Used internally by CCParticleBatchNode This method doesn't enlarge the array if newIndex + quads to be moved > capacity. More...
 
void fillWithEmptyQuadsFromIndex (unsigned int index, unsigned int amount)
 Ensures that after a realloc quads are still empty Used internally by CCParticleBatchNode. More...
 
void drawNumberOfQuads (unsigned int n)
 draws n quads n can't be greater than the capacity of the Atlas More...
 
void drawNumberOfQuads (unsigned int n, unsigned int start)
 draws n quads from an index (offset). More...
 
void drawQuads ()
 draws all the Atlas's Quads More...
 
void listenBackToForeground (CCObject *obj)
 listen the event that coming to foreground on Android More...
 
bool isDirty (void)
 whether or not the array buffer of the VBO needs to be updated More...
 
void setDirty (bool bDirty)
 specify if the array buffer of the VBO needs to be updated More...
 
- Public Member Functions inherited from CCObject
 CCObject (void)
virtual ~CCObject (void)
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)
- Public Member Functions inherited from CCCopying
virtual CCObjectcopyWithZone (CCZone *pZone)

Static Public Member Functions

static CCTextureAtlascreate (const char *file, unsigned int capacity)
 creates a TextureAtlas with an filename and with an initial capacity for Quads. More...
 
static CCTextureAtlascreateWithTexture (CCTexture2D *texture, unsigned int capacity)
 creates a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for n Quads. More...
 

Protected Attributes

GLushort * m_pIndices
GLuint m_pBuffersVBO [2]
bool m_bDirty
unsigned int m_uTotalQuads
 quantity of quads that are going to be drawn More...
 
unsigned int m_uCapacity
 quantity of quads that can be stored with the current texture atlas size More...
 
CCTexture2Dm_pTexture
 Texture of the texture atlas. More...
 
ccV3F_C4B_T2F_Quadm_pQuads
 Quads that are going to be rendered. More...
 
- Protected Attributes inherited from CCObject
unsigned int m_uReference
unsigned int m_uAutoReleaseCount

Additional Inherited Members

- Public Attributes inherited from CCObject
unsigned int m_uID
int m_nLuaID

Detailed Description

A class that implements a Texture Atlas.

Supported features: The atlas file can be a PVRTC, PNG or any other format supported by Texture2D Quads can be updated in runtime Quads can be added in runtime Quads can be removed in runtime Quads can be re-ordered in runtime The TextureAtlas capacity can be increased or decreased in runtime OpenGL component: V3F, C4B, T2F. The quads are rendered using an OpenGL ES VBO. To render the quads using an interleaved vertex array list, you should modify the ccConfig.h file

Constructor & Destructor Documentation

virtual ~CCTextureAtlas ( )
virtual

Member Function Documentation

static CCTextureAtlas* create ( const char *  file,
unsigned int  capacity 
)
static

creates a TextureAtlas with an filename and with an initial capacity for Quads.

The TextureAtlas capacity can be increased in runtime.

static CCTextureAtlas*
createWithTexture
( CCTexture2D texture,
unsigned int  capacity 
)
static

creates a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for n Quads.

The TextureAtlas capacity can be increased in runtime.

const char* description ( )
void drawNumberOfQuads ( unsigned int  n)

draws n quads n can't be greater than the capacity of the Atlas

void drawNumberOfQuads ( unsigned int  n,
unsigned int  start 
)

draws n quads from an index (offset).

n + start can't be greater than the capacity of the atlas

Since
v1.0
void drawQuads ( )

draws all the Atlas's Quads

void fillWithEmptyQuadsFromIndex ( unsigned int  index,
unsigned int  amount 
)

Ensures that after a realloc quads are still empty Used internally by CCParticleBatchNode.

Since
1.1
virtual unsigned int getCapacity ( void  )
virtual

getCapacity

virtual ccV3F_C4B_T2F_Quad*
getQuads
( void  )
virtual

getQuads

virtual CCTexture2D* getTexture ( void  )
virtual

getTexture

virtual unsigned int getTotalQuads ( void  )
virtual

getTotalQuads

void increaseTotalQuadsWith ( unsigned int  amount)

Used internally by CCParticleBatchNode don't use this unless you know what you're doing.

Since
1.1
bool initWithFile ( const char *  file,
unsigned int  capacity 
)

initializes a TextureAtlas with a filename and with a certain capacity for Quads.

The TextureAtlas capacity can be increased in runtime.

WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)

bool initWithTexture ( CCTexture2D texture,
unsigned int  capacity 
)

initializes a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for Quads.

The TextureAtlas capacity can be increased in runtime.

WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)

void insertQuad ( ccV3F_C4B_T2F_Quad quad,
unsigned int  index 
)

Inserts a Quad (texture, vertex and color) at a certain index

index must be between 0 and the atlas capacity - 1

Since
v0.8
void insertQuadFromIndex ( unsigned int  fromIndex,
unsigned int  newIndex 
)

Removes the quad that is located at a certain index and inserts it at a new index

This operation is faster than removing and inserting in a quad in 2 different steps

Since
v0.7.2
void insertQuads ( ccV3F_C4B_T2F_Quad quads,
unsigned int  index,
unsigned int  amount 
)

Inserts a c array of quads at a given index index must be between 0 and the atlas capacity - 1 this method doesn't enlarge the array when amount + index > totalQuads.

Since
v1.1
bool isDirty ( void  )
inline

whether or not the array buffer of the VBO needs to be updated

void listenBackToForeground ( CCObject obj)

listen the event that coming to foreground on Android

void moveQuadsFromIndex ( unsigned int  oldIndex,
unsigned int  amount,
unsigned int  newIndex 
)

Moves an amount of quads from oldIndex at newIndex.

Since
v1.1
void moveQuadsFromIndex ( unsigned int  index,
unsigned int  newIndex 
)

Moves quads from index till totalQuads to the newIndex Used internally by CCParticleBatchNode This method doesn't enlarge the array if newIndex + quads to be moved > capacity.

Since
1.1
void removeAllQuads ( )

removes all Quads.

The TextureAtlas capacity remains untouched. No memory is freed. The total number of quads to be drawn will be 0

Since
v0.7.2
void removeQuadAtIndex ( unsigned int  index)

removes a quad at a given index number.

The capacity remains the same, but the total number of quads to be drawn is reduced in 1

Since
v0.7.2
void removeQuadsAtIndex ( unsigned int  index,
unsigned int  amount 
)

removes a amount of quads starting from index

Since
1.1
bool resizeCapacity ( unsigned int  n)

resize the capacity of the CCTextureAtlas.

The new capacity can be lower or higher than the current one It returns YES if the resize was successful. If it fails to resize the capacity it will return NO with a new capacity of 0.

void setDirty ( bool  bDirty)
inline

specify if the array buffer of the VBO needs to be updated

virtual void setQuads ( ccV3F_C4B_T2F_Quad var)
virtual

setQuads

virtual void setTexture ( CCTexture2D var)
virtual

setTexture

void updateQuad ( ccV3F_C4B_T2F_Quad quad,
unsigned int  index 
)

updates a Quad (texture, vertex and color) at a certain index index must be between 0 and the atlas capacity - 1

Since
v0.8

Member Data Documentation

bool m_bDirty
protected
GLuint m_pBuffersVBO[2]
protected
GLushort* m_pIndices
protected
ccV3F_C4B_T2F_Quad* m_pQuads
protected

Quads that are going to be rendered.

CCTexture2D* m_pTexture
protected

Texture of the texture atlas.

unsigned int m_uCapacity
protected

quantity of quads that can be stored with the current texture atlas size

unsigned int m_uTotalQuads
protected

quantity of quads that are going to be drawn


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