#include <CCTexture2D.h>
Classes | |
struct | PixelFormatInfo |
Public Types | |
enum | PixelFormat { AUTO, BGRA8888, RGBA8888, RGB888, RGB565, A8, I8, AI88, RGBA4444, RGB5A1, PVRTC4, PVRTC4A, PVRTC2, PVRTC2A, ETC, S3TC_DXT1, S3TC_DXT3, S3TC_DXT5, ATC_RGB, ATC_EXPLICIT_ALPHA, ATC_INTERPOLATED_ALPHA, DEFAULT = AUTO, NONE = -1 } |
Possible texture pixel formats. More... | |
typedef std::map < Texture2D::PixelFormat, const PixelFormatInfo > | PixelFormatInfoMap |
Public Member Functions | |
Texture2D () | |
virtual | ~Texture2D () |
virtual std::string | getDescription () const |
Get texutre name, dimensions and coordinates message by a string. More... | |
void | releaseGLTexture () |
Release only the gl texture. More... | |
bool | initWithData (const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size &contentSize) |
Initializes with a texture2d with data. More... | |
bool | initWithMipmaps (MipmapInfo *mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh) |
Initializes with mipmaps. More... | |
bool | updateWithData (const void *data, int offsetX, int offsetY, int width, int height) |
Update with texture data. More... | |
void | drawAtPoint (const Vec2 &point) |
Drawing extensions to make it easy to draw basic quads using a Texture2D object. More... | |
void | drawInRect (const Rect &rect) |
Draws a texture inside a rect. More... | |
bool | initWithImage (Image *image) |
Extensions to make it easy to create a Texture2D object from an image file. More... | |
bool | initWithImage (Image *image, PixelFormat format) |
Initializes a texture from a UIImage object. More... | |
bool | initWithString (const char *text, const std::string &fontName, float fontSize, const Size &dimensions=Size(0, 0), TextHAlignment hAlignment=TextHAlignment::CENTER, TextVAlignment vAlignment=TextVAlignment::TOP) |
Initializes a texture from a string with dimensions, alignment, font name and font size. More... | |
bool | initWithString (const char *text, const FontDefinition &textDefinition) |
Initializes a texture from a string using a text definition. More... | |
void | setTexParameters (const TexParams &texParams) |
Sets the min filter, mag filter, wrap s and wrap t texture parameters. More... | |
void | setTexParameters (const TexParams *texParams) |
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 * | getStringForFormat () const |
Returns the pixel format. More... | |
const char * | stringForFormat () const |
unsigned int | getBitsPerPixelForFormat () const |
Returns the bits-per-pixel of the in-memory OpenGL texture. More... | |
unsigned int | bitsPerPixelForFormat () const |
unsigned int | getBitsPerPixelForFormat (Texture2D::PixelFormat format) const |
Helper functions that returns bits per pixels for a given format. More... | |
unsigned int | bitsPerPixelForFormat (Texture2D::PixelFormat format) const |
const Size & | getContentSizeInPixels () |
Get content size. More... | |
bool | hasPremultipliedAlpha () const |
Whether or not the texture has their Alpha premultiplied. More... | |
bool | hasMipmaps () const |
Whether or not the texture has mip maps. More... | |
Texture2D::PixelFormat | getPixelFormat () const |
Gets the pixel format of the texture. More... | |
int | getPixelsWide () const |
Gets the width of the texture in pixels. More... | |
int | getPixelsHigh () const |
Gets the height of the texture in pixels. More... | |
GLuint | getName () const |
Gets the texture name. More... | |
GLfloat | getMaxS () const |
Gets max S. More... | |
void | setMaxS (GLfloat maxS) |
Sets max S. More... | |
GLfloat | getMaxT () const |
Gets max T. More... | |
void | setMaxT (GLfloat maxT) |
Sets max T. More... | |
Size | getContentSize () const |
Get the texture content size. More... | |
void | setGLProgram (GLProgram *program) |
Set a shader program to the texture. More... | |
GLProgram * | getGLProgram () const |
Get a shader program from the texture. More... | |
![]() | |
void | retain () |
Retains the ownership. More... | |
void | release () |
Releases the ownership immediately. More... | |
Ref * | autorelease () |
Releases the ownership sometime soon automatically. More... | |
unsigned int | getReferenceCount () const |
Returns the Ref's current reference count. More... | |
virtual | ~Ref () |
Destructor. More... | |
Static Public Member Functions | |
static void | setDefaultAlphaPixelFormat (Texture2D::PixelFormat format) |
sets the default pixel format for UIImagescontains alpha channel. More... | |
static Texture2D::PixelFormat | getDefaultAlphaPixelFormat () |
Returns the alpha pixel format. More... | |
static Texture2D::PixelFormat | defaultAlphaPixelFormat () |
static void | PVRImagesHavePremultipliedAlpha (bool haveAlphaPremultiplied) |
Treats (or not) PVR files as if they have alpha premultiplied. More... | |
static const PixelFormatInfoMap & | getPixelFormatInfoMap () |
Get pixel info map, the key-value pairs is PixelFormat and PixelFormatInfo. More... | |
Protected Attributes | |
Texture2D::PixelFormat | _pixelFormat |
pixel format of the texture More... | |
int | _pixelsWide |
width in pixels More... | |
int | _pixelsHigh |
height in pixels More... | |
GLuint | _name |
texture name More... | |
GLfloat | _maxS |
texture max S More... | |
GLfloat | _maxT |
texture max T More... | |
Size | _contentSize |
content size More... | |
bool | _hasPremultipliedAlpha |
whether or not the texture has their Alpha premultiplied More... | |
bool | _hasMipmaps |
whether or not the texture has mip maps More... | |
GLProgram * | _shaderProgram |
shader program used by drawAtPoint and drawInRect More... | |
bool | _antialiasEnabled |
![]() | |
unsigned int | _referenceCount |
count of references More... | |
Static Protected Attributes | |
static const PixelFormatInfoMap | _pixelFormatInfoTables |
Additional Inherited Members | |
![]() | |
Ref () | |
Constructor. More... | |
Texture2D class.
This class allows to easily create OpenGL 2D textures from images, text or raw data. The created Texture2D object will always have power-of-two dimensions. Depending on how you create the Texture2D 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!
typedef std::map <Texture2D::PixelFormat, const PixelFormatInfo> PixelFormatInfoMap |
Texture2D | ( | ) |
|
virtual |
|
inline |
|
inline |
|
inlinestatic |
void drawAtPoint | ( | const Vec2 & | point | ) |
Drawing extensions to make it easy to draw basic quads using a Texture2D 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 Rect & | 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).
unsigned int getBitsPerPixelForFormat |
( | ) | const |
Returns the bits-per-pixel of the in-memory OpenGL texture.
unsigned int getBitsPerPixelForFormat |
( | Texture2D::PixelFormat | format | ) | const |
Helper functions that returns bits per pixels for a given format.
Size getContentSize | ( | ) | const |
Get the texture content size.
const Size& getContentSizeInPixels | ( | ) |
Get content size.
|
static |
Returns the alpha pixel format.
|
virtual |
Get texutre name, dimensions and coordinates message by a string.
GLProgram* getGLProgram | ( | ) | const |
Get a shader program from the texture.
GLfloat getMaxS | ( | ) | const |
Gets max S.
GLfloat getMaxT | ( | ) | const |
Gets max T.
GLuint getName | ( | ) | const |
Gets the texture name.
Texture2D::PixelFormat getPixelFormat |
( | ) | const |
Gets the pixel format of the texture.
|
static |
Get pixel info map, the key-value pairs is PixelFormat and PixelFormatInfo.
int getPixelsHigh | ( | ) | const |
Gets the height of the texture in pixels.
int getPixelsWide | ( | ) | const |
Gets the width of the texture in pixels.
const char* getStringForFormat | ( | ) | const |
Returns the pixel format.
bool hasMipmaps | ( | ) | const |
Whether or not the texture has mip maps.
bool hasPremultipliedAlpha | ( | ) | const |
Whether or not the texture has their Alpha premultiplied.
bool initWithData | ( | const void * | data, |
ssize_t | dataLen, | ||
Texture2D::PixelFormat | pixelFormat, | ||
int | pixelsWide, | ||
int | pixelsHigh, | ||
const Size & | contentSize | ||
) |
Initializes with a texture2d with data.
data | Specifies a pointer to the image data in memory. |
dataLen | The image data length. |
pixelFormat | The image pixelFormat. |
pixelsWide | The image width. |
pixelsHigh | The image height. |
contentSize | The image content size. |
bool initWithImage | ( | Image * | image | ) |
Extensions to make it easy to create a Texture2D object from an image file.
Initializes a texture from a UIImage object.
We will use the format you specified with setDefaultAlphaPixelFormat to convert the image for texture. NOTE: It will not convert the pvr image file.
image | An UIImage object. |
bool initWithImage | ( | Image * | image, |
PixelFormat | format | ||
) |
Initializes a texture from a UIImage object.
We will use the format you passed to the function to convert the image format to the texture format. If you pass PixelFormat::Automatic, we will auto detect the image render type and use that type for texture to render.
image | An UIImage object. |
format | Texture pixel formats. |
bool initWithMipmaps | ( | MipmapInfo * | mipmaps, |
int | mipmapsNum, | ||
Texture2D::PixelFormat | pixelFormat, | ||
int | pixelsWide, | ||
int | pixelsHigh | ||
) |
Initializes with mipmaps.
mipmaps | Specifies a pointer to the image data in memory. |
mipmapsNum | The mipmaps number. |
pixelFormat | The image pixelFormat. |
pixelsWide | The image width. |
pixelsHigh | The image height. |
bool initWithString | ( | const char * | text, |
const std::string & | fontName, | ||
float | fontSize, | ||
const Size & | dimensions = Size(0, 0) , |
||
TextHAlignment | hAlignment = TextHAlignment::CENTER , |
||
TextVAlignment | vAlignment = TextVAlignment::TOP |
||
) |
Initializes a texture from a string with dimensions, alignment, font name and font size.
text | A null terminated string. |
fontName | The font name. |
dimensions | The font dimension. |
hAlignment | The font horizontal text alignment type. |
vAlignment | The font vertical text alignment type. |
bool initWithString | ( | const char * | text, |
const FontDefinition & | textDefinition | ||
) |
Initializes a texture from a string using a text definition.
text | A null terminated string. |
textDefinition | A FontDefinition object contains font attributes. |
|
static |
Treats (or not) PVR files as if they have alpha premultiplied.
haveAlphaPremultiplied | 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.
deprecated, please use Image::setPVRImagesHavePremultipliedAlpha() instead.
void releaseGLTexture | ( | ) |
Release only the gl texture.
void setAliasTexParameters | ( | ) |
Sets alias texture parameters:
void setAntiAliasTexParameters | ( | ) |
Sets antialias texture parameters:
|
static |
sets the default pixel format for UIImagescontains alpha channel.
format | If the UIImage contains alpha channel, then the options are:
|
How does it work ?
This parameter is not valid for PVR / PVR.CCZ images.
void setGLProgram | ( | GLProgram * | program | ) |
Set a shader program to the texture.
It's used by drawAtPoint and drawInRect
void setMaxS | ( | GLfloat | maxS | ) |
Sets max S.
void setMaxT | ( | GLfloat | maxT | ) |
Sets max T.
void setTexParameters | ( | const TexParams & | 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}.
|
inline |
|
inline |
bool updateWithData | ( | const void * | data, |
int | offsetX, | ||
int | offsetY, | ||
int | width, | ||
int | height | ||
) |
Update with texture data.
data | Specifies a pointer to the image data in memory. |
offsetX | Specifies a texel offset in the x direction within the texture array. |
offsetY | Specifies a texel offset in the y direction within the texture array. |
width | Specifies the width of the texture subimage. |
height | Specifies the height of the texture subimage. |
|
protected |
|
protected |
content size
|
protected |
whether or not the texture has mip maps
|
protected |
whether or not the texture has their Alpha premultiplied
|
protected |
texture max S
|
protected |
texture max T
|
protected |
texture name
|
protected |
pixel format of the texture
|
staticprotected |
|
protected |
height in pixels
|
protected |
width in pixels
|
protected |
shader program used by drawAtPoint and drawInRect