diff --git a/cocos/2d/CCAutoPolygon.cpp b/cocos/2d/CCAutoPolygon.cpp index a8baa2656e..f2cff63a92 100644 --- a/cocos/2d/CCAutoPolygon.cpp +++ b/cocos/2d/CCAutoPolygon.cpp @@ -187,7 +187,7 @@ AutoPolygon::AutoPolygon(const std::string &filename) _filename = filename; _image = new (std::nothrow) Image(); _image->initWithImageFile(filename); - CCASSERT(_image->getPixelFormat()==Texture2D::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); + CCASSERT(_image->getPixelFormat()==backend::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); _data = _image->getData(); _width = _image->getWidth(); _height = _image->getHeight(); diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 8c8ea92aac..958692d953 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -144,18 +144,18 @@ FontAtlas::~FontAtlas() void FontAtlas::initTextureWithZeros(Texture2D *texture) { char *zeros = nullptr; - Texture2D::PixelFormat pixelFormat; + backend::PixelFormat pixelFormat; float outlineSize = _fontFreeType->getOutlineSize(); size_t zeroBytes = 0; if (outlineSize > 0) { //metal do no support AI88 format - pixelFormat = Texture2D::PixelFormat::RGBA8888; + pixelFormat = backend::PixelFormat::RGBA8888; zeroBytes = CacheTextureWidth * CacheTextureWidth * 4; } else { - pixelFormat = Texture2D::PixelFormat::A8; + pixelFormat = backend::PixelFormat::A8; zeroBytes = CacheTextureWidth * CacheTextureWidth; } zeros = new char[zeroBytes](); @@ -389,7 +389,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text) FontLetterDefinition tempDef; auto scaleFactor = CC_CONTENT_SCALE_FACTOR(); - auto pixelFormat = _fontFreeType->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; + auto pixelFormat = _fontFreeType->getOutlineSize() > 0 ? backend::PixelFormat::AI88 : backend::PixelFormat::A8; float startY = _currentPageOrigY; @@ -477,11 +477,11 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text) return true; } -void FontAtlas::updateTextureContent(Texture2D::PixelFormat format, int startY) +void FontAtlas::updateTextureContent(backend::PixelFormat format, int startY) { unsigned char *data = nullptr; auto outlineSize = _fontFreeType->getOutlineSize(); - if (outlineSize > 0 && format == Texture2D::PixelFormat::AI88) + if (outlineSize > 0 && format == backend::PixelFormat::AI88) { int nLen = CacheTextureWidth * (_currentPageOrigY - startY + _currLineHeight); data = _currentPageData + CacheTextureWidth * (int)startY * 2; diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 959bb4d172..aa492f0b6f 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -131,7 +131,7 @@ protected: */ void scaleFontLetterDefinition(float scaleFactor); - void updateTextureContent(Texture2D::PixelFormat format, int startY); + void updateTextureContent(backend::PixelFormat format, int startY); std::unordered_map _atlasTextures; std::unordered_map _letterDefinitions; diff --git a/cocos/2d/CCGrid.cpp b/cocos/2d/CCGrid.cpp index 4e07413d55..139add8b4a 100644 --- a/cocos/2d/CCGrid.cpp +++ b/cocos/2d/CCGrid.cpp @@ -63,7 +63,7 @@ bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect & descriptor.width = POTWide; descriptor.height = POTHigh; descriptor.textureUsage = backend::TextureUsage::RENDER_TARGET; - descriptor.textureFormat = backend::TextureFormat::R8G8B8A8; + descriptor.textureFormat = backend::PixelFormat::RGBA8888; auto backendTexture = backend::Device::getInstance()->newTexture(descriptor); texture->initWithBackendTexture(backendTexture); backendTexture->release(); diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index cb8207c65a..61d8b36bd7 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -38,7 +38,6 @@ THE SOFTWARE. #include "renderer/CCTextureCache.h" #include "renderer/backend/Device.h" #include "renderer/backend/Texture.h" -#include "renderer/backend/StringUtils.h" NS_CC_BEGIN @@ -77,11 +76,11 @@ void RenderTexture::listenToBackground(EventCustom* /*event*/) _UITextureImage = uiTextureImage; CC_SAFE_RETAIN(_UITextureImage); const Size& s = _texture2D->getContentSizeInPixels(); - VolatileTextureMgr::addDataTexture(_texture2D, uiTextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s); + VolatileTextureMgr::addDataTexture(_texture2D, uiTextureImage->getData(), s.width * s.height * 4, backend::PixelFormat::RGBA8888, s); if ( _texture2DCopy ) { - VolatileTextureMgr::addDataTexture(_texture2DCopy, uiTextureImage->getData(), s.width * s.height * 4, Texture2D::PixelFormat::RGBA8888, s); + VolatileTextureMgr::addDataTexture(_texture2DCopy, uiTextureImage->getData(), s.width * s.height * 4, backend::PixelFormat::RGBA8888, s); } } else @@ -114,7 +113,7 @@ void RenderTexture::listenToForeground(EventCustom* /*event*/) #endif } -RenderTexture * RenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat) +RenderTexture * RenderTexture::create(int w, int h, backend::PixelFormat eFormat) { RenderTexture *ret = new (std::nothrow) RenderTexture(); @@ -127,7 +126,7 @@ RenderTexture * RenderTexture::create(int w, int h, Texture2D::PixelFormat eForm return nullptr; } -RenderTexture * RenderTexture::create(int w ,int h, Texture2D::PixelFormat eFormat, TextureFormat uDepthStencilFormat) +RenderTexture * RenderTexture::create(int w ,int h, backend::PixelFormat eFormat, PixelFormat uDepthStencilFormat) { RenderTexture *ret = new (std::nothrow) RenderTexture(); @@ -144,7 +143,7 @@ RenderTexture * RenderTexture::create(int w, int h) { RenderTexture *ret = new (std::nothrow) RenderTexture(); - if(ret && ret->initWithWidthAndHeight(w, h, Texture2D::PixelFormat::RGBA8888, TextureFormat::NONE)) + if(ret && ret->initWithWidthAndHeight(w, h, backend::PixelFormat::RGBA8888, PixelFormat::NONE)) { ret->autorelease(); return ret; @@ -153,14 +152,14 @@ RenderTexture * RenderTexture::create(int w, int h) return nullptr; } -bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat) +bool RenderTexture::initWithWidthAndHeight(int w, int h, backend::PixelFormat eFormat) { - return initWithWidthAndHeight(w, h, eFormat, TextureFormat::NONE); + return initWithWidthAndHeight(w, h, eFormat, PixelFormat::NONE); } -bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, TextureFormat depthStencilFormat) +bool RenderTexture::initWithWidthAndHeight(int w, int h, backend::PixelFormat format, PixelFormat depthStencilFormat) { - CCASSERT(format != Texture2D::PixelFormat::A8, "only RGB and RGBA formats are valid for a render texture"); + CCASSERT(format != backend::PixelFormat::A8, "only RGB and RGBA formats are valid for a render texture"); bool ret = false; do @@ -189,7 +188,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat descriptor.width = powW; descriptor.height = powH; descriptor.textureUsage = TextureUsage::RENDER_TARGET; - descriptor.textureFormat = TextureFormat::R8G8B8A8; + descriptor.textureFormat = PixelFormat::RGBA8888; auto texture = backend::Device::getInstance()->newTexture(descriptor); if (! texture) break; @@ -207,7 +206,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat clearColorAttachment(); - if (TextureFormat::D24S8 == depthStencilFormat) + if (PixelFormat::D24S8 == depthStencilFormat) { _renderTargetFlags = RenderTargetFlag::ALL; descriptor.textureFormat = depthStencilFormat; @@ -411,7 +410,7 @@ void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA) /* get buffer as Image */ void RenderTexture::newImage(std::function imageCallback, bool flipImage) { - CCASSERT(_pixelFormat == Texture2D::PixelFormat::RGBA8888, "only RGBA8888 can be saved as image"); + CCASSERT(_pixelFormat == backend::PixelFormat::RGBA8888, "only RGBA8888 can be saved as image"); if ((nullptr == _texture2D)) { diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index b608b02dc9..c818571ef3 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -32,6 +32,7 @@ THE SOFTWARE. #include "renderer/CCGroupCommand.h" #include "renderer/CCCustomCommand.h" #include "renderer/CCCallbackCommand.h" +#include "renderer/backend/Types.h" NS_CC_BEGIN @@ -66,7 +67,7 @@ public: * @param format In Points and a pixel format( only RGB and RGBA formats are valid ). * @param depthStencilFormat The depthStencil format. */ - static RenderTexture * create(int w ,int h, Texture2D::PixelFormat format, TextureFormat depthStencilFormat); + static RenderTexture * create(int w ,int h, backend::PixelFormat format, backend::PixelFormat depthStencilFormat); /** Creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid. * @@ -74,7 +75,7 @@ public: * @param h The RenderTexture object height. * @param format In Points and a pixel format( only RGB and RGBA formats are valid ). */ - static RenderTexture * create(int w, int h, Texture2D::PixelFormat format); + static RenderTexture * create(int w, int h, backend::PixelFormat format); /** Creates a RenderTexture object with width and height in Points, pixel format is RGBA8888. * @@ -303,7 +304,7 @@ public: * @param format In Points and a pixel format( only RGB and RGBA formats are valid ). * @return If succeed, it will return true. */ - bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format); + bool initWithWidthAndHeight(int w, int h, backend::PixelFormat format); /** Initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format. * * @param w The RenderTexture object width. @@ -312,7 +313,7 @@ public: * @param depthStencilFormat The depthStencil format. * @return If succeed, it will return true. */ - bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, TextureFormat depthStencilFormat); + bool initWithWidthAndHeight(int w, int h, backend::PixelFormat format, backend::PixelFormat depthStencilFormat); protected: virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, ClearFlag flags); @@ -339,7 +340,7 @@ protected: RenderTargetFlag _renderTargetFlags; RenderTargetFlag _oldRenderTargetFlag; Image* _UITextureImage = nullptr; - Texture2D::PixelFormat _pixelFormat = Texture2D::PixelFormat::RGBA8888; + backend::PixelFormat _pixelFormat = backend::PixelFormat::RGBA8888; Color4F _clearColor; float _clearDepth = 1.f; diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index e0e67987f1..c9792b1fa2 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -307,26 +307,26 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dict, const std:: } Texture2D *texture = nullptr; - static std::unordered_map pixelFormats = { - {"RGBA8888", Texture2D::PixelFormat::RGBA8888}, - {"RGBA4444", Texture2D::PixelFormat::RGBA4444}, - {"RGB5A1", Texture2D::PixelFormat::RGB5A1}, - {"RGBA5551", Texture2D::PixelFormat::RGB5A1}, - {"RGB565", Texture2D::PixelFormat::RGB565}, - {"A8", Texture2D::PixelFormat::A8}, - {"ALPHA", Texture2D::PixelFormat::A8}, - {"I8", Texture2D::PixelFormat::I8}, - {"AI88", Texture2D::PixelFormat::AI88}, - {"ALPHA_INTENSITY", Texture2D::PixelFormat::AI88}, - //{"BGRA8888", Texture2D::PixelFormat::BGRA8888}, no Image conversion RGBA -> BGRA - {"RGB888", Texture2D::PixelFormat::RGB888} + static std::unordered_map pixelFormats = { + {"RGBA8888", backend::PixelFormat::RGBA8888}, + {"RGBA4444", backend::PixelFormat::RGBA4444}, + {"RGB5A1", backend::PixelFormat::RGB5A1}, + {"RGBA5551", backend::PixelFormat::RGB5A1}, + {"RGB565", backend::PixelFormat::RGB565}, + {"A8", backend::PixelFormat::A8}, + {"ALPHA", backend::PixelFormat::A8}, + {"I8", backend::PixelFormat::I8}, + {"AI88", backend::PixelFormat::AI88}, + {"ALPHA_INTENSITY", backend::PixelFormat::AI88}, + //{"BGRA8888", backend::PixelFormat::BGRA8888}, no Image conversion RGBA -> BGRA + {"RGB888", backend::PixelFormat::RGB888} }; auto pixelFormatIt = pixelFormats.find(pixelFormatName); if (pixelFormatIt != pixelFormats.end()) { - const Texture2D::PixelFormat pixelFormat = (*pixelFormatIt).second; - const Texture2D::PixelFormat currentPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); + const backend::PixelFormat pixelFormat = (*pixelFormatIt).second; + const backend::PixelFormat currentPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(pixelFormat); texture = Director::getInstance()->getTextureCache()->addImage(texturePath); Texture2D::setDefaultAlphaPixelFormat(currentPixelFormat); diff --git a/cocos/2d/CCTransition.cpp b/cocos/2d/CCTransition.cpp index 0f1cef4c35..50ceddd665 100644 --- a/cocos/2d/CCTransition.cpp +++ b/cocos/2d/CCTransition.cpp @@ -1317,7 +1317,7 @@ void TransitionCrossFade::onEnter() LayerColor* layer = LayerColor::create(color); // create the first render texture for inScene - RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888, TextureFormat::D24S8); + RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8888, PixelFormat::D24S8); if (nullptr == inTexture) { @@ -1334,7 +1334,7 @@ void TransitionCrossFade::onEnter() inTexture->end(); // create the second render texture for outScene - RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888, TextureFormat::D24S8); + RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8888, PixelFormat::D24S8); outTexture->getSprite()->setAnchorPoint( Vec2(0.5f,0.5f) ); outTexture->setPosition(size.width/2, size.height/2); outTexture->setAnchorPoint( Vec2(0.5f,0.5f) ); diff --git a/cocos/2d/CCTransitionProgress.cpp b/cocos/2d/CCTransitionProgress.cpp index 8e5b469aa8..ce545f0729 100644 --- a/cocos/2d/CCTransitionProgress.cpp +++ b/cocos/2d/CCTransitionProgress.cpp @@ -72,7 +72,7 @@ void TransitionProgress::onEnter() Size size = Director::getInstance()->getWinSize(); // create the second render texture for outScene - RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888, backend::TextureFormat::D24S8); + RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8888, backend::PixelFormat::D24S8); texture->getSprite()->setAnchorPoint(Vec2(0.5f,0.5f)); texture->setPosition(size.width/2, size.height/2); texture->setAnchorPoint(Vec2(0.5f,0.5f)); diff --git a/cocos/3d/CCTerrain.cpp b/cocos/3d/CCTerrain.cpp index 30a0523ab6..5b98eed56a 100644 --- a/cocos/3d/CCTerrain.cpp +++ b/cocos/3d/CCTerrain.cpp @@ -370,13 +370,13 @@ float Terrain::getImageHeight(int pixel_x, int pixel_y) const int byte_stride = 1; switch (_heightMapImage->getPixelFormat()) { - case Texture2D::PixelFormat::BGRA8888: + case backend::PixelFormat::BGRA8888: byte_stride = 4; break; - case Texture2D::PixelFormat::RGB888: + case backend::PixelFormat::RGB888: byte_stride = 3; break; - case Texture2D::PixelFormat::I8: + case backend::PixelFormat::I8: byte_stride = 1; break; default: diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 484b45fcc6..67e6f327bd 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -223,11 +223,11 @@ void Director::setDefaultValues(void) // Default pixel format for PNG images with alpha std::string pixel_format = conf->getValue("cocos2d.x.texture.pixel_format_for_png", Value("rgba8888")).asString(); if (pixel_format == "rgba8888") - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888); else if(pixel_format == "rgba4444") - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4444); else if(pixel_format == "rgba5551") - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1); // PVR v2 has alpha premultiplied ? bool pvr_alpha_premultiplied = conf->getValue("cocos2d.x.texture.pvrv2_has_alpha_premultiplied", Value(false)).asBool(); @@ -1250,8 +1250,8 @@ void Director::createStatsLabel() FileUtils::getInstance()->purgeCachedEntries(); } - Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat(); - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); + backend::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat(); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4444); unsigned char *data = nullptr; ssize_t dataLength = 0; getFPSImageData(&data, &dataLength); diff --git a/cocos/base/CCNinePatchImageParser.cpp b/cocos/base/CCNinePatchImageParser.cpp index a594809876..bbde91b47f 100644 --- a/cocos/base/CCNinePatchImageParser.cpp +++ b/cocos/base/CCNinePatchImageParser.cpp @@ -48,7 +48,7 @@ NinePatchImageParser::NinePatchImageParser(Image* image) ,_isRotated(false) { this->_imageFrame = Rect(0,0,image->getWidth(), image->getHeight()); - CCASSERT(image->getPixelFormat()==Texture2D::PixelFormat::RGBA8888, + CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); } @@ -57,7 +57,7 @@ NinePatchImageParser::NinePatchImageParser(Image* image, const Rect& frame, bool ,_imageFrame(frame) ,_isRotated(rotated) { - CCASSERT(image->getPixelFormat()==Texture2D::PixelFormat::RGBA8888, + CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); } @@ -192,7 +192,7 @@ Rect NinePatchImageParser::parseCapInset() const void NinePatchImageParser::setSpriteFrameInfo(Image* image, const cocos2d::Rect& frameRect, bool rotated ) { this->_image = image; - CCASSERT(image->getPixelFormat()==Texture2D::PixelFormat::RGBA8888, + CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); this->_imageFrame = frameRect; this->_isRotated = rotated; diff --git a/cocos/base/ccTypes.h b/cocos/base/ccTypes.h index a6ae73a2f9..e5a62e68ba 100644 --- a/cocos/base/ccTypes.h +++ b/cocos/base/ccTypes.h @@ -653,10 +653,8 @@ enum class RenderTargetFlag : uint8_t ALL = COLOR | DEPTH | STENCIL }; ENABLE_BITMASK_OPERATORS(RenderTargetFlag) - -// export backend types to cocos2d namespance -using TextureFormat = backend::TextureFormat; using TextureUsage = backend::TextureUsage; +using PixelFormat = backend::PixelFormat; NS_CC_END // end group diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 9adee535cd..66e7d06fdf 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -181,7 +181,7 @@ void captureNode(Node* startNode, std::function imageCallback, flo RenderTexture* finalRtx = nullptr; - auto rtx = RenderTexture::create(size.width, size.height, Texture2D::PixelFormat::RGBA8888, TextureFormat::D24S8); + auto rtx = RenderTexture::create(size.width, size.height, backend::PixelFormat::RGBA8888, PixelFormat::D24S8); // rtx->setKeepMatrix(true); Point savedPos = startNode->getPosition(); Point anchor; @@ -204,7 +204,7 @@ void captureNode(Node* startNode, std::function imageCallback, flo #ifndef CC_USE_METAL sprite->setFlippedY(true); #endif - finalRtx = RenderTexture::create(size.width * scale, size.height * scale, Texture2D::PixelFormat::RGBA8888, TextureFormat::D24S8); + finalRtx = RenderTexture::create(size.width * scale, size.height * scale, backend::PixelFormat::RGBA8888, PixelFormat::D24S8); sprite->setScale(scale); // or use finalRtx->setKeepMatrix(true); finalRtx->begin(); diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 5dba76e014..3b6b82f2a9 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -215,47 +215,47 @@ namespace // v2 - typedef const std::map _pixel2_formathash; + typedef const std::map _pixel2_formathash; static const _pixel2_formathash::value_type v2_pixel_formathash_value[] = { - _pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, Texture2D::PixelFormat::A8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, Texture2D::PixelFormat::I8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, Texture2D::PixelFormat::AI88), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, backend::PixelFormat::BGRA8888), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, backend::PixelFormat::RGBA8888), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, backend::PixelFormat::RGBA4444), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, backend::PixelFormat::RGB5A1), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, backend::PixelFormat::RGB565), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, backend::PixelFormat::RGB888), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, backend::PixelFormat::A8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, backend::PixelFormat::I8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, backend::PixelFormat::AI88), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, backend::PixelFormat::PVRTC2A), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, backend::PixelFormat::PVRTC4A), }; static const int PVR2_MAX_TABLE_ELEMENTS = sizeof(v2_pixel_formathash_value) / sizeof(v2_pixel_formathash_value[0]); static const _pixel2_formathash v2_pixel_formathash(v2_pixel_formathash_value, v2_pixel_formathash_value + PVR2_MAX_TABLE_ELEMENTS); // v3 - typedef const std::map _pixel3_formathash; + typedef const std::map _pixel3_formathash; static _pixel3_formathash::value_type v3_pixel_formathash_value[] = { - _pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, Texture2D::PixelFormat::A8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, Texture2D::PixelFormat::I8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, Texture2D::PixelFormat::AI88), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, backend::PixelFormat::BGRA8888), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, backend::PixelFormat::RGBA8888), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, backend::PixelFormat::RGBA4444), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, backend::PixelFormat::RGB5A1), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, backend::PixelFormat::RGB565), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, backend::PixelFormat::RGB888), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, backend::PixelFormat::A8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, backend::PixelFormat::I8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, backend::PixelFormat::AI88), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, Texture2D::PixelFormat::PVRTC2), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, Texture2D::PixelFormat::PVRTC4), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, backend::PixelFormat::PVRTC2), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, backend::PixelFormat::PVRTC2A), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, backend::PixelFormat::PVRTC4), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, backend::PixelFormat::PVRTC4A), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, Texture2D::PixelFormat::ETC), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, backend::PixelFormat::ETC), }; static const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3_pixel_formathash_value) / sizeof(v3_pixel_formathash_value[0]); @@ -455,22 +455,22 @@ namespace #endif //CC_USE_PNG } -Texture2D::PixelFormat getDevicePixelFormat(Texture2D::PixelFormat format) +backend::PixelFormat getDevicePixelFormat(backend::PixelFormat format) { switch (format) { - case Texture2D::PixelFormat::PVRTC4: - case Texture2D::PixelFormat::PVRTC4A: - case Texture2D::PixelFormat::PVRTC2: - case Texture2D::PixelFormat::PVRTC2A: + case backend::PixelFormat::PVRTC4: + case backend::PixelFormat::PVRTC4A: + case backend::PixelFormat::PVRTC2: + case backend::PixelFormat::PVRTC2A: if(Configuration::getInstance()->supportsPVRTC()) return format; else - return Texture2D::PixelFormat::RGBA8888; - case Texture2D::PixelFormat::ETC: + return backend::PixelFormat::RGBA8888; + case backend::PixelFormat::ETC: if(Configuration::getInstance()->supportsETC()) return format; else - return Texture2D::PixelFormat::RGB888; + return backend::PixelFormat::RGB888; default: return format; } @@ -488,7 +488,7 @@ Image::Image() , _height(0) , _unpack(false) , _fileType(Format::UNKNOWN) -, _pixelFormat(Texture2D::PixelFormat::NONE) +, _pixelFormat(backend::PixelFormat::NONE) , _numberOfMipmaps(0) , _hasPremultipliedAlpha(false) { @@ -875,11 +875,11 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) // we only support RGB or grayscale if (cinfo.jpeg_color_space == JCS_GRAYSCALE) { - _pixelFormat = Texture2D::PixelFormat::I8; + _pixelFormat = backend::PixelFormat::I8; }else { cinfo.out_color_space = JCS_RGB; - _pixelFormat = Texture2D::PixelFormat::RGB888; + _pixelFormat = backend::PixelFormat::RGB888; } /* Start decompression jpeg here */ @@ -1003,16 +1003,16 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) switch (color_type) { case PNG_COLOR_TYPE_GRAY: - _pixelFormat = Texture2D::PixelFormat::I8; + _pixelFormat = backend::PixelFormat::I8; break; case PNG_COLOR_TYPE_GRAY_ALPHA: - _pixelFormat = Texture2D::PixelFormat::AI88; + _pixelFormat = backend::PixelFormat::AI88; break; case PNG_COLOR_TYPE_RGB: - _pixelFormat = Texture2D::PixelFormat::RGB888; + _pixelFormat = backend::PixelFormat::RGB888; break; case PNG_COLOR_TYPE_RGB_ALPHA: - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; break; default: break; @@ -1211,7 +1211,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) npixels = w * h; - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; _width = w; _height = h; @@ -1635,7 +1635,7 @@ bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen) { //old opengl version has no define for GL_ETC1_RGB8_OES, add macro to make compiler happy. #ifdef GL_ETC1_RGB8_OES - _pixelFormat = Texture2D::PixelFormat::ETC; + _pixelFormat = backend::PixelFormat::ETC; _dataLen = dataLen - ETC_PKM_HEADER_SIZE; _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); memcpy(_data, static_cast(data) + ETC_PKM_HEADER_SIZE, _dataLen); @@ -1651,7 +1651,7 @@ bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen) //if it is not gles or device do not support ETC, decode texture by software int bytePerPixel = 3; unsigned int stride = _width * bytePerPixel; - _pixelFormat = Texture2D::PixelFormat::RGB888; + _pixelFormat = backend::PixelFormat::RGB888; _dataLen = _width * _height * bytePerPixel; _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); @@ -1686,15 +1686,15 @@ bool Image::initWithTGAData(tImageTGA* tgaData) // unsupported RGB555 if (tgaData->pixelDepth == 16) { - _pixelFormat = Texture2D::PixelFormat::RGB5A1; + _pixelFormat = backend::PixelFormat::RGB5A1; } else if(tgaData->pixelDepth == 24) { - _pixelFormat = Texture2D::PixelFormat::RGB888; + _pixelFormat = backend::PixelFormat::RGB888; } else if(tgaData->pixelDepth == 32) { - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; } else { @@ -1707,7 +1707,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData) // gray if (8 == tgaData->pixelDepth) { - _pixelFormat = Texture2D::PixelFormat::I8; + _pixelFormat = backend::PixelFormat::I8; } else { @@ -1805,18 +1805,18 @@ bool Image::initWithS3TCData(const unsigned char * data, ssize_t dataLen) if (FOURCC_DXT1 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC) { - _pixelFormat = Texture2D::PixelFormat::S3TC_DXT1; + _pixelFormat = backend::PixelFormat::S3TC_DXT1; } else if (FOURCC_DXT3 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC) { - _pixelFormat = Texture2D::PixelFormat::S3TC_DXT3; + _pixelFormat = backend::PixelFormat::S3TC_DXT3; } else if (FOURCC_DXT5 == header->ddsd.DUMMYUNIONNAMEN4.ddpfPixelFormat.fourCC) { - _pixelFormat = Texture2D::PixelFormat::S3TC_DXT5; + _pixelFormat = backend::PixelFormat::S3TC_DXT5; } } else { //will software decode - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; } /* load the mipmaps */ @@ -1954,13 +1954,13 @@ bool Image::initWithATITCData(const unsigned char *data, ssize_t dataLen) switch (header->glInternalFormat) { case CC_GL_ATC_RGB_AMD: - _pixelFormat = Texture2D::PixelFormat::ATC_RGB; + _pixelFormat = backend::PixelFormat::ATC_RGB; break; case CC_GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: - _pixelFormat = Texture2D::PixelFormat::ATC_EXPLICIT_ALPHA; + _pixelFormat = backend::PixelFormat::ATC_EXPLICIT_ALPHA; break; case CC_GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: - _pixelFormat = Texture2D::PixelFormat::ATC_INTERPOLATED_ALPHA; + _pixelFormat = backend::PixelFormat::ATC_INTERPOLATED_ALPHA; break; default: break; @@ -1977,7 +1977,7 @@ bool Image::initWithATITCData(const unsigned char *data, ssize_t dataLen) int bytePerPixel = 4; unsigned int stride = width * bytePerPixel; - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; std::vector decodeImageData(stride * height); switch (header->glInternalFormat) @@ -2028,7 +2028,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) if (config.input.width == 0 || config.input.height == 0) break; config.output.colorspace = config.input.has_alpha?MODE_rgbA:MODE_RGB; - _pixelFormat = config.input.has_alpha?Texture2D::PixelFormat::RGBA8888:Texture2D::PixelFormat::RGB888; + _pixelFormat = config.input.has_alpha?backend::PixelFormat::RGBA8888:backend::PixelFormat::RGB888; _width = config.input.width; _height = config.input.height; @@ -2070,7 +2070,7 @@ bool Image::initWithRawData(const unsigned char * data, ssize_t /*dataLen*/, int _height = height; _width = width; _hasPremultipliedAlpha = preMulti; - _pixelFormat = Texture2D::PixelFormat::RGBA8888; + _pixelFormat = backend::PixelFormat::RGBA8888; // only RGBA8888 supported int bytesPerComponent = 4; @@ -2089,10 +2089,10 @@ bool Image::initWithRawData(const unsigned char * data, ssize_t /*dataLen*/, int #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) bool Image::saveToFile(const std::string& filename, bool isToRGB) { - //only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data - if (isCompressed() || (_pixelFormat != Texture2D::PixelFormat::RGB888 && _pixelFormat != Texture2D::PixelFormat::RGBA8888)) + //only support for backend::PixelFormat::RGB888 or backend::PixelFormat::RGBA8888 uncompressed data + if (isCompressed() || (_pixelFormat != backend::PixelFormat::RGB888 && _pixelFormat != backend::PixelFormat::RGBA8888)) { - CCLOG("cocos2d: Image: saveToFile is only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data for now"); + CCLOG("cocos2d: Image: saveToFile is only support for backend::PixelFormat::RGB888 or backend::PixelFormat::RGBA8888 uncompressed data for now"); return false; } @@ -2347,7 +2347,7 @@ void Image::premultipliedAlpha() _hasPremultipliedAlpha = false; return; #else - CCASSERT(_pixelFormat == Texture2D::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!"); + CCASSERT(_pixelFormat == backend::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!"); unsigned int* fourBytes = (unsigned int*)_data; for(int i = 0; i < _width * _height; i++) diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index 303d16e2b7..a83bae80e1 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -136,7 +136,7 @@ public: unsigned char * getData() { return _data; } ssize_t getDataLen() { return _dataLen; } Format getFileType() { return _fileType; } - Texture2D::PixelFormat getPixelFormat() { return _pixelFormat; } + backend::PixelFormat getPixelFormat() { return _pixelFormat; } int getWidth() { return _width; } int getHeight() { return _height; } int getNumberOfMipmaps() { return _numberOfMipmaps; } @@ -191,7 +191,7 @@ protected: int _height; bool _unpack; Format _fileType; - Texture2D::PixelFormat _pixelFormat; + backend::PixelFormat _pixelFormat; MipmapInfo _mipmaps[MIPMAP_MAX]; // pointer to mipmap images int _numberOfMipmaps; // false if we can't auto detect the image is premultiplied or not. diff --git a/cocos/platform/ios/CCImage-ios.mm b/cocos/platform/ios/CCImage-ios.mm index 2e73553d8d..0571dc857e 100644 --- a/cocos/platform/ios/CCImage-ios.mm +++ b/cocos/platform/ios/CCImage-ios.mm @@ -40,10 +40,10 @@ NS_CC_BEGIN bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB) { - //only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data - if (isCompressed() || (_pixelFormat != Texture2D::PixelFormat::RGB888 && _pixelFormat != Texture2D::PixelFormat::RGBA8888)) + //only support for backend::PixelFormat::RGB888 or backend::PixelFormat::RGBA8888 uncompressed data + if (isCompressed() || (_pixelFormat != backend::PixelFormat::RGB888 && _pixelFormat != backend::PixelFormat::RGBA8888)) { - CCLOG("cocos2d: Image: saveToFile is only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data for now"); + CCLOG("cocos2d: Image: saveToFile is only support for backend::PixelFormat::RGB888 or backend::PixelFormat::RGBA8888 uncompressed data for now"); return false; } bool saveToPNG = false; diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index 2a0c6796a0..5a5c724710 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -758,9 +758,9 @@ backend::RenderPipeline* Renderer::getRenderPipeline(const backend::RenderPipeli { void* program; unsigned int vertexLayoutInfo[32]; - backend::TextureFormat colorAttachment; - backend::TextureFormat depthAttachment; - backend::TextureFormat stencilAttachment; + backend::PixelFormat colorAttachment; + backend::PixelFormat depthAttachment; + backend::PixelFormat stencilAttachment; bool blendEnabled; unsigned int writeMask; unsigned int rgbBlendOperation; @@ -850,7 +850,7 @@ void Renderer::setRenderPipeline(const PipelineDescriptor& pipelineDescriptor, c } else { - renderPipelineDescriptor.depthAttachmentFormat = TextureFormat::D24S8; + renderPipelineDescriptor.depthAttachmentFormat = PixelFormat::D24S8; } if (renderPassDescriptor.stencilAttachmentTexture) @@ -859,7 +859,7 @@ void Renderer::setRenderPipeline(const PipelineDescriptor& pipelineDescriptor, c } else { - renderPipelineDescriptor.stencilAttachmentFormat = TextureFormat::D24S8; + renderPipelineDescriptor.stencilAttachmentFormat = PixelFormat::D24S8; } } diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index faa1e70c9d..c1b0074239 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -44,7 +44,6 @@ THE SOFTWARE. #include "base/CCDirector.h" #include "base/CCNinePatchImageParser.h" #include "renderer/backend/Device.h" -#include "renderer/backend/StringUtils.h" #include "renderer/backend/ProgramState.h" #include "renderer/ccShaders.h" #include "renderer/CCTextureUtils.h" @@ -62,127 +61,72 @@ namespace { typedef Texture2D::PixelFormatInfoMap::value_type PixelFormatInfoMapValue; static const PixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] = { - PixelFormatInfoMapValue(Texture2D::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA4444, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB5A1, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB565, Texture2D::PixelFormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, false, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB888, Texture2D::PixelFormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 24, false, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::A8, Texture2D::PixelFormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 8, false, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::I8, Texture2D::PixelFormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, false, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::AI88, Texture2D::PixelFormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 16, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::RGBA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::RGBA4444, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::RGB5A1, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::RGB565, Texture2D::PixelFormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 16, false, false)), + PixelFormatInfoMapValue(backend::PixelFormat::RGB888, Texture2D::PixelFormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 24, false, false)), + PixelFormatInfoMapValue(backend::PixelFormat::A8, Texture2D::PixelFormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 8, false, false)), + PixelFormatInfoMapValue(backend::PixelFormat::I8, Texture2D::PixelFormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 8, false, false)), + PixelFormatInfoMapValue(backend::PixelFormat::AI88, Texture2D::PixelFormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 16, false, true)), #ifndef CC_USE_METAL //OpenGL only #ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC2, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC2A, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC4, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC4A, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC2, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC2A, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, true)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC4, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC4A, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true)), #endif #else //Metal && iOS #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC2, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC2A, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC4, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::PVRTC4A, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC2, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC2A, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 2, true, true)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC4, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::PVRTC4A, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, true)), #endif #endif #ifdef GL_ETC1_RGB8_OES - PixelFormatInfoMapValue(Texture2D::PixelFormat::ETC, Texture2D::PixelFormatInfo(GL_ETC1_RGB8_OES, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::ETC, Texture2D::PixelFormatInfo(GL_ETC1_RGB8_OES, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT - PixelFormatInfoMapValue(Texture2D::PixelFormat::S3TC_DXT1, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::S3TC_DXT1, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT - PixelFormatInfoMapValue(Texture2D::PixelFormat::S3TC_DXT3, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::S3TC_DXT3, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT - PixelFormatInfoMapValue(Texture2D::PixelFormat::S3TC_DXT5, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), + PixelFormatInfoMapValue(backend::PixelFormat::S3TC_DXT5, Texture2D::PixelFormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), #endif #ifdef GL_ATC_RGB_AMD - PixelFormatInfoMapValue(Texture2D::PixelFormat::ATC_RGB, Texture2D::PixelFormatInfo(GL_ATC_RGB_AMD, + PixelFormatInfoMapValue(backend::PixelFormat::ATC_RGB, Texture2D::PixelFormatInfo(GL_ATC_RGB_AMD, 0xFFFFFFFF, 0xFFFFFFFF, 4, true, false)), #endif #ifdef GL_ATC_RGBA_EXPLICIT_ALPHA_AMD - PixelFormatInfoMapValue(Texture2D::PixelFormat::ATC_EXPLICIT_ALPHA, Texture2D::PixelFormatInfo(GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, + PixelFormatInfoMapValue(backend::PixelFormat::ATC_EXPLICIT_ALPHA, Texture2D::PixelFormatInfo(GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), #endif #ifdef GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD - PixelFormatInfoMapValue(Texture2D::PixelFormat::ATC_INTERPOLATED_ALPHA, Texture2D::PixelFormatInfo(GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, + PixelFormatInfoMapValue(backend::PixelFormat::ATC_INTERPOLATED_ALPHA, Texture2D::PixelFormatInfo(GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, 0xFFFFFFFF, 0xFFFFFFFF, 8, true, false)), #endif //metal formats #ifdef CC_USE_METAL #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - PixelFormatInfoMapValue(Texture2D::PixelFormat::MTL_ABGR4, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 16, false, true)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::MTL_B5G6R5, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 16, false, false)), - PixelFormatInfoMapValue(Texture2D::PixelFormat::MTL_BGR5A1, Texture2D::PixelFormatInfo(0xFFFFFFFF,0xFFFFFFFF, 0xFFFFFFFF, 16, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::MTL_ABGR4, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 16, false, true)), + PixelFormatInfoMapValue(backend::PixelFormat::MTL_B5G6R5, Texture2D::PixelFormatInfo(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 16, false, false)), + PixelFormatInfoMapValue(backend::PixelFormat::MTL_BGR5A1, Texture2D::PixelFormatInfo(0xFFFFFFFF,0xFFFFFFFF, 0xFFFFFFFF, 16, false, true)), #endif #endif }; - - backend::SamplerFilter GLToBackendMagFilter(GLint magFilter) - { - switch (magFilter) - { - case GL_LINEAR: - return backend::SamplerFilter::LINEAR; - case GL_NEAREST: - return backend::SamplerFilter::NEAREST; - default: - return backend::SamplerFilter::LINEAR; - } - } - - - GLint toGLAddressMode(backend::SamplerAddressMode addressMode, bool isPow2) - { - GLint ret = GL_REPEAT; - if (!isPow2 && (addressMode != backend::SamplerAddressMode::CLAMP_TO_EDGE)) - { - cocos2d::log("Change texture wrap mode to CLAMP_TO_EDGE since non-power-of-two texture occur in %s %s %d", __FILE__, __FUNCTION__, __LINE__); - return GL_CLAMP_TO_EDGE; - } - - switch (addressMode) - { - case backend::SamplerAddressMode::REPEAT: - ret = GL_REPEAT; - break; - case backend::SamplerAddressMode::MIRROR_REPEAT: - ret = GL_MIRRORED_REPEAT; - break; - case backend::SamplerAddressMode::CLAMP_TO_EDGE: - ret = GL_CLAMP_TO_EDGE; - break; - default: - break; - } - return ret; - } - - backend::SamplerAddressMode GLToBackendAddressMode(int addressMode) - { - switch (addressMode) - { - case GL_REPEAT: - return backend::SamplerAddressMode::REPEAT; - case GL_MIRRORED_REPEAT: - return backend::SamplerAddressMode::MIRROR_REPEAT; - case GL_CLAMP_TO_EDGE: - return backend::SamplerAddressMode::CLAMP_TO_EDGE; - default: - return backend::SamplerAddressMode::REPEAT; - } - } } //CLASS IMPLEMENTATIONS: @@ -193,11 +137,11 @@ const Texture2D::PixelFormatInfoMap Texture2D::_pixelFormatInfoTables(TexturePix // If the image has alpha, you can create RGBA8 (32-bit) or RGBA4 (16-bit) or RGB5A1 (16-bit) // Default is: RGBA8888 (32-bit textures) -static Texture2D::PixelFormat g_defaultAlphaPixelFormat = Texture2D::PixelFormat::DEFAULT; +static backend::PixelFormat g_defaultAlphaPixelFormat = backend::PixelFormat::DEFAULT; Texture2D::Texture2D() -: _pixelFormat(Texture2D::PixelFormat::DEFAULT) +: _pixelFormat(backend::PixelFormat::DEFAULT) , _pixelsWide(0) , _pixelsHigh(0) , _maxS(0.0) @@ -210,7 +154,7 @@ Texture2D::Texture2D() , _alphaTexture(nullptr) { backend::TextureDescriptor textureDescriptor; - textureDescriptor.textureFormat = TextureFormat::NONE; + textureDescriptor.textureFormat = PixelFormat::NONE; _texture = static_cast(backend::Device::getInstance()->newTexture(textureDescriptor)); } @@ -229,7 +173,7 @@ Texture2D::~Texture2D() CC_SAFE_RELEASE(_programState); } -Texture2D::PixelFormat Texture2D::getPixelFormat() const +backend::PixelFormat Texture2D::getPixelFormat() const { return _pixelFormat; } @@ -293,7 +237,7 @@ bool Texture2D::hasPremultipliedAlpha() const return _hasPremultipliedAlpha; } -bool Texture2D::initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, Texture2D::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& /*contentSize*/) +bool Texture2D::initWithData(const void *data, ssize_t dataLen, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& /*contentSize*/) { CCASSERT(dataLen>0 && pixelsWide>0 && pixelsHigh>0, "Invalid size"); @@ -304,7 +248,7 @@ bool Texture2D::initWithData(const void *data, ssize_t dataLen, Texture2D::Pixel return initWithMipmaps(&mipmap, 1, pixelFormat, renderFormat, pixelsWide, pixelsHigh); } -bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat pixelFormat, PixelFormat renderFormat, int pixelsWide, int pixelsHigh) +bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh) { //the pixelFormat must be a certain value CCASSERT(pixelFormat != PixelFormat::NONE && pixelFormat != PixelFormat::AUTO, "the \"pixelFormat\" param must be a certain value!"); @@ -345,45 +289,64 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat backend::TextureDescriptor textureDescriptor; textureDescriptor.width = pixelsWide; textureDescriptor.height = pixelsHigh; - textureDescriptor.samplerDescriptor.minFilter = (_antialiasEnabled) ? backend::SamplerFilter::LINEAR : backend::SamplerFilter::NEAREST; textureDescriptor.samplerDescriptor.magFilter = (_antialiasEnabled) ? backend::SamplerFilter::LINEAR : backend::SamplerFilter::NEAREST; - if (mipmapsNum > 1) + if (mipmapsNum == 1) { - textureDescriptor.samplerDescriptor.mipmapFilter = backend::SamplerFilter::NEAREST; + textureDescriptor.samplerDescriptor.minFilter = (_antialiasEnabled) ? backend::SamplerFilter::LINEAR : backend::SamplerFilter::NEAREST; + } + else + { + textureDescriptor.samplerDescriptor.minFilter = (_antialiasEnabled) ? backend::SamplerFilter::LINEAR_MIPMAP_NEAREST : backend::SamplerFilter::NEAREST_MIPMAP_NEAREST; } - unsigned char *data = mipmaps[0].address; - - size_t dataLen = mipmaps[0].len; - unsigned char *outData = data; - size_t outDataLen; - - if(renderFormat != pixelFormat) //need conversion + int width = pixelsWide; + int height = pixelsHigh; + backend::PixelFormat oriPixelFormat = pixelFormat; + for (int i = 0; i < mipmapsNum; ++i) { - auto convertedFormat = backend::PixelFormatUtils::convertDataToFormat(data, dataLen, pixelFormat, renderFormat, &outData, &outDataLen); + unsigned char *data = mipmaps[i].address; + size_t dataLen = mipmaps[i].len; + unsigned char *outData = data; + size_t outDataLen = dataLen; + + if(renderFormat != oriPixelFormat && !info.compressed) //need conversion + { + auto convertedFormat = backend::PixelFormatUtils::convertDataToFormat(data, dataLen, oriPixelFormat, renderFormat, &outData, &outDataLen); #ifdef CC_USE_METAL - CCASSERT(convertedFormat == renderFormat, "PixelFormat convert failed!"); + CCASSERT(convertedFormat == renderFormat, "PixelFormat convert failed!"); #endif - if(convertedFormat == renderFormat) pixelFormat = renderFormat; - } + if(convertedFormat == renderFormat) pixelFormat = renderFormat; + } + + textureDescriptor.textureFormat = pixelFormat; + CCASSERT(textureDescriptor.textureFormat != backend::PixelFormat::NONE, "PixelFormat should not be NONE"); - backend::StringUtils::PixelFormat format = static_cast(pixelFormat); - CCASSERT(format != backend::StringUtils::PixelFormat::NONE, "PixelFormat should not be NONE"); - - textureDescriptor.textureFormat = backend::StringUtils::PixelFormat2TextureFormat(format); - CCASSERT(textureDescriptor.textureFormat != backend::TextureFormat::NONE, "TextureFormat should not be NONE"); - - textureDescriptor.compressed = info.compressed; + if(_texture->getTextureFormat() != textureDescriptor.textureFormat) + _texture->updateTextureDescriptor(textureDescriptor); - if(_texture->getTextureFormat() != textureDescriptor.textureFormat) - _texture->updateTextureDescriptor(textureDescriptor); + if(info.compressed) + { + _texture->updateCompressedData(data, width, height, dataLen, i); + } + else + { + _texture->updateData(outData, width, height, i); + } - _texture->updateData(outData); - if(outData && outData != data && outDataLen > 0) - { - free(outData); - outData = nullptr; - outDataLen = 0; + if(outData && outData != data && outDataLen > 0) + { + free(outData); + outData = nullptr; + outDataLen = 0; + } + + if (i > 0 && (width != height || ccNextPOT(width) != width )) + { + CCLOG("cocos2d: Texture2D. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%d != height=%d", i, width, height); + } + + width = MAX(width >> 1, 1); + height = MAX(height >> 1, 1); } _contentSize = Size((float)pixelsWide, (float)pixelsHigh); @@ -404,7 +367,7 @@ bool Texture2D::updateWithData(void *data,int offsetX,int offsetY,int width,int if (_texture && width > 0 && height > 0) { uint8_t* textureData = static_cast(data); - _texture->updateSubData(offsetX, offsetY, width, height, textureData); + _texture->updateSubData(offsetX, offsetY, width, height, 0, textureData); return true; } return false; @@ -416,7 +379,7 @@ bool Texture2D::initWithImage(Image *image) return initWithImage(image, g_defaultAlphaPixelFormat); } -bool Texture2D::initWithImage(Image *image, PixelFormat format) +bool Texture2D::initWithImage(Image *image, backend::PixelFormat format) { if (image == nullptr) { @@ -438,8 +401,8 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) unsigned char* tempData = image->getData(); Size imageSize = Size((float)imageWidth, (float)imageHeight); - PixelFormat renderFormat = ((PixelFormat::NONE == format) || (PixelFormat::AUTO == format)) ? image->getPixelFormat() : format; - PixelFormat imagePixelFormat = image->getPixelFormat(); + backend::PixelFormat renderFormat = ((PixelFormat::NONE == format) || (PixelFormat::AUTO == format)) ? image->getPixelFormat() : format; + backend::PixelFormat imagePixelFormat = image->getPixelFormat(); size_t tempDataLen = image->getDataLen(); @@ -635,18 +598,24 @@ bool Texture2D::initWithBackendTexture(backend::Texture *texture) bool Texture2D::hasMipmaps() const { - return _hasMipmaps; + return _texture->hasMipmaps(); } void Texture2D::setAliasTexParameters() { - backend::SamplerDescriptor descriptor(false, - backend::SamplerFilter::NEAREST, - backend::SamplerFilter::NEAREST, - backend::SamplerFilter::NEAREST, - backend::SamplerAddressMode::DONT_CARE, - backend::SamplerAddressMode::DONT_CARE + if (! _antialiasEnabled) + { + return; + } + + _antialiasEnabled = false; + + backend::SamplerDescriptor descriptor( + backend::SamplerFilter::NEAREST, //magFilter + (_texture->hasMipmaps()) ? backend::SamplerFilter::NEAREST_MIPMAP_NEAREST : backend::SamplerFilter::NEAREST, //minFilter + backend::SamplerAddressMode::DONT_CARE, //sAddressMode + backend::SamplerAddressMode::DONT_CARE//tAddressMode ); _texture->updateSamplerDescriptor(descriptor); } @@ -654,12 +623,17 @@ void Texture2D::setAliasTexParameters() void Texture2D::setAntiAliasTexParameters() { - backend::SamplerDescriptor descriptor(false, - backend::SamplerFilter::LINEAR, - backend::SamplerFilter::LINEAR, - backend::SamplerFilter::LINEAR, - backend::SamplerAddressMode::DONT_CARE, - backend::SamplerAddressMode::DONT_CARE + if ( _antialiasEnabled ) + { + return; + } + _antialiasEnabled = true; + + backend::SamplerDescriptor descriptor( + backend::SamplerFilter::LINEAR, //magFilter + (_texture->hasMipmaps()) ? backend::SamplerFilter::LINEAR_MIPMAP_NEAREST : backend::SamplerFilter::LINEAR, //minFilter + backend::SamplerAddressMode::DONT_CARE, //sAddressMode + backend::SamplerAddressMode::DONT_CARE //tAddressMode ); _texture->updateSamplerDescriptor(descriptor); } @@ -668,70 +642,70 @@ const char* Texture2D::getStringForFormat() const { switch (_pixelFormat) { - case Texture2D::PixelFormat::RGBA8888: + case backend::PixelFormat::RGBA8888: return "RGBA8888"; - case Texture2D::PixelFormat::RGB888: + case backend::PixelFormat::RGB888: return "RGB888"; - case Texture2D::PixelFormat::RGB565: + case backend::PixelFormat::RGB565: return "RGB565"; - case Texture2D::PixelFormat::RGBA4444: + case backend::PixelFormat::RGBA4444: return "RGBA4444"; - case Texture2D::PixelFormat::RGB5A1: + case backend::PixelFormat::RGB5A1: return "RGB5A1"; - case Texture2D::PixelFormat::AI88: + case backend::PixelFormat::AI88: return "AI88"; - case Texture2D::PixelFormat::A8: + case backend::PixelFormat::A8: return "A8"; - case Texture2D::PixelFormat::I8: + case backend::PixelFormat::I8: return "I8"; - case Texture2D::PixelFormat::PVRTC4: + case backend::PixelFormat::PVRTC4: return "PVRTC4"; - case Texture2D::PixelFormat::PVRTC2: + case backend::PixelFormat::PVRTC2: return "PVRTC2"; - case Texture2D::PixelFormat::PVRTC2A: + case backend::PixelFormat::PVRTC2A: return "PVRTC2A"; - case Texture2D::PixelFormat::PVRTC4A: + case backend::PixelFormat::PVRTC4A: return "PVRTC4A"; - case Texture2D::PixelFormat::ETC: + case backend::PixelFormat::ETC: return "ETC"; - case Texture2D::PixelFormat::S3TC_DXT1: + case backend::PixelFormat::S3TC_DXT1: return "S3TC_DXT1"; - case Texture2D::PixelFormat::S3TC_DXT3: + case backend::PixelFormat::S3TC_DXT3: return "S3TC_DXT3"; - case Texture2D::PixelFormat::S3TC_DXT5: + case backend::PixelFormat::S3TC_DXT5: return "S3TC_DXT5"; - case Texture2D::PixelFormat::ATC_RGB: + case backend::PixelFormat::ATC_RGB: return "ATC_RGB"; - case Texture2D::PixelFormat::ATC_EXPLICIT_ALPHA: + case backend::PixelFormat::ATC_EXPLICIT_ALPHA: return "ATC_EXPLICIT_ALPHA"; - case Texture2D::PixelFormat::ATC_INTERPOLATED_ALPHA: + case backend::PixelFormat::ATC_INTERPOLATED_ALPHA: return "ATC_INTERPOLATED_ALPHA"; - case Texture2D::PixelFormat::MTL_ABGR4: + case backend::PixelFormat::MTL_ABGR4: return "MTL_ABGR4"; - case Texture2D::PixelFormat::MTL_B5G6R5: + case backend::PixelFormat::MTL_B5G6R5: return "MTL_RGB565"; - case Texture2D::PixelFormat::MTL_BGR5A1: + case backend::PixelFormat::MTL_BGR5A1: return "MTL_BGR5A1"; default: @@ -748,17 +722,17 @@ const char* Texture2D::getStringForFormat() const // // implementation Texture2D (PixelFormat) -void Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat format) +void Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat format) { g_defaultAlphaPixelFormat = format; } -Texture2D::PixelFormat Texture2D::getDefaultAlphaPixelFormat() +backend::PixelFormat Texture2D::getDefaultAlphaPixelFormat() { return g_defaultAlphaPixelFormat; } -unsigned int Texture2D::getBitsPerPixelForFormat(Texture2D::PixelFormat format) const +unsigned int Texture2D::getBitsPerPixelForFormat(backend::PixelFormat format) const { if (format == PixelFormat::NONE || format == PixelFormat::DEFAULT) { @@ -860,7 +834,6 @@ void Texture2D::generateMipmap() CCASSERT(_pixelsWide == ccNextPOT(_pixelsWide) && _pixelsHigh == ccNextPOT(_pixelsHigh), "Mipmap texture only works in POT textures"); _texture->generateMipmaps(); - _hasMipmaps = true; } void Texture2D::initProgram() diff --git a/cocos/renderer/CCTexture2D.h b/cocos/renderer/CCTexture2D.h index df26add38a..5673c47c4d 100644 --- a/cocos/renderer/CCTexture2D.h +++ b/cocos/renderer/CCTexture2D.h @@ -72,66 +72,6 @@ namespace backend { class CC_DLL Texture2D : public Ref { public: - /** @typedef Texture2D::PixelFormat - Possible texture pixel formats - */ - enum class PixelFormat - { - //! auto detect the type - AUTO, - //! 32-bit texture: BGRA8888 - BGRA8888, - //! 32-bit texture: RGBA8888 - RGBA8888, - //! 24-bit texture: RGBA888 - RGB888, - //! 16-bit texture without Alpha channel - RGB565, - //! 8-bit textures used as masks - A8, - //! 8-bit intensity texture - I8, - //! 16-bit textures used as masks - AI88, - //! 16-bit textures: RGBA4444 - RGBA4444, - //! 16-bit textures: RGB5A1 - RGB5A1, - //! 4-bit PVRTC-compressed texture: PVRTC4 - PVRTC4, - //! 4-bit PVRTC-compressed texture: PVRTC4 (has alpha channel) - PVRTC4A, - //! 2-bit PVRTC-compressed texture: PVRTC2 - PVRTC2, - //! 2-bit PVRTC-compressed texture: PVRTC2 (has alpha channel) - PVRTC2A, - //! ETC-compressed texture: ETC - ETC, - //! S3TC-compressed texture: S3TC_Dxt1 - S3TC_DXT1, - //! S3TC-compressed texture: S3TC_Dxt3 - S3TC_DXT3, - //! S3TC-compressed texture: S3TC_Dxt5 - S3TC_DXT5, - //! ATITC-compressed texture: ATC_RGB - ATC_RGB, - //! ATITC-compressed texture: ATC_EXPLICIT_ALPHA - ATC_EXPLICIT_ALPHA, - //! ATITC-compressed texture: ATC_INTERPOLATED_ALPHA - ATC_INTERPOLATED_ALPHA, - //! Default texture format: AUTO - - MTL_B5G6R5, - //MTL_A1BGR5, - MTL_BGR5A1, - MTL_ABGR4, - - DEFAULT = AUTO, - - NONE = -1 - }; - - struct PixelFormatInfo { PixelFormatInfo(GLenum anInternalFormat, GLenum aFormat, GLenum aType, int aBpp, bool aCompressed, bool anAlpha) @@ -151,7 +91,7 @@ public: bool alpha; }; - typedef std::map PixelFormatInfoMap; + typedef std::map PixelFormatInfoMap; /** * Extension to set the Min / Mag filter @@ -163,12 +103,12 @@ public: @param format If the UIImage contains alpha channel, then the options are: - - 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) + - generate 32-bit textures: backend::PixelFormat::RGBA8888 (default one) + - generate 24-bit textures: backend::PixelFormat::RGB888 + - generate 16-bit textures: backend::PixelFormat::RGBA4444 + - generate 16-bit textures: backend::PixelFormat::RGB5A1 + - generate 16-bit textures: backend::PixelFormat::RGB565 + - generate 8-bit textures: backend::PixelFormat::A8 (only use it if you use just 1 color) 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) @@ -178,12 +118,12 @@ public: @since v0.8 */ - static void setDefaultAlphaPixelFormat(Texture2D::PixelFormat format); + static void setDefaultAlphaPixelFormat(backend::PixelFormat format); /** Returns the alpha pixel format. @since v0.8 */ - static Texture2D::PixelFormat getDefaultAlphaPixelFormat(); + static backend::PixelFormat getDefaultAlphaPixelFormat(); public: /** @@ -207,7 +147,7 @@ public: * @js NA * @lua NA */ - bool initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize) { return initWithData(data, dataLen, pixelFormat, pixelFormat, pixelsWide, pixelsHigh, contentSize);} + bool initWithData(const void *data, ssize_t dataLen, backend::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize) { return initWithData(data, dataLen, pixelFormat, pixelFormat, pixelsWide, pixelsHigh, contentSize);} /** Initializes with a texture2d with data. @@ -221,7 +161,7 @@ public: * @js NA * @lua NA */ - bool initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, Texture2D::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& contentSize); + bool initWithData(const void *data, ssize_t dataLen, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh, const Size& contentSize); /** Initializes with mipmaps. @@ -231,7 +171,7 @@ public: @param pixelsWide The image width. @param pixelsHigh The image height. */ - bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, Texture2D::PixelFormat renderFormat, int pixelsWide, int pixelsHigh); + bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, backend::PixelFormat pixelFormat, backend::PixelFormat renderFormat, int pixelsWide, int pixelsHigh); /** Update with texture data. @@ -271,7 +211,7 @@ public: @param image An UIImage object. @param format Texture pixel formats. **/ - bool initWithImage(Image * image, PixelFormat format); + bool initWithImage(Image * image, backend::PixelFormat format); /** Initializes a texture from a string with dimensions, alignment, font name and font size. @@ -339,7 +279,7 @@ public: /** Helper functions that returns bits per pixels for a given format. @since v2.0 */ - unsigned int getBitsPerPixelForFormat(Texture2D::PixelFormat format) const; + unsigned int getBitsPerPixelForFormat(backend::PixelFormat format) const; /** Get content size. */ const Size& getContentSizeInPixels(); @@ -351,7 +291,7 @@ public: bool hasMipmaps() const; /** Gets the pixel format of the texture. */ - Texture2D::PixelFormat getPixelFormat() const; + backend::PixelFormat getPixelFormat() const; /** Gets the width of the texture in pixels. */ int getPixelsWide() const; @@ -433,7 +373,7 @@ private: protected: /** pixel format of the texture */ - Texture2D::PixelFormat _pixelFormat; + backend::PixelFormat _pixelFormat; /** width in pixels */ int _pixelsWide; diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index 2d65a7b0b0..8160c4a338 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -101,7 +101,7 @@ public: std::string callbackKey; Image image; Image imageAlpha; - Texture2D::PixelFormat pixelFormat; + backend::PixelFormat pixelFormat; bool loadSuccess; }; @@ -718,7 +718,7 @@ VolatileTexture::VolatileTexture(Texture2D *t) , _uiImage(nullptr) , _cashedImageType(kInvalid) , _textureData(nullptr) -, _pixelFormat(Texture2D::PixelFormat::RGBA8888) +, _pixelFormat(backend::PixelFormat::RGBA8888) , _fileName("") , _text("") { @@ -777,7 +777,7 @@ VolatileTexture* VolatileTextureMgr::findVolotileTexture(Texture2D *tt) return vt; } -void VolatileTextureMgr::addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize) +void VolatileTextureMgr::addDataTexture(Texture2D *tt, void* data, int dataLen, backend::PixelFormat pixelFormat, const Size& contentSize) { if (_isReloading) { @@ -869,7 +869,7 @@ void VolatileTextureMgr::reloadAllTextures() _isReloading = false; } -void VolatileTextureMgr::reloadTexture(Texture2D* texture, const std::string& filename, Texture2D::PixelFormat pixelFormat) +void VolatileTextureMgr::reloadTexture(Texture2D* texture, const std::string& filename, backend::PixelFormat pixelFormat) { if (!texture) return; diff --git a/cocos/renderer/CCTextureCache.h b/cocos/renderer/CCTextureCache.h index b8043e6cb1..b541b5d5d5 100644 --- a/cocos/renderer/CCTextureCache.h +++ b/cocos/renderer/CCTextureCache.h @@ -257,7 +257,7 @@ protected: void *_textureData; int _dataLen; Size _textureSize; - Texture2D::PixelFormat _pixelFormat; + backend::PixelFormat _pixelFormat; std::string _fileName; @@ -270,7 +270,7 @@ class CC_DLL VolatileTextureMgr public: static void addImageTexture(Texture2D *tt, const std::string& imageFileName); static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition); - static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize); + static void addDataTexture(Texture2D *tt, void* data, int dataLen, backend::PixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); static void removeTexture(Texture2D *t); static void reloadAllTextures(); @@ -284,7 +284,7 @@ public: static VolatileTexture* findVolotileTexture(Texture2D *tt); private: - static void reloadTexture(Texture2D* texture, const std::string& filename, Texture2D::PixelFormat pixelFormat); + static void reloadTexture(Texture2D* texture, const std::string& filename, backend::PixelFormat pixelFormat); }; #endif diff --git a/cocos/renderer/CCTextureCube.cpp b/cocos/renderer/CCTextureCube.cpp index aa947f944d..5c0165e875 100644 --- a/cocos/renderer/CCTextureCube.cpp +++ b/cocos/renderer/CCTextureCube.cpp @@ -63,7 +63,7 @@ namespace { } } -unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) +unsigned char* getImageData(Image* img, backend::PixelFormat& ePixFmt) { unsigned char* pTmpData = img->getData(); unsigned int* inPixel32 = nullptr; @@ -78,24 +78,24 @@ unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) // compute pixel format if (bHasAlpha) { - ePixFmt = Texture2D::PixelFormat::DEFAULT; + ePixFmt = backend::PixelFormat::DEFAULT; } else { if (uBPP >= 8) { - ePixFmt = Texture2D::PixelFormat::RGB888; + ePixFmt = backend::PixelFormat::RGB888; } else { - ePixFmt = Texture2D::PixelFormat::RGB565; + ePixFmt = backend::PixelFormat::RGB565; } } // Repack the pixel data into the right format unsigned int uLen = nWidth * nHeight; - if (ePixFmt == Texture2D::PixelFormat::RGB565) + if (ePixFmt == backend::PixelFormat::RGB565) { if (bHasAlpha) { @@ -133,7 +133,7 @@ unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) } } - if (bHasAlpha && ePixFmt == Texture2D::PixelFormat::RGB888) + if (bHasAlpha && ePixFmt == backend::PixelFormat::RGB888) { // Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRRRRGGGGGGGGBBBBBBBB" inPixel32 = (unsigned int*)img->getData(); @@ -253,16 +253,16 @@ bool TextureCube::init(const std::string& positive_x, const std::string& negativ { Image* img = images[i]; - Texture2D::PixelFormat ePixelFmt; + backend::PixelFormat ePixelFmt; unsigned char* pData = getImageData(img, ePixelFmt); uint8_t *cData = nullptr; uint8_t *useData = pData; //convert pixel format to RGBA - if (ePixelFmt != Texture2D::PixelFormat::RGBA8888) + if (ePixelFmt != backend::PixelFormat::RGBA8888) { size_t len = 0; - backend::PixelFormatUtils::convertDataToFormat(pData, img->getDataLen(), ePixelFmt, Texture2D::PixelFormat::RGBA8888, &cData, &len); + backend::PixelFormatUtils::convertDataToFormat(pData, img->getDataLen(), ePixelFmt, backend::PixelFormat::RGBA8888, &cData, &len); if (cData != pData) //convert error { useData = cData; diff --git a/cocos/renderer/CCTextureUtils.cpp b/cocos/renderer/CCTextureUtils.cpp index a28517cb68..1a17e85605 100644 --- a/cocos/renderer/CCTextureUtils.cpp +++ b/cocos/renderer/CCTextureUtils.cpp @@ -566,7 +566,7 @@ namespace backend { namespace PixelFormatUtils { - cocos2d::Texture2D::PixelFormat convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -634,7 +634,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -704,7 +704,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -772,7 +772,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) @@ -842,7 +842,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertRGB5A1ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertRGB5A1ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -870,7 +870,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertRGB565ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertRGB565ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -899,7 +899,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertA8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertA8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -922,7 +922,7 @@ namespace backend { namespace PixelFormatUtils { return format; } - cocos2d::Texture2D::PixelFormat convertRGBA4444ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertRGBA4444ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -982,7 +982,7 @@ namespace backend { namespace PixelFormatUtils { rgba(1) -> 12345678 */ - cocos2d::Texture2D::PixelFormat convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen) + cocos2d::backend::PixelFormat convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen) { // don't need to convert if (format == originFormat || format == PixelFormat::AUTO) diff --git a/cocos/renderer/CCTextureUtils.h b/cocos/renderer/CCTextureUtils.h index 4c9c9f5072..4f82393faf 100644 --- a/cocos/renderer/CCTextureUtils.h +++ b/cocos/renderer/CCTextureUtils.h @@ -7,7 +7,7 @@ NS_CC_BEGIN namespace backend { namespace PixelFormatUtils { - typedef cocos2d::Texture2D::PixelFormat PixelFormat; + typedef cocos2d::backend::PixelFormat PixelFormat; /**convert functions*/ diff --git a/cocos/renderer/CMakeLists.txt b/cocos/renderer/CMakeLists.txt index 19e9648535..5f298fd083 100644 --- a/cocos/renderer/CMakeLists.txt +++ b/cocos/renderer/CMakeLists.txt @@ -33,7 +33,6 @@ set(COCOS_RENDERER_HEADER renderer/backend/RenderPipeline.h renderer/backend/RenderPipelineDescriptor.h renderer/backend/ShaderModule.h - renderer/backend/StringUtils.h renderer/backend/Texture.h renderer/backend/Types.h renderer/backend/VertexLayout.h @@ -67,7 +66,6 @@ set(COCOS_RENDERER_SRC renderer/backend/DepthStencilState.cpp renderer/backend/Device.cpp renderer/backend/ShaderModule.cpp - renderer/backend/StringUtils.cpp renderer/backend/Texture.cpp renderer/backend/Types.cpp renderer/backend/VertexLayout.cpp diff --git a/cocos/renderer/backend/RenderPipelineDescriptor.h b/cocos/renderer/backend/RenderPipelineDescriptor.h index 90cad9e65d..4f7d268a90 100644 --- a/cocos/renderer/backend/RenderPipelineDescriptor.h +++ b/cocos/renderer/backend/RenderPipelineDescriptor.h @@ -18,9 +18,9 @@ struct RenderPipelineDescriptor ProgramState* programState = nullptr; BlendState* blendState = nullptr; std::shared_ptr> vertexLayouts = std::make_shared>(); - TextureFormat colorAttachmentsFormat[MAX_COLOR_ATTCHMENT] = { TextureFormat::SYSTEM_DEFAULT }; - TextureFormat depthAttachmentFormat = TextureFormat::NONE; - TextureFormat stencilAttachmentFormat = TextureFormat::NONE; + PixelFormat colorAttachmentsFormat[MAX_COLOR_ATTCHMENT] = { PixelFormat::DEFAULT }; + PixelFormat depthAttachmentFormat = PixelFormat::NONE; + PixelFormat stencilAttachmentFormat = PixelFormat::NONE; }; CC_BACKEND_END diff --git a/cocos/renderer/backend/StringUtils.cpp b/cocos/renderer/backend/StringUtils.cpp deleted file mode 100644 index 49d70268a2..0000000000 --- a/cocos/renderer/backend/StringUtils.cpp +++ /dev/null @@ -1,255 +0,0 @@ -// -// StringUtils.cpp -// Test -// -// Created by Cocos on 2018/11/2. -// Copyright © 2018 cocos. All rights reserved. -// - -#include "StringUtils.h" - -CC_BACKEND_BEGIN - -std::string StringUtils::TextureFormat2String(const TextureFormat& textureFormat) -{ - switch (textureFormat) { - case TextureFormat::R8G8B8A8: - return "R8G8B8A8"; - case TextureFormat::R8G8B8: - return "R8G8B8"; - case TextureFormat::A8: - return "A8"; - default: - return ""; - } -} - -std::string StringUtils::TextureType2String(const TextureType& textureType) -{ - switch (textureType) { - case TextureType::TEXTURE_2D: - return "TEXTURE_2D"; - case TextureType::TEXTURE_CUBE: - return "TEXTURE_CUBE"; - default: - return ""; - } -} - -std::string StringUtils::TextureUsage2String(const TextureUsage& textureUsage) -{ - switch (textureUsage) { - case TextureUsage::READ: - return "READ"; - case TextureUsage::WRITE: - return "WRITE"; - case TextureUsage::RENDER_TARGET: - return "RENDER_TARGET"; - default: - return ""; - } -} - -std::string StringUtils::SamplerFilterType2String(const SamplerFilter& filterType) -{ - switch (filterType) { - case SamplerFilter::LINEAR: - return "LINEAR"; - case SamplerFilter::NEAREST: - return "NEAREST"; - default: - return ""; - } -} - -std::string StringUtils::SamplerAddressMode2String(const SamplerAddressMode& addressMode) -{ - switch (addressMode) { - case SamplerAddressMode::REPEAT: - return "REPEAT"; - case SamplerAddressMode::MIRROR_REPEAT: - return "MIRROR_REPEAT"; - case SamplerAddressMode::CLAMP_TO_EDGE: - return "CLAMP_TO_EDGE"; - default: - return ""; - } -} - -std::string StringUtils::SamplerDescriptor2String(const SamplerDescriptor& descriptor) -{ - std::string samplerInfo = descriptor.mipmapEnabled ? "mipmapEnable":"mipmapDisable"; - samplerInfo += SamplerFilterType2String(descriptor.magFilter); - samplerInfo += SamplerFilterType2String(descriptor.minFilter); - samplerInfo += SamplerFilterType2String(descriptor.mipmapFilter); - samplerInfo += SamplerAddressMode2String(descriptor.sAddressMode); - samplerInfo += SamplerAddressMode2String(descriptor.tAddressMode); - return samplerInfo; -} - -std::string StringUtils::StencilOperation2String(const StencilOperation& operation) -{ - switch (operation) { - case StencilOperation::KEEP: - return "KEEP"; - case StencilOperation::ZERO: - return "ZERO"; - case StencilOperation::REPLACE: - return "REPLACE"; - case StencilOperation::INVERT: - return "INVERT"; - case StencilOperation::INCREMENT_WRAP: - return "INCREMENT_WRAP"; - case StencilOperation::DECREMENT_WRAP: - return "DECREMENT_WRAP"; - default: - return ""; - } -} - -std::string StringUtils::CompareFunction2String(const CompareFunction& compareFunction) -{ - switch (compareFunction) { - case CompareFunction::NEVER: - return "NEVER"; - case CompareFunction::LESS: - return "LESS"; - case CompareFunction::LESS_EQUAL: - return "LESS_EQUAL"; - case CompareFunction::GREATER: - return "GREATER"; - case CompareFunction::GREATER_EQUAL: - return "GREATER_EQUAL"; - case CompareFunction::EQUAL: - return "EQUAL"; - case CompareFunction::NOT_EQUAL: - return "NOT_EQUAL"; - case CompareFunction::ALWAYS: - return "ALWAYS"; - default: - return ""; - } -} - -std::string StringUtils::ColorWriteMask2String(const ColorWriteMask& colorWriteMask) -{ - switch (colorWriteMask) { - case ColorWriteMask::NONE: - return "NONE"; - case ColorWriteMask::RED: - return "RED"; - case ColorWriteMask::GREEN: - return "GREEN"; - case ColorWriteMask::BLUE: - return "BLUE"; - case ColorWriteMask::ALPHA: - return "ALPHA"; - case ColorWriteMask::ALL: - return "ALL"; - default: - return ""; - } -} - -std::string StringUtils::BlendOperation2String(const BlendOperation& blendOperation) -{ - switch (blendOperation) { - case BlendOperation::ADD: - return "ADD"; - case BlendOperation::SUBTRACT: - return "SUBTRACT"; - case BlendOperation::RESERVE_SUBTRACT: - return "RESERVE_SUBTRACT"; - default: - return ""; - } -} - -std::string StringUtils::BlendFactor2String(const BlendFactor& blendFactor) -{ - switch (blendFactor) { - case BlendFactor::ZERO: - return "ZERO"; - case BlendFactor::ONE: - return "ONE"; - case BlendFactor::SRC_COLOR: - return "SRC_COLOR"; - case BlendFactor::ONE_MINUS_SRC_COLOR: - return "ONE_MINUS_SRC_COLOR"; - case BlendFactor::SRC_ALPHA: - return "SRC_ALPHA"; - case BlendFactor::ONE_MINUS_SRC_ALPHA: - return "ONE_MINUS_SRC_ALPHA"; - case BlendFactor::DST_COLOR: - return "DST_COLOR"; - case BlendFactor::ONE_MINUS_DST_COLOR: - return "ONE_MINUS_DST_COLOR"; - case BlendFactor::DST_ALPHA: - return "DST_ALPHA"; - case BlendFactor::ONE_MINUS_DST_ALPHA: - return "ONE_MINUS_DST_ALPHA"; - case BlendFactor::SRC_ALPHA_SATURATE: - return "SRC_ALPHA_SATURATE"; - case BlendFactor::BLEND_CLOLOR: - return "BLEND_CLOLOR"; - default: - return ""; - } -} - -TextureFormat StringUtils::PixelFormat2TextureFormat(const PixelFormat& pixleFormat) -{ - switch (pixleFormat) { - case PixelFormat::BGRA8888: - return TextureFormat::BGRA8888; - case PixelFormat::RGBA8888: - return TextureFormat::R8G8B8A8; - case PixelFormat::RGB888: - return TextureFormat::R8G8B8; - case PixelFormat::A8: - return TextureFormat::A8; - case PixelFormat::RGBA4444: - return TextureFormat::RGBA4444; - case PixelFormat::I8: - return TextureFormat::I8; - case PixelFormat::AI88: - return TextureFormat::AI88; - case PixelFormat::RGB565: - return TextureFormat::RGB565; - case PixelFormat::RGB5A1: - return TextureFormat::RGB5A1; - case PixelFormat::ETC: - return TextureFormat::ETC1; - case PixelFormat::ATC_RGB: - return TextureFormat::ATC_RGB; - case PixelFormat::ATC_EXPLICIT_ALPHA: - return TextureFormat::ATC_EXPLICIT_ALPHA; - case PixelFormat::ATC_INTERPOLATED_ALPHA: - return TextureFormat::ATC_INTERPOLATED_ALPHA; - case PixelFormat::PVRTC2: - return TextureFormat::PVRTC2; - case PixelFormat::PVRTC2A: - return TextureFormat::PVRTC2A; - case PixelFormat::PVRTC4: - return TextureFormat::PVRTC4; - case PixelFormat::PVRTC4A: - return TextureFormat::PVRTC4A; - case PixelFormat::S3TC_DXT1: - return TextureFormat::S3TC_DXT1; - case PixelFormat::S3TC_DXT3: - return TextureFormat::S3TC_DXT3; - case PixelFormat::S3TC_DXT5: - return TextureFormat::S3TC_DXT5; - case PixelFormat::MTL_ABGR4: - return TextureFormat::MTL_ABGR4; - case PixelFormat::MTL_BGR5A1: - return TextureFormat::MTL_BGR5A1; - case PixelFormat::MTL_B5G6R5: - return TextureFormat::MTL_B5G6R5; - default: - return TextureFormat::NONE; - break; - } -} - -CC_BACKEND_END diff --git a/cocos/renderer/backend/StringUtils.h b/cocos/renderer/backend/StringUtils.h deleted file mode 100644 index ed08955c6d..0000000000 --- a/cocos/renderer/backend/StringUtils.h +++ /dev/null @@ -1,91 +0,0 @@ -// -// StringUtils.hpp -// Test -// -// Created by Cocos on 2018/11/2. -// Copyright © 2018 cocos. All rights reserved. -// - -#ifndef StringUtils_hpp -#define StringUtils_hpp - -#include -#include "Types.h" -CC_BACKEND_BEGIN - -class StringUtils -{ -public: - enum class PixelFormat - { - //! auto detect the type - AUTO, - //! 32-bit texture: BGRA8888 - BGRA8888, - //! 32-bit texture: RGBA8888 - RGBA8888, - //! 24-bit texture: RGBA888 - RGB888, - //! 16-bit texture without Alpha channel - RGB565, - //! 8-bit textures used as masks - A8, - //! 8-bit intensity texture - I8, - //! 16-bit textures used as masks - AI88, - //! 16-bit textures: RGBA4444 - RGBA4444, - //! 16-bit textures: RGB5A1 - RGB5A1, - //! 4-bit PVRTC-compressed texture: PVRTC4 - PVRTC4, - //! 4-bit PVRTC-compressed texture: PVRTC4 (has alpha channel) - PVRTC4A, - //! 2-bit PVRTC-compressed texture: PVRTC2 - PVRTC2, - //! 2-bit PVRTC-compressed texture: PVRTC2 (has alpha channel) - PVRTC2A, - //! ETC-compressed texture: ETC - ETC, - //! S3TC-compressed texture: S3TC_Dxt1 - S3TC_DXT1, - //! S3TC-compressed texture: S3TC_Dxt3 - S3TC_DXT3, - //! S3TC-compressed texture: S3TC_Dxt5 - S3TC_DXT5, - //! ATITC-compressed texture: ATC_RGB - ATC_RGB, - //! ATITC-compressed texture: ATC_EXPLICIT_ALPHA - ATC_EXPLICIT_ALPHA, - //! ATITC-compressed texture: ATC_INTERPOLATED_ALPHA - ATC_INTERPOLATED_ALPHA, - //! Default texture format: AUTO - - //metal 16-bits packed pixel formats - MTL_B5G6R5, - //MTL_A1BGR5, - MTL_BGR5A1, - MTL_ABGR4, - - DEFAULT = AUTO, - - NONE = -1 - }; - - static std::string TextureFormat2String(const TextureFormat& textureFormat); - static std::string TextureType2String(const TextureType& textureType); - static std::string TextureUsage2String(const TextureUsage& textureUsage); - static std::string SamplerFilterType2String(const SamplerFilter& filterType); - static std::string SamplerAddressMode2String(const SamplerAddressMode& addressMode); - static std::string SamplerDescriptor2String(const SamplerDescriptor& descriptor); - static std::string StencilOperation2String(const StencilOperation& operation); - static std::string CompareFunction2String(const CompareFunction& compareFunction); - static std::string ColorWriteMask2String(const ColorWriteMask& colorWriteMask); - static std::string BlendOperation2String(const BlendOperation& blendOperation); - static std::string BlendFactor2String(const BlendFactor& blendFactor); - static TextureFormat PixelFormat2TextureFormat(const PixelFormat& pixleFormat); -}; - -CC_BACKEND_END -#endif /* StringUtils_hpp */ diff --git a/cocos/renderer/backend/Texture.cpp b/cocos/renderer/backend/Texture.cpp index b052964a4c..eb5fa4b940 100644 --- a/cocos/renderer/backend/Texture.cpp +++ b/cocos/renderer/backend/Texture.cpp @@ -6,56 +6,56 @@ CC_BACKEND_BEGIN #define bit(n) (n) namespace { - uint8_t computeBitsPerElement(TextureFormat textureFormat) + uint8_t computeBitsPerElement(PixelFormat textureFormat) { switch (textureFormat) { - case TextureFormat::R8G8B8A8: - case TextureFormat::BGRA8888: + case PixelFormat::RGBA8888: + case PixelFormat::BGRA8888: return byte(4); - case TextureFormat::R8G8B8: + case PixelFormat::RGB888: return byte(3); - case TextureFormat::RGBA4444: + case PixelFormat::RGBA4444: return byte(2); - case TextureFormat::A8: + case PixelFormat::A8: return byte(1); - case TextureFormat::I8: + case PixelFormat::I8: return byte(1); - case TextureFormat::RGB565: + case PixelFormat::RGB565: return byte(2); - case TextureFormat::RGB5A1: + case PixelFormat::RGB5A1: return byte(2); - case TextureFormat::AI88: + case PixelFormat::AI88: return byte(2); - case TextureFormat::ETC1: + case PixelFormat::ETC: return bit(4); - case TextureFormat::ATC_RGB: + case PixelFormat::ATC_RGB: return bit(4); - case TextureFormat::ATC_EXPLICIT_ALPHA: + case PixelFormat::ATC_EXPLICIT_ALPHA: return byte(1); - case TextureFormat::ATC_INTERPOLATED_ALPHA: + case PixelFormat::ATC_INTERPOLATED_ALPHA: return byte(1); - case TextureFormat::PVRTC2: + case PixelFormat::PVRTC2: return bit(2); - case TextureFormat::PVRTC2A: + case PixelFormat::PVRTC2A: return bit(2); - case TextureFormat::PVRTC4: + case PixelFormat::PVRTC4: return bit(4); - case TextureFormat::PVRTC4A: + case PixelFormat::PVRTC4A: return bit(4); - case TextureFormat::S3TC_DXT1: + case PixelFormat::S3TC_DXT1: return bit(4); - case TextureFormat::S3TC_DXT3: + case PixelFormat::S3TC_DXT3: return byte(1); - case TextureFormat::S3TC_DXT5: + case PixelFormat::S3TC_DXT5: return byte(1); - case TextureFormat::MTL_BGR5A1: + case PixelFormat::MTL_BGR5A1: return byte(2); - case TextureFormat::MTL_B5G6R5: + case PixelFormat::MTL_B5G6R5: return byte(2); - case TextureFormat::MTL_ABGR4: + case PixelFormat::MTL_ABGR4: return byte(2); - case TextureFormat::D24S8: + case PixelFormat::D24S8: #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) //ios use MTLPixelFormatDepth32Float_Stencil8 as DepthStencil combined format, its 64 bits return byte(8); @@ -72,11 +72,11 @@ namespace Texture::Texture(const TextureDescriptor& descriptor) : _bitsPerElement(computeBitsPerElement(descriptor.textureFormat)) - , _isMipmapEnabled(descriptor.samplerDescriptor.mipmapEnabled) - , _isCompressed(descriptor.compressed) , _textureType(descriptor.textureType) , _textureFormat(descriptor.textureFormat) , _textureUsage(descriptor.textureUsage) + , _width(descriptor.width) + , _height(descriptor.height) { } @@ -86,23 +86,20 @@ Texture::~Texture() void Texture::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor) { _bitsPerElement = computeBitsPerElement(descriptor.textureFormat); - _isMipmapEnabled = descriptor.samplerDescriptor.mipmapEnabled; - _isCompressed = descriptor.compressed; _textureType = descriptor.textureType; _textureFormat = descriptor.textureFormat; _textureUsage = descriptor.textureUsage; + _width = descriptor.width; + _height = descriptor.height; } Texture2D::Texture2D(const TextureDescriptor& descriptor) : Texture(descriptor) - , _width(descriptor.width) - , _height(descriptor.height) { } TextureCubemap::TextureCubemap(const TextureDescriptor &descriptor) : Texture(descriptor) - , _size(descriptor.width) { } diff --git a/cocos/renderer/backend/Texture.h b/cocos/renderer/backend/Texture.h index 72fc1450bf..3132f34da5 100644 --- a/cocos/renderer/backend/Texture.h +++ b/cocos/renderer/backend/Texture.h @@ -11,12 +11,11 @@ CC_BACKEND_BEGIN struct TextureDescriptor { TextureType textureType = TextureType::TEXTURE_2D; - TextureFormat textureFormat = TextureFormat::R8G8B8A8; + PixelFormat textureFormat = PixelFormat::RGBA8888; TextureUsage textureUsage = TextureUsage::READ; uint32_t width = 0; uint32_t height = 0; uint32_t depth = 0; - bool compressed = false; SamplerDescriptor samplerDescriptor; }; @@ -28,9 +27,10 @@ public: virtual void generateMipmaps() = 0; virtual void updateTextureDescriptor(const TextureDescriptor& descriptor); - inline TextureFormat getTextureFormat() const { return _textureFormat; } + inline PixelFormat getTextureFormat() const { return _textureFormat; } inline TextureUsage getTextureUsage() const { return _textureUsage; } inline TextureType getTextureType() const { return _textureType; } + inline bool hasMipmaps() const { return _hasMipmaps; } protected: Texture(const TextureDescriptor& descriptor); @@ -38,12 +38,13 @@ protected: // The bytes of all components. uint8_t _bitsPerElement = 0; - bool _isMipmapEnabled = false; + bool _hasMipmaps = false; bool _isCompressed = false; - bool _isMipmapGenerated = false; + uint32_t _width = 0; + uint32_t _height = 0; TextureType _textureType = TextureType::TEXTURE_2D; - TextureFormat _textureFormat = TextureFormat::R8G8B8; + PixelFormat _textureFormat = PixelFormat::RGBA8888; TextureUsage _textureUsage = TextureUsage::READ; }; @@ -51,27 +52,25 @@ protected: class Texture2D : public Texture { public: - virtual void updateData(uint8_t* data) = 0; - virtual void updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint8_t* data) = 0; + virtual void updateData(uint8_t* data, uint32_t width , uint32_t height, uint32_t level) = 0; + virtual void updateCompressedData(uint8_t* data, uint32_t width , uint32_t height, uint32_t dataLen, uint32_t level) = 0; + virtual void updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t level, uint8_t* data) = 0; + virtual void updateCompressedSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t dataLen, uint32_t level, uint8_t* data) = 0; inline uint32_t getWidth() const { return _width; } inline uint32_t getHeight() const { return _height; } protected: Texture2D(const TextureDescriptor& descriptor); - uint32_t _width = 0; - uint32_t _height = 0; - }; class TextureCubemap : public Texture { public: virtual void updateFaceData(TextureCubeFace side, void *data) = 0; - void setSize(uint32_t size) { _size = size; } + protected: TextureCubemap(const TextureDescriptor& descriptor); - uint32_t _size = 0; }; CC_BACKEND_END diff --git a/cocos/renderer/backend/Types.h b/cocos/renderer/backend/Types.h index 86f0a417ae..49b742a27f 100644 --- a/cocos/renderer/backend/Types.h +++ b/cocos/renderer/backend/Types.h @@ -41,43 +41,68 @@ enum class VertexFormat : uint32_t UBYTE4 }; -enum class TextureFormat : uint32_t +/** @typedef backend::PixelFormat + Possible texture pixel formats + */ +enum class PixelFormat { - NONE, + //! auto detect the type + AUTO, + //! 32-bit texture: BGRA8888 BGRA8888, - // Four 8-bit normalized unsigned integer components in RGBA order. - R8G8B8A8, - // Three 8-bit normalized unsigned integer components in RGB order. - R8G8B8, - // One 8-bit normalized unsigned integer component. - A8, - // A packed 32-bit combined depth and stencil pixel format with two nomorlized unsigned integer - // components: 24 bits, typically used for a depth render target, and 8 bits, typically used for - // a stencil render target. - D24S8, - I8, - AI88, - RGBA4444, + //! 32-bit texture: RGBA8888 + RGBA8888, + //! 24-bit texture: RGBA888 + RGB888, + //! 16-bit texture without Alpha channel RGB565, + //! 8-bit textures used as masks + A8, + //! 8-bit intensity texture + I8, + //! 16-bit textures used as masks + AI88, + //! 16-bit textures: RGBA4444 + RGBA4444, + //! 16-bit textures: RGB5A1 RGB5A1, - //metal 16 bits pixel formats + //! 4-bit PVRTC-compressed texture: PVRTC4 + PVRTC4, + //! 4-bit PVRTC-compressed texture: PVRTC4 (has alpha channel) + PVRTC4A, + //! 2-bit PVRTC-compressed texture: PVRTC2 + PVRTC2, + //! 2-bit PVRTC-compressed texture: PVRTC2 (has alpha channel) + PVRTC2A, + //! ETC-compressed texture: ETC + ETC, + //! S3TC-compressed texture: S3TC_Dxt1 + S3TC_DXT1, + //! S3TC-compressed texture: S3TC_Dxt3 + S3TC_DXT3, + //! S3TC-compressed texture: S3TC_Dxt5 + S3TC_DXT5, + //! ATITC-compressed texture: ATC_RGB + ATC_RGB, + //! ATITC-compressed texture: ATC_EXPLICIT_ALPHA + ATC_EXPLICIT_ALPHA, + //! ATITC-compressed texture: ATC_INTERPOLATED_ALPHA + ATC_INTERPOLATED_ALPHA, + //! Default texture format: AUTO + MTL_B5G6R5, //MTL_A1BGR5, MTL_BGR5A1, MTL_ABGR4, - // compressed format - ETC1, - ATC_RGB, - ATC_EXPLICIT_ALPHA, - ATC_INTERPOLATED_ALPHA, - PVRTC2, - PVRTC2A, - PVRTC4, - PVRTC4A, - S3TC_DXT1, - S3TC_DXT3, - S3TC_DXT5, - SYSTEM_DEFAULT + + // A packed 32-bit combined depth and stencil pixel format with two nomorlized unsigned integer + // components: 24 bits, typically used for a depth render target, and 8 bits, typically used for + // a stencil render target. + D24S8, + + DEFAULT = AUTO, + + NONE = -1 }; enum class TextureUsage : uint32_t @@ -125,7 +150,11 @@ enum class SamplerAddressMode: uint32_t enum class SamplerFilter: uint32_t { NEAREST, + NEAREST_MIPMAP_NEAREST, + NEAREST_MIPMAP_LINEAR, LINEAR, + LINEAR_MIPMAP_LINEAR, + LINEAR_MIPMAP_NEAREST, DONT_CARE, }; @@ -188,10 +217,8 @@ enum class ColorWriteMask: uint32_t struct SamplerDescriptor { - bool mipmapEnabled = false; SamplerFilter magFilter = SamplerFilter::LINEAR; SamplerFilter minFilter = SamplerFilter::LINEAR; - SamplerFilter mipmapFilter = SamplerFilter::LINEAR; SamplerAddressMode sAddressMode = SamplerAddressMode::CLAMP_TO_EDGE; SamplerAddressMode tAddressMode = SamplerAddressMode::CLAMP_TO_EDGE; @@ -204,16 +231,6 @@ struct SamplerDescriptor SamplerAddressMode _tAddressMode ) : magFilter(_magFilter), minFilter(_minFilter), sAddressMode(_sAddressMode), tAddressMode(_tAddressMode) {} - - SamplerDescriptor(bool _mipmapEnabled, - SamplerFilter _magFilter, - SamplerFilter _minFilter, - SamplerFilter _mipmapFilter, - SamplerAddressMode _sAddressMode, - SamplerAddressMode _tAddressMode - ) :mipmapEnabled(_mipmapEnabled), magFilter(_magFilter), minFilter(_minFilter), - mipmapFilter(_mipmapFilter), sAddressMode(_sAddressMode), tAddressMode(_tAddressMode) {} - }; enum class CullMode: uint32_t diff --git a/cocos/renderer/backend/metal/DeviceInfoMTL.mm b/cocos/renderer/backend/metal/DeviceInfoMTL.mm index f0102c8f60..980eb33435 100644 --- a/cocos/renderer/backend/metal/DeviceInfoMTL.mm +++ b/cocos/renderer/backend/metal/DeviceInfoMTL.mm @@ -397,6 +397,9 @@ const char* DeviceInfoMTL::getExtension() const bool DeviceInfoMTL::checkForFeatureSupported(FeatureType feature) { + //TODO coulsonwang, removed it later. + return false; + bool featureSupported = false; switch (feature) { diff --git a/cocos/renderer/backend/metal/RenderPipelineMTL.mm b/cocos/renderer/backend/metal/RenderPipelineMTL.mm index 0b8d70cd5c..fd2c7fc939 100644 --- a/cocos/renderer/backend/metal/RenderPipelineMTL.mm +++ b/cocos/renderer/backend/metal/RenderPipelineMTL.mm @@ -148,7 +148,7 @@ void RenderPipelineMTL::setBlendStateAndFormat(const RenderPipelineDescriptor& d { for (int i = 0; i < MAX_COLOR_ATTCHMENT; ++i) { - if (TextureFormat::NONE == descriptor.colorAttachmentsFormat[i]) + if (PixelFormat::NONE == descriptor.colorAttachmentsFormat[i]) continue; _mtlRenderPipelineDescriptor.colorAttachments[i].pixelFormat = Utils::toMTLPixelFormat(descriptor.colorAttachmentsFormat[i]); diff --git a/cocos/renderer/backend/metal/TextureMTL.h b/cocos/renderer/backend/metal/TextureMTL.h index 94e7bcbeb8..34bd09a75c 100644 --- a/cocos/renderer/backend/metal/TextureMTL.h +++ b/cocos/renderer/backend/metal/TextureMTL.h @@ -12,8 +12,10 @@ public: TextureMTL(id mtlDevice, const TextureDescriptor& descriptor); ~TextureMTL(); - virtual void updateData(uint8_t* data) override; - virtual void updateSubData(unsigned int xoffset, unsigned int yoffset, unsigned int width, unsigned int height, uint8_t* data) override; + virtual void updateData(uint8_t* data, uint32_t width , uint32_t height, uint32_t level) override; + virtual void updateCompressedData(uint8_t* data, uint32_t width , uint32_t height, uint32_t dataLen, uint32_t level) override; + virtual void updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t level, uint8_t* data) override; + virtual void updateCompressedSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t dataLen, uint32_t level, uint8_t* data) override; virtual void updateSamplerDescriptor(const SamplerDescriptor &sampler) override; virtual void getBytes(int x, int y, int width, int height, bool flipImage, std::function callback) override; diff --git a/cocos/renderer/backend/metal/TextureMTL.mm b/cocos/renderer/backend/metal/TextureMTL.mm index 63a39ad833..a3c7e704bc 100644 --- a/cocos/renderer/backend/metal/TextureMTL.mm +++ b/cocos/renderer/backend/metal/TextureMTL.mm @@ -29,8 +29,12 @@ namespace { switch (mode) { case SamplerFilter::NEAREST: + case SamplerFilter::NEAREST_MIPMAP_LINEAR: + case SamplerFilter::NEAREST_MIPMAP_NEAREST: return MTLSamplerMinMagFilterNearest; case SamplerFilter::LINEAR: + case SamplerFilter::LINEAR_MIPMAP_LINEAR: + case SamplerFilter::LINEAR_MIPMAP_NEAREST: return MTLSamplerMinMagFilterLinear; case SamplerFilter::DONT_CARE: return MTLSamplerMinMagFilterNearest; @@ -40,8 +44,12 @@ namespace MTLSamplerMipFilter toMTLSamplerMipFilter(SamplerFilter mode) { switch (mode) { case SamplerFilter::NEAREST: + case SamplerFilter::LINEAR_MIPMAP_NEAREST: + case SamplerFilter::NEAREST_MIPMAP_NEAREST: return MTLSamplerMipFilterNearest; case SamplerFilter::LINEAR: + case SamplerFilter::LINEAR_MIPMAP_LINEAR: + case SamplerFilter::NEAREST_MIPMAP_LINEAR: return MTLSamplerMipFilterLinear; case SamplerFilter::DONT_CARE: return MTLSamplerMipFilterNearest; @@ -60,13 +68,13 @@ namespace } - bool convertData(uint8_t* src, unsigned int length, TextureFormat format, uint8_t** out) + bool convertData(uint8_t* src, unsigned int length, PixelFormat format, uint8_t** out) { *out = src; bool converted = false; switch (format) { - case TextureFormat::R8G8B8: + case PixelFormat::RGB888: { *out = (uint8_t*)malloc(length * 4); convertRGB2RGBA(src, *out, length); @@ -79,23 +87,36 @@ namespace return converted; } - bool isColorRenderable(TextureFormat textureFormat) + bool isColorRenderable(PixelFormat textureFormat) { switch (textureFormat) { - case TextureFormat::R8G8B8A8: - case TextureFormat::R8G8B8: - case TextureFormat::RGBA4444: - case TextureFormat::RGB565: - case TextureFormat::RGB5A1: - case TextureFormat::MTL_BGR5A1: - case TextureFormat::MTL_B5G6R5: - case TextureFormat::MTL_ABGR4: + case PixelFormat::RGBA8888: + case PixelFormat::RGB888: + case PixelFormat::RGBA4444: + case PixelFormat::RGB565: + case PixelFormat::RGB5A1: + case PixelFormat::MTL_BGR5A1: + case PixelFormat::MTL_B5G6R5: + case PixelFormat::MTL_ABGR4: return true; default: return false; } } + + bool isCompressedFormat(PixelFormat textureFormat) + { + MTLPixelFormat pixelFormat = Utils::toMTLPixelFormat(textureFormat); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + bool isCompressed = (pixelFormat >= MTLPixelFormatPVRTC_RGB_2BPP && + pixelFormat <= MTLPixelFormatASTC_12x12_LDR); +#else + bool isCompressed = (pixelFormat >= MTLPixelFormatBC1_RGBA && + pixelFormat <= MTLPixelFormatBC7_RGBAUnorm_sRGB); +#endif + return isCompressed; + } } TextureMTL::TextureMTL(id mtlDevice, const TextureDescriptor& descriptor) @@ -103,6 +124,7 @@ TextureMTL::TextureMTL(id mtlDevice, const TextureDescriptor& descrip { _mtlDevice = mtlDevice; updateTextureDescriptor(descriptor); + _isCompressed = isCompressedFormat(descriptor.textureFormat); } TextureMTL::~TextureMTL() @@ -121,7 +143,7 @@ void TextureMTL::updateTextureDescriptor(const cocos2d::backend::TextureDescript Texture::updateTextureDescriptor(descriptor); createTexture(_mtlDevice, descriptor); updateSamplerDescriptor(descriptor.samplerDescriptor); - if (TextureFormat::R8G8B8 == _textureFormat) + if (PixelFormat::RGB888 == _textureFormat) { _bitsPerElement = 4 * 8; } @@ -129,12 +151,12 @@ void TextureMTL::updateTextureDescriptor(const cocos2d::backend::TextureDescript _bytesPerRow = descriptor.width * _bitsPerElement / 8 ; } -void TextureMTL::updateData(uint8_t* data) +void TextureMTL::updateData(uint8_t* data, uint32_t width , uint32_t height, uint32_t level) { - updateSubData(0, 0, (unsigned int)_mtlTexture.width, (unsigned int)_mtlTexture.height, data); + updateSubData(0, 0, width, height, level, data); } -void TextureMTL::updateSubData(unsigned int xoffset, unsigned int yoffset, unsigned int width, unsigned int height, uint8_t* data) +void TextureMTL::updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t level, uint8_t* data) { MTLRegion region = { @@ -147,23 +169,30 @@ void TextureMTL::updateSubData(unsigned int xoffset, unsigned int yoffset, unsig (uint32_t)(width * height), _textureFormat, &convertedData); + //TODO coulsonwang, it seems that only PVRTC has such limitation. //when pixel format is a compressed one, bytePerRow should be set to ZERO - int bytesPerRow = _isCompressed ? 0 : _bytesPerRow; + int bytesPerRow = _isCompressed ? 0 : (width * _bitsPerElement / 8); [_mtlTexture replaceRegion:region - mipmapLevel:0 + mipmapLevel:level withBytes:convertedData bytesPerRow:bytesPerRow]; if (converted) free(convertedData); - // metal doesn't generate mipmaps automatically, so should generate it manually. - if (_isMipmapEnabled) - { - _isMipmapGenerated = false; - generateMipmaps(); - } + if(!_hasMipmaps && level > 0) + _hasMipmaps = true; +} + +void TextureMTL::updateCompressedData(uint8_t *data, uint32_t width, uint32_t height, uint32_t dataLen, uint32_t level) +{ + updateCompressedSubData(0, 0, width, height, dataLen, level, data); +} + +void TextureMTL::updateCompressedSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t dataLen, uint32_t level, uint8_t *data) +{ + updateSubData(xoffset, yoffset, width, height, level, data); } void TextureMTL::createTexture(id mtlDevice, const TextureDescriptor& descriptor) @@ -181,7 +210,7 @@ void TextureMTL::createTexture(id mtlDevice, const TextureDescriptor& if (TextureUsage::RENDER_TARGET == descriptor.textureUsage) { //DepthStencil, and Multisample textures must be allocated with the MTLResourceStorageModePrivate resource option - if(TextureFormat::D24S8 == descriptor.textureFormat) + if(PixelFormat::D24S8 == descriptor.textureFormat) textureDescriptor.resourceOptions = MTLResourceStorageModePrivate; textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead; } @@ -199,8 +228,6 @@ void TextureMTL::createSampler(id mtlDevice, const SamplerDescriptor mtlDescriptor.minFilter = descriptor.minFilter == SamplerFilter::DONT_CARE ? _minFilter : toMTLSamplerMinMagFilter(descriptor.minFilter); mtlDescriptor.magFilter = descriptor.magFilter == SamplerFilter::DONT_CARE ? _magFilter : toMTLSamplerMinMagFilter(descriptor.magFilter); - if (_isMipmapEnabled) - mtlDescriptor.mipFilter = descriptor.mipmapFilter == SamplerFilter::DONT_CARE ? _mipFilter : toMTLSamplerMipFilter(descriptor.mipmapFilter); if(_mtlSamplerState) { @@ -253,9 +280,9 @@ void TextureMTL::generateMipmaps() if (TextureUsage::RENDER_TARGET == _textureUsage || isColorRenderable(_textureFormat) == false) return; - if(!_isMipmapGenerated) + if(!_hasMipmaps) { - _isMipmapGenerated = true; + _hasMipmaps = true; Utils::generateMipmaps(_mtlTexture); } @@ -281,7 +308,7 @@ void TextureCubeMTL::updateTextureDescriptor(const cocos2d::backend::TextureDesc updateSamplerDescriptor(descriptor.samplerDescriptor); // Metal doesn't support RGB888/RGBA4444, so should convert to RGBA888; - if (TextureFormat::R8G8B8 == _textureFormat) + if (PixelFormat::RGB888 == _textureFormat) { _bitsPerElement = 4 * 8; } @@ -319,8 +346,6 @@ void TextureCubeMTL::createSampler(id mtlDevice, const SamplerDescrip mtlDescriptor.minFilter = descriptor.minFilter == SamplerFilter::DONT_CARE ? _minFilter : toMTLSamplerMinMagFilter(descriptor.minFilter); mtlDescriptor.magFilter = descriptor.magFilter == SamplerFilter::DONT_CARE ? _magFilter : toMTLSamplerMinMagFilter(descriptor.magFilter); - if (_isMipmapEnabled) - mtlDescriptor.mipFilter = descriptor.mipmapFilter == SamplerFilter::DONT_CARE ? _mipFilter : toMTLSamplerMipFilter(descriptor.mipmapFilter); if(_mtlSamplerState) { @@ -353,11 +378,6 @@ void TextureCubeMTL::updateFaceData(TextureCubeFace side, void *data) withBytes:data bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage]; - if(_isMipmapEnabled) - { - _isMipmapGenerated = true; - generateMipmaps(); - } } void TextureCubeMTL::getBytes(int x, int y, int width, int height, bool flipImage, std::function callback) @@ -394,9 +414,9 @@ void TextureCubeMTL::generateMipmaps() if (TextureUsage::RENDER_TARGET == _textureUsage || isColorRenderable(_textureFormat) == false) return; - if(!_isMipmapGenerated) + if(!_hasMipmaps) { - _isMipmapGenerated = true; + _hasMipmaps = true; Utils::generateMipmaps(_mtlTexture); } } diff --git a/cocos/renderer/backend/metal/Utils.h b/cocos/renderer/backend/metal/Utils.h index 8805021c40..26480da481 100644 --- a/cocos/renderer/backend/metal/Utils.h +++ b/cocos/renderer/backend/metal/Utils.h @@ -16,7 +16,7 @@ public: static id getDefaultDepthStencilTexture(); - static MTLPixelFormat toMTLPixelFormat(TextureFormat textureFormat); + static MTLPixelFormat toMTLPixelFormat(PixelFormat textureFormat); static void generateMipmaps(id texture); static void getTextureBytes(int origX, int origY, int rectWidth, int rectHeight, id texture, std::function callback); static void swizzleImage(unsigned char* image, int width, int height, MTLPixelFormat format); diff --git a/cocos/renderer/backend/metal/Utils.mm b/cocos/renderer/backend/metal/Utils.mm index 6ca53ae864..83e0a8e4e9 100644 --- a/cocos/renderer/backend/metal/Utils.mm +++ b/cocos/renderer/backend/metal/Utils.mm @@ -78,42 +78,42 @@ void Utils::updateDefaultColorAttachmentTexture(id texture) Utils::_defaultColorAttachmentTexture = texture; } -MTLPixelFormat Utils::toMTLPixelFormat(TextureFormat textureFormat) +MTLPixelFormat Utils::toMTLPixelFormat(PixelFormat textureFormat) { switch (textureFormat) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - case TextureFormat::MTL_ABGR4: + case PixelFormat::MTL_ABGR4: return MTLPixelFormatABGR4Unorm; - case TextureFormat::MTL_BGR5A1: + case PixelFormat::MTL_BGR5A1: return MTLPixelFormatBGR5A1Unorm; - case TextureFormat::MTL_B5G6R5: + case PixelFormat::MTL_B5G6R5: return MTLPixelFormatB5G6R5Unorm; - case TextureFormat::PVRTC4A: + case PixelFormat::PVRTC4A: return MTLPixelFormatPVRTC_RGBA_4BPP; - case TextureFormat::PVRTC4: + case PixelFormat::PVRTC4: return MTLPixelFormatPVRTC_RGB_4BPP; - case TextureFormat::PVRTC2A: + case PixelFormat::PVRTC2A: return MTLPixelFormatPVRTC_RGBA_2BPP; - case TextureFormat::PVRTC2: + case PixelFormat::PVRTC2: return MTLPixelFormatPVRTC_RGB_2BPP; #endif - case TextureFormat::R8G8B8A8: + case PixelFormat::RGBA8888: return MTLPixelFormatRGBA8Unorm; // Should transfer the data to match pixel format when updating data. - case TextureFormat::R8G8B8: + case PixelFormat::RGB888: return MTLPixelFormatRGBA8Unorm; - case TextureFormat::A8: + case PixelFormat::A8: return MTLPixelFormatA8Unorm; - case TextureFormat::BGRA8888: + case PixelFormat::BGRA8888: return MTLPixelFormatBGRA8Unorm; //on mac, D24S8 means MTLPixelFormatDepth24Unorm_Stencil8, while on ios it means MTLPixelFormatDepth32Float_Stencil8 - case TextureFormat::D24S8: + case PixelFormat::D24S8: return getSupportedDepthStencilFormat(); - case TextureFormat::SYSTEM_DEFAULT: + case PixelFormat::DEFAULT: return COLOR_ATTAHCMENT_PIXEL_FORMAT; - case TextureFormat::NONE: + case PixelFormat::NONE: default: return MTLPixelFormatInvalid; } diff --git a/cocos/renderer/backend/opengl/TextureGL.cpp b/cocos/renderer/backend/opengl/TextureGL.cpp index 8d3994125f..1ac04e95f9 100644 --- a/cocos/renderer/backend/opengl/TextureGL.cpp +++ b/cocos/renderer/backend/opengl/TextureGL.cpp @@ -11,7 +11,24 @@ CC_BACKEND_BEGIN #define ISPOW2(n) (((n) & (n-1)) == 0) -void TextureInfoGL::applySamplerDescriptor(const SamplerDescriptor& descriptor, bool isPow2) +namespace { + bool isMipmapEnabled(GLint filter) + { + switch(filter) + { + case GL_LINEAR_MIPMAP_LINEAR: + case GL_LINEAR_MIPMAP_NEAREST: + case GL_NEAREST_MIPMAP_NEAREST: + case GL_NEAREST_MIPMAP_LINEAR: + return true; + default: + break; + } + return false; + } +} + +void TextureInfoGL::applySamplerDescriptor(const SamplerDescriptor& descriptor, bool isPow2, bool hasMipmaps) { if (descriptor.magFilter != SamplerFilter::DONT_CARE) { @@ -20,7 +37,7 @@ void TextureInfoGL::applySamplerDescriptor(const SamplerDescriptor& descriptor, if (descriptor.minFilter != SamplerFilter::DONT_CARE) { - minFilterGL = UtilsGL::toGLMinFilter(descriptor.minFilter, descriptor.mipmapFilter, descriptor.mipmapEnabled, isPow2); + minFilterGL = UtilsGL::toGLMinFilter(descriptor.minFilter, hasMipmaps, isPow2); } if (descriptor.sAddressMode != SamplerAddressMode::DONT_CARE) @@ -37,19 +54,8 @@ void TextureInfoGL::applySamplerDescriptor(const SamplerDescriptor& descriptor, Texture2DGL::Texture2DGL(const TextureDescriptor& descriptor) : Texture2D(descriptor) { glGenTextures(1, &_textureInfo.texture); - UtilsGL::toGLTypes(_textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); - bool isPow2 = ISPOW2(_width) && ISPOW2(_height); - _textureInfo.magFilterGL = UtilsGL::toGLMagFilter(descriptor.samplerDescriptor.magFilter); - _textureInfo.minFilterGL = UtilsGL::toGLMinFilter(descriptor.samplerDescriptor.minFilter, - descriptor.samplerDescriptor.mipmapFilter, _isMipmapEnabled, isPow2); - - _textureInfo.sAddressModeGL = UtilsGL::toGLAddressMode(descriptor.samplerDescriptor.sAddressMode, isPow2); - _textureInfo.tAddressModeGL = UtilsGL::toGLAddressMode(descriptor.samplerDescriptor.tAddressMode, isPow2); - - // Update data here because `updateData()` may not be invoked later. - // For example, a texture used as depth buffer will not invoke updateData(). - initWithZeros(); + updateTextureDescriptor(descriptor); #if CC_ENABLE_CACHE_TEXTURE_DATA // Listen this event to restored texture id after coming to foreground on Android. @@ -66,7 +72,7 @@ void Texture2DGL::initWithZeros() auto size = _width * _height * _bitsPerElement / 8; uint8_t* data = (uint8_t*)malloc(size); memset(data, 0, size); - updateData(data); + updateData(data, _width, _height, 0); free(data); } @@ -74,9 +80,18 @@ void Texture2DGL::updateTextureDescriptor(const cocos2d::backend::TextureDescrip { Texture::updateTextureDescriptor(descriptor); UtilsGL::toGLTypes(descriptor.textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); - _width = descriptor.width; - _height = descriptor.height; + + bool isPow2 = ISPOW2(_width) && ISPOW2(_height); + _textureInfo.magFilterGL = UtilsGL::toGLMagFilter(descriptor.samplerDescriptor.magFilter); + _textureInfo.minFilterGL = UtilsGL::toGLMinFilter(descriptor.samplerDescriptor.minFilter, _hasMipmaps, isPow2); + + _textureInfo.sAddressModeGL = UtilsGL::toGLAddressMode(descriptor.samplerDescriptor.sAddressMode, isPow2); + _textureInfo.tAddressModeGL = UtilsGL::toGLAddressMode(descriptor.samplerDescriptor.tAddressMode, isPow2); + updateSamplerDescriptor(descriptor.samplerDescriptor); + + // Update data here because `updateData()` may not be invoked later. + // For example, a texture used as depth buffer will not invoke updateData(). initWithZeros(); } @@ -92,7 +107,7 @@ Texture2DGL::~Texture2DGL() void Texture2DGL::updateSamplerDescriptor(const SamplerDescriptor &sampler) { bool isPow2 = ISPOW2(_width) && ISPOW2(_height); - _textureInfo.applySamplerDescriptor(sampler, isPow2); + _textureInfo.applySamplerDescriptor(sampler, isPow2, _hasMipmaps); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _textureInfo.texture); @@ -118,15 +133,14 @@ void Texture2DGL::updateSamplerDescriptor(const SamplerDescriptor &sampler) { } } -void Texture2DGL::updateData(uint8_t* data) +void Texture2DGL::updateData(uint8_t* data, uint32_t width , uint32_t height, uint32_t level) { - // TODO: support texture cube, and compressed data. - //Set the row align only when mipmapsNum == 1 and the data is uncompressed - if(!_isMipmapEnabled && !_isCompressed) + auto mipmapEnalbed = isMipmapEnabled(_textureInfo.minFilterGL) || isMipmapEnabled(_textureInfo.magFilterGL); + if(!mipmapEnalbed) { - unsigned int bytesPerRow = _width * _bitsPerElement / 8; - + unsigned int bytesPerRow = width * _bitsPerElement / 8; + if(bytesPerRow % 8 == 0) { glPixelStorei(GL_UNPACK_ALIGNMENT, 8); @@ -148,7 +162,7 @@ void Texture2DGL::updateData(uint8_t* data) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } - + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _textureInfo.texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _textureInfo.magFilterGL); @@ -157,39 +171,55 @@ void Texture2DGL::updateData(uint8_t* data) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureInfo.tAddressModeGL); - if(_isCompressed) - { - auto datalen = _width * _height * _bitsPerElement / 8; - glCompressedTexImage2D(GL_TEXTURE_2D, 0, _textureInfo.internalFormat, (GLsizei)_width, (GLsizei)_height, 0, datalen, data); - } - else - { - glTexImage2D(GL_TEXTURE_2D, - 0, - _textureInfo.internalFormat, - _width, - _height, - 0, - _textureInfo.format, - _textureInfo.type, - data); - } + glTexImage2D(GL_TEXTURE_2D, + level, + _textureInfo.internalFormat, + width, + height, + 0, + _textureInfo.format, + _textureInfo.type, + data); CHECK_GL_ERROR_DEBUG(); - if(_isMipmapEnabled) - { - _isMipmapGenerated = false; - generateMipmaps(); - } - CHECK_GL_ERROR_DEBUG(); + if(!_hasMipmaps && level > 0) + _hasMipmaps = true; } -void Texture2DGL::updateSubData(unsigned int xoffset, unsigned int yoffset, unsigned int width, unsigned int height, uint8_t* data) +void Texture2DGL::updateCompressedData(uint8_t *data, uint32_t width, uint32_t height, + uint32_t dataLen, uint32_t level) +{ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, _textureInfo.texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _textureInfo.magFilterGL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _textureInfo.minFilterGL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _textureInfo.sAddressModeGL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureInfo.tAddressModeGL); + + + glCompressedTexImage2D(GL_TEXTURE_2D, + level, + _textureInfo.internalFormat, + (GLsizei)width, + (GLsizei)height, + 0, + dataLen, + data); + CHECK_GL_ERROR_DEBUG(); + + if(!_hasMipmaps && level > 0) + _hasMipmaps = true; +} + +void Texture2DGL::updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t level, uint8_t* data) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _textureInfo.texture); + glTexSubImage2D(GL_TEXTURE_2D, - 0, + level, xoffset, yoffset, width, @@ -199,12 +229,30 @@ void Texture2DGL::updateSubData(unsigned int xoffset, unsigned int yoffset, unsi data); CHECK_GL_ERROR_DEBUG(); - if(_isMipmapEnabled) - { - _isMipmapGenerated = false; - generateMipmaps(); - } + if(!_hasMipmaps && level > 0) + _hasMipmaps = true; +} + +void Texture2DGL::updateCompressedSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, + uint32_t height, uint32_t dataLen, uint32_t level, + uint8_t *data) +{ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, _textureInfo.texture); + + glCompressedTexSubImage2D(GL_TEXTURE_2D, + level, + xoffset, + yoffset, + width, + height, + _textureInfo.format, + dataLen, + data); CHECK_GL_ERROR_DEBUG(); + + if(!_hasMipmaps && level > 0) + _hasMipmaps = true; } void Texture2DGL::apply(int index) const @@ -218,9 +266,9 @@ void Texture2DGL::generateMipmaps() if (TextureUsage::RENDER_TARGET == _textureUsage) return; - if(!_isMipmapGenerated) + if(!_hasMipmaps) { - _isMipmapGenerated = true; + _hasMipmaps = true; glGenerateMipmap(GL_TEXTURE_2D); } } @@ -264,8 +312,7 @@ void Texture2DGL::getBytes(int x, int y, int width, int height, bool flipImage, TextureCubeGL::TextureCubeGL(const TextureDescriptor& descriptor) :TextureCubemap(descriptor) { - assert(descriptor.width == descriptor.height); - _size = descriptor.width; + assert(_width == _height); _textureType = TextureType::TEXTURE_CUBE; UtilsGL::toGLTypes(_textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); glGenTextures(1, &_textureInfo.texture); @@ -299,7 +346,6 @@ void TextureCubeGL::updateTextureDescriptor(const cocos2d::backend::TextureDescr { UtilsGL::toGLTypes(descriptor.textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); _textureFormat = descriptor.textureFormat; - _size = descriptor.width; updateSamplerDescriptor(descriptor.samplerDescriptor); } @@ -316,7 +362,7 @@ TextureCubeGL::~TextureCubeGL() void TextureCubeGL::updateSamplerDescriptor(const SamplerDescriptor &sampler) { - _textureInfo.applySamplerDescriptor(sampler, true); + _textureInfo.applySamplerDescriptor(sampler, true, _hasMipmaps); setTexParameters(); } @@ -336,17 +382,13 @@ void TextureCubeGL::updateFaceData(TextureCubeFace side, void *data) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, // level GL_RGBA, // internal format - _size, // width - _size, // height + _width, // width + _height, // height 0, // border _textureInfo.internalFormat, // format _textureInfo.type, // type data); // pixel data - if(_isMipmapEnabled) - { - _isMipmapGenerated = false; - generateMipmaps(); - } + CHECK_GL_ERROR_DEBUG(); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); } @@ -391,9 +433,9 @@ void TextureCubeGL::generateMipmaps() if (TextureUsage::RENDER_TARGET == _textureUsage) return; - if(!_isMipmapGenerated) + if(!_hasMipmaps) { - _isMipmapGenerated = true; + _hasMipmaps = true; glGenerateMipmap(GL_TEXTURE_CUBE_MAP); } } diff --git a/cocos/renderer/backend/opengl/TextureGL.h b/cocos/renderer/backend/opengl/TextureGL.h index 9285215203..648c0ed2c2 100644 --- a/cocos/renderer/backend/opengl/TextureGL.h +++ b/cocos/renderer/backend/opengl/TextureGL.h @@ -8,7 +8,7 @@ CC_BACKEND_BEGIN struct TextureInfoGL { - void applySamplerDescriptor(const SamplerDescriptor &desc, bool isPow2); + void applySamplerDescriptor(const SamplerDescriptor &desc, bool isPow2, bool hasMipmaps); GLint magFilterGL = GL_LINEAR; GLint minFilterGL = GL_LINEAR; @@ -29,8 +29,10 @@ public: Texture2DGL(const TextureDescriptor& descriptor); ~Texture2DGL(); - virtual void updateData(uint8_t* data) override; - virtual void updateSubData(unsigned int xoffset, unsigned int yoffset, unsigned int width, unsigned int height, uint8_t* data) override; + virtual void updateData(uint8_t* data, uint32_t width , uint32_t height, uint32_t level) override; + virtual void updateCompressedData(uint8_t* data, uint32_t width , uint32_t height, uint32_t dataLen, uint32_t level) override; + virtual void updateSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t level, uint8_t* data) override; + virtual void updateCompressedSubData(uint32_t xoffset, uint32_t yoffset, uint32_t width, uint32_t height, uint32_t dataLen, uint32_t level, uint8_t* data) override; virtual void updateSamplerDescriptor(const SamplerDescriptor &sampler) override; virtual void getBytes(int x, int y, int width, int height, bool flipImage, std::function callback) override; virtual void generateMipmaps() override; @@ -44,7 +46,6 @@ private: void initWithZeros(); SamplerDescriptor _samplerDescriptor; - bool _isCompressed = false; TextureInfoGL _textureInfo; EventListener* _backToForegroundListener = nullptr; }; diff --git a/cocos/renderer/backend/opengl/UtilsGL.cpp b/cocos/renderer/backend/opengl/UtilsGL.cpp index b7f4e3a079..99d57ef4cd 100644 --- a/cocos/renderer/backend/opengl/UtilsGL.cpp +++ b/cocos/renderer/backend/opengl/UtilsGL.cpp @@ -126,50 +126,35 @@ GLint UtilsGL::toGLMagFilter(SamplerFilter magFilter) return ret; } -GLint UtilsGL::toGLMinFilter(SamplerFilter minFilter, SamplerFilter mipmapFilter, bool mipmapEnabled, bool isPow2) +GLint UtilsGL::toGLMinFilter(SamplerFilter minFilter, bool hasMipmaps, bool isPow2) { - if (mipmapEnabled) - { - if (!isPow2) - { - cocos2d::log("Change minification filter to either NEAREST or LINEAR since non-power-of-two texture occur in %s %s %d", __FILE__, __FUNCTION__, __LINE__); - if (SamplerFilter::LINEAR == minFilter) - return GL_LINEAR; - else - return GL_NEAREST; - } - - switch (minFilter) - { - case SamplerFilter::LINEAR: - switch (mipmapFilter) - { - case SamplerFilter::LINEAR: - return GL_LINEAR_MIPMAP_LINEAR; - case SamplerFilter::NEAREST: - return GL_LINEAR_MIPMAP_NEAREST; - case SamplerFilter::DONT_CARE: - return GL_LINEAR_MIPMAP_NEAREST; - } - case SamplerFilter::NEAREST: - switch (mipmapFilter) - { - case SamplerFilter::LINEAR: - return GL_NEAREST_MIPMAP_LINEAR; - case SamplerFilter::NEAREST: - return GL_NEAREST_MIPMAP_NEAREST; - case SamplerFilter::DONT_CARE: - return GL_LINEAR_MIPMAP_NEAREST; - } - } - } - else + if (hasMipmaps && !isPow2) { + CCLOG("Change minification filter to either NEAREST or LINEAR since non-power-of-two texture occur in %s %s %d", __FILE__, __FUNCTION__, __LINE__); if (SamplerFilter::LINEAR == minFilter) return GL_LINEAR; else return GL_NEAREST; } + + switch (minFilter) + { + case SamplerFilter::LINEAR: + return GL_LINEAR; + case SamplerFilter::LINEAR_MIPMAP_LINEAR: + return GL_LINEAR_MIPMAP_LINEAR; + case SamplerFilter::LINEAR_MIPMAP_NEAREST: + return GL_LINEAR_MIPMAP_NEAREST; + case SamplerFilter::NEAREST: + return GL_NEAREST; + case SamplerFilter::NEAREST_MIPMAP_NEAREST: + return GL_NEAREST_MIPMAP_NEAREST; + case SamplerFilter::NEAREST_MIPMAP_LINEAR: + return GL_NEAREST_MIPMAP_LINEAR; + default: + break; + } + return GL_NEAREST; } @@ -178,7 +163,7 @@ GLint UtilsGL::toGLAddressMode(SamplerAddressMode addressMode, bool isPow2) GLint ret = GL_REPEAT; if (!isPow2 && (addressMode != SamplerAddressMode::CLAMP_TO_EDGE)) { - cocos2d::log("Change texture wrap mode to CLAMP_TO_EDGE since non-power-of-two texture occur in %s %s %d", __FILE__, __FUNCTION__, __LINE__); + CCLOG("Change texture wrap mode to CLAMP_TO_EDGE since non-power-of-two texture occur in %s %s %d", __FILE__, __FUNCTION__, __LINE__); return GL_CLAMP_TO_EDGE; } @@ -200,52 +185,52 @@ GLint UtilsGL::toGLAddressMode(SamplerAddressMode addressMode, bool isPow2) } -void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLuint &format, GLenum &type, bool &isCompressed) +void UtilsGL::toGLTypes(PixelFormat textureFormat, GLint &internalFormat, GLuint &format, GLenum &type, bool &isCompressed) { switch (textureFormat) { - case TextureFormat::R8G8B8A8: + case PixelFormat::RGBA8888: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_BYTE; break; - case TextureFormat::R8G8B8: + case PixelFormat::RGB888: internalFormat = GL_RGB; format = GL_RGB; type = GL_UNSIGNED_BYTE; break; - case TextureFormat::RGBA4444: + case PixelFormat::RGBA4444: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_4_4_4_4; break; - case TextureFormat::A8: + case PixelFormat::A8: internalFormat = GL_ALPHA; format = GL_ALPHA; type = GL_UNSIGNED_BYTE; break; - case TextureFormat::I8: + case PixelFormat::I8: internalFormat = GL_LUMINANCE; format = GL_LUMINANCE; type = GL_UNSIGNED_BYTE; break; - case TextureFormat::AI88: + case PixelFormat::AI88: internalFormat = GL_LUMINANCE_ALPHA; format = GL_LUMINANCE_ALPHA; type = GL_UNSIGNED_BYTE; break; - case TextureFormat::RGB565: + case PixelFormat::RGB565: internalFormat = GL_RGB; format = GL_RGB; type = GL_UNSIGNED_SHORT_5_6_5; break; - case TextureFormat::RGB5A1: + case PixelFormat::RGB5A1: internalFormat = GL_RGBA; format = GL_RGBA; type = GL_UNSIGNED_SHORT_5_5_5_1; break; #ifdef GL_ETC1_RGB8_OES - case TextureFormat::ETC1: + case PixelFormat::ETC: internalFormat = GL_ETC1_RGB8_OES; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -253,7 +238,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif // GL_ETC1_RGB8_OES #ifdef GL_ATC_RGB_AMD - case TextureFormat::ATC_RGB: + case PixelFormat::ATC_RGB: internalFormat = GL_ATC_RGB_AMD; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -261,14 +246,14 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif // GL_ATC_RGB_AMD #ifdef GL_ATC_RGBA_EXPLICIT_ALPHA_AMD - case TextureFormat::ATC_EXPLICIT_ALPHA: + case PixelFormat::ATC_EXPLICIT_ALPHA: internalFormat = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD; format = 0xFFFFFFFF; type = 0xFFFFFFFF; isCompressed = true; #endif // GL_ATC_RGBA_EXPLICIT_ALPHA_AMD #ifdef GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD - case TextureFormat::ATC_INTERPOLATED_ALPHA: + case PixelFormat::ATC_INTERPOLATED_ALPHA: internalFormat = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -277,7 +262,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui #endif // GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD #ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG - case TextureFormat::PVRTC2: + case PixelFormat::PVRTC2: internalFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -285,7 +270,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG - case TextureFormat::PVRTC2A: + case PixelFormat::PVRTC2A: internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -293,7 +278,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG - case TextureFormat::PVRTC4: + case PixelFormat::PVRTC4: internalFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -301,7 +286,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG - case TextureFormat::PVRTC4A: + case PixelFormat::PVRTC4A: internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -309,7 +294,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT - case TextureFormat::S3TC_DXT1: + case PixelFormat::S3TC_DXT1: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -317,7 +302,7 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT - case TextureFormat::S3TC_DXT3: + case PixelFormat::S3TC_DXT3: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; format = 0xFFFFFFFF; type = 0xFFFFFFFF; @@ -325,18 +310,18 @@ void UtilsGL::toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLui break; #endif #ifdef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT - case TextureFormat::S3TC_DXT5: + case PixelFormat::S3TC_DXT5: internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; format = 0xFFFFFFFF; type = 0xFFFFFFFF; isCompressed = true; break; #endif - // case TextureFormat::D16: + // case PixelFormat::D16: // format = GL_DEPTH_COMPONENT; // internalFormat = GL_DEPTH_COMPONENT; // type = GL_UNSIGNED_INT; - case TextureFormat::D24S8: + case PixelFormat::D24S8: #ifdef CC_USE_GLES format = GL_DEPTH_STENCIL_OES; internalFormat = GL_DEPTH_STENCIL_OES; diff --git a/cocos/renderer/backend/opengl/UtilsGL.h b/cocos/renderer/backend/opengl/UtilsGL.h index bceb362c28..27642a41dd 100644 --- a/cocos/renderer/backend/opengl/UtilsGL.h +++ b/cocos/renderer/backend/opengl/UtilsGL.h @@ -14,9 +14,9 @@ public: static GLsizei getGLDataTypeSize(GLenum size); static GLint toGLMagFilter(SamplerFilter magFilter); - static GLint toGLMinFilter(SamplerFilter minFilter, SamplerFilter mipmapFilter, bool mipmapEnabled, bool isPow2); + static GLint toGLMinFilter(SamplerFilter minFilter, bool hasMipmaps, bool isPow2); static GLint toGLAddressMode(SamplerAddressMode addressMode, bool isPow2); - static void toGLTypes(TextureFormat textureFormat, GLint &internalFormat, GLuint &format, GLenum &type, bool &isCompressed); + static void toGLTypes(PixelFormat textureFormat, GLint &internalFormat, GLuint &format, GLenum &type, bool &isCompressed); static GLenum toGLComareFunction(CompareFunction compareFunction); static GLenum toGLStencilOperation(StencilOperation stencilOperation); diff --git a/cocos/scripting/deprecated/CCDeprecated.h b/cocos/scripting/deprecated/CCDeprecated.h index ae78f3c37c..78668f5f8d 100644 --- a/cocos/scripting/deprecated/CCDeprecated.h +++ b/cocos/scripting/deprecated/CCDeprecated.h @@ -873,19 +873,19 @@ CC_DEPRECATED_ATTRIBUTE const TextHAlignment kCCTextAlignmentLeft = TextHAlignme CC_DEPRECATED_ATTRIBUTE const TextHAlignment kCCTextAlignmentCenter = TextHAlignment::CENTER; CC_DEPRECATED_ATTRIBUTE const TextHAlignment kCCTextAlignmentRight = TextHAlignment::RIGHT; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_RGBA8888 = Texture2D::PixelFormat::RGBA8888; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_RGB888 = Texture2D::PixelFormat::RGB888; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_RGB565 = Texture2D::PixelFormat::RGB565; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_A8 = Texture2D::PixelFormat::A8; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_I8 = Texture2D::PixelFormat::I8; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_AI88 = Texture2D::PixelFormat::AI88; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_RGBA4444 = Texture2D::PixelFormat::RGBA4444; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_RGB5A1 = Texture2D::PixelFormat::RGB5A1; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_PVRTC4 = Texture2D::PixelFormat::PVRTC4; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_PVRTC2 = Texture2D::PixelFormat::PVRTC2; -CC_DEPRECATED_ATTRIBUTE const Texture2D::PixelFormat kCCTexture2DPixelFormat_Default = Texture2D::PixelFormat::DEFAULT; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_RGBA8888 = backend::PixelFormat::RGBA8888; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_RGB888 = backend::PixelFormat::RGB888; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_RGB565 = backend::PixelFormat::RGB565; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_A8 = backend::PixelFormat::A8; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_I8 = backend::PixelFormat::I8; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_AI88 = backend::PixelFormat::AI88; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_RGBA4444 = backend::PixelFormat::RGBA4444; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_RGB5A1 = backend::PixelFormat::RGB5A1; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_PVRTC4 = backend::PixelFormat::PVRTC4; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_PVRTC2 = backend::PixelFormat::PVRTC2; +CC_DEPRECATED_ATTRIBUTE const backend::PixelFormat kCCTexture2DPixelFormat_Default = backend::PixelFormat::DEFAULT; -CC_DEPRECATED_ATTRIBUTE typedef Texture2D::PixelFormat CCTexture2DPixelFormat; +CC_DEPRECATED_ATTRIBUTE typedef backend::PixelFormat CCTexture2DPixelFormat; CC_DEPRECATED_ATTRIBUTE const int kCCParticleDurationInfinity = ParticleSystem::DURATION_INFINITY; diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index efc0567eaf..bdb81b28e5 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -762,7 +762,7 @@ int lua_cocos2dx_Texture2D_initWithImage(lua_State* tolua_S) ok &= luaval_to_object(tolua_S, 2, "cc.Image",&arg0, "cc.Texture2D:initWithImage"); if (!ok) { break; } - cocos2d::Texture2D::PixelFormat arg1; + cocos2d::backend::PixelFormat arg1; ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.Texture2D:initWithImage"); if (!ok) { break; } @@ -1005,7 +1005,7 @@ int lua_cocos2dx_Texture2D_getBitsPerPixelForFormat(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; do{ if (argc == 1) { - cocos2d::Texture2D::PixelFormat arg0; + cocos2d::backend::PixelFormat arg0; ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.Texture2D:getBitsPerPixelForFormat"); if (!ok) { break; } @@ -1033,53 +1033,6 @@ int lua_cocos2dx_Texture2D_getBitsPerPixelForFormat(lua_State* tolua_S) return 0; } -int lua_cocos2dx_Texture2D_getName(lua_State* tolua_S) -{ - int argc = 0; - cocos2d::Texture2D* cobj = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"cc.Texture2D",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = (cocos2d::Texture2D*)tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (!cobj) - { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Texture2D_getName'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Texture2D_getName'", nullptr); - return 0; - } - unsigned int ret = cobj->getName(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Texture2D:getName",argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Texture2D_getName'.",&tolua_err); -#endif - - return 0; -} int lua_cocos2dx_Texture2D_initWithString(lua_State* tolua_S) { int argc = 0; @@ -1991,7 +1944,7 @@ int lua_cocos2dx_Texture2D_setDefaultAlphaPixelFormat(lua_State* tolua_S) if (argc == 1) { - cocos2d::Texture2D::PixelFormat arg0; + cocos2d::backend::PixelFormat arg0; ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.Texture2D:setDefaultAlphaPixelFormat"); if(!ok) { @@ -2103,7 +2056,6 @@ int lua_register_cocos2dx_Texture2D(lua_State* tolua_S) tolua_function(tolua_S,"getPixelsHigh",lua_cocos2dx_Texture2D_getPixelsHigh); tolua_function(tolua_S,"getAlphaTextureName",lua_cocos2dx_Texture2D_getAlphaTextureName); tolua_function(tolua_S,"getBitsPerPixelForFormat",lua_cocos2dx_Texture2D_getBitsPerPixelForFormat); - tolua_function(tolua_S,"getName",lua_cocos2dx_Texture2D_getName); tolua_function(tolua_S,"initWithString",lua_cocos2dx_Texture2D_initWithString); tolua_function(tolua_S,"setMaxT",lua_cocos2dx_Texture2D_setMaxT); tolua_function(tolua_S,"getPath",lua_cocos2dx_Texture2D_getPath); @@ -77406,11 +77358,11 @@ int lua_cocos2dx_RenderTexture_initWithWidthAndHeight(lua_State* tolua_S) ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.RenderTexture:initWithWidthAndHeight"); if (!ok) { break; } - cocos2d::Texture2D::PixelFormat arg2; + cocos2d::backend::PixelFormat arg2; ok &= luaval_to_int32(tolua_S, 4,(int *)&arg2, "cc.RenderTexture:initWithWidthAndHeight"); if (!ok) { break; } - cocos2d::backend::TextureFormat arg3; + cocos2d::backend::PixelFormat arg3; ok &= luaval_to_int32(tolua_S, 5,(int *)&arg3, "cc.RenderTexture:initWithWidthAndHeight"); if (!ok) { break; } @@ -77430,7 +77382,7 @@ int lua_cocos2dx_RenderTexture_initWithWidthAndHeight(lua_State* tolua_S) ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.RenderTexture:initWithWidthAndHeight"); if (!ok) { break; } - cocos2d::Texture2D::PixelFormat arg2; + cocos2d::backend::PixelFormat arg2; ok &= luaval_to_int32(tolua_S, 4,(int *)&arg2, "cc.RenderTexture:initWithWidthAndHeight"); if (!ok) { break; } @@ -77474,7 +77426,7 @@ int lua_cocos2dx_RenderTexture_create(lua_State* tolua_S) int arg1; ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.RenderTexture:create"); if (!ok) { break; } - cocos2d::Texture2D::PixelFormat arg2; + cocos2d::backend::PixelFormat arg2; ok &= luaval_to_int32(tolua_S, 4,(int *)&arg2, "cc.RenderTexture:create"); if (!ok) { break; } cocos2d::RenderTexture* ret = cocos2d::RenderTexture::create(arg0, arg1, arg2); @@ -77493,10 +77445,10 @@ int lua_cocos2dx_RenderTexture_create(lua_State* tolua_S) int arg1; ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.RenderTexture:create"); if (!ok) { break; } - cocos2d::Texture2D::PixelFormat arg2; + cocos2d::backend::PixelFormat arg2; ok &= luaval_to_int32(tolua_S, 4,(int *)&arg2, "cc.RenderTexture:create"); if (!ok) { break; } - cocos2d::backend::TextureFormat arg3; + cocos2d::backend::PixelFormat arg3; ok &= luaval_to_int32(tolua_S, 5,(int *)&arg3, "cc.RenderTexture:create"); if (!ok) { break; } cocos2d::RenderTexture* ret = cocos2d::RenderTexture::create(arg0, arg1, arg2, arg3); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp index 36ff99bf7a..25dbfda421 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp @@ -75,8 +75,8 @@ int lua_register_cocos2dx_backend_VertexFormat(lua_State* tolua_S) int lua_register_cocos2dx_backend_TextureFormat(lua_State* tolua_S) { - tolua_module(tolua_S, "TextureFormat", 0); - tolua_beginmodule(tolua_S,"TextureFormat"); + tolua_module(tolua_S, "PixelFormat", 0); + tolua_beginmodule(tolua_S,"PixelFormat"); tolua_constant(tolua_S, "NONE", 0); tolua_constant(tolua_S, "R8G8B8A8", 1); tolua_constant(tolua_S, "R8G8B8", 2); @@ -103,9 +103,9 @@ int lua_register_cocos2dx_backend_TextureFormat(lua_State* tolua_S) tolua_constant(tolua_S, "S3TC_DXT5", 23); tolua_constant(tolua_S, "SYSTEM_DEFAULT", 24); tolua_endmodule(tolua_S); - std::string typeName = typeid(cocos2d::backend::TextureFormat).name(); - g_luaType[typeName] = "ccb.TextureFormat"; - g_typeCast["TextureFormat"] = "ccb.TextureFormat"; + std::string typeName = typeid(cocos2d::backend::PixelFormat).name(); + g_luaType[typeName] = "ccb.PixelFormat"; + g_typeCast["PixelFormat"] = "ccb.PixelFormat"; return 1; } diff --git a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp index c9854de4b7..ac818122b5 100644 --- a/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp +++ b/cocos/scripting/lua-bindings/manual/LuaBasicConversions.cpp @@ -3205,12 +3205,6 @@ void texParams_to_luaval(lua_State* L, const cocos2d::Texture2D::TexParams& inVa lua_pushstring(L, "sAddressMode"); /* L: table key */ lua_pushnumber(L, (lua_Number) inValue.tAddressMode); /* L: table key value*/ lua_rawset(L, -3); - lua_pushstring(L, "mipmapFilter"); - lua_pushnumber(L, (lua_Number)inValue.mipmapFilter); - lua_rawset(L, -3); - lua_pushstring(L, "mipmapEnabled"); - lua_pushboolean(L, inValue.mipmapEnabled); - lua_rawset(L, -3); } void std_vector_vec3_to_luaval(lua_State* L, const std::vector& inValue) @@ -3334,14 +3328,6 @@ bool luaval_to_samplerDescriptor(lua_State* L, int pos, cocos2d::backend::Sample } lua_pop(L, 1); - lua_pushstring(L, "mipmapFilter"); - lua_gettable(L, pos); - if (!lua_isnil(L, -1)) - { - output.mipmapFilter = static_cast(lua_tointeger(L, -1)); - } - lua_pop(L, 1); - lua_pushstring(L, "sAddressMode"); lua_gettable(L, pos); if (!lua_isnil(L, -1)) @@ -3358,13 +3344,6 @@ bool luaval_to_samplerDescriptor(lua_State* L, int pos, cocos2d::backend::Sample } lua_pop(L, 1); - lua_pushstring(L, "mipmapEnabled"); - lua_gettable(L, pos); - if (!lua_isnil(L, -1)) - { - output.mipmapEnabled = lua_toboolean(L, -1); - } - lua_pop(L, 1); return true; } diff --git a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp index 84199a7ac8..da4e303238 100644 --- a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -963,7 +963,7 @@ void ClippingToRenderTextureTest::reproduceBug() // container rendered on Texture the size of the screen and because Clipping node use stencil buffer so we need to // create RenderTexture with depthStencil format parameter - RenderTexture* rt = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888, TextureFormat::D24S8); + RenderTexture* rt = RenderTexture::create(visibleSize.width, visibleSize.height, backend::PixelFormat::RGBA8888, PixelFormat::D24S8); rt->setPosition(visibleSize.width/2, visibleSize.height/2); this->addChild(rt); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index 1a909b34ed..8e541813b9 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -49,7 +49,7 @@ RenderTextureSave::RenderTextureSave() auto s = Director::getInstance()->getWinSize(); // create a render texture, this is what we are going to draw into - _target = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _target = RenderTexture::create(s.width, s.height, backend::PixelFormat::RGBA8888); _target->retain(); _target->setPosition(Vec2(s.width / 2, s.height / 2)); @@ -191,7 +191,7 @@ RenderTextureIssue937::RenderTextureIssue937() spr_nonpremulti->setPosition(Vec2(s.width/2-16, s.height/2-16)); /* A2 & B2 setup */ - auto rend = RenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888); + auto rend = RenderTexture::create(32, 64, backend::PixelFormat::RGBA8888); if (nullptr == rend) { @@ -393,7 +393,7 @@ RenderTexturePartTest::RenderTexturePartTest() addChild(sprite2); addChild(sprite22); - _rend = RenderTexture::create(200, 200, Texture2D::PixelFormat::RGBA8888); + _rend = RenderTexture::create(200, 200, backend::PixelFormat::RGBA8888); _rend->retain(); _rend->setKeepMatrix(true); Size pixelSize = Director::getInstance()->getWinSizeInPixels(); @@ -448,7 +448,7 @@ RenderTextureTestDepthStencil::RenderTextureTestDepthStencil() //! move sprite half width and height, and draw only where not marked _spriteDraw->setPosition(_spriteDraw->getPosition() + Vec2(_spriteDraw->getContentSize().width * _spriteDraw->getScale() * 0.5, _spriteDraw->getContentSize().height * _spriteDraw->getScale() * 0.5)); - _rend = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, TextureFormat::D24S8); + _rend = RenderTexture::create(s.width, s.height, backend::PixelFormat::RGBA4444, PixelFormat::D24S8); _rend->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f)); @@ -549,7 +549,7 @@ RenderTextureTargetNode::RenderTextureTargetNode() auto s = Director::getInstance()->getWinSize(); /* Create the render texture */ - auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444); + auto renderTexture = RenderTexture::create(s.width, s.height, backend::PixelFormat::RGBA4444); this->renderTexture = renderTexture; renderTexture->setPosition(Vec2(s.width/2, s.height/2)); @@ -638,7 +638,7 @@ void SpriteRenderTextureBug::SimpleSprite::draw(Renderer *renderer, const Mat4 & if (_rt == nullptr) { auto s = Director::getInstance()->getWinSize(); - _rt = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _rt = RenderTexture::create(s.width, s.height, backend::PixelFormat::RGBA8888); _rt->retain(); } _rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); @@ -726,7 +726,7 @@ Issue16113Test::Issue16113Test() auto winSize = Director::getInstance()->getVisibleSize(); auto text = Label::createWithTTF("hello world", "fonts/Marker Felt.ttf", 40); text->setTextColor(Color4B::RED); - auto target = RenderTexture::create(winSize.width, winSize.height, Texture2D::PixelFormat::RGBA8888); + auto target = RenderTexture::create(winSize.width, winSize.height, backend::PixelFormat::RGBA8888); target->beginWithClear(0,0,0,0); text->setPosition(winSize.width / 2,winSize.height/2); text->Node::visit(); @@ -783,12 +783,12 @@ RenderTextureWithSprite3DIssue16894::RenderTextureWithSprite3DIssue16894() // } // // RenderTextures - // _renderTexDefault = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888); + // _renderTexDefault = RenderTexture::create(visibleSize.width, visibleSize.height, backend::PixelFormat::RGBA8888); // _renderTexDefault->setKeepMatrix(true); // addChild(_renderTexDefault); // _renderTexDefault->setPosition(visibleSize.width/4 * 3, visibleSize.height/2); - // _renderTexWithBuffer = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8); + // _renderTexWithBuffer = RenderTexture::create(visibleSize.width, visibleSize.height, backend::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8); // _renderTexWithBuffer->setKeepMatrix(true); // addChild(_renderTexWithBuffer); // _renderTexWithBuffer->setPosition(visibleSize.width/4 * 4, visibleSize.height/2); diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp index c8204a1ffc..45f2b67a5c 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp @@ -51,30 +51,30 @@ SpriteFrameCachePixelFormatTest::SpriteFrameCachePixelFormatTest() addChild(infoLabel); // load atlas definition with specified PixelFormat and check that it matches to expected format - loadSpriteFrames("Images/sprite_frames_test/test_A8.plist", Texture2D::PixelFormat::A8); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - loadSpriteFrames("Images/sprite_frames_test/test_AI88.plist", Texture2D::PixelFormat::AI88); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - loadSpriteFrames("Images/sprite_frames_test/test_RGB565.plist", Texture2D::PixelFormat::RGB565); - loadSpriteFrames("Images/sprite_frames_test/test_RGB888.plist", Texture2D::PixelFormat::RGB888); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA4444.plist", Texture2D::PixelFormat::RGBA4444); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA5551.plist", Texture2D::PixelFormat::RGB5A1); + loadSpriteFrames("Images/sprite_frames_test/test_A8.plist", backend::PixelFormat::A8); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_AI88.plist", backend::PixelFormat::AI88); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGB565.plist", backend::PixelFormat::RGB565); + loadSpriteFrames("Images/sprite_frames_test/test_RGB888.plist", backend::PixelFormat::RGB888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA4444.plist", backend::PixelFormat::RGBA4444); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA5551.plist", backend::PixelFormat::RGB5A1); if (Configuration::getInstance()->supportsPVRTC()) { - loadSpriteFrames("Images/sprite_frames_test/test_PVRTC2.plist", Texture2D::PixelFormat::PVRTC2A); - loadSpriteFrames("Images/sprite_frames_test/test_PVRTC4.plist", Texture2D::PixelFormat::PVRTC4A); - loadSpriteFrames("Images/sprite_frames_test/test_PVRTC2_NOALPHA.plist", Texture2D::PixelFormat::PVRTC2); + loadSpriteFrames("Images/sprite_frames_test/test_PVRTC2.plist", backend::PixelFormat::PVRTC2A); + loadSpriteFrames("Images/sprite_frames_test/test_PVRTC4.plist", backend::PixelFormat::PVRTC4A); + loadSpriteFrames("Images/sprite_frames_test/test_PVRTC2_NOALPHA.plist", backend::PixelFormat::PVRTC2); } // test loading atlases without PixelFormat specified - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1); - loadSpriteFrames("Images/sprite_frames_test/test_NoFormat.plist", Texture2D::PixelFormat::RGB5A1); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1); + loadSpriteFrames("Images/sprite_frames_test/test_NoFormat.plist", backend::PixelFormat::RGB5A1); // restore default alpha pixel format - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888); } -void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) +void SpriteFrameCachePixelFormatTest::loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); @@ -97,14 +97,14 @@ SpriteFrameCacheLoadMultipleTimes::SpriteFrameCacheLoadMultipleTimes() const Size screenSize = Director::getInstance()->getWinSize(); // load atlas definition with specified PixelFormat and check that it matches to expected format - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); - loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", Texture2D::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); + loadSpriteFrames("Images/sprite_frames_test/test_RGBA8888.plist", backend::PixelFormat::RGBA8888); } -void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) +void SpriteFrameCacheLoadMultipleTimes::loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file); SpriteFrame *spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini.png"); @@ -120,10 +120,10 @@ SpriteFrameCacheFullCheck::SpriteFrameCacheFullCheck() { const Size screenSize = Director::getInstance()->getWinSize(); // load atlas definition with specified PixelFormat and check that it matches to expected format - loadSpriteFrames("Images/test_polygon.plist", Texture2D::PixelFormat::RGBA8888); + loadSpriteFrames("Images/test_polygon.plist", backend::PixelFormat::RGBA8888); } -void SpriteFrameCacheFullCheck::loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat) +void SpriteFrameCacheFullCheck::loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat) { auto cache = SpriteFrameCache::getInstance(); diff --git a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h index 9937702818..abdde843bc 100644 --- a/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h +++ b/tests/cpp-tests/Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.h @@ -41,7 +41,7 @@ public: SpriteFrameCachePixelFormatTest(); private: - void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); + void loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat); private: cocos2d::Label *infoLabel; @@ -58,7 +58,7 @@ public: SpriteFrameCacheLoadMultipleTimes(); private: - void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); + void loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat); }; @@ -74,6 +74,6 @@ public: SpriteFrameCacheFullCheck(); private: - void loadSpriteFrames(const std::string &file, cocos2d::Texture2D::PixelFormat expectedFormat); + void loadSpriteFrames(const std::string &file, cocos2d::backend::PixelFormat expectedFormat); }; \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp index e4873fe6da..c6a49ee1b9 100644 --- a/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp +++ b/tests/cpp-tests/Classes/Texture2dTest/Texture2dTest.cpp @@ -304,10 +304,13 @@ void TextureMipMap::onEnter() auto s = Director::getInstance()->getWinSize(); auto texture0 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png"); - //TODO: minggo -// texture0->generateMipmap(); -// Texture2D::TexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; -// texture0->setSamplerDescriptor(texParams); + texture0->generateMipmap(); + Texture2D::TexParams texParams = { + backend::SamplerFilter::LINEAR_MIPMAP_LINEAR, + backend::SamplerFilter::LINEAR, + backend::SamplerAddressMode::CLAMP_TO_EDGE, + backend::SamplerAddressMode::CLAMP_TO_EDGE }; + texture0->setTexParameters(texParams); auto texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas_nomipmap.png"); @@ -362,9 +365,12 @@ void TexturePVRMipMap::onEnter() addChild(imgMipMap); // support mipmap filtering - //TODO minggo -// Texture2D::TexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; -// imgMipMap->getTexture()->setSamplerDescriptor(texParams); + Texture2D::TexParams texParams = { + backend::SamplerFilter::LINEAR_MIPMAP_LINEAR, + backend::SamplerFilter::LINEAR, + backend::SamplerAddressMode::CLAMP_TO_EDGE, + backend::SamplerAddressMode::CLAMP_TO_EDGE }; + imgMipMap->getTexture()->setTexParameters(texParams); } auto img = Sprite::create("Images/logo-nomipmap.pvr"); @@ -409,9 +415,12 @@ void TexturePVRMipMap2::onEnter() addChild(imgMipMap); // support mipmap filtering - //TODO minggo -// Texture2D::TexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; -// imgMipMap->getTexture()->setSamplerDescriptor(texParams); + Texture2D::TexParams texParams = { + backend::SamplerFilter::LINEAR_MIPMAP_LINEAR, + backend::SamplerFilter::LINEAR, + backend::SamplerAddressMode::CLAMP_TO_EDGE, + backend::SamplerAddressMode::CLAMP_TO_EDGE }; + imgMipMap->getTexture()->setTexParameters(texParams); auto img = Sprite::create("Images/test_image.png"); img->setPosition(Vec2( s.width/2.0f+100, s.height/2.0f)); @@ -1360,7 +1369,7 @@ void TexturePixelFormat::onEnter() addChild(background, -1); // RGBA 8888 image (32-bit) - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888); auto sprite1 = Sprite::create("Images/test-rgba1.png"); sprite1->setPosition(Vec2(1*s.width/7, s.height/2+32)); addChild(sprite1, 0); @@ -1369,7 +1378,7 @@ void TexturePixelFormat::onEnter() Director::getInstance()->getTextureCache()->removeTexture(sprite1->getTexture()); // RGBA 4444 image (16-bit) - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4444); auto sprite2 = Sprite::create("Images/test-rgba1.png"); sprite2->setPosition(Vec2(2*s.width/7, s.height/2-32)); addChild(sprite2, 0); @@ -1378,7 +1387,7 @@ void TexturePixelFormat::onEnter() Director::getInstance()->getTextureCache()->removeTexture(sprite2->getTexture()); // RGB5A1 image (16-bit) - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1); auto sprite3 = Sprite::create("Images/test-rgba1.png"); sprite3->setPosition(Vec2(3*s.width/7, s.height/2+32)); addChild(sprite3, 0); @@ -1387,7 +1396,7 @@ void TexturePixelFormat::onEnter() Director::getInstance()->getTextureCache()->removeTexture(sprite3->getTexture()); // RGB888 image - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB888); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB888); auto sprite4 = Sprite::create("Images/test-rgba1.png"); sprite4->setPosition(Vec2(4*s.width/7, s.height/2-32)); addChild(sprite4, 0); @@ -1396,7 +1405,7 @@ void TexturePixelFormat::onEnter() Director::getInstance()->getTextureCache()->removeTexture(sprite4->getTexture()); // RGB565 image (16-bit) - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB565); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB565); auto sprite5 = Sprite::create("Images/test-rgba1.png"); sprite5->setPosition(Vec2(5*s.width/7, s.height/2+32)); addChild(sprite5, 0); @@ -1405,7 +1414,7 @@ void TexturePixelFormat::onEnter() Director::getInstance()->getTextureCache()->removeTexture(sprite5->getTexture()); // A8 image (8-bit) - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::A8); auto sprite6 = Sprite::create("Images/test-rgba1.png"); sprite6->setPosition(Vec2(6*s.width/7, s.height/2-32)); addChild(sprite6, 0); @@ -1429,7 +1438,7 @@ void TexturePixelFormat::onEnter() sprite5->runAction(seq_4ever5); // restore default - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::DEFAULT); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } @@ -1987,7 +1996,7 @@ TexturePVRv3Premult::TexturePVRv3Premult() transformSprite(pvr2); // PNG - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8888); Director::getInstance()->getTextureCache()->removeTextureForKey("Images/grossinis_sister1-testalpha.png"); auto png = Sprite::create("Images/grossinis_sister1-testalpha.png"); addChild(png, 0); @@ -2195,7 +2204,7 @@ std::string TextureATITCInterpolated::subtitle() const return "ATITC RGBA Interpolated Alpha compressed texture test"; } -static void addImageToDemo(TextureDemo& demo, float x, float y, const char* path, Texture2D::PixelFormat format) +static void addImageToDemo(TextureDemo& demo, float x, float y, const char* path, backend::PixelFormat format) { Texture2D::setDefaultAlphaPixelFormat(format); auto sprite = Sprite::create(path); @@ -2217,17 +2226,17 @@ void TextureConvertRGB888::onEnter() addChild(background, -1); const char* img = "Images/test_image_rgb888.png"; - addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA8888); - addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB888); - addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGB565); - addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::A8); - addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::I8); - addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::AI88); - addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA4444); - addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB5A1); + addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA8888); + addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB888); + addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, backend::PixelFormat::RGB565); + addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, backend::PixelFormat::A8); + addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, backend::PixelFormat::I8); + addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, backend::PixelFormat::AI88); + addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA4444); + addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB5A1); // restore default - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::DEFAULT); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } @@ -2251,17 +2260,17 @@ void TextureConvertRGBA8888::onEnter() addChild(background, -1); const char* img = "Images/test_image_rgba8888.png"; - addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA8888); - addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB888); - addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGB565); - addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::A8); - addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::I8); - addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::AI88); - addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA4444); - addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB5A1); + addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA8888); + addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB888); + addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, backend::PixelFormat::RGB565); + addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, backend::PixelFormat::A8); + addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, backend::PixelFormat::I8); + addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, backend::PixelFormat::AI88); + addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA4444); + addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB5A1); // restore default - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::DEFAULT); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } @@ -2285,17 +2294,17 @@ void TextureConvertI8::onEnter() addChild(background, -1); const char* img = "Images/test_image_i8.png"; - addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA8888); - addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB888); - addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGB565); - addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::A8); - addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::I8); - addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::AI88); - addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA4444); - addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB5A1); + addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA8888); + addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB888); + addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, backend::PixelFormat::RGB565); + addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, backend::PixelFormat::A8); + addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, backend::PixelFormat::I8); + addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, backend::PixelFormat::AI88); + addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA4444); + addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB5A1); // restore default - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::DEFAULT); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } @@ -2319,17 +2328,17 @@ void TextureConvertAI88::onEnter() addChild(background, -1); const char* img = "Images/test_image_ai88.png"; - addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA8888); - addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB888); - addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGB565); - addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::A8); - addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::I8); - addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::AI88); - addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, Texture2D::PixelFormat::RGBA4444); - addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, Texture2D::PixelFormat::RGB5A1); + addImageToDemo(*this, 1*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA8888); + addImageToDemo(*this, 2*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB888); + addImageToDemo(*this, 3*s.width/9, s.height/2+32, img, backend::PixelFormat::RGB565); + addImageToDemo(*this, 4*s.width/9, s.height/2-32, img, backend::PixelFormat::A8); + addImageToDemo(*this, 5*s.width/9, s.height/2+32, img, backend::PixelFormat::I8); + addImageToDemo(*this, 6*s.width/9, s.height/2-32, img, backend::PixelFormat::AI88); + addImageToDemo(*this, 7*s.width/9, s.height/2+32, img, backend::PixelFormat::RGBA4444); + addImageToDemo(*this, 8*s.width/9, s.height/2-32, img, backend::PixelFormat::RGB5A1); // restore default - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::DEFAULT); log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); }