mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[sfml] Added multi-page atlas support. Closes #725
This commit is contained in:
parent
315b442b7b
commit
dfa9ea5913
@ -92,14 +92,21 @@ void SkeletonDrawable::update (float deltaTime) {
|
|||||||
|
|
||||||
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||||
vertexArray->clear();
|
vertexArray->clear();
|
||||||
|
states.texture = 0;
|
||||||
|
|
||||||
sf::Vertex vertices[4];
|
sf::Vertex vertices[4];
|
||||||
sf::Vertex vertex;
|
sf::Vertex vertex;
|
||||||
|
Texture* texture = 0;
|
||||||
for (int i = 0; i < skeleton->slotsCount; ++i) {
|
for (int i = 0; i < skeleton->slotsCount; ++i) {
|
||||||
Slot* slot = skeleton->drawOrder[i];
|
Slot* slot = skeleton->drawOrder[i];
|
||||||
Attachment* attachment = slot->attachment;
|
Attachment* attachment = slot->attachment;
|
||||||
if (!attachment) continue;
|
if (!attachment) continue;
|
||||||
|
|
||||||
|
if (attachment->type == ATTACHMENT_REGION) {
|
||||||
|
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
||||||
|
texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
|
||||||
|
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, worldVertices, 0, 2);
|
||||||
|
|
||||||
sf::BlendMode blend;
|
sf::BlendMode blend;
|
||||||
switch (slot->data->blendMode) {
|
switch (slot->data->blendMode) {
|
||||||
case BLEND_MODE_ADDITIVE:
|
case BLEND_MODE_ADDITIVE:
|
||||||
@ -112,18 +119,16 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
|||||||
default:
|
default:
|
||||||
blend = BlendAlpha;
|
blend = BlendAlpha;
|
||||||
}
|
}
|
||||||
if (states.blendMode != blend) {
|
|
||||||
|
if (states.texture == 0) states.texture = texture;
|
||||||
|
|
||||||
|
if (states.blendMode != blend || states.texture != texture) {
|
||||||
target.draw(*vertexArray, states);
|
target.draw(*vertexArray, states);
|
||||||
vertexArray->clear();
|
vertexArray->clear();
|
||||||
states.blendMode = blend;
|
states.blendMode = blend;
|
||||||
|
states.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture* texture = 0;
|
|
||||||
if (attachment->type == ATTACHMENT_REGION) {
|
|
||||||
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
|
||||||
texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
|
|
||||||
spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, worldVertices, 0, 2);
|
|
||||||
|
|
||||||
Uint8 r = static_cast<Uint8>(skeleton->color.r * slot->color.r * 255);
|
Uint8 r = static_cast<Uint8>(skeleton->color.r * slot->color.r * 255);
|
||||||
Uint8 g = static_cast<Uint8>(skeleton->color.g * slot->color.g * 255);
|
Uint8 g = static_cast<Uint8>(skeleton->color.g * slot->color.g * 255);
|
||||||
Uint8 b = static_cast<Uint8>(skeleton->color.b * slot->color.b * 255);
|
Uint8 b = static_cast<Uint8>(skeleton->color.b * slot->color.b * 255);
|
||||||
@ -179,6 +184,28 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
|||||||
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
|
texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject;
|
||||||
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
|
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
|
||||||
|
|
||||||
|
sf::BlendMode blend;
|
||||||
|
switch (slot->data->blendMode) {
|
||||||
|
case BLEND_MODE_ADDITIVE:
|
||||||
|
blend = BlendAdd;
|
||||||
|
break;
|
||||||
|
case BLEND_MODE_MULTIPLY:
|
||||||
|
blend = BlendMultiply;
|
||||||
|
break;
|
||||||
|
case BLEND_MODE_SCREEN: // Unsupported, fall through.
|
||||||
|
default:
|
||||||
|
blend = BlendAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (states.texture == 0) states.texture = texture;
|
||||||
|
|
||||||
|
if (states.blendMode != blend || states.texture != texture) {
|
||||||
|
target.draw(*vertexArray, states);
|
||||||
|
vertexArray->clear();
|
||||||
|
states.blendMode = blend;
|
||||||
|
states.texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
Uint8 r = static_cast<Uint8>(skeleton->color.r * slot->color.r * 255);
|
Uint8 r = static_cast<Uint8>(skeleton->color.r * slot->color.r * 255);
|
||||||
Uint8 g = static_cast<Uint8>(skeleton->color.g * slot->color.g * 255);
|
Uint8 g = static_cast<Uint8>(skeleton->color.g * slot->color.g * 255);
|
||||||
Uint8 b = static_cast<Uint8>(skeleton->color.b * slot->color.b * 255);
|
Uint8 b = static_cast<Uint8>(skeleton->color.b * slot->color.b * 255);
|
||||||
@ -199,12 +226,8 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (texture) {
|
|
||||||
// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
|
||||||
states.texture = texture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
target.draw(*vertexArray, states);
|
target.draw(*vertexArray, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user