/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2020 c4games.com
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "Texture.h"
#include <cassert>
CC_BACKEND_BEGIN
#define byte(n) ((n) * 8)
#define bit(n) (n)
namespace
{
// !!!FIXME: GPU supported compression texture formats, bpp could be ignore and doesn't to set, leave it=0
// ASTC have float bpp, such as ASTC6x6 3.56 BPP
static uint8_t computeBitsPerElement(PixelFormat textureFormat)
switch (textureFormat)
case PixelFormat::RGBA8888:
case PixelFormat::BGRA8888:
return byte(4);
case PixelFormat::RGB888:
return byte(3);
case PixelFormat::RGBA4444:
return byte(2);
case PixelFormat::A8:
return byte(1);
case PixelFormat::I8:
case PixelFormat::RGB565:
case PixelFormat::RGB5A1:
case PixelFormat::AI88:
case PixelFormat::ATC_RGB:
return bit(4);
case PixelFormat::ATC_EXPLICIT_ALPHA:
case PixelFormat::ATC_INTERPOLATED_ALPHA:
case PixelFormat::PVRTC2:
return bit(2);
case PixelFormat::PVRTC2A:
case PixelFormat::PVRTC4:
case PixelFormat::PVRTC4A:
case PixelFormat::S3TC_DXT1:
case PixelFormat::S3TC_DXT3:
case PixelFormat::S3TC_DXT5:
case PixelFormat::MTL_BGR5A1:
case PixelFormat::MTL_B5G6R5:
case PixelFormat::MTL_ABGR4:
case PixelFormat::D24S8:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
//ios use MTLPixelFormatDepth32Float_Stencil8 as DepthStencil combined format, its 64 bits
return byte(8);
#else
//mac and opengl use Depth24_Stnicl8 combined format, its 32 bits
#endif
default:
return byte(0); //"textureFormat pixel size in bytes not defined!";
}
return 0;
TextureBackend::~TextureBackend()
{}
void TextureBackend::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor, int /*index*/)
_bitsPerElement = computeBitsPerElement(descriptor.textureFormat);
_textureType = descriptor.textureType;
_textureFormat = descriptor.textureFormat;
_textureUsage = descriptor.textureUsage;
_width = descriptor.width;
_height = descriptor.height;
CC_BACKEND_END