From 949700ca1a8dcad798871c9ead41a17885708f85 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 21 Mar 2013 15:50:41 +0800 Subject: [PATCH] issue #1848:use CCConfiguration::supportsPVRTC() to determine if the device support powertc format --- cocos2dx/platform/CCPlatformConfig.h | 1 - cocos2dx/textures/CCTexture2D.cpp | 39 ----------------------- cocos2dx/textures/CCTexture2D.h | 9 ------ cocos2dx/textures/CCTextureCache.cpp | 39 ----------------------- cocos2dx/textures/CCTextureCache.h | 12 ------- cocos2dx/textures/CCTexturePVR.cpp | 24 ++++++++------ samples/Cpp/TestCpp/proj.android/.project | 10 ------ 7 files changed, 15 insertions(+), 119 deletions(-) diff --git a/cocos2dx/platform/CCPlatformConfig.h b/cocos2dx/platform/CCPlatformConfig.h index 110af8ab0b..342148b4d2 100644 --- a/cocos2dx/platform/CCPlatformConfig.h +++ b/cocos2dx/platform/CCPlatformConfig.h @@ -58,7 +58,6 @@ Config of cocos2d-x project, per target platform. #if defined(CC_TARGET_OS_IPHONE) #undef CC_TARGET_PLATFORM #define CC_TARGET_PLATFORM CC_PLATFORM_IOS - #define CC_SUPPORT_PVRTC #endif // android diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 3824f0710a..d51856987f 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -518,45 +518,6 @@ void CCTexture2D::drawInRect(const CCRect& rect) glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } -#ifdef CC_SUPPORT_PVRTC -// implementation CCTexture2D (PVRTC); -bool CCTexture2D::initWithPVRTCData(const void *data, int level, int bpp, bool hasAlpha, int length, CCTexture2DPixelFormat pixelFormat) -{ - if( !(CCConfiguration::sharedConfiguration()->supportsPVRTC()) ) - { - CCLOG("cocos2d: WARNING: PVRTC images is not supported."); - return false; - } - - glGenTextures(1, &m_uName); - glBindTexture(GL_TEXTURE_2D, m_uName); - - this->setAntiAliasTexParameters(); - - GLenum format; - GLsizei size = length * length * bpp / 8; - if(hasAlpha) { - format = (bpp == 4) ? GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - } else { - format = (bpp == 4) ? GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG : GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; - } - if(size < 32) { - size = 32; - } - glCompressedTexImage2D(GL_TEXTURE_2D, level, format, length, length, 0, size, data); - - m_tContentSize = CCSizeMake((float)(length), (float)(length)); - m_uPixelsWide = length; - m_uPixelsHigh = length; - m_fMaxS = 1.0f; - m_fMaxT = 1.0f; - m_bHasPremultipliedAlpha = PVRHaveAlphaPremultiplied_; - m_ePixelFormat = pixelFormat; - - return true; -} -#endif // CC_SUPPORT_PVRTC - bool CCTexture2D::initWithPVRFile(const char* file) { bool bRet = false; diff --git a/cocos2dx/textures/CCTexture2D.h b/cocos2dx/textures/CCTexture2D.h index 7a7a379ce4..3e224b0072 100644 --- a/cocos2dx/textures/CCTexture2D.h +++ b/cocos2dx/textures/CCTexture2D.h @@ -138,15 +138,6 @@ public: bool initWithString(const char *text, const char *fontName, float fontSize, const CCSize& dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment); /** Initializes a texture from a string with font name and font size */ bool initWithString(const char *text, const char *fontName, float fontSize); - -#ifdef CC_SUPPORT_PVRTC - /** - Extensions to make it easy to create a CCTexture2D object from a PVRTC file - Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). - */ - /** Initializes a texture from a PVRTC buffer */ - bool initWithPVRTCData(const void *data, int level, int bpp, bool hasAlpha, int length, CCTexture2DPixelFormat pixelFormat); -#endif // CC_SUPPORT_PVRTC /** Initializes a texture from a PVR file */ bool initWithPVRFile(const char* file); diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index a7684ca853..19599bb487 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -482,45 +482,6 @@ CCTexture2D * CCTextureCache::addImage(const char * path) return texture; } -#ifdef CC_SUPPORT_PVRTC -CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAlpha, int width) -{ - CCAssert(path != NULL, "TextureCache: fileimage MUST not be nil"); - CCAssert( bpp==2 || bpp==4, "TextureCache: bpp must be either 2 or 4"); - - CCTexture2D * texture; - - std::string temp(path); - - if ( (texture = (CCTexture2D*)m_pTextures->objectForKey(temp.c_str())) ) - { - return texture; - } - - // Split up directory and filename - std::string fullpath( CCFileUtils::sharedFileUtils()->fullPathForFilename(path) ); - - unsigned long nLen = 0; - unsigned char* pData = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), "rb", &nLen); - - texture = new CCTexture2D(); - - if( texture->initWithPVRTCData(pData, 0, bpp, hasAlpha, width, - (bpp==2 ? kCCTexture2DPixelFormat_PVRTC2 : kCCTexture2DPixelFormat_PVRTC4))) - { - m_pTextures->setObject(texture, temp.c_str()); - texture->autorelease(); - } - else - { - CCLOG("cocos2d: Couldn't add PVRTCImage:%s in CCTextureCache",path); - } - CC_SAFE_DELETE_ARRAY(pData); - - return texture; -} -#endif // CC_SUPPORT_PVRTC - CCTexture2D * CCTextureCache::addPVRImage(const char* path) { CCAssert(path != NULL, "TextureCache: fileimage MUST not be nil"); diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index 0db94e670e..51bcc84900 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -148,18 +148,6 @@ public: * @since v1.0 */ void dumpCachedTextureInfo(); - -#ifdef CC_SUPPORT_PVRTC - /** Returns a Texture2D object given an PVRTC RAW filename - * If the file image was not previously loaded, it will create a new CCTexture2D - * object and it will return it. Otherwise it will return a reference of a previously loaded image - * - * It can only load square images: width == height, and it must be a power of 2 (128,256,512...) - * bpp can only be 2 or 4. 2 means more compression but lower quality. - * hasAlpha: whether or not the image contains alpha channel - */ - CCTexture2D* addPVRTCImage(const char* fileimage, int bpp, bool hasAlpha, int width); -#endif // CC_SUPPORT_PVRTC /** Returns a Texture2D object given an PVR filename * If the file image was not previously loaded, it will create a new CCTexture2D diff --git a/cocos2dx/textures/CCTexturePVR.cpp b/cocos2dx/textures/CCTexturePVR.cpp index 1925d3fa9d..8f15b8984b 100644 --- a/cocos2dx/textures/CCTexturePVR.cpp +++ b/cocos2dx/textures/CCTexturePVR.cpp @@ -63,8 +63,7 @@ static const ccPVRTexturePixelFormatInfo PVRTableFormats[] = { {GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, false, false, kCCTexture2DPixelFormat_I8}, // 8: LA_88 {GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 16, false, true, kCCTexture2DPixelFormat_AI88}, - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // 9: PVRTC 2BPP RGB {GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false, kCCTexture2DPixelFormat_PVRTC2}, // 10: PVRTC 2BPP RGBA @@ -73,7 +72,6 @@ static const ccPVRTexturePixelFormatInfo PVRTableFormats[] = { {GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false, kCCTexture2DPixelFormat_PVRTC4}, // 12: PVRTC 4BPP RGBA {GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true, kCCTexture2DPixelFormat_PVRTC4}, -#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) }; struct _pixel_formathash { @@ -149,10 +147,8 @@ static struct _pixel_formathash v2_pixel_formathash[] = { { kPVR2TexturePixelFormat_I_8, &PVRTableFormats[7] }, { kPVR2TexturePixelFormat_AI_88, &PVRTableFormats[8] }, -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) { kPVR2TexturePixelFormat_PVRTC_2BPP_RGBA, &PVRTableFormats[10] }, { kPVR2TexturePixelFormat_PVRTC_4BPP_RGBA, &PVRTableFormats[12] }, -#endif // iphone only }; #define PVR2_MAX_TABLE_ELEMENTS (sizeof(v2_pixel_formathash) / sizeof(v2_pixel_formathash[0])) @@ -170,12 +166,10 @@ struct _pixel_formathash v3_pixel_formathash[] = { {kPVR3TexturePixelFormat_L_8, &PVRTableFormats[7] }, {kPVR3TexturePixelFormat_LA_88, &PVRTableFormats[8] }, -#ifdef __CC_PLATFORM_IOS {kPVR3TexturePixelFormat_PVRTC_2BPP_RGB, &PVRTableFormats[9] }, {kPVR3TexturePixelFormat_PVRTC_2BPP_RGBA, &PVRTableFormats[10] }, {kPVR3TexturePixelFormat_PVRTC_4BPP_RGB, &PVRTableFormats[11] }, {kPVR3TexturePixelFormat_PVRTC_4BPP_RGBA, &PVRTableFormats[12] }, -#endif // #__CC_PLATFORM_IOS }; @@ -289,8 +283,14 @@ bool CCTexturePVR::unpackPVRv2Data(unsigned char* data, unsigned int len) CCLOG("cocos2d: ERROR: Loading an NPOT texture (%dx%d) but is not supported on this device", header->width, header->height); return false; } + + unsigned int pvr2TableElements = PVR2_MAX_TABLE_ELEMENTS; + if (! CCConfiguration::sharedConfiguration()->supportsPVRTC()) + { + pvr2TableElements = 9; + } - for (unsigned int i = 0; i < (unsigned int)PVR2_MAX_TABLE_ELEMENTS; i++) + for (unsigned int i = 0; i < pvr2TableElements; i++) { //Does image format in table fits to the one parsed from header? if (v2_pixel_formathash[i].pixelFormat == formatFlags) @@ -414,8 +414,14 @@ bool CCTexturePVR::unpackPVRv3Data(unsigned char* dataPointer, unsigned int data bool infoValid = false; + + int pvr3TableElements = PVR3_MAX_TABLE_ELEMENTS; + if (! CCConfiguration::sharedConfiguration()->supportsPVRTC()) + { + pvr3TableElements = 9; + } - for(unsigned int i = 0; i < PVR3_MAX_TABLE_ELEMENTS; i++) + for(unsigned int i = 0; i < pvr3TableElements; i++) { if( v3_pixel_formathash[i].pixelFormat == pixelFormat ) { diff --git a/samples/Cpp/TestCpp/proj.android/.project b/samples/Cpp/TestCpp/proj.android/.project index 1b0de91d5a..ba4ce24ee5 100644 --- a/samples/Cpp/TestCpp/proj.android/.project +++ b/samples/Cpp/TestCpp/proj.android/.project @@ -20,16 +20,6 @@ - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Javah_jni_builder.launch - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental,