From 2363622a67a95b16466477094a166ffe9ca90b89 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Tue, 4 Aug 2015 21:49:14 +0800 Subject: [PATCH 1/2] Label:support auto batch with bitmap font or char map. --- cocos/2d/CCLabel.cpp | 16 +++++++++++++--- cocos/2d/CCLabel.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 6869152334..e1da0ceafe 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1208,10 +1208,20 @@ void Label::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) if (_insideBounds) #endif { - _customCommand.init(_globalZOrder, transform, flags); - _customCommand.func = CC_CALLBACK_0(Label::onDraw, this, transform, transformUpdated); + if (!_shadowEnabled && (_currentLabelType == LabelType::BMFONT || _currentLabelType == LabelType::CHARMAP)) + { + auto textureAtlas = _batchNodes.at(0)->getTextureAtlas(); + _quadCommand.init(_globalZOrder, textureAtlas->getTexture()->getName(), getGLProgramState(), + _blendFunc, textureAtlas->getQuads(), textureAtlas->getTotalQuads(), transform, flags); + renderer->addCommand(&_quadCommand); + } + else + { + _customCommand.init(_globalZOrder, transform, flags); + _customCommand.func = CC_CALLBACK_0(Label::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_customCommand); + renderer->addCommand(&_customCommand); + } } } diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index bbfeb34dee..0b29f3ffa8 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -28,6 +28,7 @@ #include "2d/CCNode.h" #include "renderer/CCCustomCommand.h" +#include "renderer/CCQuadCommand.h" #include "2d/CCFontAtlas.h" #include "base/ccTypes.h" @@ -573,6 +574,7 @@ protected: Color4B _textColor; Color4F _textColorF; + QuadCommand _quadCommand; CustomCommand _customCommand; Mat4 _shadowTransform; GLuint _uniformEffectColor; From b9edd6fc29e081d0d856afbb95dc19fa3c7600cd Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Wed, 5 Aug 2015 00:21:06 +0800 Subject: [PATCH 2/2] Fixed transform --- cocos/2d/CCLabel.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index e1da0ceafe..58a99790be 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -466,8 +466,10 @@ void Label::updateShaderProgram() setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL)); else if (_useA8Shader) setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_NORMAL)); - else + else if (_shadowEnabled) setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + else + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); break; case cocos2d::LabelEffect::OUTLINE: @@ -872,6 +874,18 @@ void Label::enableShadow(const Color4B& shadowColor /* = Color4B::BLACK */,const _shadowColor4F.g = shadowColor.g / 255.0f; _shadowColor4F.b = shadowColor.b / 255.0f; _shadowColor4F.a = shadowColor.a / 255.0f; + + 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)); + } + } } void Label::disableEffect() @@ -1210,6 +1224,10 @@ void Label::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { if (!_shadowEnabled && (_currentLabelType == LabelType::BMFONT || _currentLabelType == LabelType::CHARMAP)) { + for (auto&& it : _letters) + { + it.second->updateTransform(); + } auto textureAtlas = _batchNodes.at(0)->getTextureAtlas(); _quadCommand.init(_globalZOrder, textureAtlas->getTexture()->getName(), getGLProgramState(), _blendFunc, textureAtlas->getQuads(), textureAtlas->getTotalQuads(), transform, flags);