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 Effect3DOutline::draw(const Mat4 &transform) { //draw Color4F color(_sprite->getDisplayedColor()); color.a = _sprite->getDisplayedOpacity() / 255.0f; _glProgramState->setUniformVec4("u_color", Vec4(color.r, color.g, color.b, color.a)); if(_sprite && _sprite->getMesh()) { glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); glEnable(GL_DEPTH_TEST); auto mesh = _sprite->getMesh(); glBindBuffer(GL_ARRAY_BUFFER, mesh->getVertexBuffer()); auto skin = _sprite->getMesh()->getSkin(); if(_sprite && skin) { auto function = std::bind(MatrixPalleteCallBack, std::placeholders::_1, std::placeholders::_2, skin->getMatrixPaletteSize(), (float*)skin->getMatrixPalette()); _glProgramState->setUniformCallback("u_matrixPalette", function); } if(_sprite) _glProgramState->apply(transform); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->getIndexBuffer()); glDrawElements(mesh->getPrimitiveType(), (GLsizei)mesh->getIndexCount(), mesh->getIndexFormat(), 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, mesh->getIndexCount()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisable(GL_DEPTH_TEST); glCullFace(GL_BACK); glDisable(GL_CULL_FACE); } }
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); } }