2011-07-19 15:14:59 +08:00
|
|
|
/****************************************************************************
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2011 Jirka Fajfr for cocos2d-x
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-19 15:14:59 +08:00
|
|
|
Copyright (c) 2008 Apple Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCTexture2D.h"
|
|
|
|
#include "CCTexturePVR.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCConfiguration.h"
|
|
|
|
#include "support/ccUtils.h"
|
|
|
|
#include "CCStdC.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2011-07-19 15:14:59 +08:00
|
|
|
#include "support/zip_support/ZipUtils.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "shaders/ccGLStateCache.h"
|
2012-08-18 05:45:21 +08:00
|
|
|
#include <ctype.h>
|
2011-07-19 15:14:59 +08:00
|
|
|
#include <cctype>
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
//
|
|
|
|
// XXX DO NO ALTER THE ORDER IN THIS LIST XXX
|
|
|
|
//
|
|
|
|
static const ccPVRTexturePixelFormatInfo PVRTableFormats[] = {
|
|
|
|
|
|
|
|
// 0: BGRA_8888
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true, kTexture2DPixelFormat_RGBA8888},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 1: RGBA_8888
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true, kTexture2DPixelFormat_RGBA8888},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 2: RGBA_4444
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true, kTexture2DPixelFormat_RGBA4444},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 3: RGBA_5551
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true, kTexture2DPixelFormat_RGB5A1},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 4: RGB_565
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, false, false, kTexture2DPixelFormat_RGB565},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 5: RGB_888
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 24, false, false, kTexture2DPixelFormat_RGB888},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 6: A_8
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 8, false, false, kTexture2DPixelFormat_A8},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 7: L_8
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, false, false, kTexture2DPixelFormat_I8},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 8: LA_88
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 16, false, true, kTexture2DPixelFormat_AI88},
|
2013-03-21 15:50:41 +08:00
|
|
|
|
2013-03-22 03:14:13 +08:00
|
|
|
// Not all platforms include GLES/gl2ext.h so these PVRTC enums are not always
|
|
|
|
// available.
|
|
|
|
#ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
|
2012-11-14 18:05:15 +08:00
|
|
|
// 9: PVRTC 2BPP RGB
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false, kTexture2DPixelFormat_PVRTC2},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 10: PVRTC 2BPP RGBA
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, true, kTexture2DPixelFormat_PVRTC2},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 11: PVRTC 4BPP RGB
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false, kTexture2DPixelFormat_PVRTC4},
|
2012-11-14 18:05:15 +08:00
|
|
|
// 12: PVRTC 4BPP RGBA
|
2013-06-20 14:13:12 +08:00
|
|
|
{GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true, kTexture2DPixelFormat_PVRTC4},
|
2013-03-22 03:14:13 +08:00
|
|
|
#endif
|
2012-11-14 18:05:15 +08:00
|
|
|
};
|
|
|
|
|
2013-02-26 18:08:51 +08:00
|
|
|
struct _pixel_formathash {
|
2012-11-14 18:05:15 +08:00
|
|
|
uint64_t pixelFormat;
|
|
|
|
const ccPVRTexturePixelFormatInfo * pixelFormatInfo;
|
|
|
|
};
|
|
|
|
|
2011-07-19 15:14:59 +08:00
|
|
|
// Values taken from PVRTexture.h from http://www.imgtec.com
|
|
|
|
enum {
|
2013-02-26 18:08:51 +08:00
|
|
|
kPVR2TextureFlagMipmap = (1<<8), // has mip map levels
|
|
|
|
kPVR2TextureFlagTwiddle = (1<<9), // is twiddled
|
|
|
|
kPVR2TextureFlagBumpmap = (1<<10), // has normals encoded for a bump map
|
|
|
|
kPVR2TextureFlagTiling = (1<<11), // is bordered for tiled pvr
|
|
|
|
kPVR2TextureFlagCubemap = (1<<12), // is a cubemap/skybox
|
|
|
|
kPVR2TextureFlagFalseMipCol = (1<<13), // are there false colored MIP levels
|
|
|
|
kPVR2TextureFlagVolume = (1<<14), // is this a volume texture
|
|
|
|
kPVR2TextureFlagAlpha = (1<<15), // v2.1 is there transparency info in the texture
|
|
|
|
kPVR2TextureFlagVerticalFlip = (1<<16), // v2.1 is the texture vertically flipped
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kPVR3TextureFlagPremultipliedAlpha = (1<<1) // has premultiplied alpha
|
2011-07-19 15:14:59 +08:00
|
|
|
};
|
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
static char gPVRTexIdentifier[5] = "PVR!";
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// v2
|
|
|
|
typedef enum
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2012-11-14 18:05:15 +08:00
|
|
|
kPVR2TexturePixelFormat_RGBA_4444= 0x10,
|
|
|
|
kPVR2TexturePixelFormat_RGBA_5551,
|
|
|
|
kPVR2TexturePixelFormat_RGBA_8888,
|
|
|
|
kPVR2TexturePixelFormat_RGB_565,
|
|
|
|
kPVR2TexturePixelFormat_RGB_555, // unsupported
|
|
|
|
kPVR2TexturePixelFormat_RGB_888,
|
|
|
|
kPVR2TexturePixelFormat_I_8,
|
|
|
|
kPVR2TexturePixelFormat_AI_88,
|
|
|
|
kPVR2TexturePixelFormat_PVRTC_2BPP_RGBA,
|
|
|
|
kPVR2TexturePixelFormat_PVRTC_4BPP_RGBA,
|
|
|
|
kPVR2TexturePixelFormat_BGRA_8888,
|
|
|
|
kPVR2TexturePixelFormat_A_8,
|
|
|
|
} ccPVR2TexturePixelFormat;
|
|
|
|
|
|
|
|
// v3
|
2012-12-10 10:22:06 +08:00
|
|
|
/* supported predefined formats */
|
|
|
|
#define kPVR3TexturePixelFormat_PVRTC_2BPP_RGB 0
|
|
|
|
#define kPVR3TexturePixelFormat_PVRTC_2BPP_RGBA 1
|
|
|
|
#define kPVR3TexturePixelFormat_PVRTC_4BPP_RGB 2
|
|
|
|
#define kPVR3TexturePixelFormat_PVRTC_4BPP_RGBA 3
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2012-12-10 10:22:06 +08:00
|
|
|
/* supported channel type formats */
|
|
|
|
#define kPVR3TexturePixelFormat_BGRA_8888 0x0808080861726762ULL
|
|
|
|
#define kPVR3TexturePixelFormat_RGBA_8888 0x0808080861626772ULL
|
|
|
|
#define kPVR3TexturePixelFormat_RGBA_4444 0x0404040461626772ULL
|
|
|
|
#define kPVR3TexturePixelFormat_RGBA_5551 0x0105050561626772ULL
|
|
|
|
#define kPVR3TexturePixelFormat_RGB_565 0x0005060500626772ULL
|
|
|
|
#define kPVR3TexturePixelFormat_RGB_888 0x0008080800626772ULL
|
|
|
|
#define kPVR3TexturePixelFormat_A_8 0x0000000800000061ULL
|
|
|
|
#define kPVR3TexturePixelFormat_L_8 0x000000080000006cULL
|
|
|
|
#define kPVR3TexturePixelFormat_LA_88 0x000008080000616cULL
|
2012-11-14 18:05:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
// v2
|
2013-02-26 18:08:51 +08:00
|
|
|
static struct _pixel_formathash v2_pixel_formathash[] = {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
{ kPVR2TexturePixelFormat_BGRA_8888, &PVRTableFormats[0] },
|
|
|
|
{ kPVR2TexturePixelFormat_RGBA_8888, &PVRTableFormats[1] },
|
|
|
|
{ kPVR2TexturePixelFormat_RGBA_4444, &PVRTableFormats[2] },
|
|
|
|
{ kPVR2TexturePixelFormat_RGBA_5551, &PVRTableFormats[3] },
|
|
|
|
{ kPVR2TexturePixelFormat_RGB_565, &PVRTableFormats[4] },
|
|
|
|
{ kPVR2TexturePixelFormat_RGB_888, &PVRTableFormats[5] },
|
|
|
|
{ kPVR2TexturePixelFormat_A_8, &PVRTableFormats[6] },
|
|
|
|
{ kPVR2TexturePixelFormat_I_8, &PVRTableFormats[7] },
|
|
|
|
{ kPVR2TexturePixelFormat_AI_88, &PVRTableFormats[8] },
|
|
|
|
|
2013-03-22 03:14:13 +08:00
|
|
|
#ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
|
2012-11-14 18:05:15 +08:00
|
|
|
{ kPVR2TexturePixelFormat_PVRTC_2BPP_RGBA, &PVRTableFormats[10] },
|
|
|
|
{ kPVR2TexturePixelFormat_PVRTC_4BPP_RGBA, &PVRTableFormats[12] },
|
2013-03-22 03:14:13 +08:00
|
|
|
#endif
|
2011-07-19 15:14:59 +08:00
|
|
|
};
|
|
|
|
|
2013-02-26 18:08:51 +08:00
|
|
|
#define PVR2_MAX_TABLE_ELEMENTS (sizeof(v2_pixel_formathash) / sizeof(v2_pixel_formathash[0]))
|
2012-11-14 18:05:15 +08:00
|
|
|
|
|
|
|
// v3
|
2013-02-26 18:08:51 +08:00
|
|
|
struct _pixel_formathash v3_pixel_formathash[] = {
|
2012-11-14 18:05:15 +08:00
|
|
|
|
|
|
|
{kPVR3TexturePixelFormat_BGRA_8888, &PVRTableFormats[0] },
|
|
|
|
{kPVR3TexturePixelFormat_RGBA_8888, &PVRTableFormats[1] },
|
|
|
|
{kPVR3TexturePixelFormat_RGBA_4444, &PVRTableFormats[2] },
|
|
|
|
{kPVR3TexturePixelFormat_RGBA_5551, &PVRTableFormats[3] },
|
|
|
|
{kPVR3TexturePixelFormat_RGB_565, &PVRTableFormats[4] },
|
|
|
|
{kPVR3TexturePixelFormat_RGB_888, &PVRTableFormats[5] },
|
|
|
|
{kPVR3TexturePixelFormat_A_8, &PVRTableFormats[6] },
|
|
|
|
{kPVR3TexturePixelFormat_L_8, &PVRTableFormats[7] },
|
|
|
|
{kPVR3TexturePixelFormat_LA_88, &PVRTableFormats[8] },
|
|
|
|
|
2013-03-22 03:14:13 +08:00
|
|
|
#ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
|
2012-11-14 18:05:15 +08:00
|
|
|
{kPVR3TexturePixelFormat_PVRTC_2BPP_RGB, &PVRTableFormats[9] },
|
|
|
|
{kPVR3TexturePixelFormat_PVRTC_2BPP_RGBA, &PVRTableFormats[10] },
|
|
|
|
{kPVR3TexturePixelFormat_PVRTC_4BPP_RGB, &PVRTableFormats[11] },
|
|
|
|
{kPVR3TexturePixelFormat_PVRTC_4BPP_RGBA, &PVRTableFormats[12] },
|
2013-03-22 03:14:13 +08:00
|
|
|
#endif
|
2012-11-14 18:05:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-19 15:14:59 +08:00
|
|
|
//Tells How large is tableFormats
|
2013-02-26 18:08:51 +08:00
|
|
|
#define PVR3_MAX_TABLE_ELEMENTS (sizeof(v3_pixel_formathash) / sizeof(v3_pixel_formathash[0]))
|
2011-07-19 15:14:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct _PVRTexHeader
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int headerLength;
|
|
|
|
unsigned int height;
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int numMipmaps;
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int dataLength;
|
|
|
|
unsigned int bpp;
|
|
|
|
unsigned int bitmaskRed;
|
|
|
|
unsigned int bitmaskGreen;
|
|
|
|
unsigned int bitmaskBlue;
|
|
|
|
unsigned int bitmaskAlpha;
|
|
|
|
unsigned int pvrTag;
|
|
|
|
unsigned int numSurfs;
|
2012-11-14 18:05:15 +08:00
|
|
|
} ccPVRv2TexHeader;
|
|
|
|
|
2012-11-16 17:08:34 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma pack(push,1)
|
|
|
|
#endif
|
2012-11-14 18:05:15 +08:00
|
|
|
typedef struct {
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t flags;
|
|
|
|
uint64_t pixelFormat;
|
|
|
|
uint32_t colorSpace;
|
|
|
|
uint32_t channelType;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t depth;
|
|
|
|
uint32_t numberOfSurfaces;
|
|
|
|
uint32_t numberOfFaces;
|
|
|
|
uint32_t numberOfMipmaps;
|
|
|
|
uint32_t metadataLength;
|
2012-11-16 17:08:34 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
} ccPVRv3TexHeader;
|
|
|
|
#pragma pack(pop)
|
|
|
|
#else
|
|
|
|
} __attribute__((packed)) ccPVRv3TexHeader;
|
|
|
|
#endif
|
|
|
|
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TexturePVR::TexturePVR()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _numberOfMipmaps(0)
|
|
|
|
, _width(0)
|
|
|
|
, _height(0)
|
|
|
|
, _name(0)
|
|
|
|
, _hasAlpha(false)
|
|
|
|
, _hasPremultipliedAlpha(false)
|
|
|
|
, _forcePremultipliedAlpha(false)
|
|
|
|
, _retainName(false)
|
2013-06-20 14:13:12 +08:00
|
|
|
, _format(kTexture2DPixelFormat_Default)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _pixelFormatInfo(NULL)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TexturePVR::~TexturePVR()
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CCLOGINFO( "cocos2d: deallocing TexturePVR: %p", this );
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_name != 0 && ! _retainName)
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
ccGLDeleteTexture(_name);
|
2012-06-12 12:02:15 +08:00
|
|
|
}
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TexturePVR::unpackPVRv2Data(unsigned char* data, unsigned int len)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
bool success = false;
|
2012-11-14 18:05:15 +08:00
|
|
|
ccPVRv2TexHeader *header = NULL;
|
2011-07-19 15:14:59 +08:00
|
|
|
unsigned int flags, pvrTag;
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int dataLength = 0, dataOffset = 0, dataSize = 0;
|
|
|
|
unsigned int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
|
|
|
unsigned int width = 0, height = 0, bpp = 4;
|
|
|
|
unsigned char *bytes = NULL;
|
2011-07-19 15:14:59 +08:00
|
|
|
unsigned int formatFlags;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//Cast first sizeof(PVRTexHeader) bytes of data stream as PVRTexHeader
|
2012-11-14 18:05:15 +08:00
|
|
|
header = (ccPVRv2TexHeader *)data;
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//Make sure that tag is in correct formatting
|
|
|
|
pvrTag = CC_SWAP_INT32_LITTLE_TO_HOST(header->pvrTag);
|
|
|
|
|
2013-03-05 02:21:45 +08:00
|
|
|
if (gPVRTexIdentifier[0] != (char)(((pvrTag >> 0) & 0xff)) ||
|
|
|
|
gPVRTexIdentifier[1] != (char)(((pvrTag >> 8) & 0xff)) ||
|
|
|
|
gPVRTexIdentifier[2] != (char)(((pvrTag >> 16) & 0xff)) ||
|
|
|
|
gPVRTexIdentifier[3] != (char)(((pvrTag >> 24) & 0xff)))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Configuration *configuration = Configuration::sharedConfiguration();
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags);
|
|
|
|
formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK;
|
2013-02-26 18:08:51 +08:00
|
|
|
bool flipped = (flags & kPVR2TextureFlagVerticalFlip) ? true : false;
|
2012-06-12 12:02:15 +08:00
|
|
|
if (flipped)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
|
|
|
CCLOG("cocos2d: WARNING: Image is flipped. Regenerate it using PVRTexTool");
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
if (! configuration->supportsNPOT() &&
|
2011-07-19 15:14:59 +08:00
|
|
|
(header->width != ccNextPOT(header->width) || header->height != ccNextPOT(header->height)))
|
|
|
|
{
|
2012-09-17 15:02:24 +08:00
|
|
|
CCLOG("cocos2d: ERROR: Loading an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height);
|
2011-07-19 15:14:59 +08:00
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 15:50:41 +08:00
|
|
|
|
|
|
|
unsigned int pvr2TableElements = PVR2_MAX_TABLE_ELEMENTS;
|
2013-06-20 14:13:12 +08:00
|
|
|
if (! Configuration::sharedConfiguration()->supportsPVRTC())
|
2013-03-21 15:50:41 +08:00
|
|
|
{
|
|
|
|
pvr2TableElements = 9;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-03-21 15:50:41 +08:00
|
|
|
for (unsigned int i = 0; i < pvr2TableElements; i++)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
//Does image format in table fits to the one parsed from header?
|
2013-02-26 18:08:51 +08:00
|
|
|
if (v2_pixel_formathash[i].pixelFormat == formatFlags)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_pixelFormatInfo = v2_pixel_formathash[i].pixelFormatInfo;
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//Reset num of mipmaps
|
2013-06-15 14:03:30 +08:00
|
|
|
_numberOfMipmaps = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
//Get size of mipmap
|
2013-06-15 14:03:30 +08:00
|
|
|
_width = width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width);
|
|
|
|
_height = height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//Do we use alpha ?
|
|
|
|
if (CC_SWAP_INT32_LITTLE_TO_HOST(header->bitmaskAlpha))
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_hasAlpha = true;
|
2012-06-12 12:02:15 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
else
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_hasAlpha = false;
|
2012-06-12 12:02:15 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//Get ptr to where data starts..
|
|
|
|
dataLength = CC_SWAP_INT32_LITTLE_TO_HOST(header->dataLength);
|
|
|
|
|
|
|
|
//Move by size of header
|
2012-11-14 18:05:15 +08:00
|
|
|
bytes = ((unsigned char *)data) + sizeof(ccPVRv2TexHeader);
|
2013-06-15 14:03:30 +08:00
|
|
|
_format = _pixelFormatInfo->ccPixelFormat;
|
|
|
|
bpp = _pixelFormatInfo->bpp;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Calculate the data size for each texture level and respect the minimum number of blocks
|
|
|
|
while (dataOffset < dataLength)
|
|
|
|
{
|
|
|
|
switch (formatFlags) {
|
2012-11-14 18:05:15 +08:00
|
|
|
case kPVR2TexturePixelFormat_PVRTC_2BPP_RGBA:
|
2012-04-19 14:35:52 +08:00
|
|
|
blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
|
|
|
|
widthBlocks = width / 8;
|
|
|
|
heightBlocks = height / 4;
|
|
|
|
break;
|
2012-11-14 18:05:15 +08:00
|
|
|
case kPVR2TexturePixelFormat_PVRTC_4BPP_RGBA:
|
2012-04-19 14:35:52 +08:00
|
|
|
blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
|
|
|
|
widthBlocks = width / 4;
|
|
|
|
heightBlocks = height / 4;
|
|
|
|
break;
|
2012-11-14 18:05:15 +08:00
|
|
|
case kPVR2TexturePixelFormat_BGRA_8888:
|
2013-06-20 14:13:12 +08:00
|
|
|
if (Configuration::sharedConfiguration()->supportsBGRA8888() == false)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCLOG("cocos2d: TexturePVR. BGRA8888 not supported on this device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
blockSize = 1;
|
|
|
|
widthBlocks = width;
|
|
|
|
heightBlocks = height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp to minimum number of blocks
|
|
|
|
if (widthBlocks < 2)
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
widthBlocks = 2;
|
2012-06-12 12:02:15 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
if (heightBlocks < 2)
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
heightBlocks = 2;
|
2012-06-12 12:02:15 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
|
2012-08-22 15:51:25 +08:00
|
|
|
unsigned int packetLength = (dataLength - dataOffset);
|
2012-04-19 14:35:52 +08:00
|
|
|
packetLength = packetLength > dataSize ? dataSize : packetLength;
|
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
//Make record to the mipmaps array and increment counter
|
2013-06-15 14:03:30 +08:00
|
|
|
_asMipmaps[_numberOfMipmaps].address = bytes + dataOffset;
|
|
|
|
_asMipmaps[_numberOfMipmaps].len = packetLength;
|
|
|
|
_numberOfMipmaps++;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//Check that we didn't overflow
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert(_numberOfMipmaps < CC_PVRMIPMAP_MAX,
|
2012-09-17 15:02:24 +08:00
|
|
|
"TexturePVR: Maximum number of mipmaps reached. Increase the CC_PVRMIPMAP_MAX value");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
dataOffset += packetLength;
|
|
|
|
|
|
|
|
//Update width and height to the next lower power of two
|
|
|
|
width = MAX(width >> 1, 1);
|
|
|
|
height = MAX(height >> 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Mark pass as success
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
if (! success)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
CCLOG("cocos2d: WARNING: Unsupported PVR Pixel Format: 0x%2x. Re-encode it with a OpenGL pixel format variant", formatFlags);
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return success;
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TexturePVR::unpackPVRv3Data(unsigned char* dataPointer, unsigned int dataLength)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
|
|
|
if (dataLength < sizeof(ccPVRv3TexHeader))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccPVRv3TexHeader *header = (ccPVRv3TexHeader *)dataPointer;
|
|
|
|
|
|
|
|
// validate version
|
|
|
|
if (CC_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: WARNING: pvr file version mismatch");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse pixel format
|
|
|
|
uint64_t pixelFormat = header->pixelFormat;
|
|
|
|
|
|
|
|
|
|
|
|
bool infoValid = false;
|
2013-03-21 15:50:41 +08:00
|
|
|
|
2013-04-08 11:56:04 +08:00
|
|
|
unsigned int pvr3TableElements = PVR3_MAX_TABLE_ELEMENTS;
|
2013-06-20 14:13:12 +08:00
|
|
|
if (! Configuration::sharedConfiguration()->supportsPVRTC())
|
2013-03-21 15:50:41 +08:00
|
|
|
{
|
|
|
|
pvr3TableElements = 9;
|
|
|
|
}
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2013-04-08 13:51:24 +08:00
|
|
|
for(unsigned int i = 0; i < pvr3TableElements; i++)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2013-02-26 18:08:51 +08:00
|
|
|
if( v3_pixel_formathash[i].pixelFormat == pixelFormat )
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_pixelFormatInfo = v3_pixel_formathash[i].pixelFormatInfo;
|
2013-06-18 22:16:17 +08:00
|
|
|
_format = _pixelFormatInfo->ccPixelFormat;
|
2013-06-15 14:03:30 +08:00
|
|
|
_hasAlpha = _pixelFormatInfo->alpha;
|
2012-11-14 18:05:15 +08:00
|
|
|
infoValid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unsupported / bad pixel format
|
|
|
|
if (! infoValid)
|
|
|
|
{
|
2013-05-09 20:17:45 +08:00
|
|
|
CCLOG("cocos2d: WARNING: unsupported pvr pixelformat: %lx", (unsigned long)pixelFormat );
|
2012-11-14 18:05:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-26 18:08:51 +08:00
|
|
|
// flags
|
|
|
|
uint32_t flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags);
|
|
|
|
|
|
|
|
// PVRv3 specifies premultiply alpha in a flag -- should always respect this in PVRv3 files
|
2013-06-15 14:03:30 +08:00
|
|
|
_forcePremultipliedAlpha = true;
|
2013-02-26 18:08:51 +08:00
|
|
|
if (flags & kPVR3TextureFlagPremultipliedAlpha)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_hasPremultipliedAlpha = true;
|
2013-02-26 18:08:51 +08:00
|
|
|
}
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// sizing
|
|
|
|
uint32_t width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width);
|
|
|
|
uint32_t height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height);
|
2013-06-15 14:03:30 +08:00
|
|
|
_width = width;
|
|
|
|
_height = height;
|
2012-11-14 18:05:15 +08:00
|
|
|
uint32_t dataOffset = 0, dataSize = 0;
|
|
|
|
uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0;
|
|
|
|
uint8_t *bytes = NULL;
|
|
|
|
|
|
|
|
dataOffset = (sizeof(ccPVRv3TexHeader) + header->metadataLength);
|
|
|
|
bytes = dataPointer;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_numberOfMipmaps = header->numberOfMipmaps;
|
|
|
|
CCAssert(_numberOfMipmaps < CC_PVRMIPMAP_MAX, "TexturePVR: Maximum number of mimpaps reached. Increate the CC_PVRMIPMAP_MAX value");
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
for (unsigned int i = 0; i < _numberOfMipmaps; i++)
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
|
|
|
switch (pixelFormat)
|
|
|
|
{
|
|
|
|
case kPVR3TexturePixelFormat_PVRTC_2BPP_RGB :
|
|
|
|
case kPVR3TexturePixelFormat_PVRTC_2BPP_RGBA :
|
|
|
|
blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
|
|
|
|
widthBlocks = width / 8;
|
|
|
|
heightBlocks = height / 4;
|
|
|
|
break;
|
|
|
|
case kPVR3TexturePixelFormat_PVRTC_4BPP_RGB :
|
|
|
|
case kPVR3TexturePixelFormat_PVRTC_4BPP_RGBA :
|
|
|
|
blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
|
|
|
|
widthBlocks = width / 4;
|
|
|
|
heightBlocks = height / 4;
|
|
|
|
break;
|
|
|
|
case kPVR3TexturePixelFormat_BGRA_8888:
|
2013-06-20 14:13:12 +08:00
|
|
|
if( ! Configuration::sharedConfiguration()->supportsBGRA8888())
|
2012-11-14 18:05:15 +08:00
|
|
|
{
|
|
|
|
CCLOG("cocos2d: TexturePVR. BGRA8888 not supported on this device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
blockSize = 1;
|
|
|
|
widthBlocks = width;
|
|
|
|
heightBlocks = height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp to minimum number of blocks
|
|
|
|
if (widthBlocks < 2)
|
|
|
|
{
|
|
|
|
widthBlocks = 2;
|
|
|
|
}
|
|
|
|
if (heightBlocks < 2)
|
|
|
|
{
|
|
|
|
heightBlocks = 2;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
dataSize = widthBlocks * heightBlocks * ((blockSize * _pixelFormatInfo->bpp) / 8);
|
2012-11-14 18:05:15 +08:00
|
|
|
unsigned int packetLength = ((unsigned int)dataLength-dataOffset);
|
|
|
|
packetLength = packetLength > dataSize ? dataSize : packetLength;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_asMipmaps[i].address = bytes+dataOffset;
|
|
|
|
_asMipmaps[i].len = packetLength;
|
2012-11-14 18:05:15 +08:00
|
|
|
|
|
|
|
dataOffset += packetLength;
|
|
|
|
CCAssert(dataOffset <= dataLength, "CCTexurePVR: Invalid lenght");
|
|
|
|
|
|
|
|
|
|
|
|
width = MAX(width >> 1, 1);
|
|
|
|
height = MAX(height >> 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TexturePVR::createGLTexture()
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned int width = _width;
|
|
|
|
unsigned int height = _height;
|
2012-04-19 14:35:52 +08:00
|
|
|
GLenum err;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_numberOfMipmaps > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_name != 0)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
ccGLDeleteTexture(_name);
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
// From PVR sources: "PVR files are never row aligned."
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
glGenTextures(1, &_name);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _name);
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
// Default: Anti alias.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_numberOfMipmaps == 1)
|
2012-06-12 12:02:15 +08:00
|
|
|
{
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
|
|
|
}
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
CHECK_GL_ERROR_DEBUG(); // clean possible GL error
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
GLenum internalFormat = _pixelFormatInfo->internalFormat;
|
|
|
|
GLenum format = _pixelFormatInfo->format;
|
|
|
|
GLenum type = _pixelFormatInfo->type;
|
|
|
|
bool compressed = _pixelFormatInfo->compressed;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Generate textures with mipmaps
|
2013-06-15 14:03:30 +08:00
|
|
|
for (unsigned int i = 0; i < _numberOfMipmaps; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (compressed && ! Configuration::sharedConfiguration()->supportsPVRTC())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
CCLOG("cocos2d: WARNING: PVRTC images are not supported");
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
unsigned char *data = _asMipmaps[i].address;
|
|
|
|
GLsizei datalen = _asMipmaps[i].len;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
if (compressed)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
glCompressedTexImage2D(GL_TEXTURE_2D, i, internalFormat, width, height, 0, datalen, data);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-06-12 12:02:15 +08:00
|
|
|
else
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, i, internalFormat, width, height, 0, format, type, data);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
if (i > 0 && (width != height || ccNextPOT(width) != width ))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
CCLOG("cocos2d: TexturePVR. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%u != height=%u", i, width, height);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 12:02:15 +08:00
|
|
|
err = glGetError();
|
|
|
|
if (err != GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: TexturePVR: Error uploading compressed texture level: %u . glError: 0x%04X", i, err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = MAX(width >> 1, 1);
|
|
|
|
height = MAX(height >> 1, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TexturePVR::initWithContentsOfFile(const char* path)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
|
|
|
unsigned char* pvrdata = NULL;
|
|
|
|
int pvrlen = 0;
|
|
|
|
|
|
|
|
std::string lowerCase(path);
|
|
|
|
for (unsigned int i = 0; i < lowerCase.length(); ++i)
|
|
|
|
{
|
|
|
|
lowerCase[i] = tolower(lowerCase[i]);
|
|
|
|
}
|
|
|
|
|
2011-10-19 15:24:19 +08:00
|
|
|
if (lowerCase.find(".ccz") != std::string::npos)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
|
|
|
pvrlen = ZipUtils::ccInflateCCZFile(path, &pvrdata);
|
|
|
|
}
|
2011-10-19 15:24:19 +08:00
|
|
|
else if (lowerCase.find(".gz") != std::string::npos)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
|
|
|
pvrlen = ZipUtils::ccInflateGZipFile(path, &pvrdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
pvrdata = FileUtils::sharedFileUtils()->getFileData(path, "rb", (unsigned long *)(&pvrlen));
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pvrlen < 0)
|
|
|
|
{
|
|
|
|
this->release();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_numberOfMipmaps = 0;
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_name = 0;
|
|
|
|
_width = _height = 0;
|
|
|
|
_pixelFormatInfo = NULL;
|
|
|
|
_hasAlpha = false;
|
|
|
|
_forcePremultipliedAlpha = false;
|
|
|
|
_hasPremultipliedAlpha = false;
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_retainName = false; // cocos2d integration
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
if (! ((unpackPVRv2Data(pvrdata, pvrlen) || unpackPVRv3Data(pvrdata, pvrlen)) && createGLTexture()) )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-19 16:31:26 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(pvrdata);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->release();
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-06-19 16:31:26 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(pvrdata);
|
2011-07-19 15:14:59 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TexturePVR * TexturePVR::create(const char* path)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TexturePVR * pTexture = new TexturePVR();
|
2012-06-12 12:02:15 +08:00
|
|
|
if (pTexture)
|
2011-07-19 15:14:59 +08:00
|
|
|
{
|
2012-06-12 12:02:15 +08:00
|
|
|
if (pTexture->initWithContentsOfFile(path))
|
|
|
|
{
|
|
|
|
pTexture->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete pTexture;
|
|
|
|
pTexture = NULL;
|
|
|
|
}
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
2012-06-12 12:02:15 +08:00
|
|
|
|
|
|
|
return pTexture;
|
2011-07-19 15:14:59 +08:00
|
|
|
}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
|
|
|
|