[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.13 版本

This commit is contained in:
SmallMain
2024-10-16 16:23:25 +08:00
parent 7f956acda7
commit 887d4a96c9
61 changed files with 1313 additions and 981 deletions

View File

@@ -34,7 +34,7 @@ DRAGONBONES_NAMESPACE_BEGIN
class CacheModeAttachUtil;
class CCArmatureCacheDisplay : public cocos2d::middleware::IMiddleware, public cocos2d::Ref
class CCArmatureCacheDisplay : public cocos2d::Ref, public cocos2d::middleware::IMiddleware
{
public:
CCArmatureCacheDisplay(const std::string& armatureName, const std::string& armatureKey, const std::string& atlasUUID, bool isShare);

View File

@@ -106,7 +106,7 @@ enum EmitterMode
RADIUS = 1
};
class ParticleSimulator : public cocos2d::middleware::IMiddleware, public cocos2d::Ref {
class ParticleSimulator : public cocos2d::Ref, public cocos2d::middleware::IMiddleware {
//* @enum
enum {

View File

@@ -130,6 +130,10 @@ SkeletonAnimation::SkeletonAnimation ()
}
SkeletonAnimation::~SkeletonAnimation () {
SkeletonAnimation::destroy();
}
void SkeletonAnimation::destroy() {
_startListener = nullptr;
_interruptListener = nullptr;
_endListener = nullptr;
@@ -139,9 +143,12 @@ SkeletonAnimation::~SkeletonAnimation () {
if (_state) {
clearTracks();
if (_ownsAnimationStateData) delete _state->getData();
delete _state;
if (_ownsAnimationStateData) {
delete _state->getData();
}
CC_SAFE_DELETE(_state);
}
SkeletonRenderer::destroy();
}
void SkeletonAnimation::update (float deltaTime) {

View File

@@ -92,6 +92,7 @@ public:
virtual void onAnimationStateEvent (TrackEntry* entry, EventType type, Event* event);
virtual void onTrackEntryEvent (TrackEntry* entry, EventType type, Event* event);
virtual void destroy();
AnimationState* getState() const;

View File

@@ -76,7 +76,7 @@ namespace spine {
bool inEffect = false;
std::vector<TextureMultiData> textureDatas;
};
struct BoneData {
cocos2d::Mat4 globalTransformMatrix;
};

View File

@@ -63,6 +63,11 @@ namespace spine {
}
SkeletonCacheAnimation::~SkeletonCacheAnimation () {
destroy();
}
void SkeletonCacheAnimation::destroy() {
stopSchedule();
if (_skeletonCache) {
_skeletonCache->release();
_skeletonCache = nullptr;
@@ -73,9 +78,8 @@ namespace spine {
delete ani;
}
CC_SAFE_RELEASE_NULL(_attachUtil);
CC_SAFE_RELEASE(_nodeProxy);
CC_SAFE_RELEASE(_effect);
stopSchedule();
CC_SAFE_RELEASE_NULL(_nodeProxy);
CC_SAFE_RELEASE_NULL(_effect);
}
void SkeletonCacheAnimation::update(float dt) {
@@ -207,13 +211,13 @@ namespace spine {
return multiSegments;
}
void SkeletonCacheAnimation::render(float dt) {
if (_useMulti) {
renderMulti(dt);
return;
}
if (!_nodeProxy || !_effect) {
return;
}
@@ -826,7 +830,7 @@ namespace spine {
void SkeletonCacheAnimation::setUseMulti(bool enabled) {
_useMulti = enabled;
}
void SkeletonCacheAnimation::setAnimation (const std::string& name, bool loop) {
_playTimes = loop ? 0 : 1;
_animationName = name;

View File

@@ -39,7 +39,7 @@ namespace spine {
class CacheModeAttachUtil;
class SkeletonCacheAnimation : public cocos2d::middleware::IMiddleware, public cocos2d::Ref {
class SkeletonCacheAnimation : public cocos2d::Ref, public cocos2d::middleware::IMiddleware {
public:
SkeletonCacheAnimation (const std::string& uuid, bool isShare);
virtual ~SkeletonCacheAnimation ();
@@ -47,7 +47,7 @@ namespace spine {
virtual void update(float dt) override;
virtual void render(float dt) override;
virtual uint32_t getRenderOrder() const override;
void renderMulti(float dt);
std::vector<spine::SkeletonCache::SegmentMultiData> toMultiSegments(
const std::vector<spine::SkeletonCache::SegmentData*>& segments);
@@ -83,7 +83,7 @@ namespace spine {
void onDisable();
void setUseTint(bool enabled);
void setUseMulti(bool enabled);
void setAnimation (const std::string& name, bool loop);
void addAnimation (const std::string& name, bool loop, float delay = 0);
Animation* findAnimation(const std::string& name) const;
@@ -98,6 +98,7 @@ namespace spine {
void setToSetupPose ();
void setBonesToSetupPose ();
void setSlotsToSetupPose ();
void destroy();
private:
float _timeScale = 1;
bool _paused = false;
@@ -124,7 +125,7 @@ namespace spine {
std::string _animationName = "";
bool _useTint = false;
bool _useMulti = false;
struct AniQueueData {
std::string animationName = "";
bool loop = false;

View File

@@ -151,23 +151,37 @@ SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const s
}
SkeletonRenderer::~SkeletonRenderer () {
CC_SAFE_RELEASE(_effectDelegate);
if (_ownsSkeletonData) delete _skeleton->getData();
if (_ownsSkeleton) delete _skeleton;
if (_ownsAtlas && _atlas) delete _atlas;
if (_attachmentLoader) delete _attachmentLoader;
if (_uuid != "") SkeletonDataMgr::getInstance()->releaseByUUID(_uuid);
if (_clipper) delete _clipper;
if (_debugBuffer) {
delete _debugBuffer;
_debugBuffer = nullptr;
}
CC_SAFE_RELEASE(_attachUtil);
CC_SAFE_RELEASE(_nodeProxy);
CC_SAFE_RELEASE(_effect);
SkeletonRenderer::destroy();
}
void SkeletonRenderer::destroy() {
stopSchedule();
CC_SAFE_RELEASE_NULL(_effectDelegate);
if (_ownsSkeletonData) {
if (_skeleton) {
delete _skeleton->getData();
}
_ownsSkeletonData = false;
}
if (_ownsSkeleton) {
CC_SAFE_DELETE(_skeleton);
}
if (_ownsAtlas && _atlas) {
CC_SAFE_DELETE(_atlas);
}
_skeleton = nullptr;
_atlas = nullptr;
CC_SAFE_DELETE(_attachmentLoader);
if (_uuid != "") {
SkeletonDataMgr::getInstance()->releaseByUUID(_uuid);
_uuid = "";
}
CC_SAFE_DELETE(_clipper);
CC_SAFE_DELETE(_debugBuffer);
CC_SAFE_RELEASE_NULL(_attachUtil);
CC_SAFE_RELEASE_NULL(_nodeProxy);
CC_SAFE_RELEASE_NULL(_effect);
}
void SkeletonRenderer::initWithUUID(const std::string& uuid) {
@@ -298,7 +312,7 @@ void SkeletonRenderer::render (float deltaTime) {
// vertex size int bytes with one color
int vbs1 = _useMulti ? sizeof(V2F_T2F_C4B_T1F) : sizeof(V2F_T2F_C4B);
// vertex size in floats with one color
// vertex size in floats with one color
int vs1 = vbs1 / sizeof(float);
// vertex size int bytes with two color
int vbs2 = _useMulti ? sizeof(V2F_T2F_C4B_C4B_T1F) :sizeof(V2F_T2F_C4B_C4B);
@@ -315,11 +329,11 @@ void SkeletonRenderer::render (float deltaTime) {
int preBlendMode = -1;
GLuint preTextureIndex = -1;
GLuint curTextureIndex = -1;
float curTextureId = -1;
bool texInEffect = false;
int preISegWritePos = -1;
int preISegWritePos = -1;
int curISegLen = 0;
int materialLen = 0;
@@ -361,7 +375,7 @@ void SkeletonRenderer::render (float deltaTime) {
curBlendSrc = _premultipliedAlpha ? BlendFactor::ONE : BlendFactor::SRC_ALPHA;
curBlendDst = BlendFactor::ONE_MINUS_SRC_ALPHA;
}
double curHash =
(_useMulti && texInEffect)
? ((curBlendMode << 16) + ((int)_useTint << 24) +
@@ -470,34 +484,34 @@ void SkeletonRenderer::render (float deltaTime) {
}
if (!_useMulti) {
if (!_useTint) {
triangles.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize);
attachment->computeWorldVertices(slot->getBone(), (float*)triangles.verts, 0, vs1);
if (!_useTint) {
triangles.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize);
attachment->computeWorldVertices(slot->getBone(), (float*)triangles.verts, 0, vs1);
triangles.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, attachmentVertices->_triangles->indices, ibSize);
} else {
trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
attachment->computeWorldVertices(slot->getBone(), (float*)trianglesTwoColor.verts, 0, vs2);
trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, attachmentVertices->_triangles->indices, ibSize);
triangles.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, attachmentVertices->_triangles->indices, ibSize);
} else {
trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
attachment->computeWorldVertices(slot->getBone(), (float*)trianglesTwoColor.verts, 0, vs2);
trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, attachmentVertices->_triangles->indices, ibSize);
}
} else {
if (!_useTint) {
@@ -565,34 +579,34 @@ void SkeletonRenderer::render (float deltaTime) {
}
if (!_useMulti) {
if (!_useTint) {
triangles.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize);
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), (float*)triangles.verts, 0, vs1);
if (!_useTint) {
triangles.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize);
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), (float*)triangles.verts, 0, vs1);
triangles.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, attachmentVertices->_triangles->indices, ibSize);
} else {
trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), (float*)trianglesTwoColor.verts, 0, vs2);
trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, attachmentVertices->_triangles->indices, ibSize);
triangles.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, attachmentVertices->_triangles->indices, ibSize);
} else {
trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {
trianglesTwoColor.verts[ii].texCoord = attachmentVertices->_triangles->verts[ii].texCoord;
}
attachment->computeWorldVertices(*slot, 0, attachment->getWorldVerticesLength(), (float*)trianglesTwoColor.verts, 0, vs2);
trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, attachmentVertices->_triangles->indices, ibSize);
}
} else {
if (!_useTint) {
@@ -650,7 +664,7 @@ void SkeletonRenderer::render (float deltaTime) {
: (float*)trianglesTexId.verts)
: (_useTint ? (float*)trianglesTwoColor.verts
: (float*)triangles.verts);
int stride = _useTint ? vs2 : vs1;
_debugBuffer->writeFloat32(DebugType::Mesh);
_debugBuffer->writeFloat32(indexCount * 2);
@@ -702,217 +716,217 @@ void SkeletonRenderer::render (float deltaTime) {
darkColor.b = 0;
}
darkColor.a = _premultipliedAlpha ? 255 : 0;
if (!_useMulti) {
// One color tint logic
if (!_useTint) {
// Cliping logic
if (_clipper->isClipping()) {
_clipper->clipTriangles((float*)&triangles.verts[0].vertex, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoord, vs1);
if (_clipper->getClippedTriangles().size() == 0) {
_clipper->clipEnd(*slot);
continue;
// One color tint logic
if (!_useTint) {
// Cliping logic
if (_clipper->isClipping()) {
_clipper->clipTriangles((float*)&triangles.verts[0].vertex, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoord, vs1);
if (_clipper->getClippedTriangles().size() == 0) {
_clipper->clipEnd(*slot);
continue;
}
triangles.vertCount = (int)_clipper->getClippedVertices().size() >> 1;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
triangles.indexCount = (int)_clipper->getClippedTriangles().size();
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
float* verts = _clipper->getClippedVertices().buffer();
float* uvs = _clipper->getClippedUVs().buffer();
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = dark.g = dark.b = dark.a = 0;
for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv+=2) {
V2F_T2F_C4B* vertex = triangles.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
}
triangles.vertCount = (int)_clipper->getClippedVertices().size() >> 1;
vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B);
isFull |= vb.checkSpace(vbSize, true);
triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer();
triangles.indexCount = (int)_clipper->getClippedTriangles().size();
ibSize = triangles.indexCount * sizeof(unsigned short);
ib.checkSpace(ibSize, true);
triangles.indices = (unsigned short*)ib.getCurBuffer();
memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
float* verts = _clipper->getClippedVertices().buffer();
float* uvs = _clipper->getClippedUVs().buffer();
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = dark.g = dark.b = dark.a = 0;
for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv+=2) {
V2F_T2F_C4B* vertex = triangles.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
}
} else {
for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv+=2) {
V2F_T2F_C4B* vertex = triangles.verts + v;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
}
}
// No cliping logic
} else {
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = dark.g = dark.b = dark.a = 0;
for (int v = 0, vn = triangles.vertCount; v < vn; ++v) {
V2F_T2F_C4B* vertex = triangles.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
}
} else {
for (int v = 0, vn = triangles.vertCount; v < vn; ++v) {
V2F_T2F_C4B* vertex = triangles.verts + v;
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
}
for (int v = 0, vn = triangles.vertCount, vv = 0; v < vn; ++v, vv+=2) {
V2F_T2F_C4B* vertex = triangles.verts + v;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
}
}
// No cliping logic
} else {
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = dark.g = dark.b = dark.a = 0;
for (int v = 0, vn = triangles.vertCount; v < vn; ++v) {
V2F_T2F_C4B* vertex = triangles.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
}
} else {
for (int v = 0, vn = triangles.vertCount; v < vn; ++v) {
V2F_T2F_C4B* vertex = triangles.verts + v;
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
}
}
}
// Two color tint logic
else {
if (_clipper->isClipping()) {
_clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].vertex, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoord, vs2);
if (_clipper->getClippedTriangles().size() == 0) {
_clipper->clipEnd(*slot);
continue;
}
trianglesTwoColor.vertCount = (int)_clipper->getClippedVertices().size() >> 1;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
trianglesTwoColor.indexCount = (int)_clipper->getClippedTriangles().size();
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
float* verts = _clipper->getClippedVertices().buffer();
float* uvs = _clipper->getClippedUVs().buffer();
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = darkColor.r / 255.0f;
dark.g = darkColor.g / 255.0f;
dark.b = darkColor.b / 255.0f;
dark.a = darkColor.a / 255.0f;
for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = (GLubyte)darkColor.a;
}
} else {
for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = (GLubyte)darkColor.a;
}
}
// Two color tint logic
else {
if (_clipper->isClipping()) {
_clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].vertex, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoord, vs2);
if (_clipper->getClippedTriangles().size() == 0) {
_clipper->clipEnd(*slot);
continue;
}
trianglesTwoColor.vertCount = (int)_clipper->getClippedVertices().size() >> 1;
vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B);
isFull |= vb.checkSpace(vbSize, true);
trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer();
trianglesTwoColor.indexCount = (int)_clipper->getClippedTriangles().size();
ibSize = trianglesTwoColor.indexCount * sizeof(unsigned short);
trianglesTwoColor.indices = (unsigned short*)ib.getCurBuffer();
memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size());
float* verts = _clipper->getClippedVertices().buffer();
float* uvs = _clipper->getClippedUVs().buffer();
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = darkColor.r / 255.0f;
dark.g = darkColor.g / 255.0f;
dark.b = darkColor.b / 255.0f;
dark.a = darkColor.a / 255.0f;
for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = (GLubyte)darkColor.a;
}
} else {
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = darkColor.r / 255.0f;
dark.g = darkColor.g / 255.0f;
dark.b = darkColor.b / 255.0f;
dark.a = darkColor.a / 255.0f;
for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = (GLubyte)darkColor.a;
}
} else {
for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = (GLubyte)darkColor.a;
}
for (int v = 0, vn = trianglesTwoColor.vertCount, vv = 0; v < vn; ++v, vv += 2) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
vertex->vertex.x = verts[vv];
vertex->vertex.y = verts[vv + 1];
vertex->texCoord.u = uvs[vv];
vertex->texCoord.v = uvs[vv + 1];
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = (GLubyte)darkColor.a;
}
}
} else {
if (effect) {
Color light;
Color dark;
light.r = color.r / 255.0f;
light.g = color.g / 255.0f;
light.b = color.b / 255.0f;
light.a = color.a / 255.0f;
dark.r = darkColor.r / 255.0f;
dark.g = darkColor.g / 255.0f;
dark.b = darkColor.b / 255.0f;
dark.a = darkColor.a / 255.0f;
for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
Color lightCopy = light;
Color darkCopy = dark;
effect->transform(vertex->vertex.x, vertex->vertex.y, vertex->texCoord.u, vertex->texCoord.v, lightCopy, darkCopy);
vertex->color.r = (GLubyte)(lightCopy.r * 255);
vertex->color.g = (GLubyte)(lightCopy.g * 255);
vertex->color.b = (GLubyte)(lightCopy.b * 255);
vertex->color.a = (GLubyte)(lightCopy.a * 255);
vertex->color2.r = (GLubyte)(darkCopy.r * 255);
vertex->color2.g = (GLubyte)(darkCopy.g * 255);
vertex->color2.b = (GLubyte)(darkCopy.b * 255);
vertex->color2.a = (GLubyte)darkColor.a;
}
} else {
for (int v = 0, vn = trianglesTwoColor.vertCount; v < vn; ++v) {
V2F_T2F_C4B_C4B* vertex = trianglesTwoColor.verts + v;
vertex->color.r = (GLubyte)color.r;
vertex->color.g = (GLubyte)color.g;
vertex->color.b = (GLubyte)color.b;
vertex->color.a = (GLubyte)color.a;
vertex->color2.r = (GLubyte)darkColor.r;
vertex->color2.g = (GLubyte)darkColor.g;
vertex->color2.b = (GLubyte)darkColor.b;
vertex->color2.a = (GLubyte)darkColor.a;
}
}
}
texture = attachmentVertices->_texture;
}
texture = attachmentVertices->_texture;
curTextureIndex =
attachmentVertices->_texture->getNativeTexture()->getHandle();
// If texture or blendMode change,will change material.
// If texture or blendMode change,will change material.
if (preTextureIndex != curTextureIndex ||
preBlendMode != slot->getData().getBlendMode() || isFull) {
flush();
flush();
}
}
else {

View File

@@ -50,7 +50,7 @@ namespace spine {
/** Draws a skeleton.
*/
class SkeletonRenderer: public cocos2d::middleware::IMiddleware, public cocos2d::Ref {
class SkeletonRenderer: public cocos2d::Ref, public cocos2d::middleware::IMiddleware {
public:
static SkeletonRenderer* create ();
static SkeletonRenderer* createWithSkeleton(Skeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
@@ -99,7 +99,7 @@ namespace spine {
void setUseTint(bool enabled);
void setUseMulti(bool enabled);
/* Sets the vertex effect to be used, set to 0 to disable vertex effects */
void setVertexEffectDelegate(VertexEffectDelegate* effectDelegate);
/* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */
@@ -126,6 +126,7 @@ namespace spine {
virtual void stopSchedule();
void onEnable();
void onDisable();
virtual void destroy();
CC_CONSTRUCTOR_ACCESS:
SkeletonRenderer ();