diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index d798d5545c..3071dc1b2e 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -dccf17d9f8ea8fb44f9484d8068bad5a12f82519 \ No newline at end of file +94814b9c3b3739c16749aced912bf674ec4f29c6 \ No newline at end of file diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index c5520792ab..0fb234dad2 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -131,8 +131,7 @@ text_input_node/CCTextFieldTTF.cpp \ textures/CCTexture2D.cpp \ textures/CCTextureAtlas.cpp \ textures/CCTextureCache.cpp \ -textures/CCTextureETC.cpp \ -textures/etc/etc1.cpp\ +platform/third_party/common/etc/etc1.cpp\ tilemap_parallax_nodes/CCParallaxNode.cpp \ tilemap_parallax_nodes/CCTMXLayer.cpp \ tilemap_parallax_nodes/CCTMXObjectGroup.cpp \ @@ -146,12 +145,15 @@ touch_dispatcher/CCTouch.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/include \ $(LOCAL_PATH)/kazmath/include \ - $(LOCAL_PATH)/platform/android + $(LOCAL_PATH)/platform/android \ + $(LOCAL_PATH)/platform/third_party/common/etc LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/include \ $(LOCAL_PATH)/kazmath/include \ - $(LOCAL_PATH)/platform/android + $(LOCAL_PATH)/platform/android \ + $(LOCAL_PATH)/platform/third_party/common/etc + LOCAL_LDLIBS := -lGLESv2 \ -llog \ diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 8a781d0f04..f0ac53317e 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -103,11 +103,11 @@ void RenderTexture::listenToBackground(cocos2d::Object *obj) if (_UITextureImage) { const Size& s = _texture->getContentSizeInPixels(); - VolatileTexture::addDataTexture(_texture, _UITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); + VolatileTexture::addDataTexture(_texture, _UITextureImage->getData(), s.width * s.height * 4, kTexture2DPixelFormat_RGBA8888, s); if ( _textureCopy ) { - VolatileTexture::addDataTexture(_textureCopy, _UITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); + VolatileTexture::addDataTexture(_textureCopy, _UITextureImage->getData(), s.width * s.height * 4, kTexture2DPixelFormat_RGBA8888, s); } } else diff --git a/cocos2dx/platform/CCImage.h b/cocos2dx/platform/CCImage.h index ebb2b1385c..d888ea184c 100644 --- a/cocos2dx/platform/CCImage.h +++ b/cocos2dx/platform/CCImage.h @@ -201,9 +201,7 @@ protected: int _height; FileType _fileType; Texture2DPixelFormat _renderFormat; - bool _hasAlpha; bool _preMulti; - bool _compressed; MipmapInfo _mipmaps[CC_MIPMAP_MAX]; // pointer to mipmap images int _numberOfMipmaps; diff --git a/cocos2dx/platform/CCImageCommonWebp.cpp b/cocos2dx/platform/CCImageCommonWebp.cpp index ec29e22301..1e59d4255d 100644 --- a/cocos2dx/platform/CCImageCommonWebp.cpp +++ b/cocos2dx/platform/CCImageCommonWebp.cpp @@ -52,7 +52,6 @@ bool Image::_initWithWebpData(void *data, int dataLen) _renderFormat = kTexture2DPixelFormat_RGBA8888; _width = config.input.width; _height = config.input.height; - _hasAlpha = true; int bufferSize = _width * _height * 4; _data = new unsigned char[bufferSize]; diff --git a/cocos2dx/platform/CCImageCommon_cpp.h b/cocos2dx/platform/CCImageCommon_cpp.h index b4543203c4..3ef2f14ded 100644 --- a/cocos2dx/platform/CCImageCommon_cpp.h +++ b/cocos2dx/platform/CCImageCommon_cpp.h @@ -36,7 +36,7 @@ THE SOFTWARE. #include "png.h" #include "jpeglib.h" #include "tiffio.h" -#include "etc/etc1.h" +#include "etc1.h" #include "CCCommon.h" #include "CCStdC.h" @@ -233,9 +233,7 @@ Image::Image() , _height(0) , _fileType(kFmtUnKnown) , _renderFormat(kTexture2DPixelFormat_None) -, _hasAlpha(false) , _preMulti(false) -, _compressed(false) , _numberOfMipmaps(0) { @@ -337,7 +335,7 @@ bool Image::initWithImageData(void * data, int dataLen) case kFmtPvr: return _initWithPVRData(data, dataLen); case kFmtEtc: - return _initWithETCData(data,, dataLen); + return _initWithETCData(data, dataLen); default: CCAssert(false, "unsupport data format!"); return false; @@ -362,7 +360,7 @@ bool Image::isPng(void *data, int dataLen) bool Image::isEtc(void *data, int dataLen) { - return (bool)etc1_pkm_is_valid(data); + return (bool)etc1_pkm_is_valid((etc1_byte*)data); } bool Image::isJpg(void *data, int dataLen) @@ -569,7 +567,6 @@ bool Image::_initWithJpgData(void * data, int dataLen) /* init image info */ _width = (short)(cinfo.output_width); _height = (short)(cinfo.output_height); - _hasAlpha = false; _preMulti = false; row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components]; CC_BREAK_IF(! row_pointer[0]); @@ -685,8 +682,6 @@ bool Image::_initWithPngData(void * data, int dataLen) bit_depth = png_get_bit_depth(png_ptr, info_ptr); color_type = png_get_color_type(png_ptr, info_ptr); - _hasAlpha = color_type & PNG_COLOR_MASK_ALPHA; - switch (color_type) { case PNG_COLOR_TYPE_GRAY: @@ -875,7 +870,6 @@ bool Image::_initWithTiffData(void* data, int dataLen) npixels = w * h; - _hasAlpha = true; _renderFormat = kTexture2DPixelFormat_RGBA8888; _width = w; _height = h; @@ -932,7 +926,6 @@ bool Image::_initWithPVRv2Data(void *data, int dataLen) unsigned int dataLength = 0, dataOffset = 0, dataSize = 0; unsigned int blockSize = 0, widthBlocks = 0, heightBlocks = 0; unsigned int width = 0, height = 0; - unsigned char *bytes = NULL; int formatFlags; //Cast first sizeof(PVRTexHeader) bytes of data stream as PVRTexHeader @@ -995,16 +988,6 @@ bool Image::_initWithPVRv2Data(void *data, int dataLen) _width = width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); _height = height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height); - //Do we use alpha ? - if (CC_SWAP_INT32_LITTLE_TO_HOST(header->bitmaskAlpha)) - { - _hasAlpha = true; - } - else - { - _hasAlpha = false; - } - //Get ptr to where data starts.. dataLength = CC_SWAP_INT32_LITTLE_TO_HOST(header->dataLength); @@ -1113,9 +1096,12 @@ bool Image::_initWithPVRv3Data(void *data, int dataLen) // 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 - _preMulti = true; + + // PVRv3 specifies premultiply alpha in a flag -- should always respect this in PVRv3 files + if (flags & kPVR3TextureFlagPremultipliedAlpha) + { + _preMulti = true; + } // sizing uint32_t width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); @@ -1124,9 +1110,7 @@ bool Image::_initWithPVRv3Data(void *data, int dataLen) _height = height; uint32_t dataOffset = 0, dataSize = 0; uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0; - uint8_t *bytes = NULL; - dataOffset = (sizeof(ccPVRv3TexHeader) + header->metadataLength); _dataLen = dataLen - (sizeof(ccPVRv3TexHeader) + header->metadataLength); _data = new unsigned char[_dataLen]; memcpy(_data, (unsigned char*)data + sizeof(ccPVRv3TexHeader) + header->metadataLength, _dataLen); @@ -1193,7 +1177,53 @@ bool Image::_initWithPVRv3Data(void *data, int dataLen) bool Image::_initWithETCData(void *data, int dataLen) { + etc1_byte* header = (etc1_byte*)data; + + //check the data + if(!etc1_pkm_is_valid(header)) + { + return false; + } + _width = etc1_pkm_get_width(header); + _height = etc1_pkm_get_height(header); + + if( 0 == _width || 0 == _height ) + { + return false; + } + + if(Configuration::getInstance()->supportsETC()) + { + //old opengl version has no define for GL_ETC1_RGB8_OES, add macro to make compiler happy. +#ifdef GL_ETC1_RGB8_OES + _renderFormat = kTexture2DPixelFormat_ETC; + _dataLen = dataLen - ETC_PKM_HEADER_SIZE; + _data = new unsigned char[_dataLen]; + memcpy(_data, (unsigned char*)data + ETC_PKM_HEADER_SIZE, _dataLen); + return true; +#endif + } + else + { + //if it is not gles or device do not support ETC, decode texture by software + int bytePerPixel = 3; + unsigned int stride = _width * bytePerPixel; + _renderFormat = kTexture2DPixelFormat_RGB888; + + _dataLen = _width * _height * bytePerPixel; + _data = new unsigned char[_dataLen]; + + if (etc1_decode_image((unsigned char*)data + ETC_PKM_HEADER_SIZE, (etc1_byte*)_data, _width, _height, bytePerPixel, stride) != 0) + { + _dataLen = 0; + CC_SAFE_DELETE_ARRAY(_data); + return false; + } + + return true; + } + return false; } bool Image::_initWithPVRData(void *data, int dataLen) @@ -1210,7 +1240,6 @@ bool Image::initWithRawData(void * data, int dataLen, int nWidth, int nHeight, i _height = (short)nHeight; _width = (short)nWidth; - _hasAlpha = true; _preMulti = bPreMulti; _renderFormat = kTexture2DPixelFormat_RGBA8888; @@ -1229,6 +1258,13 @@ bool Image::initWithRawData(void * data, int dataLen, int nWidth, int nHeight, i bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) { + //only support for kTexture2DPixelFormat_RGB888 or kTexture2DPixelFormat_RGBA8888 uncompressed data + if (isCompressed() || (_renderFormat != kTexture2DPixelFormat_RGB888 && _renderFormat != kTexture2DPixelFormat_RGBA8888)) + { + CCLOG("cocos2d: Image: saveToFile is only support for kTexture2DPixelFormat_RGB888 or kTexture2DPixelFormat_RGBA8888 uncompressed data for now"); + return false; + } + #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) assert(false); return false; @@ -1311,7 +1347,7 @@ bool Image::_saveImageToPNG(const char * pszFilePath, bool bIsToRGB) #endif png_init_io(png_ptr, fp); - if (!bIsToRGB && _hasAlpha) + if (!bIsToRGB && hasAlpha()) { png_set_IHDR(png_ptr, info_ptr, _width, _height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -1337,7 +1373,7 @@ bool Image::_saveImageToPNG(const char * pszFilePath, bool bIsToRGB) break; } - if (!_hasAlpha) + if (hasAlpha()) { for (int i = 0; i < (int)_height; i++) { @@ -1442,7 +1478,7 @@ bool Image::_saveImageToJPG(const char * pszFilePath) row_stride = _width * 3; /* JSAMPLEs per row in image_buffer */ - if (_hasAlpha) + if (hasAlpha()) { unsigned char *pTempData = new unsigned char[_width * _height * 3]; if (NULL == pTempData) diff --git a/cocos2dx/platform/android/CCImage.cpp b/cocos2dx/platform/android/CCImage.cpp index d45d7c9ddb..978cb44017 100644 --- a/cocos2dx/platform/android/CCImage.cpp +++ b/cocos2dx/platform/android/CCImage.cpp @@ -168,9 +168,8 @@ bool Image::initWithString( _width = (short)dc._width; _height = (short)dc._height; - _hasAlpha = true; _preMulti = true; - _bitDepth = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; bRet = true; } while (0); @@ -220,9 +219,8 @@ bool Image::initWithStringShadowStroke( _width = (short)dc._width; _height = (short)dc._height; - _hasAlpha = true; _preMulti = true; - _bitDepth = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; // swap the alpha channel (ARGB to RGBA) swapAlphaChannel((unsigned int *)_data, (_width * _height) ); diff --git a/cocos2dx/platform/blackberry/CCImage.cpp b/cocos2dx/platform/blackberry/CCImage.cpp index 61baf47e65..32c6dfe3dd 100644 --- a/cocos2dx/platform/blackberry/CCImage.cpp +++ b/cocos2dx/platform/blackberry/CCImage.cpp @@ -426,9 +426,8 @@ bool Image::initWithString( _width = (short)dc.iMaxLineWidth; _height = (short)dc.iMaxLineHeight; - _hasAlpha = true; _preMulti = true; - _bitDepth = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; bRet = true; diff --git a/cocos2dx/platform/emscripten/CCImage.cpp b/cocos2dx/platform/emscripten/CCImage.cpp index 2838803772..2b20a13b7d 100644 --- a/cocos2dx/platform/emscripten/CCImage.cpp +++ b/cocos2dx/platform/emscripten/CCImage.cpp @@ -306,9 +306,8 @@ bool Image::initWithString( _width = (short)dc.iMaxLineWidth; _height = (short)dc.iMaxLineHeight; - _hasAlpha = true; _preMulti = true; - _bitDepth = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; bRet = true; diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index e1e6518d04..f28a8e3267 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -38,7 +38,6 @@ typedef struct { unsigned int height; unsigned int width; - bool hasAlpha; bool isPremultipliedAlpha; bool hasShadow; CGSize shadowOffset; @@ -57,90 +56,6 @@ typedef struct } tImageInfo; -static bool _initWithImage(CGImageRef cgImage, tImageInfo *pImageinfo) -{ - if(cgImage == NULL) - { - return false; - } - - // get image info - - pImageinfo->width = CGImageGetWidth(cgImage); - pImageinfo->height = CGImageGetHeight(cgImage); - - CGImageAlphaInfo info = CGImageGetAlphaInfo(cgImage); - pImageinfo->hasAlpha = (info == kCGImageAlphaPremultipliedLast) - || (info == kCGImageAlphaPremultipliedFirst) - || (info == kCGImageAlphaLast) - || (info == kCGImageAlphaFirst); - - // If OS version < 5.x, add condition to support jpg - float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue]; - if(systemVersion < 5.0f) - { - pImageinfo->hasAlpha = (pImageinfo->hasAlpha || (info == kCGImageAlphaNoneSkipLast)); - } - - CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage); - if (colorSpace) - { - if (pImageinfo->hasAlpha) - { - info = kCGImageAlphaPremultipliedLast; - pImageinfo->isPremultipliedAlpha = true; - } - else - { - info = kCGImageAlphaNoneSkipLast; - pImageinfo->isPremultipliedAlpha = false; - } - } - else - { - return false; - } - - // change to RGBA8888 - pImageinfo->hasAlpha = true; - pImageinfo->data = new unsigned char[pImageinfo->width * pImageinfo->height * 4]; - colorSpace = CGColorSpaceCreateDeviceRGB(); - CGContextRef context = CGBitmapContextCreate(pImageinfo->data, - pImageinfo->width, - pImageinfo->height, - 8, - 4 * pImageinfo->width, - colorSpace, - info | kCGBitmapByteOrder32Big); - - CGContextClearRect(context, CGRectMake(0, 0, pImageinfo->width, pImageinfo->height)); - //CGContextTranslateCTM(context, 0, 0); - CGContextDrawImage(context, CGRectMake(0, 0, pImageinfo->width, pImageinfo->height), cgImage); - - CGContextRelease(context); - CFRelease(colorSpace); - - return true; -} - -static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo) -{ - bool ret = false; - - if (pBuffer) - { - CGImageRef CGImage; - NSData *data; - - data = [NSData dataWithBytes:pBuffer length:length]; - CGImage = [[UIImage imageWithData:data] CGImage]; - - ret = _initWithImage(CGImage, pImageinfo); - } - - return ret; -} - static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize) { NSArray *listItems = [str componentsSeparatedByString: @"\n"]; @@ -386,7 +301,6 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign // output params pInfo->data = data; - pInfo->hasAlpha = true; pInfo->isPremultipliedAlpha = true; pInfo->width = dim.width; pInfo->height = dim.height; @@ -458,7 +372,6 @@ bool Image::initWithStringShadowStroke( } _height = (short)info.height; _width = (short)info.width; - _hasAlpha = info.hasAlpha; _renderFormat = kTexture2DPixelFormat_RGBA8888; _preMulti = info.isPremultipliedAlpha; _data = info.data; @@ -477,7 +390,7 @@ bool Image::_iosSaveToFile(const char *pszFilePath, bool bIsToRGB) } int bitsPerComponent = 8; - int bitsPerPixel = _hasAlpha ? 32 : 24; + int bitsPerPixel = hasAlpha() ? 32 : 24; if ((! saveToPNG) || bIsToRGB) { bitsPerPixel = 24; @@ -490,7 +403,7 @@ bool Image::_iosSaveToFile(const char *pszFilePath, bool bIsToRGB) // The data has alpha channel, and want to save it with an RGB png file, // or want to save as jpg, remove the alpha channel. - if ((saveToPNG && _hasAlpha && bIsToRGB) + if ((saveToPNG && hasAlpha() && bIsToRGB) || (! saveToPNG)) { pixels = new unsigned char[myDataLength]; @@ -510,7 +423,7 @@ bool Image::_iosSaveToFile(const char *pszFilePath, bool bIsToRGB) // make data provider with data. CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; - if (saveToPNG && _hasAlpha && (! bIsToRGB)) + if (saveToPNG && hasAlpha() && (! bIsToRGB)) { bitmapInfo |= kCGImageAlphaPremultipliedLast; } diff --git a/cocos2dx/platform/linux/CCImage.cpp b/cocos2dx/platform/linux/CCImage.cpp index 9c9b0af1b3..4311930317 100644 --- a/cocos2dx/platform/linux/CCImage.cpp +++ b/cocos2dx/platform/linux/CCImage.cpp @@ -449,9 +449,8 @@ bool Image::initWithString( _width = (short)dc.iMaxLineWidth; _height = (short)dc.iMaxLineHeight; - _hasAlpha = true; + _renderFormat = kTexture2DPixelFormat_RGBA8888; _preMulti = true; - _bitDepth = 8; bRet = true; diff --git a/cocos2dx/platform/nacl/CCImage.cpp b/cocos2dx/platform/nacl/CCImage.cpp index 81eb6538f3..568cd751d2 100644 --- a/cocos2dx/platform/nacl/CCImage.cpp +++ b/cocos2dx/platform/nacl/CCImage.cpp @@ -462,9 +462,8 @@ bool Image::initWithString( _width = (short)dc.iMaxLineWidth; _height = (short)dc.iMaxLineHeight; - _hasAlpha = true; _preMulti = true; - _bitsPerComponent = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; bRet = true; diff --git a/cocos2dx/textures/etc/etc1.cpp b/cocos2dx/platform/third_party/common/etc/etc1.cpp similarity index 100% rename from cocos2dx/textures/etc/etc1.cpp rename to cocos2dx/platform/third_party/common/etc/etc1.cpp diff --git a/cocos2dx/textures/etc/etc1.h b/cocos2dx/platform/third_party/common/etc/etc1.h similarity index 100% rename from cocos2dx/textures/etc/etc1.h rename to cocos2dx/platform/third_party/common/etc/etc1.h diff --git a/cocos2dx/platform/tizen/CCImage.cpp b/cocos2dx/platform/tizen/CCImage.cpp index 5dcb778522..0b5f063a3d 100644 --- a/cocos2dx/platform/tizen/CCImage.cpp +++ b/cocos2dx/platform/tizen/CCImage.cpp @@ -449,9 +449,8 @@ bool Image::initWithString( _width = (short)dc.iMaxLineWidth; _height = (short)dc.iMaxLineHeight; - _hasAlpha = true; _preMulti = true; - _bitsPerComponent = 8; + _renderFormat = kTexture2DPixelFormat_RGBA8888; bRet = true; diff --git a/cocos2dx/platform/win32/CCImage.cpp b/cocos2dx/platform/win32/CCImage.cpp index a7b997e1d8..17aaeabb55 100644 --- a/cocos2dx/platform/win32/CCImage.cpp +++ b/cocos2dx/platform/win32/CCImage.cpp @@ -405,7 +405,6 @@ bool Image::initWithString( _width = (short)size.cx; _height = (short)size.cy; - _hasAlpha = true; _preMulti = false; _renderFormat = kTexture2DPixelFormat_RGBA8888; // copy pixed data diff --git a/cocos2dx/proj.win32/cocos2d.vcxproj b/cocos2dx/proj.win32/cocos2d.vcxproj index 411119ecc1..238646ffbe 100644 --- a/cocos2dx/proj.win32/cocos2d.vcxproj +++ b/cocos2dx/proj.win32/cocos2d.vcxproj @@ -69,7 +69,7 @@ Disabled - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;$(ProjectDir)..\platform\third_party\common\etc;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks @@ -197,6 +197,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir + @@ -234,8 +235,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir - - @@ -343,6 +342,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir + @@ -397,8 +397,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir - - diff --git a/cocos2dx/proj.win32/cocos2d.vcxproj.filters b/cocos2dx/proj.win32/cocos2d.vcxproj.filters index 580a24f879..0f653317a1 100644 --- a/cocos2dx/proj.win32/cocos2d.vcxproj.filters +++ b/cocos2dx/proj.win32/cocos2d.vcxproj.filters @@ -103,12 +103,12 @@ {caa78ce0-9b58-4314-b117-1acae278691e} - - {5e6e45aa-50ef-451b-9bb1-f98b9b78259b} - {e7134ba0-4220-4dd1-b120-3533883394ac} + + {47fda93e-6eb4-4abc-b5bc-725bf667a395} + @@ -465,22 +465,19 @@ cocoa - - textures - support\component support\component - - textures\etc - keyboard_dispatcher + + platform\etc + @@ -943,9 +940,6 @@ cocoa - - textures - support\component @@ -953,14 +947,14 @@ support\component - - textures\etc - keyboard_dispatcher include + + platform\etc + \ No newline at end of file diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 15d3ce076f..11ced4f644 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -39,7 +39,6 @@ THE SOFTWARE. #include "CCGL.h" #include "support/ccUtils.h" #include "platform/CCPlatformMacros.h" -#include "textures/CCTextureETC.h" #include "CCDirector.h" #include "shaders/CCGLProgram.h" #include "shaders/ccGLStateCache.h" @@ -60,16 +59,6 @@ static Texture2DPixelFormat g_defaultAlphaPixelFormat = kTexture2DPixelFormat_De // By default PVR images are treated as if they don't have the alpha channel premultiplied static bool PVRHaveAlphaPremultiplied_ = false; - -TexturePixelFormatInfo::TexturePixelFormatInfo(GLenum internalFormat, GLenum format, GLenum type, int bpp, bool compressed, bool alpha) -:internalFormat(internalFormat) -,format(format) -,type(type) -,bpp(bpp) -,compressed(compressed) -,alpha(alpha) -{} - ////////////////////////////////////////////////////////////////////////// //conventer function @@ -509,14 +498,14 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2DPi const TexturePixelFormatInfo& info = g_texturePixelFormatInfoTables.at(pixelFormat); - if (info.compressed && !Configuration::getInstance()->supportsPVRTC()) + if (info.compressed && !Configuration::getInstance()->supportsPVRTC() && !Configuration::getInstance()->supportsETC()) { - CCLOG("cocos2d: WARNING: PVRTC images are not supported"); + CCLOG("cocos2d: WARNING: PVRTC/ETC images are not supported"); return false; } - //Set the row align only when mipmapsNum == 1 - if (mipmapsNum == 1) + //Set the row align only when mipmapsNum == 1 and the data is uncompressed + if (mipmapsNum == 1 && !info.compressed) { unsigned int bytesPerRow = pixelsWide * info.bpp / 8; @@ -645,7 +634,7 @@ bool Texture2D::initWithImage(Image *uiImage, Texture2DPixelFormat format) unsigned char* tempData = uiImage->getData(); Size imageSize = Size((float)imageWidth, (float)imageHeight); - Texture2DPixelFormat pixelFormat; + Texture2DPixelFormat pixelFormat = kTexture2DPixelFormat_None; Texture2DPixelFormat renderFormat = uiImage->getRenderFormat(); size_t tempDataLen = uiImage->getDataLen(); @@ -1162,34 +1151,6 @@ void Texture2D::drawInRect(const Rect& rect) glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } -bool Texture2D::initWithETCFile(const char* file) -{ - bool bRet = false; - // nothing to do with Object::init - - TextureETC *etc = new TextureETC; - bRet = etc->initWithFile(file); - - if (bRet) - { - _name = etc->getName(); - _maxS = 1.0f; - _maxT = 1.0f; - _pixelsWide = etc->getWidth(); - _pixelsHigh = etc->getHeight(); - _contentSize = Size((float)_pixelsWide, (float)_pixelsHigh); - _hasPremultipliedAlpha = true; - - etc->release(); - } - else - { - CCLOG("cocos2d: Couldn't load ETC image %s", file); - } - - return bRet; -} - void Texture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { PVRHaveAlphaPremultiplied_ = haveAlphaPremultiplied; diff --git a/cocos2dx/textures/CCTexture2D.h b/cocos2dx/textures/CCTexture2D.h index 8f0ec3d309..16bd55dbba 100644 --- a/cocos2dx/textures/CCTexture2D.h +++ b/cocos2dx/textures/CCTexture2D.h @@ -105,7 +105,8 @@ typedef struct _ccTexParams { -typedef struct _TexturePixelFormatInfo { +class TexturePixelFormatInfo { +public: GLenum internalFormat; GLenum format; GLenum type; @@ -113,9 +114,9 @@ typedef struct _TexturePixelFormatInfo { bool compressed; bool alpha; - struct _TexturePixelFormatInfo(GLenum internalFormat, GLenum format, GLenum type, int bpp, bool compressed, bool alpha) + TexturePixelFormatInfo(GLenum internalFormat, GLenum format, GLenum type, int bpp, bool compressed, bool alpha) :internalFormat(internalFormat), format(format), type(type), bpp(bpp), compressed(compressed), alpha(alpha){} -} TexturePixelFormatInfo; +}; typedef const std::map ConstTexturePixelFormatInfoMap; typedef const ConstTexturePixelFormatInfoMap::value_type ConstTexturePixelFormatInfoMapValue; @@ -140,7 +141,7 @@ static ConstTexturePixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] = #endif #ifdef GL_ETC1_RGB8_OES - ConstTexturePixelFormatInfoMapValue(kTexture2DPixelFormat_ETC, TexturePixelFormatInfo(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false)), + ConstTexturePixelFormatInfoMapValue(kTexture2DPixelFormat_ETC, TexturePixelFormatInfo(GL_ETC1_RGB8_OES, 0xFFFFFFFF, 0xFFFFFFFF, 24, true, false)), #endif }; @@ -244,9 +245,6 @@ public: bool initWithString(const char *text, const char *fontName, float fontSize); /** Initializes a texture from a string using a text definition*/ bool initWithString(const char *text, const FontDefinition& textDefinition); - - /** Initializes a texture from a ETC file */ - bool initWithETCFile(const char* file); /** 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}. diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 15b658f57a..851184ce8e 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -332,35 +332,27 @@ Texture2D * TextureCache::addImage(const char * path) // all images are handled by UIImage except PVR extension that is handled by our own handler do { - if (std::string::npos != lowerCase.find(".pkm")) + pImage = new Image(); + CC_BREAK_IF(NULL == pImage); + + bool bRet = pImage->initWithImageFile(fullpath.c_str()); + CC_BREAK_IF(!bRet); + + texture = new Texture2D(); + + if( texture && + texture->initWithImage(pImage) ) { - // ETC1 file format, only supportted on Android - texture = this->addETCImage(fullpath.c_str()); +#if CC_ENABLE_CACHE_TEXTURE_DATA + // cache the texture file name + VolatileTexture::addImageTexture(texture, fullpath.c_str()); +#endif + _textures->setObject(texture, pathKey.c_str()); + texture->release(); } else { - pImage = new Image(); - CC_BREAK_IF(NULL == pImage); - - bool bRet = pImage->initWithImageFile(fullpath.c_str()); - CC_BREAK_IF(!bRet); - - texture = new Texture2D(); - - if( texture && - texture->initWithImage(pImage) ) - { -#if CC_ENABLE_CACHE_TEXTURE_DATA - // cache the texture file name - VolatileTexture::addImageTexture(texture, fullpath.c_str()); -#endif - _textures->setObject(texture, pathKey.c_str()); - texture->release(); - } - else - { - CCLOG("cocos2d: Couldn't create texture for file:%s in TextureCache", path); - } + CCLOG("cocos2d: Couldn't create texture for file:%s in TextureCache", path); } } while (0); } @@ -370,35 +362,6 @@ Texture2D * TextureCache::addImage(const char * path) return texture; } -Texture2D* TextureCache::addETCImage(const char* path) -{ - CCAssert(path != NULL, "TextureCache: fileimage MUST not be nil"); - - Texture2D* texture = NULL; - std::string key(path); - - if( (texture = (Texture2D*)_textures->objectForKey(key.c_str())) ) - { - return texture; - } - - // Split up directory and filename - std::string fullpath = FileUtils::getInstance()->fullPathForFilename(key.c_str()); - texture = new Texture2D(); - if(texture != NULL && texture->initWithETCFile(fullpath.c_str())) - { - _textures->setObject(texture, key.c_str()); - texture->autorelease(); - } - else - { - CCLOG("cocos2d: Couldn't add ETCImage:%s in TextureCache",key.c_str()); - CC_SAFE_DELETE(texture); - } - - return texture; -} - Texture2D* TextureCache::addUIImage(Image *image, const char *key) { CCAssert(image != NULL, "TextureCache: image MUST not be nil"); @@ -626,7 +589,7 @@ VolatileTexture* VolatileTexture::findVolotileTexture(Texture2D *tt) return vt; } -void VolatileTexture::addDataTexture(Texture2D *tt, void* data, Texture2DPixelFormat pixelFormat, const Size& contentSize) +void VolatileTexture::addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2DPixelFormat pixelFormat, const Size& contentSize) { if (_isReloading) { @@ -637,6 +600,7 @@ void VolatileTexture::addDataTexture(Texture2D *tt, void* data, Texture2DPixelFo vt->_cashedImageType = kImageData; vt->_textureData = data; + vt->_dataLen = dataLen; vt->_pixelFormat = pixelFormat; vt->_textureSize = contentSize; } @@ -698,42 +662,26 @@ void VolatileTexture::reloadAllTextures() { case kImageFile: { - std::string lowerCase(vt->_fileName.c_str()); - for (unsigned int i = 0; i < lowerCase.length(); ++i) - { - lowerCase[i] = tolower(lowerCase[i]); - } - - if (std::string::npos != lowerCase.find(".pvr")) + Image* pImage = new Image(); + unsigned long nSize = 0; + unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &nSize); + + if (pImage && pImage->initWithImageData((void*)pBuffer, nSize)) { Texture2DPixelFormat oldPixelFormat = Texture2D::defaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); - - vt->_texture->initWithPVRFile(vt->_fileName.c_str()); + vt->_texture->initWithImage(pImage); Texture2D::setDefaultAlphaPixelFormat(oldPixelFormat); - } - else - { - Image* pImage = new Image(); - unsigned long nSize = 0; - unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &nSize); - - if (pImage && pImage->initWithImageData((void*)pBuffer, nSize)) - { - Texture2DPixelFormat oldPixelFormat = Texture2D::defaultAlphaPixelFormat(); - Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); - vt->_texture->initWithImage(pImage); - Texture2D::setDefaultAlphaPixelFormat(oldPixelFormat); - } - - CC_SAFE_DELETE_ARRAY(pBuffer); - CC_SAFE_RELEASE(pImage); } + + CC_SAFE_DELETE_ARRAY(pBuffer); + CC_SAFE_RELEASE(pImage); } break; case kImageData: { - vt->_texture->initWithData(vt->_textureData, + vt->_texture->initWithData(vt->_textureData, + vt->_dataLen, vt->_pixelFormat, vt->_textureSize.width, vt->_textureSize.height, diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index df4c74cbad..e860d3830f 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -145,12 +145,6 @@ public: * @since v1.0 */ void dumpCachedTextureInfo(); - - /** Returns a Texture2D object given an ETC filename - * If the file image was not previously loaded, it will create a new Texture2D - * object and it will return it. Otherwise it will return a reference of a previously loaded image - */ - Texture2D* addETCImage(const char* filename); private: void addImageAsyncCallBack(float dt); @@ -212,7 +206,7 @@ public: static void addImageTexture(Texture2D *tt, const char* imageFileName); static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition); - static void addDataTexture(Texture2D *tt, void* data, Texture2DPixelFormat pixelFormat, const Size& contentSize); + static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2DPixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); static void setTexParameters(Texture2D *t, const ccTexParams &texParams); @@ -236,6 +230,7 @@ protected: ccCachedImageType _cashedImageType; void *_textureData; + int _dataLen; Size _textureSize; Texture2DPixelFormat _pixelFormat; diff --git a/cocos2dx/textures/CCTextureETC.cpp b/cocos2dx/textures/CCTextureETC.cpp deleted file mode 100644 index 0f19b13b19..0000000000 --- a/cocos2dx/textures/CCTextureETC.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 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. - ****************************************************************************/ - -#include "CCTextureETC.h" -#include "platform/CCPlatformConfig.h" -#include "platform/CCFileUtils.h" -#include "CCConfiguration.h" -#include "etc/etc1.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#include "platform/android/jni/JniHelper.h" -#endif - -NS_CC_BEGIN - -TextureETC::TextureETC() -: _name(0) -, _width(0) -, _height(0) -{} - -TextureETC::~TextureETC() -{ -} - -bool TextureETC::initWithFile(const char *file) -{ - return loadTexture(FileUtils::getInstance()->fullPathForFilename(file).c_str()); -} - -unsigned int TextureETC::getName() const -{ - return _name; -} - -unsigned int TextureETC::getWidth() const -{ - return _width; -} - -unsigned int TextureETC::getHeight() const -{ - return _height; -} - -// Call back function for java -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#define LOG_TAG "CCTextureETC.cpp" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) - -static unsigned int sWidth = 0; -static unsigned int sHeight = 0; -static unsigned char *sData = NULL; -static unsigned int sLength = 0; - -extern "C" -{ - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxETCLoader_nativeSetTextureInfo(JNIEnv* env, jobject thiz, jint width, jint height, jbyteArray data, jint dataLength) - { - sWidth = (unsigned int)width; - sHeight = (unsigned int)height; - sLength = dataLength; - sData = new unsigned char[sLength]; - env->GetByteArrayRegion(data, 0, sLength, (jbyte*)sData); - } -} -#endif - -bool TextureETC::loadTexture(const char* file) -{ - unsigned long etcFileSize = 0; - etc1_byte* etcFileData = NULL; - etcFileData = FileUtils::getInstance()->getFileData(file, "rb", &etcFileSize); - - if(0 == etcFileSize) - { - return false; - } - - if(!etc1_pkm_is_valid(etcFileData)) - { - delete[] etcFileData; - etcFileData = NULL; - return false; - } - - _width = etc1_pkm_get_width(etcFileData); - _height = etc1_pkm_get_height(etcFileData); - - if( 0 == _width || 0 == _height ) - { - delete[] etcFileData; - etcFileData = NULL; - return false; - } - - if(Configuration::getInstance()->supportsETC()) - { - //old opengl version has no define for GL_ETC1_RGB8_OES, add macro to make compiler happy. -#ifdef GL_ETC1_RGB8_OES - glGenTextures(1, &_name); - glBindTexture(GL_TEXTURE_2D, _name); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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); - - glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_ETC1_RGB8_OES, _width, _height, 0, etcFileSize - ETC_PKM_HEADER_SIZE, - etcFileData + ETC_PKM_HEADER_SIZE); - - glBindTexture(GL_TEXTURE_2D, 0); - - delete[] etcFileData; - etcFileData = NULL; - return true; -#endif - } - else - { - //if it is not gles or device do not support ETC, decode texture by software - int bytePerPixel = 3; - GLenum fallBackType = GL_UNSIGNED_BYTE; - - /*bool fallBackUseShort = false; - if(fallBackUseShort) - { - bytePerPixel = 2; - fallBackType = GL_UNSIGNED_SHORT_5_6_5; - } - */ - unsigned int stride = _width * bytePerPixel; - - std::vector decodeImageData(stride * _height); - - etc1_decode_image(etcFileData + ETC_PKM_HEADER_SIZE, &decodeImageData[0], _width, _height, bytePerPixel, stride); - - //set decoded data to gl - glGenTextures(1, &_name); - glBindTexture(GL_TEXTURE_2D, _name); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _width, _height, 0, GL_RGB, fallBackType, &decodeImageData[0]); - glBindTexture(GL_TEXTURE_2D, 0); - delete[] etcFileData; - etcFileData = NULL; - return true; - } - return false; -} - -NS_CC_END diff --git a/cocos2dx/textures/CCTextureETC.h b/cocos2dx/textures/CCTextureETC.h deleted file mode 100644 index 96053a4954..0000000000 --- a/cocos2dx/textures/CCTextureETC.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 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 __CCETCTEXTURE_H__ -#define __CCETCTEXTURE_H__ - -#include "cocoa/CCObject.h" -#include "platform/CCPlatformMacros.h" -#include "CCGL.h" - -NS_CC_BEGIN - -class CC_DLL TextureETC : public Object -{ -public: - TextureETC(); - virtual ~TextureETC(); - - bool initWithFile(const char* file); - - unsigned int getName() const; - unsigned int getWidth() const; - unsigned int getHeight() const; - -private: - bool loadTexture(const char* file); - -private: - GLuint _name; - unsigned int _width; - unsigned int _height; -}; - -NS_CC_END - -#endif /* defined(__CCETCTEXTURE_H__) */