Additive blending for cocos2d and cocos2dx.

This commit is contained in:
NathanSweet 2013-09-30 00:54:21 +02:00
parent e4358cf904
commit 37035c4a0f
2 changed files with 23 additions and 5 deletions

View File

@ -147,6 +147,7 @@
_skeleton->b *= _skeleton->a;
}
int additive = 0;
CCTextureAtlas* textureAtlas = 0;
ccV3F_C4B_T2F_Quad quad;
quad.tl.vertices.z = 0;
@ -158,15 +159,26 @@
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
CCTextureAtlas* regionTextureAtlas = [self getTextureAtlas:attachment];
if (regionTextureAtlas != textureAtlas) {
if (slot->data->additiveBlending != additive) {
if (textureAtlas) {
[textureAtlas drawQuads];
[textureAtlas removeAllQuads];
}
additive = !additive;
ccGLBlendFunc(_blendFunc.src, additive ? GL_ONE : _blendFunc.dst);
} else if (regionTextureAtlas != textureAtlas && textureAtlas) {
[textureAtlas drawQuads];
[textureAtlas removeAllQuads];
}
textureAtlas = regionTextureAtlas;
if (textureAtlas.capacity == textureAtlas.totalQuads &&
![textureAtlas resizeCapacity:textureAtlas.capacity * 2]) return;
if (textureAtlas.capacity == textureAtlas.totalQuads) {
[textureAtlas drawQuads];
[textureAtlas removeAllQuads];
if (![textureAtlas resizeCapacity:textureAtlas.capacity * 2]) return;
}
RegionAttachment_updateQuad(attachment, slot, &quad, _premultipliedAlpha);
[textureAtlas updateQuad:&quad atIndex:textureAtlas.totalQuads];
}

View File

@ -140,6 +140,7 @@ void CCSkeleton::draw () {
skeleton->b *= skeleton->a;
}
int additive = 0;
CCTextureAtlas* textureAtlas = 0;
ccV3F_C4B_T2F_Quad quad;
quad.tl.vertices.z = 0;
@ -150,13 +151,18 @@ void CCSkeleton::draw () {
Slot* slot = skeleton->drawOrder[i];
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
CCTextureAtlas* regionTextureAtlas = getTextureAtlas(attachment);
if (regionTextureAtlas != textureAtlas) {
if (slot->data->additiveBlending != additive) {
if (textureAtlas) {
textureAtlas->drawQuads();
textureAtlas->removeAllQuads();
}
additive = !additive;
ccGLBlendFunc(blendFunc.src, additive ? GL_ONE : blendFunc.dst);
} else if (regionTextureAtlas != textureAtlas && textureAtlas) {
textureAtlas->drawQuads();
textureAtlas->removeAllQuads();
}
textureAtlas = regionTextureAtlas;