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

CCTexture2D class. More...

#include <CCTexture2D.h>

Inheritance diagram for CCTexture2D:
CCObject CCCopying

Public Member Functions

 CCTexture2D ()
virtual ~CCTexture2D ()
const char * description (void)
void releaseData (void *data)
 These functions are needed to create mutable textures. More...
 
void * keepData (void *data, unsigned int length)
bool initWithData (const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const CCSize &contentSize)
 Initializes with a texture2d with data. More...
 
void drawAtPoint (const CCPoint &point)
 Drawing extensions to make it easy to draw basic quads using a CCTexture2D object. More...
 
void drawInRect (const CCRect &rect)
 draws a texture inside a rect More...
 
bool initWithImage (CCImage *uiImage)
 Extensions to make it easy to create a CCTexture2D object from an image file. More...
 
bool initWithString (const char *text, const char *fontName, float fontSize, const CCSize &dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment)
 Initializes a texture from a string with dimensions, alignment, font name and font size. More...
 
bool initWithString (const char *text, const char *fontName, float fontSize)
 Initializes a texture from a string with font name and font size. More...
 
bool initWithString (const char *text, ccFontDefinition *textDefinition)
 Initializes a texture from a string using a text definition. More...
 
bool initWithPVRFile (const char *file)
 Initializes a texture from a PVR file. More...
 
bool initWithETCFile (const char *file)
 Initializes a texture from a ETC file. More...
 
void setTexParameters (ccTexParams *texParams)
 sets the min filter, mag filter, wrap s and wrap t texture parameters. More...
 
void setAntiAliasTexParameters ()
 sets antialias texture parameters: More...
 
void setAliasTexParameters ()
 sets alias texture parameters: More...
 
void generateMipmap ()
 Generates mipmap images for the texture. More...
 
const char * stringForFormat ()
 returns the pixel format. More...
 
unsigned int bitsPerPixelForFormat ()
 returns the bits-per-pixel of the in-memory OpenGL texture More...
 
unsigned int bitsPerPixelForFormat (CCTexture2DPixelFormat format)
 Helper functions that returns bits per pixels for a given format. More...
 
const CCSizegetContentSizeInPixels ()
 content size More...
 
bool hasPremultipliedAlpha ()
bool hasMipmaps ()
virtual CCTexture2DPixelFormat getPixelFormat (void)
 getPixelFormat More...
 
virtual unsigned int getPixelsWide (void)
 getPixelsWide More...
 
virtual unsigned int getPixelsHigh (void)
 getPixelsHigh More...
 
virtual GLuint getName (void)
 getName More...
 
virtual GLfloat getMaxS (void)
 getMaxS More...
 
virtual void setMaxS (GLfloat var)
 setMaxS More...
 
virtual GLfloat getMaxT (void)
 getMaxT More...
 
virtual void setMaxT (GLfloat var)
 setMaxT More...
 
virtual CCSize getContentSize (void)
 getContentSize More...
 
virtual CCGLProgramgetShaderProgram (void)
 getShaderProgram More...
 
virtual void setShaderProgram (CCGLProgram *var)
 setShaderProgram 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 void setDefaultAlphaPixelFormat (CCTexture2DPixelFormat format)
 sets the default pixel format for UIImagescontains alpha channel. More...
 
static CCTexture2DPixelFormat defaultAlphaPixelFormat ()
 returns the alpha pixel format More...
 
static void PVRImagesHavePremultipliedAlpha (bool haveAlphaPremultiplied)
 treats (or not) PVR files as if they have alpha premultiplied. More...
 

Public Attributes

bool m_bHasPremultipliedAlpha
 whether or not the texture has their Alpha premultiplied More...
 
bool m_bHasMipmaps
- Public Attributes inherited from CCObject
unsigned int m_uID
int m_nLuaID

Protected Attributes

CCTexture2DPixelFormat m_ePixelFormat
 pixel format of the texture More...
 
unsigned int m_uPixelsWide
 width in pixels More...
 
unsigned int m_uPixelsHigh
 height in pixels More...
 
GLuint m_uName
 texture name More...
 
GLfloat m_fMaxS
 texture max S More...
 
GLfloat m_fMaxT
 texture max T More...
 
CCSize m_tContentSize
 content size More...
 
CCGLProgramm_pShaderProgram
 shader program used by drawAtPoint and drawInRect More...
 
- Protected Attributes inherited from CCObject
unsigned int m_uReference
unsigned int m_uAutoReleaseCount

Detailed Description

CCTexture2D class.

This class allows to easily create OpenGL 2D textures from images, text or raw data. The created CCTexture2D object will always have power-of-two dimensions. Depending on how you create the CCTexture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. "contentSize" != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). Be aware that the content of the generated textures will be upside-down!

Constructor & Destructor Documentation

virtual ~CCTexture2D ( )
virtual

Member Function Documentation

unsigned int bitsPerPixelForFormat ( )

returns the bits-per-pixel of the in-memory OpenGL texture

Since
v1.0
unsigned int bitsPerPixelForFormat ( CCTexture2DPixelFormat  format)

Helper functions that returns bits per pixels for a given format.

Since
v2.0
static CCTexture2DPixelFormat
defaultAlphaPixelFormat
( )
static

returns the alpha pixel format

Since
v0.8
const char* description ( void  )
void drawAtPoint ( const CCPoint point)

Drawing extensions to make it easy to draw basic quads using a CCTexture2D object.

These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled.draws a texture at a given point

void drawInRect ( const CCRect rect)

draws a texture inside a rect

void generateMipmap ( )

Generates mipmap images for the texture.

It only works if the texture size is POT (power of 2).

Since
v0.99.0
virtual CCSize getContentSize ( void  )
virtual

getContentSize

const CCSize&
getContentSizeInPixels
( )

content size

virtual GLfloat getMaxS ( void  )
virtual

getMaxS

virtual GLfloat getMaxT ( void  )
virtual

getMaxT

virtual GLuint getName ( void  )
virtual

getName

virtual CCTexture2DPixelFormat
getPixelFormat
( void  )
virtual

getPixelFormat

virtual unsigned int getPixelsHigh ( void  )
virtual

getPixelsHigh

virtual unsigned int getPixelsWide ( void  )
virtual

getPixelsWide

virtual CCGLProgram*
getShaderProgram
( void  )
virtual

getShaderProgram

bool hasMipmaps ( )
bool hasPremultipliedAlpha ( )
bool initWithData ( const void *  data,
CCTexture2DPixelFormat  pixelFormat,
unsigned int  pixelsWide,
unsigned int  pixelsHigh,
const CCSize contentSize 
)

Initializes with a texture2d with data.

bool initWithETCFile ( const char *  file)

Initializes a texture from a ETC file.

bool initWithImage ( CCImage uiImage)

Extensions to make it easy to create a CCTexture2D object from an image file.

Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).Initializes a texture from a UIImage object

bool initWithPVRFile ( const char *  file)

Initializes a texture from a PVR file.

bool initWithString ( const char *  text,
const char *  fontName,
float  fontSize,
const CCSize dimensions,
CCTextAlignment  hAlignment,
CCVerticalTextAlignment  vAlignment 
)

Initializes a texture from a string with dimensions, alignment, font name and font size.

bool initWithString ( const char *  text,
const char *  fontName,
float  fontSize 
)

Initializes a texture from a string with font name and font size.

bool initWithString ( const char *  text,
ccFontDefinition textDefinition 
)

Initializes a texture from a string using a text definition.

void* keepData ( void *  data,
unsigned int  length 
)
static void
PVRImagesHavePremultipliedAlpha
( bool  haveAlphaPremultiplied)
static

treats (or not) PVR files as if they have alpha premultiplied.

Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is possible load them as if they have (or not) the alpha channel premultiplied.

By default it is disabled.

Since
v0.99.5
void releaseData ( void *  data)

These functions are needed to create mutable textures.

void setAliasTexParameters ( )

sets alias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_NEAREST
  • GL_TEXTURE_MAG_FILTER = GL_NEAREST
Warning
Calling this method could allocate additional texture memory.
Since
v0.8
void setAntiAliasTexParameters ( )

sets antialias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_LINEAR
  • GL_TEXTURE_MAG_FILTER = GL_LINEAR
Warning
Calling this method could allocate additional texture memory.
Since
v0.8
static void
setDefaultAlphaPixelFormat
( CCTexture2DPixelFormat  format)
static

sets the default pixel format for UIImagescontains alpha channel.

If the UIImage contains alpha channel, then the options are:

  • generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one)
  • generate 24-bit textures: kCCTexture2DPixelFormat_RGB888
  • generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444
  • generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1
  • generate 16-bit textures: kCCTexture2DPixelFormat_RGB565
  • generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color)

How does it work ?

  • If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture)
  • If the image is an RGB (without Alpha) then: If the default pixel format is RGBA8888 then a RGBA8888 (32-bit) will be used. Otherwise a RGB565 (16-bit texture) will be used.

This parameter is not valid for PVR / PVR.CCZ images.

Since
v0.8
virtual void setMaxS ( GLfloat  var)
virtual

setMaxS

virtual void setMaxT ( GLfloat  var)
virtual

setMaxT

virtual void setShaderProgram ( CCGLProgram var)
virtual

setShaderProgram

void setTexParameters ( ccTexParams texParams)

sets the min filter, mag filter, wrap s and wrap t texture parameters.

If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.

Warning
Calling this method could allocate additional texture memory.
Since
v0.8
when this functon bound to js,the input param are changed
js: var setTexParameters(var minFilter, var magFilter, var wrapS, var wrapT)
const char* stringForFormat ( )

returns the pixel format.

Since
v2.0

Member Data Documentation

bool m_bHasMipmaps
bool m_bHasPremultipliedAlpha

whether or not the texture has their Alpha premultiplied

CCTexture2DPixelFormat
m_ePixelFormat
protected

pixel format of the texture

GLfloat m_fMaxS
protected

texture max S

GLfloat m_fMaxT
protected

texture max T

CCGLProgram* m_pShaderProgram
protected

shader program used by drawAtPoint and drawInRect

CCSize m_tContentSize
protected

content size

GLuint m_uName
protected

texture name

unsigned int m_uPixelsHigh
protected

height in pixels

unsigned int m_uPixelsWide
protected

width in pixels


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