2010-08-02 10:58:00 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2008 Apple Inc. All Rights Reserved.
|
2012-06-08 14:11:48 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCTEXTURE2D_H__
|
|
|
|
#define __CCTEXTURE2D_H__
|
|
|
|
|
|
|
|
#include <string>
|
2013-07-25 21:35:00 +08:00
|
|
|
#include <map>
|
2013-11-22 05:43:59 +08:00
|
|
|
#include <map>
|
2013-07-25 21:35:00 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
#include "CCRef.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGeometry.h"
|
2010-08-16 15:02:17 +08:00
|
|
|
#include "ccTypes.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGLBufferedNode.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Image;
|
2013-07-25 21:35:00 +08:00
|
|
|
typedef struct _MipmapInfo MipmapInfo;
|
2010-07-26 17:32:23 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup textures
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-07-15 18:15:00 +08:00
|
|
|
//CONSTANTS:
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class GLProgram;
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2010-07-15 18:15:00 +08:00
|
|
|
//CLASS INTERFACES:
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief Texture2D class.
|
2010-07-15 18:15:00 +08:00
|
|
|
* This class allows to easily create OpenGL 2D textures from images, text or raw data.
|
2013-08-01 15:53:52 +08:00
|
|
|
* The created Texture2D object will always have power-of-two dimensions.
|
2013-06-20 14:13:12 +08:00
|
|
|
* 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).
|
2010-07-15 18:15:00 +08:00
|
|
|
* Be aware that the content of the generated textures will be upside-down!
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL Texture2D : public Ref
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-06-20 14:13:12 +08:00
|
|
|
, public GLBufferedNode
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2010-07-15 18:15:00 +08:00
|
|
|
{
|
2013-07-16 03:43:22 +08:00
|
|
|
public:
|
2013-07-25 19:52:44 +08:00
|
|
|
/** @typedef Texture2D::PixelFormat
|
|
|
|
Possible texture pixel formats
|
|
|
|
*/
|
2013-07-26 04:36:19 +08:00
|
|
|
enum class PixelFormat
|
2013-07-25 19:52:44 +08:00
|
|
|
{
|
2013-07-27 22:06:30 +08:00
|
|
|
//! auto detect the type
|
|
|
|
AUTO,
|
|
|
|
//! 32-bit texture: BGRA8888
|
|
|
|
BGRA8888,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 32-bit texture: RGBA8888
|
2013-07-26 04:36:19 +08:00
|
|
|
RGBA8888,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 24-bit texture: RGBA888
|
2013-07-26 04:36:19 +08:00
|
|
|
RGB888,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 16-bit texture without Alpha channel
|
2013-07-26 04:36:19 +08:00
|
|
|
RGB565,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 8-bit textures used as masks
|
2013-07-26 04:36:19 +08:00
|
|
|
A8,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 8-bit intensity texture
|
2013-07-26 04:36:19 +08:00
|
|
|
I8,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 16-bit textures used as masks
|
2013-07-26 04:36:19 +08:00
|
|
|
AI88,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 16-bit textures: RGBA4444
|
2013-07-26 04:36:19 +08:00
|
|
|
RGBA4444,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 16-bit textures: RGB5A1
|
2013-07-26 04:36:19 +08:00
|
|
|
RGB5A1,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 4-bit PVRTC-compressed texture: PVRTC4
|
2013-07-27 22:06:30 +08:00
|
|
|
PVRTC4,
|
|
|
|
//! 4-bit PVRTC-compressed texture: PVRTC4 (has alpha channel)
|
|
|
|
PVRTC4A,
|
2013-07-25 19:52:44 +08:00
|
|
|
//! 2-bit PVRTC-compressed texture: PVRTC2
|
2013-07-27 22:06:30 +08:00
|
|
|
PVRTC2,
|
|
|
|
//! 2-bit PVRTC-compressed texture: PVRTC2 (has alpha channel)
|
|
|
|
PVRTC2A,
|
|
|
|
//! ETC-compressed texture: ETC
|
|
|
|
ETC,
|
2013-08-06 11:19:45 +08:00
|
|
|
//! S3TC-compressed texture: S3TC_Dxt1
|
2013-08-09 12:54:05 +08:00
|
|
|
S3TC_DXT1,
|
2013-08-06 11:19:45 +08:00
|
|
|
//! S3TC-compressed texture: S3TC_Dxt3
|
2013-08-09 12:54:05 +08:00
|
|
|
S3TC_DXT3,
|
2013-08-06 11:19:45 +08:00
|
|
|
//! S3TC-compressed texture: S3TC_Dxt5
|
2013-08-09 12:54:05 +08:00
|
|
|
S3TC_DXT5,
|
2013-08-16 11:02:44 +08:00
|
|
|
//! ATITC-compressed texture: ATC_RGB
|
|
|
|
ATC_RGB,
|
|
|
|
//! ATITC-compressed texture: ATC_EXPLICIT_ALPHA
|
|
|
|
ATC_EXPLICIT_ALPHA,
|
|
|
|
//! ATITC-compresed texture: ATC_INTERPOLATED_ALPHA
|
|
|
|
ATC_INTERPOLATED_ALPHA,
|
2013-07-27 22:06:30 +08:00
|
|
|
//! Default texture format: AUTO
|
|
|
|
DEFAULT = AUTO,
|
|
|
|
|
|
|
|
NONE = -1
|
2013-07-26 04:36:19 +08:00
|
|
|
};
|
2013-07-25 19:52:44 +08:00
|
|
|
|
2013-08-02 14:10:23 +08:00
|
|
|
|
|
|
|
struct PixelFormatInfo {
|
2013-09-07 10:02:24 +08:00
|
|
|
|
2013-11-05 08:31:36 +08:00
|
|
|
PixelFormatInfo(GLenum anInternalFormat, GLenum aFormat, GLenum aType, int aBpp, bool aCompressed, bool anAlpha)
|
|
|
|
: internalFormat(anInternalFormat)
|
|
|
|
, format(aFormat)
|
|
|
|
, type(aType)
|
|
|
|
, bpp(aBpp)
|
|
|
|
, compressed(aCompressed)
|
|
|
|
, alpha(anAlpha)
|
2013-09-07 10:02:24 +08:00
|
|
|
{}
|
|
|
|
|
2013-08-02 14:10:23 +08:00
|
|
|
GLenum internalFormat;
|
|
|
|
GLenum format;
|
|
|
|
GLenum type;
|
|
|
|
int bpp;
|
|
|
|
bool compressed;
|
|
|
|
bool alpha;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<Texture2D::PixelFormat, const PixelFormatInfo> PixelFormatInfoMap;
|
|
|
|
|
2013-08-01 15:53:52 +08:00
|
|
|
/**
|
|
|
|
Extension to set the Min / Mag filter
|
|
|
|
*/
|
|
|
|
typedef struct _TexParams {
|
|
|
|
GLuint minFilter;
|
|
|
|
GLuint magFilter;
|
|
|
|
GLuint wrapS;
|
|
|
|
GLuint wrapT;
|
|
|
|
}TexParams;
|
|
|
|
|
|
|
|
public:
|
2013-07-16 03:43:22 +08:00
|
|
|
/** sets the default pixel format for UIImagescontains alpha channel.
|
|
|
|
If the UIImage contains alpha channel, then the options are:
|
2013-07-26 04:36:19 +08:00
|
|
|
- generate 32-bit textures: Texture2D::PixelFormat::RGBA8888 (default one)
|
|
|
|
- generate 24-bit textures: Texture2D::PixelFormat::RGB888
|
|
|
|
- generate 16-bit textures: Texture2D::PixelFormat::RGBA4444
|
|
|
|
- generate 16-bit textures: Texture2D::PixelFormat::RGB5A1
|
|
|
|
- generate 16-bit textures: Texture2D::PixelFormat::RGB565
|
|
|
|
- generate 8-bit textures: Texture2D::PixelFormat::A8 (only use it if you use just 1 color)
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2013-07-25 19:52:44 +08:00
|
|
|
static void setDefaultAlphaPixelFormat(Texture2D::PixelFormat format);
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
/** returns the alpha pixel format
|
|
|
|
@since v0.8
|
|
|
|
*/
|
2013-07-25 19:52:44 +08:00
|
|
|
static Texture2D::PixelFormat getDefaultAlphaPixelFormat();
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static Texture2D::PixelFormat defaultAlphaPixelFormat() { return Texture2D::getDefaultAlphaPixelFormat(); };
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
|
|
|
static void PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied);
|
|
|
|
|
2010-07-15 18:15:00 +08:00
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Texture2D();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~Texture2D();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-13 06:38:12 +08:00
|
|
|
virtual std::string getDescription() const;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** These functions are needed to create mutable textures
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void releaseData(void *data);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void* keepData(void *data, unsigned int length);
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** Initializes with a texture2d with data
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
bool initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
/** Initializes with mipmaps */
|
2013-12-05 17:19:01 +08:00
|
|
|
bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-03-27 15:11:04 +08:00
|
|
|
/** Update with texture data*/
|
|
|
|
bool updateWithData(const void *data,int offsetX,int offsetY,int width,int height);
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
Drawing extensions to make it easy to draw basic quads using a Texture2D object.
|
2012-04-19 14:35:52 +08:00
|
|
|
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 */
|
2014-04-15 18:08:29 +08:00
|
|
|
void drawAtPoint(const Vector2& point);
|
2012-04-19 14:35:52 +08:00
|
|
|
/** draws a texture inside a rect */
|
2013-06-20 14:13:12 +08:00
|
|
|
void drawInRect(const Rect& rect);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
Extensions to make it easy to create a Texture2D object from an image file.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-07-19 15:37:54 +08:00
|
|
|
/**
|
|
|
|
Initializes a texture from a UIImage object.
|
2013-07-25 21:35:00 +08:00
|
|
|
We will use the format you specified with setDefaultAlphaPixelFormat to convert the image for texture.
|
|
|
|
NOTE: It will not convert the pvr image file.
|
2013-07-19 15:37:54 +08:00
|
|
|
*/
|
2013-08-02 14:10:23 +08:00
|
|
|
bool initWithImage(Image * image);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a texture from a UIImage object.
|
2013-07-27 22:06:30 +08:00
|
|
|
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.
|
2013-07-25 21:35:00 +08:00
|
|
|
**/
|
2013-08-02 14:10:23 +08:00
|
|
|
bool initWithImage(Image * image, PixelFormat format);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Initializes a texture from a string with dimensions, alignment, font name and font size */
|
2013-07-27 07:04:21 +08:00
|
|
|
bool initWithString(const char *text, const char *fontName, float fontSize, const Size& dimensions = Size(0, 0), TextHAlignment hAlignment = TextHAlignment::CENTER, TextVAlignment vAlignment = TextVAlignment::TOP);
|
2013-05-14 02:35:52 +08:00
|
|
|
/** Initializes a texture from a string using a text definition*/
|
2013-07-08 15:18:16 +08:00
|
|
|
bool initWithString(const char *text, const FontDefinition& textDefinition);
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** 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}.
|
2012-06-08 14:11:48 +08:00
|
|
|
|
|
|
|
@warning Calling this method could allocate additional texture memory.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.8
|
2013-09-13 11:41:20 +08:00
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the input parameter will be changed
|
|
|
|
* In js: var setBlendFunc(var arg1, var arg2, var arg3, var arg4)
|
|
|
|
* In lua: local setBlendFunc(local arg1, local arg2, local arg3, local arg4)
|
|
|
|
* @endcode
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-08-01 15:53:52 +08:00
|
|
|
void setTexParameters(const TexParams& texParams);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-08-01 15:53:52 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void setTexParameters(const TexParams* texParams) { return setTexParameters(*texParams); };
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** sets antialias texture parameters:
|
|
|
|
- GL_TEXTURE_MIN_FILTER = GL_LINEAR
|
|
|
|
- GL_TEXTURE_MAG_FILTER = GL_LINEAR
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
@warning Calling this method could allocate additional texture memory.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
void setAntiAliasTexParameters();
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** sets alias texture parameters:
|
|
|
|
- GL_TEXTURE_MIN_FILTER = GL_NEAREST
|
|
|
|
- GL_TEXTURE_MAG_FILTER = GL_NEAREST
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
@warning Calling this method could allocate additional texture memory.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
void setAliasTexParameters();
|
2010-07-15 18:15:00 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Generates mipmap images for the texture.
|
|
|
|
It only works if the texture size is POT (power of 2).
|
|
|
|
@since v0.99.0
|
|
|
|
*/
|
|
|
|
void generateMipmap();
|
2010-07-15 18:15:00 +08:00
|
|
|
|
2012-06-13 16:20:58 +08:00
|
|
|
/** returns the pixel format.
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-07-19 14:57:54 +08:00
|
|
|
const char* getStringForFormat() const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE const char* stringForFormat() const { return getStringForFormat(); };
|
2012-06-13 16:20:58 +08:00
|
|
|
|
2012-06-11 21:58:04 +08:00
|
|
|
/** returns the bits-per-pixel of the in-memory OpenGL texture
|
|
|
|
@since v1.0
|
|
|
|
*/
|
2013-07-19 14:57:54 +08:00
|
|
|
unsigned int getBitsPerPixelForFormat() const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE unsigned int bitsPerPixelForFormat() const { return getBitsPerPixelForFormat(); };
|
2012-06-13 16:20:58 +08:00
|
|
|
|
|
|
|
/** Helper functions that returns bits per pixels for a given format.
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-07-25 19:52:44 +08:00
|
|
|
unsigned int getBitsPerPixelForFormat(Texture2D::PixelFormat format) const;
|
|
|
|
CC_DEPRECATED_ATTRIBUTE unsigned int bitsPerPixelForFormat(Texture2D::PixelFormat format) const { return getBitsPerPixelForFormat(format); };
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** content size */
|
2013-06-20 14:13:12 +08:00
|
|
|
const Size& getContentSizeInPixels();
|
2013-07-04 08:44:41 +08:00
|
|
|
|
|
|
|
bool hasPremultipliedAlpha() const;
|
|
|
|
bool hasMipmaps() const;
|
2013-07-16 03:43:22 +08:00
|
|
|
|
2013-07-23 14:05:05 +08:00
|
|
|
/** Gets the pixel format of the texture */
|
2013-07-25 19:52:44 +08:00
|
|
|
Texture2D::PixelFormat getPixelFormat() const;
|
2013-07-23 14:05:05 +08:00
|
|
|
|
|
|
|
/** Gets the width of the texture in pixels */
|
2013-12-05 17:19:01 +08:00
|
|
|
int getPixelsWide() const;
|
2013-07-23 14:05:05 +08:00
|
|
|
|
|
|
|
/** Gets the height of the texture in pixels */
|
2013-12-05 17:19:01 +08:00
|
|
|
int getPixelsHigh() const;
|
2013-07-23 14:05:05 +08:00
|
|
|
|
|
|
|
/** Gets the texture name */
|
|
|
|
GLuint getName() const;
|
|
|
|
|
|
|
|
/** Gets max S */
|
|
|
|
GLfloat getMaxS() const;
|
|
|
|
/** Sets max S */
|
|
|
|
void setMaxS(GLfloat maxS);
|
|
|
|
|
|
|
|
/** Gets max T */
|
|
|
|
GLfloat getMaxT() const;
|
|
|
|
/** Sets max T */
|
|
|
|
void setMaxT(GLfloat maxT);
|
|
|
|
|
|
|
|
Size getContentSize() const;
|
|
|
|
|
|
|
|
void setShaderProgram(GLProgram* program);
|
|
|
|
GLProgram* getShaderProgram() const;
|
|
|
|
|
2013-08-02 14:10:23 +08:00
|
|
|
public:
|
2013-08-07 11:20:41 +08:00
|
|
|
static const PixelFormatInfoMap& getPixelFormatInfoMap();
|
2013-08-02 14:10:23 +08:00
|
|
|
|
2010-07-15 18:15:00 +08:00
|
|
|
private:
|
2013-07-17 17:12:04 +08:00
|
|
|
|
2013-07-19 15:37:54 +08:00
|
|
|
/**convert functions*/
|
|
|
|
|
|
|
|
/**
|
2013-07-27 22:06:30 +08:00
|
|
|
Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you.
|
2013-07-19 15:37:54 +08:00
|
|
|
It will return the converted format to you. if the outData != data, you must delete it manually.
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
static PixelFormat convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
static PixelFormat convertI8ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
|
|
|
static PixelFormat convertAI88ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
|
|
|
static PixelFormat convertRGB888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
|
|
|
static PixelFormat convertRGBA8888ToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat format, unsigned char** outData, ssize_t* outDataLen);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
//I8 to XXX
|
2013-12-05 17:19:01 +08:00
|
|
|
static void convertI8ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertI8ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertI8ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertI8ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertI8ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertI8ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
//AI88 to XXX
|
2013-12-05 17:19:01 +08:00
|
|
|
static void convertAI88ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertAI88ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
//RGB888 to XXX
|
2013-12-05 17:19:01 +08:00
|
|
|
static void convertRGB888ToRGBA8888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGB888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGB888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGB888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGB888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGB888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
2013-07-25 21:35:00 +08:00
|
|
|
|
|
|
|
//RGBA8888 to XXX
|
2013-12-05 17:19:01 +08:00
|
|
|
static void convertRGBA8888ToRGB888(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToRGB565(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToI8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToA8(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToAI88(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToRGBA4444(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
|
|
|
static void convertRGBA8888ToRGB5A1(const unsigned char* data, ssize_t dataLen, unsigned char* outData);
|
2013-07-19 15:37:54 +08:00
|
|
|
|
2013-07-23 20:42:43 +08:00
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
/** pixel format of the texture */
|
2013-07-25 19:52:44 +08:00
|
|
|
Texture2D::PixelFormat _pixelFormat;
|
2013-07-23 14:05:05 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** width in pixels */
|
2013-12-05 17:19:01 +08:00
|
|
|
int _pixelsWide;
|
2013-07-23 14:05:05 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
/** height in pixels */
|
2013-12-05 17:19:01 +08:00
|
|
|
int _pixelsHigh;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** texture name */
|
2013-07-23 14:05:05 +08:00
|
|
|
GLuint _name;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** texture max S */
|
2013-07-23 14:05:05 +08:00
|
|
|
GLfloat _maxS;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** texture max T */
|
2013-07-23 14:05:05 +08:00
|
|
|
GLfloat _maxT;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** content size */
|
2013-07-23 14:05:05 +08:00
|
|
|
Size _contentSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** whether or not the texture has their Alpha premultiplied */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _hasPremultipliedAlpha;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _hasMipmaps;
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** shader program used by drawAtPoint and drawInRect */
|
2013-07-23 14:05:05 +08:00
|
|
|
GLProgram* _shaderProgram;
|
2013-08-06 11:19:45 +08:00
|
|
|
|
2013-08-02 14:10:23 +08:00
|
|
|
static const PixelFormatInfoMap _pixelFormatInfoTables;
|
2014-03-27 15:35:51 +08:00
|
|
|
|
|
|
|
bool _antialiasEnabled;
|
2013-07-27 22:06:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of textures group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-08-02 10:58:00 +08:00
|
|
|
|
|
|
|
#endif //__CCTEXTURE2D_H__
|
|
|
|
|