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渲染指令

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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/174355.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【云平台】STM32微信小程序阿里云平台汇总——持续更新

【云平台】STM32微信小程序阿里云平台汇总——持续更新 文章目录 前言总结 前言 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 【云平台】STM32微信小程序阿里云平台学习板 【云平台】小白从零开始&#xff1a;小程序阿里云平台控制STM32&#xff08…

1980-2022年世界各国专利、商标申请数据/世界各国知识产权专利申请数据

1980-2022年世界各国专利、商标申请数据/世界各国知识产权专利申请数据 1、时间&#xff1a;1980-2022年 2、来源&#xff1a;WIPO数据库 3、范围&#xff1a;世界各国&#xff08;180多个国家&#xff09; 4、指标&#xff1a;国家名称、年份、代码、类型、专利申请总量、…

GPU中的半格效应(half-pixel)

最近在阅读《GPGPU编程技术从GLSL、CUDA到OpenCL》时&#xff0c;章节3.4.3 卷积核中讲到了半格效应&#xff0c;该书中的英文标注为&#xff1a;0.5 effect&#xff0c;也有被称为&#xff1a;half pixel offset等。 联想到我之前的GPU计算、渲染时的代码&#xff0c;在做画质…

TUP通信

一&#xff0c;概括 二&#xff0c;常用方法 三&#xff0c; 实现步骤&#xff08;一发一收&#xff09; 四&#xff0c;案例&#xff08;一接一收&#xff09; &#xff08;1&#xff09;&#xff0c;客户端 &#xff08;2&#xff09;&#xff0c;服务端 &#xff08;3&…

歌手荆涛作品《父与子》:一首深情演绎父子情感的歌曲

在华语乐坛中&#xff0c;有很多歌曲以亲情为主题&#xff0c;其中歌手荆涛演唱的《父与子》就是其中的代表作之一。这首歌以朴实的歌词和深情的演唱&#xff0c;打动了无数听众的心灵&#xff0c;让人感受到了亲情之间的温暖和牵绊。 《父与子》这首歌以父子为主题&#xff0c…

【C++】类型转换 ④ ( 子类 和 父类 之间的类型转换 - 动态类型转换 dynamic_cast )

文章目录 一、子类 和 父类 之间的类型转换 - 动态类型转换 dynamic_cast1、构造父类和子类2、子类 和 父类 之间的类型转换 - 隐式类型转换3、子类 和 父类 之间的类型转换 - 静态类型转换 static_cast4、子类 和 父类 之间的类型转换 - 重新解释类型转换 reinterpret_cast5、…

【Java Spring】SpringBoot Bean详解

文章目录 1、Bean方法注解简介2、Bean注解重命名3、对象装配&#xff08;获取Bean对象&#xff09;3.1 对象装配之属性注入3.2 对象装配之Set 注入3.3 对象装配之构造方法注入 4、Resource VS Autowired5、Bean对象的作用域5.1 验证Bean对象的默认作用域5.2 Bean对象的六大作用…

论文解读:《数据增强:通过强化学习引导的条件生成进行文本数据扩充》

Title:<Data Boost: Text Data Augmentation Through Reinforcement Learning Guided Conditional Generation> 期刊&#xff1a;EMNLP &#xff08;顶级国际会议&#xff09; 作者 Ruibo Liu; Guangxuan Xu; Chenyan Jia; Weicheng Ma; Lili Wang; et al 出版日期 20…

基于Springboot的墙绘产品展示交易平台(有报告),Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的墙绘产品展示交易平台&#xff08;有报告&#xff09;&#xff0c;Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff0…

手势监听类GestureDetector Listener源码解析

手势监听类GestureDetector 前言一、GestureDetector是什么&#xff1f;二、Listener源码解析1.OnGestureListener2.OnDoubleTapListener3.OnContextClickListener4.SimpleOnGestureListener 总结 前言 在写自定义view的时候&#xff0c;涉及到了手势监听这块的知识&#xff0…

FLV 文件格式分析

前言 flv 是 flash video 的缩写&#xff0c;是 Adobe Flash payler 支持的一种流媒体播放格式。flv 是一种层级格式&#xff0c;除了一个 flv header 外&#xff0c;剩下全是由 一个个 tag 组成。tag 是由 tag 头和 tag 数据组成。tag 类型分为音频、视频、脚本&#xff0c;一…

交换机的VRRP主备配置例子

拓朴如下&#xff1a; 主要配置如下&#xff1a; [S1] vlan batch 10 20 # interface Vlanif10ip address 10.1.1.1 255.255.255.0vrrp vrid 1 virtual-ip 10.1.1.254vrrp vrid 1 priority 200vrrp vrid 1 preempt-mode timer delay 20 # interface Vlanif20ip address 13.1.1…

IDEA的安装与删除插件

不小心安装了一个英文转中文的插件&#xff0c;看不习惯&#xff0c;决定重新变回英文 先点击这个settings的安装 然后就看到这个下面这张图了 如果是安装就点install&#xff0c;不用了就和我一样把这个勾给去掉

MUI框架从新手入门【webapp开发教程】

文章目录 MUI -最接近原生APP体验的高性能前端框架APP开发3.25 开发记录miu框架介绍头部/搜索框&#xff1a;身体>轮播图轮播图设置数据自动跳转&#xff1a;九宫格图片九宫格图文列表底部选项卡按钮选择器手机模拟器 心得与总结&#xff1a;MUI框架在移动应用开发中的应用M…

openGauss学习笔记-133 openGauss 数据库运维-例行维护-日维护检查项

文章目录 openGauss学习笔记-133 openGauss 数据库运维-例行维护-日维护检查项133.1 检查openGauss状态133.2 检查锁信息133.3 统计事件数据133.4 对象检查133.5 SQL报告检查133.6 备份133.7 基本信息检查 openGauss学习笔记-133 openGauss 数据库运维-例行维护-日维护检查项 …

数据结构——利用堆进行对数组的排序

今天文章的内容是关于我们如何利用堆的特性对我们的数组进行排序&#xff0c;还有就是我们的TopK的问题&#xff0c;这次我们放在的是文件种&#xff0c;我们放入一亿个数字&#xff0c;然后我们取出一亿个数字中最大的十个数&#xff0c;利用上章堆的问题进行解决。 首先就是我…

【SQL Server2019SSMS】安装 | 卸载手册

目录 &#x1f4cb;前言 ⛳️【SQL Serverssms】安装 1. SQL Server自定义安装 2. SSMS安装 ⛳️【SQL Server】卸载 &#x1f4cb;前言 &#x1f308;个人主页&#xff1a;Sarapines Programmer &#x1f525; 系列专栏&#xff1a;本期文章收录在《宝藏工具使用手册》&am…

区块链介绍

区块链提供了比特币的公共账本&#xff0c;这是一个有序的、带有时间戳的交易记录。这个系统用于防止重复消费和修改之前的交易记录。 Introduction 比特币网络中的每个完全节点都独立存储只包含该节点验证的块的区块链。当多个节点在他们的区块链中都有相同的块时&#xff0…

00TDI 这件红色大衣也太适合过年穿了

分享女儿的时尚穿搭—红色大衣 这款大衣非常厚实 摸起来很软糯的触感 复合了660-700g绵羊绒 厚实度堪比一件厚实的羽绒服 门禁处做了立体的爱心装饰 精致又可爱&#xff01;&#xff01;&#xff01;

java--单继承、Object

java是单继承的&#xff0c;java中的类不支持多继承&#xff0c;但是支持多层继承。 反证法&#xff1a; 如果一个类同时继承两个类&#xff0c;然后两个类中都有同样的一个方法&#xff0c;哪当我创建这个类里的方法&#xff0c;是调用哪父类的方法 所以java中的类不支持多继…