mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-20 16:56:43 +08:00
Additive blending for spine-sfml.
This commit is contained in:
parent
63f8e4ddaf
commit
76778031ed
@ -45,6 +45,7 @@ typedef struct {
|
||||
const BoneData* const boneData;
|
||||
const char* const attachmentName;
|
||||
float r, g, b, a;
|
||||
int/*bool*/additiveBlending;
|
||||
} SlotData;
|
||||
|
||||
SlotData* SlotData_create (const char* name, BoneData* boneData);
|
||||
|
||||
@ -504,8 +504,6 @@ void AttachmentTimeline_setFrame (AttachmentTimeline* self, int frameIndex, floa
|
||||
|
||||
/**/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void _DrawOrderTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
|
||||
int i;
|
||||
int frameIndex;
|
||||
|
||||
@ -355,5 +355,5 @@ float Json_getFloat (Json* value, const char* name, float defaultValue) {
|
||||
|
||||
int Json_getInt (Json* value, const char* name, int defaultValue) {
|
||||
value = Json_getItem(value, name);
|
||||
return value ? (int)value->valueFloat : defaultValue;
|
||||
return value ? value->valueInt : defaultValue;
|
||||
}
|
||||
|
||||
@ -326,6 +326,8 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
|
||||
boneData->rotation = Json_getFloat(boneMap, "rotation", 0);
|
||||
boneData->scaleX = Json_getFloat(boneMap, "scaleX", 1);
|
||||
boneData->scaleY = Json_getFloat(boneMap, "scaleY", 1);
|
||||
boneData->inheritScale = Json_getInt(boneMap, "inheritScale", 1);
|
||||
boneData->inheritRotation = Json_getInt(boneMap, "inheritRotation", 1);
|
||||
|
||||
skeletonData->bones[i] = boneData;
|
||||
++skeletonData->boneCount;
|
||||
@ -360,6 +362,8 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
|
||||
attachmentItem = Json_getItem(slotMap, "attachment");
|
||||
if (attachmentItem) SlotData_setAttachmentName(slotData, attachmentItem->valueString);
|
||||
|
||||
slotData->additiveBlending = Json_getInt(slotMap, "additive", 0);
|
||||
|
||||
skeletonData->slots[i] = slotData;
|
||||
++skeletonData->slotCount;
|
||||
}
|
||||
|
||||
@ -87,12 +87,22 @@ void SkeletonDrawable::update (float deltaTime) {
|
||||
|
||||
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
|
||||
vertexArray->clear();
|
||||
states.blendMode = BlendAlpha;
|
||||
|
||||
float vertexPositions[8];
|
||||
for (int i = 0; i < skeleton->slotCount; ++i) {
|
||||
Slot* slot = skeleton->drawOrder[i];
|
||||
Attachment* attachment = slot->attachment;
|
||||
if (!attachment || attachment->type != ATTACHMENT_REGION) continue;
|
||||
RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
|
||||
|
||||
BlendMode blend = slot->data->additiveBlending ? BlendAdd : BlendAlpha;
|
||||
if (states.blendMode != blend) {
|
||||
target.draw(*vertexArray, states);
|
||||
vertexArray->clear();
|
||||
states.blendMode = blend;
|
||||
}
|
||||
|
||||
RegionAttachment_computeVertices(regionAttachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertexPositions);
|
||||
|
||||
Uint8 r = skeleton->r * slot->r * 255;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user