void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { GLProgramState* programstate = getGLProgramState(); Color4F color(getDisplayedColor()); color.a = getDisplayedOpacity() / 255.0f; GLuint textureID = _texture ? _texture->getName() : 0; _meshCommand.init(_globalZOrder, textureID, programstate, _blend, _mesh->getVertexBuffer(), _mesh->getIndexBuffer(), (GLenum)_mesh->getPrimitiveType(), (GLenum)_mesh->getIndexFormat(), _mesh->getIndexCount(), transform); _meshCommand.setCullFaceEnabled(true); _meshCommand.setDepthTestEnabled(true); if (_skin) { _meshCommand.setMatrixPaletteSize((int)_skin->getMatrixPaletteSize()); _meshCommand.setMatrixPalette(_skin->getMatrixPalette()); } //support tint and fade _meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a)); Director::getInstance()->getRenderer()->addCommand(&_meshCommand); }
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { if (_skeleton) _skeleton->updateBoneMatrix(); Color4F color(getDisplayedColor()); color.a = getDisplayedOpacity() / 255.0f; int i = 0; for (auto& mesh : _meshes) { if (!mesh->isVisible()) { i++; continue; } auto programstate = mesh->getGLProgramState(); auto& meshCommand = mesh->getMeshCommand(); GLuint textureID = mesh->getTexture() ? mesh->getTexture()->getName() : 0; meshCommand.init(_globalZOrder, textureID, programstate, _blend, mesh->getVertexBuffer(), mesh->getIndexBuffer(), mesh->getPrimitiveType(), mesh->getIndexFormat(), mesh->getIndexCount(), transform); auto skin = mesh->getSkin(); if (skin) { meshCommand.setMatrixPaletteSize((int)skin->getMatrixPaletteSize()); meshCommand.setMatrixPalette(skin->getMatrixPalette()); } //support tint and fade meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a)); meshCommand.setTransparent(mesh->_isTransparent); renderer->addCommand(&meshCommand); } }
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { if (_skeleton) _skeleton->updateBoneMatrix(); Color4F color(getDisplayedColor()); color.a = getDisplayedOpacity() / 255.0f; //check light and determine the shader used const auto& lights = Director::getInstance()->getRunningScene()->getLights(); bool usingLight = false; for (const auto light : lights) { usingLight = ((unsigned int)light->getLightFlag() & _lightMask) > 0; if (usingLight) break; } if (usingLight != _shaderUsingLight) genGLProgramState(usingLight); int i = 0; for (auto& mesh : _meshes) { if (!mesh->isVisible()) { i++; continue; } auto programstate = mesh->getGLProgramState(); auto& meshCommand = mesh->getMeshCommand(); GLuint textureID = mesh->getTexture() ? mesh->getTexture()->getName() : 0; meshCommand.init(_globalZOrder, textureID, programstate, _blend, mesh->getVertexBuffer(), mesh->getIndexBuffer(), mesh->getPrimitiveType(), mesh->getIndexFormat(), mesh->getIndexCount(), transform); meshCommand.setLightMask(_lightMask); auto skin = mesh->getSkin(); if (skin) { meshCommand.setMatrixPaletteSize((int)skin->getMatrixPaletteSize()); meshCommand.setMatrixPalette(skin->getMatrixPalette()); } //support tint and fade meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a)); meshCommand.setTransparent(mesh->_isTransparent); renderer->addCommand(&meshCommand); } }
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { #if CC_USE_CULLING // camera clipping if(Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&this->getAABB())) return; #endif if (_skeleton) _skeleton->updateBoneMatrix(); Color4F color(getDisplayedColor()); color.a = getDisplayedOpacity() / 255.0f; //check light and determine the shader used const auto& scene = Director::getInstance()->getRunningScene(); // Don't override GLProgramState if using manually set Material if (_usingAutogeneratedGLProgram && scene) { const auto lights = scene->getLights(); bool usingLight = false; for (const auto light : lights) { usingLight = ((unsigned int)light->getLightFlag() & _lightMask) > 0; if (usingLight) break; } if (usingLight != _shaderUsingLight) { genGLProgramState(usingLight); } } for (auto mesh: _meshes) { mesh->draw(renderer, _globalZOrder, transform, flags, _lightMask, Vec4(color.r, color.g, color.b, color.a), _forceDepthWrite); } }
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { #if CC_USE_CULLING // camera clipping if(!Camera::getVisitingCamera()->isVisibleInFrustum(&this->getAABB())) return; #endif if (_skeleton) _skeleton->updateBoneMatrix(); Color4F color(getDisplayedColor()); color.a = getDisplayedOpacity() / 255.0f; //check light and determine the shader used const auto& scene = Director::getInstance()->getRunningScene(); if (scene) { const auto& lights = scene->getLights(); bool usingLight = false; for (const auto light : lights) { usingLight = ((unsigned int)light->getLightFlag() & _lightMask) > 0; if (usingLight) break; } if (usingLight != _shaderUsingLight) genGLProgramState(usingLight); } int i = 0; for (auto& mesh : _meshes) { if (!mesh->isVisible()) { i++; continue; } auto programstate = mesh->getGLProgramState(); auto& meshCommand = mesh->getMeshCommand(); #if (!defined NDEBUG) || (defined CC_MODEL_VIEWER) GLuint textureID = 0; if(mesh->getTexture()) { textureID = mesh->getTexture()->getName(); }else { //let the mesh use a dummy texture instead of the missing or crashing texture file auto texture = getDummyTexture(); mesh->setTexture(texture); textureID = texture->getName(); } #else GLuint textureID = mesh->getTexture() ? mesh->getTexture()->getName() : 0; #endif float globalZ = _globalZOrder; bool isTransparent = (mesh->_isTransparent || color.a < 1.f); if (isTransparent && Camera::getVisitingCamera()) { // use the view matrix for Applying to recalculating transparent mesh's Z-Order const auto& viewMat = Camera::getVisitingCamera()->getViewMatrix(); //fetch the Z from the result matrix globalZ = -(viewMat.m[2] * transform.m[12] + viewMat.m[6] * transform.m[13] + viewMat.m[10] * transform.m[14] + viewMat.m[14]); } meshCommand.init(globalZ, textureID, programstate, _blend, mesh->getVertexBuffer(), mesh->getIndexBuffer(), mesh->getPrimitiveType(), mesh->getIndexFormat(), mesh->getIndexCount(), transform, flags); meshCommand.setLightMask(_lightMask); auto skin = mesh->getSkin(); if (skin) { meshCommand.setMatrixPaletteSize((int)skin->getMatrixPaletteSize()); meshCommand.setMatrixPalette(skin->getMatrixPalette()); } //support tint and fade meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a)); if (_forceDepthWrite) { meshCommand.setDepthWriteEnabled(true); } meshCommand.setTransparent(isTransparent); renderer->addCommand(&meshCommand); } }
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) { SkeletonBatch* batch = SkeletonBatch::getInstance(); Color3B nodeColor = getColor(); _skeleton->r = nodeColor.r / (float)255; _skeleton->g = nodeColor.g / (float)255; _skeleton->b = nodeColor.b / (float)255; _skeleton->a = getDisplayedOpacity() / (float)255; Color4F color; AttachmentVertices* attachmentVertices = nullptr; for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment) continue; switch (slot->attachment->type) { case SP_ATTACHMENT_REGION: { spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices); attachmentVertices = getAttachmentVertices(attachment); color.r = attachment->r; color.g = attachment->g; color.b = attachment->b; color.a = attachment->a; break; } case SP_ATTACHMENT_MESH: { spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment; spMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices); attachmentVertices = getAttachmentVertices(attachment); color.r = attachment->r; color.g = attachment->g; color.b = attachment->b; color.a = attachment->a; break; } default: continue; } color.a *= _skeleton->a * slot->a * 255; float multiplier = _premultipliedAlpha ? color.a : 255; color.r *= _skeleton->r * slot->r * multiplier; color.g *= _skeleton->g * slot->g * multiplier; color.b *= _skeleton->b * slot->b * multiplier; for (int v = 0, w = 0, vn = attachmentVertices->_triangles->vertCount; v < vn; ++v, w += 2) { V3F_C4B_T2F* vertex = attachmentVertices->_triangles->verts + v; vertex->vertices.x = _worldVertices[w]; vertex->vertices.y = _worldVertices[w + 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; } 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->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, *attachmentVertices->_triangles, transform, transformFlags); } if (_debugSlots || _debugBones) { drawDebug(renderer, transform, transformFlags); } }