Spine深入学习———— 渲染

2023-11-30 03:01
文章标签 学习 深入 渲染 spine

本文主要是介绍Spine深入学习———— 渲染,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数据有了之后,就开始渲染

渲染相关

绘制顺序

骨架的绘制顺序就是一个插槽列表,在插槽列表中上方的附件在下方之上绘制,绘制顺序可以在层级树中的骨架下查看。

在这里插入图片描述

基础流程

在这里插入图片描述

渲染实现

以下按照cocos2dx的实现来 (cocos2dx 3.7 spine3.6)

SkeletonRenderer

本身继承于Node,所以渲染部分看draw函数。

void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {SkeletonBatch* batch = SkeletonBatch::getInstance();SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();bool isTwoColorTint = this->isTwoColorTint();if (_effect) _effect->begin(_effect, _skeleton);Color4F nodeColor;nodeColor.r = getDisplayedColor().r / (float)255;nodeColor.g = getDisplayedColor().g / (float)255;nodeColor.b = getDisplayedColor().b / (float)255;nodeColor.a = getDisplayedOpacity() / (float)255;Color4F color;Color4F darkColor;AttachmentVertices* attachmentVertices = nullptr;TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {spSlot* slot = _skeleton->drawOrder[i];if (!slot->attachment) {spSkeletonClipping_clipEnd(_clipper, slot);continue;}cocos2d::TrianglesCommand::Triangles triangles;TwoColorTriangles trianglesTwoColor;switch (slot->attachment->type) {case SP_ATTACHMENT_REGION: {spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;attachmentVertices = getAttachmentVertices(attachment);if (!isTwoColorTint) {triangles.indices = attachmentVertices->_triangles->indices;triangles.indexCount = attachmentVertices->_triangles->indexCount;triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);triangles.vertCount = attachmentVertices->_triangles->vertCount;memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)triangles.verts, 0, 6);} else {trianglesTwoColor.indices = attachmentVertices->_triangles->indices;trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {trianglesTwoColor.verts[ii].texCoords = attachmentVertices->_triangles->verts[ii].texCoords;}spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)trianglesTwoColor.verts, 0, 7);}color.r = attachment->color.r;color.g = attachment->color.g;color.b = attachment->color.b;color.a = attachment->color.a;break;}case SP_ATTACHMENT_MESH: {spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;attachmentVertices = getAttachmentVertices(attachment);if (!isTwoColorTint) {triangles.indices = attachmentVertices->_triangles->indices;triangles.indexCount = attachmentVertices->_triangles->indexCount;triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);triangles.vertCount = attachmentVertices->_triangles->vertCount;memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, triangles.vertCount * sizeof(cocos2d::V3F_C4B_T2F) / 4, (float*)triangles.verts, 0, 6);} else {trianglesTwoColor.indices = attachmentVertices->_triangles->indices;trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {trianglesTwoColor.verts[ii].texCoords = attachmentVertices->_triangles->verts[ii].texCoords;}spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, trianglesTwoColor.vertCount * sizeof(V3F_C4B_C4B_T2F) / 4, (float*)trianglesTwoColor.verts, 0, 7);}color.r = attachment->color.r;color.g = attachment->color.g;color.b = attachment->color.b;color.a = attachment->color.a;break;}case SP_ATTACHMENT_CLIPPING: {spClippingAttachment* clip = (spClippingAttachment*)slot->attachment;spSkeletonClipping_clipStart(_clipper, slot, clip);}default:spSkeletonClipping_clipEnd(_clipper, slot);continue;}if (slot->darkColor) {darkColor.r = slot->darkColor->r * 255;darkColor.g = slot->darkColor->g * 255;darkColor.b = slot->darkColor->b * 255;} else {darkColor.r = 0;darkColor.g = 0;darkColor.b = 0;}color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255;// skip rendering if the color of this attachment is 0if (color.a == 0){spSkeletonClipping_clipEnd(_clipper, slot);continue;}float multiplier = _premultipliedAlpha ? color.a : 255;color.r *= nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;color.g *= nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;color.b *= nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;BlendFunc blendFunc;switch (slot->data->blendMode) {case SP_BLEND_MODE_ADDITIVE:blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;blendFunc.dst = GL_ONE;break;case SP_BLEND_MODE_MULTIPLY:blendFunc.src = GL_DST_COLOR;blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;break;case SP_BLEND_MODE_SCREEN:blendFunc.src = GL_ONE;blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;break;default:blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;}if (!isTwoColorTint) {if (spSkeletonClipping_isClipping(_clipper)) {spSkeletonClipping_clipTriangles(_clipper, (float*)&triangles.verts[0].vertices, triangles.vertCount * sizeof(cocos2d::V3F_C4B_T2F) / 4, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, 6);batch->deallocateVertices(triangles.vertCount);if (_clipper->clippedTriangles->size == 0){spSkeletonClipping_clipEnd(_clipper, slot);continue;}triangles.vertCount = _clipper->clippedVertices->size >> 1;triangles.verts = batch->allocateVertices(triangles.vertCount);triangles.indexCount = _clipper->clippedTriangles->size;triangles.indices = batch->allocateIndices(triangles.indexCount);memcpy(triangles.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);float* verts = _clipper->clippedVertices->items;float* uvs = _clipper->clippedUVs->items;if (_effect) {spColor light;spColor 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 = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;spColor lightCopy = light;spColor darkCopy = dark;vertex->vertices.x = verts[vv];vertex->vertices.y = verts[vv + 1];vertex->texCoords.u = uvs[vv];vertex->texCoords.v = uvs[vv + 1];_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);vertex->colors.r = (GLubyte)(lightCopy.r * 255);vertex->colors.g = (GLubyte)(lightCopy.g * 255);vertex->colors.b = (GLubyte)(lightCopy.b * 255);vertex->colors.a = (GLubyte)(lightCopy.a * 255);}} else {for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2) {V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;vertex->vertices.x = verts[vv];vertex->vertices.y = verts[vv + 1];vertex->texCoords.u = uvs[vv];vertex->texCoords.v = uvs[vv + 1];vertex->colors.r = (GLubyte)color.r;vertex->colors.g = (GLubyte)color.g;vertex->colors.b = (GLubyte)color.b;vertex->colors.a = (GLubyte)color.a;}}} else {cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);if (_effect) {spColor light;spColor 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 = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;spColor lightCopy = light;spColor darkCopy = dark;_effect->transform(_effect, &vertex->vertices.x, &vertex->vertices.y, &vertex->texCoords.u, &vertex->texCoords.v, &lightCopy, &darkCopy);vertex->colors.r = (GLubyte)(lightCopy.r * 255);vertex->colors.g = (GLubyte)(lightCopy.g * 255);vertex->colors.b = (GLubyte)(lightCopy.b * 255);vertex->colors.a = (GLubyte)(lightCopy.a * 255);}} else {for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;vertex->colors.r = (GLubyte)color.r;vertex->colors.g = (GLubyte)color.g;vertex->colors.b = (GLubyte)color.b;vertex->colors.a = (GLubyte)color.a;}}}} else {if (spSkeletonClipping_isClipping(_clipper)) {spSkeletonClipping_clipTriangles(_clipper, (float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.vertCount * sizeof(V3F_C4B_C4B_T2F) / 4, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, 7);twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount);if (_clipper->clippedTriangles->size == 0){spSkeletonClipping_clipEnd(_clipper, slot);continue;}trianglesTwoColor.vertCount = _clipper->clippedVertices->size >> 1;trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount);trianglesTwoColor.indexCount = _clipper->clippedTriangles->size;trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount);memcpy(trianglesTwoColor.indices, _clipper->clippedTriangles->items, sizeof(unsigned short) * _clipper->clippedTriangles->size);TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);float* verts = _clipper->clippedVertices->items;float* uvs = _clipper->clippedUVs->items;if (_effect) {spColor light;spColor 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 = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;spColor lightCopy = light;spColor darkCopy = dark;vertex->position.x = verts[vv];vertex->position.y = verts[vv + 1];vertex->texCoords.u = uvs[vv];vertex->texCoords.v = uvs[vv + 1];_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.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 = 1;}} else {for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2) {V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;vertex->position.x = verts[vv];vertex->position.y = verts[vv + 1];vertex->texCoords.u = uvs[vv];vertex->texCoords.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 = 1;}}} else {TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags);if (_effect) {spColor light;spColor 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 = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts + v;spColor lightCopy = light;spColor darkCopy = dark;_effect->transform(_effect, &vertex->position.x, &vertex->position.y, &vertex->texCoords.u, &vertex->texCoords.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 = 1;}} else {for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v) {V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().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 = 1;}}}}spSkeletonClipping_clipEnd(_clipper, slot);}spSkeletonClipping_clipEnd2(_clipper);if (lastTwoColorTrianglesCommand) {Node* parent = this->getParent();// We need to decide if we can postpone flushing the current// batch. We can postpone if the next sibling node is a// two color tinted skeleton with the same global-z.// The parent->getChildrenCount() > 100 check is a hack// as checking for a sibling is an O(n) operation, and if// all children of this nodes parent are skeletons, we// are in O(n2) territory.if (!parent || parent->getChildrenCount() > 100 || getChildrenCount() != 0) {lastTwoColorTrianglesCommand->setForceFlush(true);} else {Vector<Node*>& children = parent->getChildren();Node* sibling = nullptr;for (ssize_t i = 0; i < children.size(); i++) {if (children.at(i) == this) {if (i < children.size() - 1) {sibling = children.at(i+1);break;}}}if (!sibling) {lastTwoColorTrianglesCommand->setForceFlush(true);} else {SkeletonRenderer* siblingSkeleton = dynamic_cast<SkeletonRenderer*>(sibling);if (!siblingSkeleton || // flush is next sibling isn't a SkeletonRenderer!siblingSkeleton->isTwoColorTint() || // flush if next sibling isn't two color tinted!siblingSkeleton->isVisible() || // flush if next sibling is two color tinted but not visible(siblingSkeleton->getGlobalZOrder() != this->getGlobalZOrder())) { // flush if next sibling is two color tinted but z-order differslastTwoColorTrianglesCommand->setForceFlush(true);}}}}if (_effect) _effect->end(_effect);if (_debugSlots || _debugBones || _debugMeshes) {drawDebug(renderer, transform, transformFlags);}
}

实现有点长,一点一点分析。


SkeletonBatch* batch = SkeletonBatch::getInstance();SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance();

SkeletonBatch:骨骼合批,将所有骨骼放入合批指令中,本质上是TrianglesCommand指令。

cocos2d::TrianglesCommand* SkeletonBatch::addCommand(cocos2d::Renderer* renderer, float globalOrder, cocos2d::Texture2D* texture, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const cocos2d::TrianglesCommand::Triangles& triangles, const cocos2d::Mat4& mv, uint32_t flags) {TrianglesCommand* command = nextFreeCommand();command->init(globalOrder, texture, glProgramState, blendType, triangles, mv, flags);renderer->addCommand(command);return command;
}

SkeletonTwoColorBatch:双色着色合批。是TwoColorTrianglesCommand指令。

双色着色:TwoColorTint


    //是否双色着色bool isTwoColorTint = this->isTwoColorTint();//顶点动画if (_effect) _effect->begin(_effect, _skeleton);//计算附加着色颜色//用skeleton乘上(multiplying)槽位颜色来计算附件的着色颜色, 每通道的RGBA范围均为[0-1]Color4F nodeColor;nodeColor.r = getDisplayedColor().r / (float)255;nodeColor.g = getDisplayedColor().g / (float)255;nodeColor.b = getDisplayedColor().b / (float)255;nodeColor.a = getDisplayedOpacity() / (float)255;//双色着色使用Color4F color;Color4F darkColor;//附件顶点AttachmentVertices* attachmentVertices = nullptr;TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;

接下来遍历所有骨骼。

for (int i = 0, n = _skeleton->slotsCount; i < n; ++i)

取的时候是根据drawOrder去取的,简单说就是渲染顺序(插槽列表)。

spSlot* slot = _skeleton->drawOrder[i];
if (!slot->attachment) {spSkeletonClipping_clipEnd(_clipper, slot);continue;
}

如果插槽没有附件,那么就选择不渲染。

接下来,根据插槽附加的类型进行分别处理


SP_ATTACHMENT_REGION : 一个textured矩形

//强制转换为spRegionAttachment结构体
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
//从附件的渲染对象中获取atlas页texture(纹理坐标)
attachmentVertices = getAttachmentVertices(attachment);//如果不是双色着色
if (!isTwoColorTint) {//创建一个TrianglesCommand指令triangles.indices = attachmentVertices->_triangles->indices; //data索引 index指针triangles.indexCount = attachmentVertices->_triangles->indexCount; //索引index的数量triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount); //初始化顶点数据triangles.vertCount = attachmentVertices->_triangles->vertCount; //顶点个数//填充顶点数据memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);//调用RegionAttachment::computeWorldVertices计算其世界顶点spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)triangles.verts, 0, 6);
} else {
//如果是双色着色,那么用TwoColorTriangles去构建顶点信息trianglesTwoColor.indices = attachmentVertices->_triangles->indices;trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {trianglesTwoColor.verts[ii].texCoords = attachmentVertices->_triangles->verts[ii].texCoords;}spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)trianglesTwoColor.verts, 0, 7);
}//计算的颜色就是附件的颜色	
color.r = attachment->color.r;
color.g = attachment->color.g;
color.b = attachment->color.b;
color.a = attachment->color.a;

上面的流程就是

在这里插入图片描述


SP_ATTACHMENT_MESH :一个textured网格,其顶点受到多个有权重骨詻的影响

spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
attachmentVertices = getAttachmentVertices(attachment);if (!isTwoColorTint) {triangles.indices = attachmentVertices->_triangles->indices;triangles.indexCount = attachmentVertices->_triangles->indexCount;triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount);triangles.vertCount = attachmentVertices->_triangles->vertCount;memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount);//不同的是这里 计算世界顶点的方式spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, triangles.vertCount * sizeof(cocos2d::V3F_C4B_T2F) / 4, (float*)triangles.verts, 0, 6);
} else {trianglesTwoColor.indices = attachmentVertices->_triangles->indices;trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount;trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount);trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount;for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) {trianglesTwoColor.verts[ii].texCoords = attachmentVertices->_triangles->verts[ii].texCoords;}spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, trianglesTwoColor.vertCount * sizeof(V3F_C4B_C4B_T2F) / 4, (float*)trianglesTwoColor.verts, 0, 7);
}color.r = attachment->color.r;
color.g = attachment->color.g;
color.b = attachment->color.b;
color.a = attachment->color.a;break;

SP_ATTACHMENT_CLIPPING:一个多边形,用于在绘制中裁剪其他附件

case SP_ATTACHMENT_CLIPPING: {spClippingAttachment* clip = (spClippingAttachment*)slot->attachment;spSkeletonClipping_clipStart(_clipper, slot, clip);
}
default:spSkeletonClipping_clipEnd(_clipper, slot);continue;
}

计算附件颜色值

用skeleton乘上(multiplying)槽位颜色来计算附件的着色颜色, 每通道的RGBA范围均为[0-1]

color.a *= nodeColor.a * _skeleton->color.a * slot->color.a * 255;
// skip rendering if the color of this attachment is 0
if (color.a == 0){spSkeletonClipping_clipEnd(_clipper, slot);continue;
}
float multiplier = _premultipliedAlpha ? color.a : 255;
color.r *= nodeColor.r * _skeleton->color.r * slot->color.r * multiplier;
color.g *= nodeColor.g * _skeleton->color.g * slot->color.g * multiplier;
color.b *= nodeColor.b * _skeleton->color.b * slot->color.b * multiplier;

接下来颜色混合

BlendFunc blendFunc;
switch (slot->data->blendMode) {case SP_BLEND_MODE_ADDITIVE:blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;blendFunc.dst = GL_ONE;break;case SP_BLEND_MODE_MULTIPLY:blendFunc.src = GL_DST_COLOR;blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;break;case SP_BLEND_MODE_SCREEN:blendFunc.src = GL_ONE;blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;break;default:blendFunc.src = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA;blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
}

根据是否有裁剪附件,来添加batch渲染指令

如果有裁剪,优先处理裁剪,剔除掉裁剪区域外的纹理和顶点坐标。

然后在判断是否有顶点动画

这篇关于Spine深入学习———— 渲染的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/435375

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

深入探索协同过滤:从原理到推荐模块案例

文章目录 前言一、协同过滤1. 基于用户的协同过滤(UserCF)2. 基于物品的协同过滤(ItemCF)3. 相似度计算方法 二、相似度计算方法1. 欧氏距离2. 皮尔逊相关系数3. 杰卡德相似系数4. 余弦相似度 三、推荐模块案例1.基于文章的协同过滤推荐功能2.基于用户的协同过滤推荐功能 前言     在信息过载的时代,推荐系统成为连接用户与内容的桥梁。本文聚焦于

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

系统架构师考试学习笔记第三篇——架构设计高级知识(20)通信系统架构设计理论与实践

本章知识考点:         第20课时主要学习通信系统架构设计的理论和工作中的实践。根据新版考试大纲,本课时知识点会涉及案例分析题(25分),而在历年考试中,案例题对该部分内容的考查并不多,虽在综合知识选择题目中经常考查,但分值也不高。本课时内容侧重于对知识点的记忆和理解,按照以往的出题规律,通信系统架构设计基础知识点多来源于教材内的基础网络设备、网络架构和教材外最新时事热点技术。本课时知识

【C++高阶】C++类型转换全攻略:深入理解并高效应用

📝个人主页🌹:Eternity._ ⏩收录专栏⏪:C++ “ 登神长阶 ” 🤡往期回顾🤡:C++ 智能指针 🌹🌹期待您的关注 🌹🌹 ❀C++的类型转换 📒1. C语言中的类型转换📚2. C++强制类型转换⛰️static_cast🌞reinterpret_cast⭐const_cast🍁dynamic_cast 📜3. C++强制类型转换的原因📝