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

CCTexture2D class. More...

#include <CCTexture2D.h>

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

Public Member Functions

 CCTexture2D ()
 ctor More...
 
virtual ~CCTexture2D ()
 NA NA. More...
 
const char * description (void)
 NA NA. More...
 
void releaseData (void *data)
 These functions are needed to create mutable textures NA. More...
 
void * keepData (void *data, unsigned int length)
 NA. More...
 
bool initWithData (const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const CCSize &contentSize)
 Initializes with a texture2d with data NA NA. 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)
 
virtual unsigned int getPixelsWide (void)
 
virtual unsigned int getPixelsHigh (void)
 
virtual GLuint getName (void)
 
virtual GLfloat getMaxS (void)
 
virtual void setMaxS (GLfloat var)
 
virtual GLfloat getMaxT (void)
 
virtual void setMaxT (GLfloat var)
 
virtual CCSize getContentSize (void)
 
virtual CCGLProgramgetShaderProgram (void)
 
virtual void setShaderProgram (CCGLProgram *var)
 
- 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 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...
 
- Static Public Member Functions inherited from CCObject
static CCObjectcreateWithCoder (DS_Dictionary *)
 

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
 
int m_nTag
 
int m_eObjType
 
unsigned int m_uObjectIdxInArray
 

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

◆ CCTexture2D()

ctor

◆ ~CCTexture2D()

virtual ~CCTexture2D ( )
virtual

NA NA.

Member Function Documentation

◆ bitsPerPixelForFormat() [1/2]

unsigned int bitsPerPixelForFormat ( )

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

Since
v1.0

◆ bitsPerPixelForFormat() [2/2]

unsigned int bitsPerPixelForFormat ( CCTexture2DPixelFormat  format)

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

Since
v2.0

◆ defaultAlphaPixelFormat()

static CCTexture2DPixelFormat defaultAlphaPixelFormat ( )
static

returns the alpha pixel format

Since
v0.8 getDefaultAlphaPixelFormat

◆ description()

const char * description ( void  )

NA NA.

◆ drawAtPoint()

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

◆ drawInRect()

void drawInRect ( const CCRect rect)

draws a texture inside a rect

◆ generateMipmap()

void generateMipmap ( )

Generates mipmap images for the texture.

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

Since
v0.99.0

◆ getContentSize()

virtual CCSize getContentSize ( void  )
virtual

◆ getContentSizeInPixels()

const CCSize & getContentSizeInPixels ( )

content size

◆ getMaxS()

virtual GLfloat getMaxS ( void  )
virtual

◆ getMaxT()

virtual GLfloat getMaxT ( void  )
virtual

◆ getName()

virtual GLuint getName ( void  )
virtual

◆ getPixelFormat()

virtual CCTexture2DPixelFormat getPixelFormat ( void  )
virtual

◆ getPixelsHigh()

virtual unsigned int getPixelsHigh ( void  )
virtual

◆ getPixelsWide()

virtual unsigned int getPixelsWide ( void  )
virtual

◆ getShaderProgram()

virtual CCGLProgram * getShaderProgram ( void  )
virtual

◆ hasMipmaps()

bool hasMipmaps ( )

◆ hasPremultipliedAlpha()

bool hasPremultipliedAlpha ( )

◆ initWithData()

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

Initializes with a texture2d with data NA NA.

◆ initWithETCFile()

bool initWithETCFile ( const char *  file)

Initializes a texture from a ETC file.

◆ initWithImage()

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

◆ initWithPVRFile()

bool initWithPVRFile ( const char *  file)

Initializes a texture from a PVR file.

◆ initWithString() [1/3]

bool initWithString ( const char *  text,
ccFontDefinition textDefinition 
)

Initializes a texture from a string using a text definition.

◆ initWithString() [2/3]

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

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

◆ initWithString() [3/3]

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.

◆ keepData()

void * keepData ( void *  data,
unsigned int  length 
)

NA.

◆ PVRImagesHavePremultipliedAlpha()

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

◆ releaseData()

void releaseData ( void *  data)

These functions are needed to create mutable textures NA.

◆ setAliasTexParameters()

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

◆ setAntiAliasTexParameters()

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

◆ setDefaultAlphaPixelFormat()

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

◆ setMaxS()

virtual void setMaxS ( GLfloat  var)
virtual

◆ setMaxT()

virtual void setMaxT ( GLfloat  var)
virtual

◆ setShaderProgram()

virtual void setShaderProgram ( CCGLProgram var)
virtual

◆ setTexParameters()

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)
void setTexParameters(ccTexParams *texParams)
sets the min filter, mag filter, wrap s and wrap t texture parameters.

◆ stringForFormat()

const char * stringForFormat ( )

returns the pixel format.

Since
v2.0

Member Data Documentation

◆ m_bHasMipmaps

bool m_bHasMipmaps

◆ m_bHasPremultipliedAlpha

bool m_bHasPremultipliedAlpha

whether or not the texture has their Alpha premultiplied

◆ m_ePixelFormat

CCTexture2DPixelFormat m_ePixelFormat
protected

pixel format of the texture

◆ m_fMaxS

GLfloat m_fMaxS
protected

texture max S

◆ m_fMaxT

GLfloat m_fMaxT
protected

texture max T

◆ m_pShaderProgram

CCGLProgram* m_pShaderProgram
protected

shader program used by drawAtPoint and drawInRect

◆ m_tContentSize

CCSize m_tContentSize
protected

content size

◆ m_uName

GLuint m_uName
protected

texture name

◆ m_uPixelsHigh

unsigned int m_uPixelsHigh
protected

height in pixels

◆ m_uPixelsWide

unsigned int m_uPixelsWide
protected

width in pixels


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