Skip to content
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

Add ETC1 builtin alpha support, separated alpha file mode. #16111

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cocos/2d/CCAtlasNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
_quadsToDraw = itemsToRender;

// shader stuff
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
setGLProgramState(GLProgramState::getPositionTextureColorGLProgramState(texture)); // setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));

return true;
}
Expand Down Expand Up @@ -131,7 +131,8 @@ void AtlasNode::updateAtlasValues()
// AtlasNode - draw
void AtlasNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_quadCommand.init(_globalZOrder, _textureAtlas->getTexture()->getName(), getGLProgramState(), _blendFunc, _textureAtlas->getQuads(), _quadsToDraw, transform, flags);
// x-studio365 spec: ETC1 ALPHA supports. -- TODO
_quadCommand.init(_globalZOrder, _textureAtlas->getTexture()->getName(), getGLProgramState(), _blendFunc, _textureAtlas->getQuads(), _quadsToDraw, transform, flags, _textureAtlas->getTexture()->getAlphaName());

renderer->addCommand(&_quadCommand);

Expand Down
40 changes: 28 additions & 12 deletions cocos/2d/CCLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ void Label::reset()
setRotationSkewX(0); // reverse italics
}

// x-studio365 spec, ETC1 ALPHA supports, for LabelType::BMFONT & LabelType::CHARMAP
static Texture2D* _getTexture(Label* label)
{
struct _FontAtlasPub : public FontAtlas
{
Texture2D* getTexture()
{
if (!_atlasTextures.empty())
return _atlasTextures.begin()->second;
return nullptr;
}
};

auto fontAtlas = label->getFontAtlas();
Texture2D* texture = nullptr;
if (fontAtlas != nullptr)
texture = ((_FontAtlasPub*)(fontAtlas))->getTexture();
return texture;
}
void Label::updateShaderProgram()
{
switch (_currLabelEffect)
Expand All @@ -535,9 +554,9 @@ void Label::updateShaderProgram()
else if (_useA8Shader)
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_NORMAL));
else if (_shadowEnabled)
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
setGLProgramState(GLProgramState::getPositionTextureColorGLProgramState(_getTexture(this), false)); // setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
else
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
setGLProgramState(GLProgramState::getPositionTextureColorGLProgramState(_getTexture(this), true)); // setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));

break;
case cocos2d::LabelEffect::OUTLINE:
Expand Down Expand Up @@ -1112,14 +1131,9 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const

if (_currentLabelType == LabelType::BMFONT || _currentLabelType == LabelType::CHARMAP)
{
if (_shadowEnabled)
{
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
}
else
{
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
}
// x-studio365 spec, ETC1 ALPHA supports.
setGLProgramState(GLProgramState::getPositionTextureColorGLProgramState(_getTexture(this), !_shadowEnabled));

}
}

Expand Down Expand Up @@ -1576,9 +1590,11 @@ void Label::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
it.second->updateTransform();
}
// x-studio365 spec, ETC1 ALPHA supports for BMFONT & CHARMAP
auto textureAtlas = _batchNodes.at(0)->getTextureAtlas();
_quadCommand.init(_globalZOrder, textureAtlas->getTexture()->getName(), getGLProgramState(),
_blendFunc, textureAtlas->getQuads(), textureAtlas->getTotalQuads(), transform, flags);
auto texture = textureAtlas->getTexture();
_quadCommand.init(_globalZOrder, texture->getName(), getGLProgramState(),
_blendFunc, textureAtlas->getQuads(), textureAtlas->getTotalQuads(), transform, flags, texture->getAlphaName());
renderer->addCommand(&_quadCommand);
}
else
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCMotionStreak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;

// shader state
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
setGLProgramState(GLProgramState::getPositionTextureColorGLProgramState(texture, false)/*GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)*/);

setTexture(texture);
setColor(color);
Expand Down