2011-07-19 15:14:59 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2011 Jirka Fajfr for cocos2d-x
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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 __CCPVRTEXTURE_H__
|
|
|
|
#define __CCPVRTEXTURE_H__
|
|
|
|
|
2011-07-19 16:03:42 +08:00
|
|
|
#include "CCStdC.h"
|
2011-07-19 15:14:59 +08:00
|
|
|
#include "CCGL.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocoa/CCObject.h"
|
|
|
|
#include "cocoa/CCArray.h"
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup textures
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-07-19 15:14:59 +08:00
|
|
|
/**
|
2012-09-17 15:02:24 +08:00
|
|
|
@brief Structure which can tell where mipmap begins and how long is it
|
2011-07-19 15:14:59 +08:00
|
|
|
*/
|
|
|
|
struct CCPVRMipmap {
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned char *address;
|
|
|
|
unsigned int len;
|
2011-07-19 15:14:59 +08:00
|
|
|
};
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
typedef struct _ccPVRTexturePixelFormatInfo {
|
|
|
|
GLenum internalFormat;
|
|
|
|
GLenum format;
|
|
|
|
GLenum type;
|
|
|
|
uint32_t bpp;
|
|
|
|
bool compressed;
|
|
|
|
bool alpha;
|
|
|
|
CCTexture2DPixelFormat ccPixelFormat;
|
|
|
|
} ccPVRTexturePixelFormatInfo;
|
|
|
|
|
2011-07-19 15:14:59 +08:00
|
|
|
/**
|
2012-09-17 15:02:24 +08:00
|
|
|
@brief Determine how many mipmaps can we have.
|
2011-07-19 15:14:59 +08:00
|
|
|
Its same as define but it respects namespaces
|
|
|
|
*/
|
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_PVRMIPMAP_MAX = 16,
|
2011-07-19 15:14:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** CCTexturePVR
|
|
|
|
|
|
|
|
Object that loads PVR images.
|
|
|
|
|
|
|
|
Supported PVR formats:
|
|
|
|
- RGBA8888
|
|
|
|
- BGRA8888
|
|
|
|
- RGBA4444
|
|
|
|
- RGBA5551
|
|
|
|
- RGB565
|
|
|
|
- A8
|
|
|
|
- I8
|
|
|
|
- AI88
|
|
|
|
- PVRTC 4BPP
|
|
|
|
- PVRTC 2BPP
|
|
|
|
|
|
|
|
Limitations:
|
|
|
|
Pre-generated mipmaps, such as PVR textures with mipmap levels embedded in file,
|
|
|
|
are only supported if all individual sprites are of _square_ size.
|
|
|
|
To use mipmaps with non-square textures, instead call CCTexture2D#generateMipmap on the sheet texture itself
|
|
|
|
(and to save space, save the PVR sprite sheet without mip maps included).
|
|
|
|
*/
|
|
|
|
class CCTexturePVR : public CCObject
|
|
|
|
{
|
|
|
|
public:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCTexturePVR();
|
|
|
|
virtual ~CCTexturePVR();
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** initializes a CCTexturePVR with a path */
|
|
|
|
bool initWithContentsOfFile(const char* path);
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** creates and initializes a CCTexturePVR with a path */
|
2012-07-23 22:49:11 +08:00
|
|
|
static CCTexturePVR* create(const char* path);
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
// properties
|
|
|
|
|
2013-02-26 18:08:51 +08:00
|
|
|
/** texture id name */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline unsigned int getName() { return _name; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** texture width */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline unsigned int getWidth() { return _width; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** texture height */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline unsigned int getHeight() { return _height; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** whether or not the texture has alpha */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline bool hasAlpha() { return _hasAlpha; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** whether or not the texture has premultiplied alpha */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline bool hasPremultipliedAlpha() { return _hasPremultipliedAlpha; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** whether or not the texture should use hasPremultipliedAlpha instead of global default */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline bool isForcePremultipliedAlpha() { return _forcePremultipliedAlpha; }
|
2013-02-26 18:08:51 +08:00
|
|
|
/** how many mipmaps the texture has. 1 means one level (level 0 */
|
2013-06-15 14:03:30 +08:00
|
|
|
inline unsigned int getNumberOfMipmaps() { return _numberOfMipmaps; }
|
|
|
|
inline CCTexture2DPixelFormat getFormat() { return _format; }
|
|
|
|
inline bool isRetainName() { return _retainName; }
|
|
|
|
inline void setRetainName(bool retainName) { _retainName = retainName; }
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
private:
|
2012-11-14 18:05:15 +08:00
|
|
|
bool unpackPVRv2Data(unsigned char* data, unsigned int len);
|
|
|
|
bool unpackPVRv3Data(unsigned char* dataPointer, unsigned int dataLength);
|
2012-04-19 14:35:52 +08:00
|
|
|
bool createGLTexture();
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
struct CCPVRMipmap _asMipmaps[CC_PVRMIPMAP_MAX]; // pointer to mipmap images
|
|
|
|
unsigned int _numberOfMipmaps; // number of mipmap used
|
2012-06-12 12:02:15 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int _width, _height;
|
|
|
|
GLuint _name;
|
|
|
|
bool _hasAlpha;
|
|
|
|
bool _hasPremultipliedAlpha;
|
|
|
|
bool _forcePremultipliedAlpha;
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
// cocos2d integration
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _retainName;
|
|
|
|
CCTexture2DPixelFormat _format;
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
const ccPVRTexturePixelFormatInfo *_pixelFormatInfo;
|
2011-07-19 15:14:59 +08:00
|
|
|
};
|
2012-04-18 18:43:45 +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
|
2011-07-19 15:14:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
#endif //__CCPVRTEXTURE_H__
|