Skip to content

Refactor pixel format manipulate #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7946715
PixelFormat use table
halx99 Sep 23, 2020
ef57c64
Correct PixelFormat name to match 'GL_LUMINANCE'
halx99 Sep 23, 2020
10776de
Up
halx99 Sep 23, 2020
b98939e
fix cube update texture enum
halx99 Sep 23, 2020
88c2f22
linux build
halx99 Sep 23, 2020
a7a5f72
Refine ci
halx99 Sep 23, 2020
d6b6de8
fix linux build
halx99 Sep 23, 2020
8a51ea8
Remove unused function, match mtl framebuffer pixel format
halx99 Sep 23, 2020
a1905dc
readPixels always RGBA format
halx99 Sep 23, 2020
bc4c66f
fix ci for linux
halx99 Sep 23, 2020
1071b0f
fix linux build
halx99 Sep 23, 2020
8996951
Remove unused functions
halx99 Sep 23, 2020
443df1a
fix travis
halx99 Sep 23, 2020
bce6254
fix android ci
halx99 Sep 23, 2020
a5eb3cf
Update config.json
halx99 Sep 23, 2020
29912b1
linux glad
halx99 Sep 23, 2020
ffb882b
Update CCGLViewImpl-desktop.cpp
halx99 Sep 23, 2020
562591d
fix linux build
halx99 Sep 24, 2020
c6d9a41
Fix linux build
halx99 Sep 24, 2020
e799bdc
Link issue [skip appveyor][skip travis]
halx99 Sep 24, 2020
00536a8
Update CMakeLists.txt
halx99 Sep 24, 2020
ea740fe
Refine GL enums use
halx99 Sep 24, 2020
0bb2ded
Update test case name [skip appveyor][skip travis]
halx99 Sep 24, 2020
802cce5
fix linux link issue
halx99 Sep 24, 2020
a472787
for mtl
halx99 Sep 24, 2020
fed8c11
fix ci
halx99 Sep 24, 2020
5177260
Tidy pixelformat enums
halx99 Sep 24, 2020
563f529
fix ci
halx99 Sep 24, 2020
981d9c8
fix rgba8 to abgr4 error
halx99 Sep 24, 2020
f695ed1
fix ci
halx99 Sep 24, 2020
92832d7
fix ci for GLES
halx99 Sep 24, 2020
46232e3
Fix linux build, require glibc-2.27+
halx99 Sep 24, 2020
cc64d55
Use properly dist for travis [skip appveyor]
halx99 Sep 24, 2020
5a64c05
fix linux build [skip appveyor]
halx99 Sep 24, 2020
df14460
Update install-deps-linux.sh
halx99 Sep 24, 2020
fffbfb1
Remove unused members for pixel block info, update external to v73
halx99 Sep 24, 2020
3226da4
Merge branch 'pixelformats' of https://github.com/halx99/engine-x int…
halx99 Sep 24, 2020
36516f1
Sync from compile linux warnings
halx99 Sep 24, 2020
cae3415
Remove unused check, and PixelFormat::A8 is ordinary format, not comp…
halx99 Sep 24, 2020
cef5998
metal doesn't support rgb8 (#3)
halx99 Sep 24, 2020
867d25f
Pixel Format Descriptor Table
halx99 Sep 24, 2020
38ae632
fix ci
halx99 Sep 24, 2020
0df01a0
BGR5A1
halx99 Sep 24, 2020
65b33f8
Simplfy texture format convert function name
halx99 Sep 24, 2020
5b59854
Update
halx99 Sep 24, 2020
7f8bfba
rgba4 match mtl render format
halx99 Sep 24, 2020
16895ee
Add note about RGBA4
halx99 Sep 24, 2020
56f369b
Remove unused function
halx99 Sep 24, 2020
96f9112
fix osx
halx99 Sep 24, 2020
299912c
Already converted at texture2d
halx99 Sep 25, 2020
ddb028f
Clearly comment
halx99 Sep 25, 2020
926da35
fixup
halx99 Sep 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
language: cpp
jobs:
include:
# mac_cmake
# osx
- os: osx
env: BUILD_TARGET=mac_cmake
env: BUILD_TARGET=osx
osx_image: xcode11.6
# iOS_cmake
# ios
- os: osx
env: BUILD_TARGET=ios_cmake
env: BUILD_TARGET=ios
osx_image: xcode11.6
# android cmake
# android
- os: linux
env: BUILD_TARGET=android_cmake
dist: xenial
env: BUILD_TARGET=android
language: android
# android_lua cmake
# linux
- os: linux
dist: bionic
env:
- BUILD_TARGET=linux
- GEN_BINDING_AND_COCOSFILE=false
# android_lua
#- os: linux
# env: BUILD_TARGET=android_lua_cmake
# env: BUILD_TARGET=android_lua
# addons:
# apt:
# sources:
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/CocosConfigDepend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ macro(cocos2dx_depend)
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 userenv psapi winmm Version Iphlpapi opengl32)
elseif(LINUX)
# need review those libs: X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m
list(APPEND PLATFORM_SPECIFIC_LIBS dl X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m)
list(APPEND PLATFORM_SPECIFIC_LIBS dl X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m bsd)
# use older cmake style on below linux libs
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCAutoPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ AutoPolygon::AutoPolygon(const std::string &filename)
_filename = filename;
_image = new (std::nothrow) Image();
_image->initWithImageFile(filename);
CCASSERT(_image->getPixelFormat()==backend::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888");
CCASSERT(_image->getPixelFormat()==backend::PixelFormat::RGBA8, "unsupported format, currently only supports rgba8888");
_data = _image->getData();
_width = _image->getWidth();
_height = _image->getHeight();
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCFontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void FontAtlas::initTextureWithZeros(Texture2D *texture)
if (outlineSize > 0)
{
//metal do no support AI88 format
pixelFormat = backend::PixelFormat::RGBA8888;
pixelFormat = backend::PixelFormat::RGBA8;
zeroBytes = CacheTextureWidth * CacheTextureWidth * 4;
}
else
Expand Down Expand Up @@ -383,7 +383,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
FontLetterDefinition tempDef;

auto scaleFactor = CC_CONTENT_SCALE_FACTOR();
auto pixelFormat = _fontFreeType->getOutlineSize() > 0 ? backend::PixelFormat::AI88 : backend::PixelFormat::A8;
auto pixelFormat = _fontFreeType->getOutlineSize() > 0 ? backend::PixelFormat::LA8 : backend::PixelFormat::A8;

int startY = (int)_currentPageOrigY;

Expand Down Expand Up @@ -477,7 +477,7 @@ void FontAtlas::updateTextureContent(backend::PixelFormat format, int startY)
{
unsigned char *data = nullptr;
auto outlineSize = _fontFreeType->getOutlineSize();
if (outlineSize > 0 && format == backend::PixelFormat::AI88)
if (outlineSize > 0 && format == backend::PixelFormat::LA8)
{
int nLen = CacheTextureWidth * ((int)_currentPageOrigY - startY + _currLineHeight);
data = _currentPageData + CacheTextureWidth * (int)startY * 2;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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::PixelFormat::RGBA8888;
descriptor.textureFormat = backend::PixelFormat::RGBA8;
auto backendTexture = backend::Device::getInstance()->newTexture(descriptor);
texture->initWithBackendTexture(backendTexture);
backendTexture->release();
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/CCRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,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, backend::PixelFormat::RGBA8888, s);
VolatileTextureMgr::addDataTexture(_texture2D, uiTextureImage->getData(), s.width * s.height * 4, backend::PixelFormat::RGBA8, s);

if ( _texture2DCopy )
{
VolatileTextureMgr::addDataTexture(_texture2DCopy, uiTextureImage->getData(), s.width * s.height * 4, backend::PixelFormat::RGBA8888, s);
VolatileTextureMgr::addDataTexture(_texture2DCopy, uiTextureImage->getData(), s.width * s.height * 4, backend::PixelFormat::RGBA8, s);
}
}
else
Expand Down Expand Up @@ -145,7 +145,7 @@ RenderTexture * RenderTexture::create(int w, int h)
{
RenderTexture *ret = new (std::nothrow) RenderTexture();

if(ret && ret->initWithWidthAndHeight(w, h, backend::PixelFormat::RGBA8888, PixelFormat::NONE))
if(ret && ret->initWithWidthAndHeight(w, h, backend::PixelFormat::RGBA8, PixelFormat::NONE))
{
ret->autorelease();
return ret;
Expand Down Expand Up @@ -190,7 +190,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, backend::PixelFormat fo
descriptor.width = powW;
descriptor.height = powH;
descriptor.textureUsage = TextureUsage::RENDER_TARGET;
descriptor.textureFormat = PixelFormat::RGBA8888;
descriptor.textureFormat = PixelFormat::RGBA8;
auto texture = backend::Device::getInstance()->newTexture(descriptor);
if (! texture)
break;
Expand Down Expand Up @@ -469,7 +469,7 @@ void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA, bool
/* get buffer as Image */
void RenderTexture::newImage(std::function<void(RefPtr<Image>)> imageCallback, bool flipImage)
{
CCASSERT(_pixelFormat == backend::PixelFormat::RGBA8888, "only RGBA8888 can be saved as image");
CCASSERT(_pixelFormat == backend::PixelFormat::RGBA8, "only RGBA8888 can be saved as image");

if ((nullptr == _texture2D))
{
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCRenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class CC_DLL RenderTexture : public Node
RenderTargetFlag _renderTargetFlags{};

Image* _UITextureImage = nullptr;
backend::PixelFormat _pixelFormat = backend::PixelFormat::RGBA8888;
backend::PixelFormat _pixelFormat = backend::PixelFormat::RGBA8;

Color4F _clearColor;
float _clearDepth = 1.f;
Expand Down
14 changes: 7 additions & 7 deletions cocos/2d/CCSpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,18 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dict, const std::

Texture2D *texture = nullptr;
static std::unordered_map<std::string, backend::PixelFormat> pixelFormats = {
{"RGBA8888", backend::PixelFormat::RGBA8888},
{"RGBA4444", backend::PixelFormat::RGBA4444},
{"RGBA8888", backend::PixelFormat::RGBA8},
{"RGBA4444", backend::PixelFormat::RGBA4},
{"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}
{"I8", backend::PixelFormat::L8},
{"AI88", backend::PixelFormat::LA8},
{"ALPHA_INTENSITY", backend::PixelFormat::LA8},
//{"BGRA8888", backend::PixelFormat::BGRA8}, no Image conversion RGBA -> BGRA
{"RGB888", backend::PixelFormat::RGB8}
};

auto pixelFormatIt = pixelFormats.find(pixelFormatName);
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCTransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,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,backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8, PixelFormat::D24S8);

if (nullptr == inTexture)
{
Expand All @@ -1310,7 +1310,7 @@ void TransitionCrossFade::onEnter()
inTexture->end();

// create the second render texture for outScene
RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8, 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) );
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCTransitionProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,backend::PixelFormat::RGBA8888, backend::PixelFormat::D24S8);
RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height,backend::PixelFormat::RGBA8, 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));
Expand Down
6 changes: 3 additions & 3 deletions cocos/3d/CCTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ float Terrain::getImageHeight(int pixel_x, int pixel_y) const
int byte_stride = 1;
switch (_heightMapImage->getPixelFormat())
{
case backend::PixelFormat::BGRA8888:
case backend::PixelFormat::BGRA8:
byte_stride = 4;
break;
case backend::PixelFormat::RGB888:
case backend::PixelFormat::RGB8:
byte_stride = 3;
break;
case backend::PixelFormat::I8:
case backend::PixelFormat::L8:
byte_stride = 1;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions cocos/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ set(COCOS_AUDIO_SRC
)

# stupid, clang always compie .mm as objc/cpp mix obj
if(ANDROID)
if(ANDROID OR LINUX)
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
audio/src/android-link.cpp
audio/src/linux-link.cpp
)
else()
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
Expand Down
2 changes: 0 additions & 2 deletions cocos/audio/src/android-link.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions cocos/audio/src/linux-link.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* linux-link.cpp: the workaround for solving clang link issue, said: unrefenreced "gnu_objc_personality_v0" */
#include "AudioEngineImpl.mm"
6 changes: 3 additions & 3 deletions cocos/base/CCDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ void Director::setDefaultValues()
// 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(backend::PixelFormat::RGBA8888);
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA8);
else if(pixel_format == "rgba4444")
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4444);
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4);
else if(pixel_format == "rgba5551")
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGB5A1);

Expand Down Expand Up @@ -1248,7 +1248,7 @@ void Director::createStatsLabel()
}

backend::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat();
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4444);
Texture2D::setDefaultAlphaPixelFormat(backend::PixelFormat::RGBA4);
unsigned char *data = nullptr;
ssize_t dataLength = 0;
getFPSImageData(&data, &dataLength);
Expand Down
6 changes: 3 additions & 3 deletions cocos/base/CCNinePatchImageParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NinePatchImageParser::NinePatchImageParser(Image* image)
,_isRotated(false)
{
this->_imageFrame = Rect(0,0,image->getWidth(), image->getHeight());
CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8888,
CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8,
"unsupported format, currently only supports rgba8888");
}

Expand All @@ -57,7 +57,7 @@ NinePatchImageParser::NinePatchImageParser(Image* image, const Rect& frame, bool
,_imageFrame(frame)
,_isRotated(rotated)
{
CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8888,
CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8,
"unsupported format, currently only supports rgba8888");
}

Expand Down Expand Up @@ -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()==backend::PixelFormat::RGBA8888,
CCASSERT(image->getPixelFormat()==backend::PixelFormat::RGBA8,
"unsupported format, currently only supports rgba8888");
this->_imageFrame = frameRect;
this->_isRotated = rotated;
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCNinePatchImageParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SpriteFrame;
* The class could parse a single .9 patch image and produce the capInsets
* as well as a sprite atlas and store all the capInsets infos in a Texture2D.
* Note:
* - Currently only PixelFormat::RGBA8888 is supported.
* - Currently only PixelFormat::RGBA8 is supported.
* - TexturePacker Trim mode is not supported at the moment.
*/

Expand Down
4 changes: 2 additions & 2 deletions cocos/base/ccUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void captureNode(Node* startNode, std::function<void(RefPtr<Image>)> imageCallba

RenderTexture* finalRtx = nullptr;

auto rtx = RenderTexture::create(size.width, size.height, backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
auto rtx = RenderTexture::create(size.width, size.height, backend::PixelFormat::RGBA8, PixelFormat::D24S8);
// rtx->setKeepMatrix(true);
Point savedPos = startNode->getPosition();
Point anchor;
Expand All @@ -142,7 +142,7 @@ void captureNode(Node* startNode, std::function<void(RefPtr<Image>)> imageCallba
Sprite *sprite = Sprite::createWithTexture(rtx->getSprite()->getTexture(), finalRect);
sprite->setAnchorPoint(Point(0, 0));
sprite->setFlippedY(true);
finalRtx = RenderTexture::create(size.width * scale, size.height * scale, backend::PixelFormat::RGBA8888, PixelFormat::D24S8);
finalRtx = RenderTexture::create(size.width * scale, size.height * scale, backend::PixelFormat::RGBA8, PixelFormat::D24S8);

sprite->setScale(scale); // or use finalRtx->setKeepMatrix(true);
finalRtx->begin();
Expand Down
Loading