Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions build/cocos2d_libs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2989,18 +2989,20 @@
ED28C21C219E629B0078D854 /* TextureGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureGL.cpp; sourceTree = "<group>"; };
ED28C21D219E629B0078D854 /* DeviceGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceGL.cpp; sourceTree = "<group>"; };
ED28C21E219E629B0078D854 /* CommandBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommandBuffer.cpp; sourceTree = "<group>"; };
ED5C8CBC21C0B3C100F280A7 /* label_distanceFieldGlow.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_distanceFieldGlow.frag; sourceTree = "<group>"; };
ED5C8CBD21C0B5B700F280A7 /* positionColor.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColor.frag; sourceTree = "<group>"; };
ED5C8CBE21C0B5B800F280A7 /* positionColor.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionColor.vert; sourceTree = "<group>"; };
ED682BB9213F5FC6001BF6CB /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv_a.a; path = ../external/uv/prebuilt/mac/libuv_a.a; sourceTree = "<group>"; };
ED682BC0213F63CB001BF6CB /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv_a.a; path = ../external/uv/prebuilt/ios/libuv_a.a; sourceTree = "<group>"; };
ED682BC2213F6C7A001BF6CB /* libwebsockets.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libwebsockets.a; path = ../external/websockets/prebuilt/tvos/libwebsockets.a; sourceTree = "<group>"; };
ED682BC4213F6CBE001BF6CB /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libuv_a.a; path = ../external/uv/prebuilt/tvos/libuv_a.a; sourceTree = "<group>"; };
ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = "<group>"; };
EDDDA78321B0E1C2008926F0 /* label_distanceNormal.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_distanceNormal.frag; sourceTree = "<group>"; };
EDDDA78421B11B0C008926F0 /* label_outline.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_outline.frag; sourceTree = "<group>"; };
EDF9D8A521AE9677004374AB /* positionTextureColor.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionTextureColor.frag; sourceTree = "<group>"; };
EDF9D8A621AE9678004374AB /* positionTextureColor.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = positionTextureColor.vert; sourceTree = "<group>"; };
EDF9D8A721AF8CD1004374AB /* sprite.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.vert; sourceTree = "<group>"; };
EDF9D8A821AF8CD1004374AB /* sprite.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.frag; sourceTree = "<group>"; };
EDF9D8A921AF92C5004374AB /* label_normal.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_normal.frag; sourceTree = "<group>"; };
EDF9D8AA21AF92C5004374AB /* label_common.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = label_common.vert; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -4001,12 +4003,14 @@
460D4CC821A545420075726E /* shaders */ = {
isa = PBXGroup;
children = (
EDF9D8AA21AF92C5004374AB /* label_common.vert */,
ED5C8CBC21C0B3C100F280A7 /* label_distanceFieldGlow.frag */,
EDDDA78421B11B0C008926F0 /* label_outline.frag */,
EDDDA78321B0E1C2008926F0 /* label_distanceNormal.frag */,
EDF9D8A921AF92C5004374AB /* label_normal.frag */,
EDF9D8A821AF8CD1004374AB /* sprite.frag */,
EDF9D8A721AF8CD1004374AB /* sprite.vert */,
EDF9D8A521AE9677004374AB /* positionTextureColor.frag */,
EDF9D8A621AE9678004374AB /* positionTextureColor.vert */,
ED5C8CBD21C0B5B700F280A7 /* positionColor.frag */,
ED5C8CBE21C0B5B800F280A7 /* positionColor.vert */,
);
path = shaders;
sourceTree = "<group>";
Expand Down
55 changes: 36 additions & 19 deletions cocos/2d/CCFontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ FontAtlas::FontAtlas(Font &theFont)
, _rendererRecreatedListener(nullptr)
, _antialiasEnabled(true)
, _currLineHeight(0)
, _currentPageDataRGBA(nullptr)
{
_font->retain();

Expand Down Expand Up @@ -91,6 +92,8 @@ void FontAtlas::reinit()
_currentPageData = nullptr;
}

CC_SAFE_DELETE_ARRAY(_currentPageDataRGBA);

auto texture = new (std::nothrow) Texture2D;

_currentPageDataSize = CacheTextureWidth * CacheTextureHeight;
Expand All @@ -100,15 +103,27 @@ void FontAtlas::reinit()
{
_lineHeight += 2 * outlineSize;
_currentPageDataSize *= 2;

_currentPageDataSizeRGBA = _currentPageDataSize * 2;
_currentPageDataRGBA = new (std::nothrow) unsigned char[_currentPageDataSizeRGBA];
memset(_currentPageDataRGBA, 0, _currentPageDataSizeRGBA);
}

_currentPageData = new (std::nothrow) unsigned char[_currentPageDataSize];
memset(_currentPageData, 0, _currentPageDataSize);

auto pixelFormat = outlineSize > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
texture->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );

//metal do no support AI88 format
if(outlineSize > 0)
{
texture->initWithData(_currentPageDataRGBA, _currentPageDataSizeRGBA,
Texture2D::PixelFormat::RGBA8888, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
}
else
{
texture->initWithData(_currentPageData, _currentPageDataSize,
Texture2D::PixelFormat::A8, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );

}
addTexture(texture,0);
texture->release();
}
Expand Down Expand Up @@ -382,17 +397,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
_currentPageOrigX = 0;
if (_currentPageOrigY + _lineHeight + _letterPadding + _letterEdgeExtend >= CacheTextureHeight)
{
unsigned char *data = nullptr;
if (pixelFormat == Texture2D::PixelFormat::AI88)
{
data = _currentPageData + CacheTextureWidth * (int)startY * 2;
}
else
{
data = _currentPageData + CacheTextureWidth * (int)startY;
}
_atlasTextures[_currentPage]->updateWithData(data, 0, startY,
CacheTextureWidth, CacheTextureHeight - startY);
updateTextureContent(pixelFormat, startY);

startY = 0.0f;

Expand Down Expand Up @@ -452,18 +457,30 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
_letterDefinitions[it.first] = tempDef;
}

updateTextureContent(pixelFormat, startY);
return true;
}

void FontAtlas::updateTextureContent(Texture2D::PixelFormat format, int startY)
{
unsigned char *data = nullptr;
if (pixelFormat == Texture2D::PixelFormat::AI88)
auto outlineSize = _fontFreeType->getOutlineSize();
if (outlineSize > 0 && format == Texture2D::PixelFormat::AI88)
{
int nLen = CacheTextureWidth * (_currentPageOrigY - startY + _currLineHeight);
data = _currentPageData + CacheTextureWidth * (int)startY * 2;
for (auto i = 0; i < nLen; i++)
{
_currentPageDataRGBA[i*4] = data[i*2];
_currentPageDataRGBA[i*4+3] = data[i*2+1];
}
_atlasTextures[_currentPage]->updateWithData(_currentPageDataRGBA, 0, startY, CacheTextureWidth, _currentPageOrigY - startY + _currLineHeight);
}
else
{
data = _currentPageData + CacheTextureWidth * (int)startY;
_atlasTextures[_currentPage]->updateWithData(data, 0, startY, CacheTextureWidth, _currentPageOrigY - startY + _currLineHeight);
}
_atlasTextures[_currentPage]->updateWithData(data, 0, startY, CacheTextureWidth, _currentPageOrigY - startY + _currLineHeight);

return true;
}

void FontAtlas::addTexture(Texture2D *texture, int slot)
Expand Down
6 changes: 5 additions & 1 deletion cocos/2d/CCFontAtlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
#include "platform/CCPlatformMacros.h"
#include "base/CCRef.h"
#include "platform/CCStdC.h" // ssize_t on windows
#include "renderer/CCTexture2D.h"

NS_CC_BEGIN

class Font;
class Texture2D;
class EventCustom;
class EventListenerCustom;
class FontFreeType;
Expand Down Expand Up @@ -128,6 +128,8 @@ class CC_DLL FontAtlas : public Ref
* @param scaleFactor A float scale factor for scaling font letter info.
*/
void scaleFontLetterDefinition(float scaleFactor);

void updateTextureContent(Texture2D::PixelFormat format, int startY);

std::unordered_map<ssize_t, Texture2D*> _atlasTextures;
std::unordered_map<char32_t, FontLetterDefinition> _letterDefinitions;
Expand All @@ -139,7 +141,9 @@ class CC_DLL FontAtlas : public Ref
// Dynamic GlyphCollection related stuff
int _currentPage;
unsigned char *_currentPageData;
unsigned char *_currentPageDataRGBA;
int _currentPageDataSize;
int _currentPageDataSizeRGBA;
float _currentPageOrigX;
float _currentPageOrigY;
int _letterPadding;
Expand Down
8 changes: 5 additions & 3 deletions cocos/2d/CCFontFNT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,15 @@ void BMFontConfiguration::parseCommonArguments(const char* line)
tmp = strstr(tmp, "scaleW=") + 7;
sscanf(tmp, "%d", &value);

int maxTextureSize = Configuration::getInstance()->getMaxTextureSize();
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
//TODO coulsonwang
// int maxTextureSize = Configuration::getInstance()->getMaxTextureSize();
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");

// scaleH. sanity check
tmp = strstr(tmp, "scaleH=") + 7;
sscanf(tmp, "%d", &value);
CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
//TODO coulsonwang
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");

// pages. sanity check
tmp = strstr(tmp, "pages=") + 6;
Expand Down
Loading