mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14566 from zilongshanren/fixIssue14564
fix scale9sprite be culled unexpectedly
This commit is contained in:
commit
ea42c09243
|
@ -31,7 +31,9 @@
|
||||||
#include "renderer/ccShaders.h"
|
#include "renderer/ccShaders.h"
|
||||||
#include "platform/CCImage.h"
|
#include "platform/CCImage.h"
|
||||||
#include "base/CCNinePatchImageParser.h"
|
#include "base/CCNinePatchImageParser.h"
|
||||||
|
#include "2d/CCDrawNode.h"
|
||||||
|
#include "2d/CCCamera.h"
|
||||||
|
#include "renderer/CCRenderer.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -54,8 +56,13 @@ namespace ui {
|
||||||
,_sliceIndices(nullptr)
|
,_sliceIndices(nullptr)
|
||||||
,_sliceSpriteDirty(false)
|
,_sliceSpriteDirty(false)
|
||||||
,_renderingType(RenderingType::SLICE)
|
,_renderingType(RenderingType::SLICE)
|
||||||
|
,_insideBounds(true)
|
||||||
{
|
{
|
||||||
this->setAnchorPoint(Vec2(0.5,0.5));
|
this->setAnchorPoint(Vec2(0.5,0.5));
|
||||||
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
|
_debugDrawNode = DrawNode::create();
|
||||||
|
addChild(_debugDrawNode);
|
||||||
|
#endif //CC_SPRITE_DEBUG_DRAW
|
||||||
}
|
}
|
||||||
|
|
||||||
Scale9Sprite::~Scale9Sprite()
|
Scale9Sprite::~Scale9Sprite()
|
||||||
|
@ -674,9 +681,59 @@ namespace ui {
|
||||||
this->updateCapInset();
|
this->updateCapInset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||||
|
{
|
||||||
|
if (_scale9Image) {
|
||||||
|
#if CC_USE_CULLING
|
||||||
|
// Don't do calculate the culling if the transform was not updated
|
||||||
|
auto visitingCamera = Camera::getVisitingCamera();
|
||||||
|
auto defaultCamera = Camera::getDefaultCamera();
|
||||||
|
if (visitingCamera == defaultCamera) {
|
||||||
|
_insideBounds = ((flags & FLAGS_TRANSFORM_DIRTY)|| visitingCamera->isViewProjectionUpdated()) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_insideBounds = renderer->checkVisibility(transform, _contentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_insideBounds)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
auto textureName = _scale9Image->getTexture()->getName();
|
||||||
|
auto programState = _scale9Image->getGLProgramState();
|
||||||
|
auto blendFunc = _scale9Image->getBlendFunc();
|
||||||
|
auto& polyInfo = _scale9Image->getPolygonInfo();
|
||||||
|
auto globalZOrder = _scale9Image->getGlobalZOrder();
|
||||||
|
_trianglesCommand.init(globalZOrder,textureName, programState, blendFunc, polyInfo.triangles, transform, flags);
|
||||||
|
renderer->addCommand(&_trianglesCommand);
|
||||||
|
|
||||||
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
|
_debugDrawNode->clear();
|
||||||
|
auto count = polyInfo.triangles.indexCount/3;
|
||||||
|
auto indices = polyInfo.triangles.indices;
|
||||||
|
auto verts = polyInfo.triangles.verts;
|
||||||
|
for(ssize_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//draw 3 lines
|
||||||
|
Vec3 from =verts[indices[i*3]].vertices;
|
||||||
|
Vec3 to = verts[indices[i*3+1]].vertices;
|
||||||
|
_debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
|
||||||
|
|
||||||
|
from =verts[indices[i*3+1]].vertices;
|
||||||
|
to = verts[indices[i*3+2]].vertices;
|
||||||
|
_debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
|
||||||
|
|
||||||
|
from =verts[indices[i*3+2]].vertices;
|
||||||
|
to = verts[indices[i*3]].vertices;
|
||||||
|
_debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
|
||||||
|
}
|
||||||
|
#endif //CC_SPRITE_DEBUG_DRAW
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
|
||||||
{
|
{
|
||||||
|
|
||||||
// quick return if not visible. children won't be drawn.
|
// quick return if not visible. children won't be drawn.
|
||||||
if (!_visible)
|
if (!_visible)
|
||||||
{
|
{
|
||||||
|
@ -714,26 +771,11 @@ namespace ui {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_scale9Image && _scale9Image->getLocalZOrder() < 0 )
|
|
||||||
{
|
|
||||||
_scale9Image->visit(renderer, _modelViewTransform, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// draw self
|
// draw self
|
||||||
//
|
//
|
||||||
if (isVisitableByVisitingCamera())
|
if (isVisitableByVisitingCamera())
|
||||||
this->draw(renderer, _modelViewTransform, flags);
|
this->draw(renderer, _modelViewTransform, flags);
|
||||||
|
|
||||||
//
|
|
||||||
// draw children and protectedChildren zOrder >= 0
|
|
||||||
//
|
|
||||||
if (_scale9Image && _scale9Image->getLocalZOrder() >= 0 )
|
|
||||||
{
|
|
||||||
_scale9Image->visit(renderer, _modelViewTransform, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
|
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
|
||||||
(*it)->visit(renderer, _modelViewTransform, flags);
|
(*it)->visit(renderer, _modelViewTransform, flags);
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
class DrawNode;
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -590,6 +592,7 @@ namespace ui {
|
||||||
|
|
||||||
/// @} end of Children and Parent
|
/// @} end of Children and Parent
|
||||||
|
|
||||||
|
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||||
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
||||||
|
|
||||||
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
|
||||||
|
@ -720,6 +723,12 @@ namespace ui {
|
||||||
unsigned short* _sliceIndices;
|
unsigned short* _sliceIndices;
|
||||||
bool _sliceSpriteDirty;
|
bool _sliceSpriteDirty;
|
||||||
RenderingType _renderingType;
|
RenderingType _renderingType;
|
||||||
|
|
||||||
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
|
DrawNode *_debugDrawNode;
|
||||||
|
#endif //CC_SPRITE_DEBUG_DRAW
|
||||||
|
bool _insideBounds; /// whether or not the sprite was inside bounds the previous frame
|
||||||
|
TrianglesCommand _trianglesCommand; ///
|
||||||
};
|
};
|
||||||
|
|
||||||
}} //end of namespace
|
}} //end of namespace
|
||||||
|
|
|
@ -153,8 +153,12 @@ bool UIButtonTest_Scale9::init()
|
||||||
Button* button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
Button* button = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
|
||||||
// open scale9 render
|
// open scale9 render
|
||||||
button->setScale9Enabled(true);
|
button->setScale9Enabled(true);
|
||||||
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
||||||
button->setContentSize(Size(150, 70));
|
button->setContentSize(Size(150, 70));
|
||||||
|
button->setPosition(Vec2(-button->getContentSize().width - 10, widgetSize.height / 2.0f));
|
||||||
|
auto moveBy = MoveBy::create(1.0, Vec2(widgetSize.width/2, 0));
|
||||||
|
auto moveByReverse = moveBy->reverse()->clone();
|
||||||
|
button->runAction(RepeatForever::create(
|
||||||
|
Sequence::create(moveBy,moveByReverse, NULL)));
|
||||||
button->setPressedActionEnabled(true);
|
button->setPressedActionEnabled(true);
|
||||||
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9::touchEvent, this));
|
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9::touchEvent, this));
|
||||||
_uiLayer->addChild(button);
|
_uiLayer->addChild(button);
|
||||||
|
|
Loading…
Reference in New Issue