mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[cocos2dx] Closes #370, fix primitives deprecation in debug renderer
This commit is contained in:
parent
16489aaf58
commit
103ba493d6
@ -154,7 +154,6 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
_skeleton->a = getDisplayedOpacity() / (float)255;
|
||||
|
||||
Color4B color;
|
||||
int vertexCount = 0;
|
||||
AttachmentVertices* attachmentVertices = nullptr;
|
||||
for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
|
||||
spSlot* slot = _skeleton->drawOrder[i];
|
||||
@ -222,57 +221,56 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
|
||||
}
|
||||
|
||||
if (_debugSlots || _debugBones) {
|
||||
_debugCommand.init(_globalZOrder);
|
||||
_debugCommand.func = CC_CALLBACK_0(SkeletonRenderer::drawDebug, this, transform, transformFlags);
|
||||
renderer->addCommand(&_debugCommand);
|
||||
drawDebug(renderer, transform, transformFlags);
|
||||
}
|
||||
}
|
||||
|
||||
void SkeletonRenderer::drawDebug (const Mat4 &transform, uint32_t transformFlags) {
|
||||
getGLProgramState()->apply(transform);
|
||||
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
|
||||
|
||||
Director* director = Director::getInstance();
|
||||
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
|
||||
|
||||
if (_debugSlots) {
|
||||
// Slots.
|
||||
DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
|
||||
glLineWidth(1);
|
||||
Vec2 points[4];
|
||||
V3F_C4B_T2F_Quad quad;
|
||||
for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
|
||||
spSlot* slot = _skeleton->drawOrder[i];
|
||||
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
|
||||
points[0] = Vec2(_worldVertices[0], _worldVertices[1]);
|
||||
points[1] = Vec2(_worldVertices[2], _worldVertices[3]);
|
||||
points[2] = Vec2(_worldVertices[4], _worldVertices[5]);
|
||||
points[3] = Vec2(_worldVertices[6], _worldVertices[7]);
|
||||
DrawPrimitives::drawPoly(points, 4, true);
|
||||
}
|
||||
}
|
||||
if (_debugBones) {
|
||||
// Bone lengths.
|
||||
glLineWidth(2);
|
||||
DrawPrimitives::setDrawColor4B(255, 0, 0, 255);
|
||||
for (int i = 0, n = _skeleton->bonesCount; i < n; ++i) {
|
||||
spBone *bone = _skeleton->bones[i];
|
||||
float x = bone->data->length * bone->a + bone->worldX;
|
||||
float y = bone->data->length * bone->c + bone->worldY;
|
||||
DrawPrimitives::drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y));
|
||||
}
|
||||
// Bone origins.
|
||||
DrawPrimitives::setPointSize(4);
|
||||
DrawPrimitives::setDrawColor4B(0, 0, 255, 255); // Root bone is blue.
|
||||
for (int i = 0, n = _skeleton->bonesCount; i < n; ++i) {
|
||||
spBone *bone = _skeleton->bones[i];
|
||||
DrawPrimitives::drawPoint(Vec2(bone->worldX, bone->worldY));
|
||||
if (i == 0) DrawPrimitives::setDrawColor4B(0, 255, 0, 255);
|
||||
}
|
||||
}
|
||||
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
Director* director = Director::getInstance();
|
||||
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
|
||||
|
||||
DrawNode* drawNode = DrawNode::create();
|
||||
|
||||
if (_debugSlots) {
|
||||
// Slots.
|
||||
// DrawPrimitives::setDrawColor4B(0, 0, 255, 255);
|
||||
glLineWidth(1);
|
||||
Vec2 points[4];
|
||||
V3F_C4B_T2F_Quad quad;
|
||||
for (int i = 0, n = _skeleton->slotsCount; i < n; i++) {
|
||||
spSlot* slot = _skeleton->drawOrder[i];
|
||||
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
|
||||
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
||||
spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
|
||||
points[0] = Vec2(_worldVertices[0], _worldVertices[1]);
|
||||
points[1] = Vec2(_worldVertices[2], _worldVertices[3]);
|
||||
points[2] = Vec2(_worldVertices[4], _worldVertices[5]);
|
||||
points[3] = Vec2(_worldVertices[6], _worldVertices[7]);
|
||||
drawNode->drawPoly(points, 4, true, Color4F::BLUE);
|
||||
}
|
||||
}
|
||||
if (_debugBones) {
|
||||
// Bone lengths.
|
||||
glLineWidth(2);
|
||||
for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
|
||||
spBone *bone = _skeleton->bones[i];
|
||||
float x = bone->data->length * bone->a + bone->worldX;
|
||||
float y = bone->data->length * bone->c + bone->worldY;
|
||||
drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED);
|
||||
}
|
||||
// Bone origins.
|
||||
auto color = Color4F::BLUE; // Root bone is blue.
|
||||
for (int i = 0, n = _skeleton->bonesCount; i < n; i++) {
|
||||
spBone *bone = _skeleton->bones[i];
|
||||
drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color);
|
||||
if (i == 0) color = Color4F::GREEN;
|
||||
}
|
||||
}
|
||||
|
||||
drawNode->draw(renderer, transform, transformFlags);
|
||||
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
}
|
||||
|
||||
AttachmentVertices* SkeletonRenderer::getAttachmentVertices (spRegionAttachment* attachment) const {
|
||||
|
||||
@ -49,7 +49,7 @@ public:
|
||||
|
||||
virtual void update (float deltaTime) override;
|
||||
virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
|
||||
virtual void drawDebug (const cocos2d::Mat4& transform, uint32_t transformFlags);
|
||||
virtual void drawDebug (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags);
|
||||
virtual cocos2d::Rect getBoundingBox () const override;
|
||||
virtual void onEnter () override;
|
||||
virtual void onExit () override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user