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

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

#include <CCTextureAtlas.h>

Inheritance diagram for TextureAtlas:
Ref

Public Member Functions

 TextureAtlas ()
 ctor More...
 
virtual ~TextureAtlas ()
 NA NA More...
 
bool initWithFile (const std::string &file, ssize_t capacity)
 initializes a TextureAtlas with a filename and with a certain capacity for Quads. More...
 
bool initWithTexture (Texture2D *texture, ssize_t capacity)
 initializes a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for Quads. More...
 
void updateQuad (V3F_C4B_T2F_Quad *quad, ssize_t 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 (V3F_C4B_T2F_Quad *quad, ssize_t 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 (V3F_C4B_T2F_Quad *quads, ssize_t index, ssize_t 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 (ssize_t fromIndex, ssize_t 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 (ssize_t index)
 removes a quad at a given index number. More...
 
void removeQuadsAtIndex (ssize_t index, ssize_t amount)
 removes a amount of quads starting from index More...
 
void removeAllQuads ()
 removes all Quads. More...
 
bool resizeCapacity (ssize_t capacity)
 resize the capacity of the TextureAtlas. More...
 
void increaseTotalQuadsWith (ssize_t amount)
 Used internally by ParticleBatchNode don't use this unless you know what you're doing. More...
 
void moveQuadsFromIndex (ssize_t oldIndex, ssize_t amount, ssize_t newIndex)
 Moves an amount of quads from oldIndex at newIndex. More...
 
void moveQuadsFromIndex (ssize_t index, ssize_t newIndex)
 Moves quads from index till totalQuads to the newIndex Used internally by ParticleBatchNode This method doesn't enlarge the array if newIndex + quads to be moved > capacity. More...
 
void fillWithEmptyQuadsFromIndex (ssize_t index, ssize_t amount)
 Ensures that after a realloc quads are still empty Used internally by ParticleBatchNode. More...
 
void drawNumberOfQuads (ssize_t n)
 draws n quads n can't be greater than the capacity of the Atlas More...
 
void drawNumberOfQuads (ssize_t numberOfQuads, ssize_t start)
 draws n quads from an index (offset). More...
 
void drawQuads ()
 draws all the Atlas's Quads More...
 
void listenRendererRecreated (EventCustom *event)
 listen the event that renderer was recreated 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...
 
virtual std::string getDescription () const
 NA NA More...
 
ssize_t getTotalQuads () const
 Gets the quantity of quads that are going to be drawn. More...
 
ssize_t getCapacity () const
 Gets the quantity of quads that can be stored with the current texture atlas size. More...
 
Texture2DgetTexture () const
 Gets the texture of the texture atlas. More...
 
void setTexture (Texture2D *texture)
 Sets the texture for the texture atlas. More...
 
V3F_C4B_T2F_QuadgetQuads ()
 Gets the quads that are going to be rendered. More...
 
void setQuads (V3F_C4B_T2F_Quad *quads)
 Sets the quads that are going to be rendered. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 NA NA More...
 

Static Public Member Functions

static TextureAtlascreate (const std::string &file, ssize_t capacity)
 creates a TextureAtlas with an filename and with an initial capacity for Quads. More...
 
static TextureAtlascreateWithTexture (Texture2D *texture, ssize_t capacity)
 creates a TextureAtlas with a previously initialized Texture2D object, and with an initial capacity for n Quads. More...
 

Protected Attributes

GLushort * _indices
 
GLuint _VAOname
 
GLuint _buffersVBO [2]
 
bool _dirty
 
ssize_t _totalQuads
 quantity of quads that are going to be drawn More...
 
ssize_t _capacity
 quantity of quads that can be stored with the current texture atlas size More...
 
Texture2D_texture
 Texture of the texture atlas. More...
 
V3F_C4B_T2F_Quad_quads
 Quads that are going to be rendered. More...
 
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Additional Inherited Members

- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

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

Warning
If you want to use TextureAtlas, you'd better setup GL status before it's rendered. Otherwise, the effect of TextureAtlas will be affected by the GL status of other nodes.

Constructor & Destructor Documentation

ctor

virtual ~TextureAtlas ( )
virtual

NA NA

Member Function Documentation

static TextureAtlas* create ( const std::string &  file,
ssize_t  capacity 
)
static

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

The TextureAtlas capacity can be increased in runtime.

static TextureAtlas* createWithTexture ( Texture2D texture,
ssize_t  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.

void drawNumberOfQuads ( ssize_t  n)

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

void drawNumberOfQuads ( ssize_t  numberOfQuads,
ssize_t  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 ( ssize_t  index,
ssize_t  amount 
)

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

Since
1.1
ssize_t getCapacity ( ) const

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

virtual std::string getDescription ( ) const
virtual

NA NA

V3F_C4B_T2F_Quad* getQuads ( )

Gets the quads that are going to be rendered.

Texture2D* getTexture ( ) const

Gets the texture of the texture atlas.

ssize_t getTotalQuads ( ) const

Gets the quantity of quads that are going to be drawn.

void increaseTotalQuadsWith ( ssize_t  amount)

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

Since
1.1
bool initWithFile ( const std::string &  file,
ssize_t  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 ( Texture2D texture,
ssize_t  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 ( V3F_C4B_T2F_Quad quad,
ssize_t  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 ( ssize_t  fromIndex,
ssize_t  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 ( V3F_C4B_T2F_Quad quads,
ssize_t  index,
ssize_t  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 listenRendererRecreated ( EventCustom event)

listen the event that renderer was recreated on Android

void moveQuadsFromIndex ( ssize_t  oldIndex,
ssize_t  amount,
ssize_t  newIndex 
)

Moves an amount of quads from oldIndex at newIndex.

Since
v1.1
void moveQuadsFromIndex ( ssize_t  index,
ssize_t  newIndex 
)

Moves quads from index till totalQuads to the newIndex Used internally by ParticleBatchNode 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 ( ssize_t  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 ( ssize_t  index,
ssize_t  amount 
)

removes a amount of quads starting from index

Since
1.1
bool resizeCapacity ( ssize_t  capacity)

resize the capacity of the TextureAtlas.

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

void setDirty ( bool  bDirty)
inline

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

void setQuads ( V3F_C4B_T2F_Quad quads)

Sets the quads that are going to be rendered.

void setTexture ( Texture2D texture)

Sets the texture for the texture atlas.

void updateQuad ( V3F_C4B_T2F_Quad quad,
ssize_t  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

GLuint _buffersVBO[2]
protected
ssize_t _capacity
protected

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

bool _dirty
protected
GLushort* _indices
protected
V3F_C4B_T2F_Quad* _quads
protected

Quads that are going to be rendered.

Texture2D* _texture
protected

Texture of the texture atlas.

ssize_t _totalQuads
protected

quantity of quads that are going to be drawn

GLuint _VAOname
protected

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