| 1661 | } |
| 1662 | |
| 1663 | void Node::Grabber::grab(Node* target) { |
| 1664 | float width = std::floor(target->getWidth()); // init RT with integer size |
| 1665 | float height = std::floor(target->getHeight()); |
| 1666 | |
| 1667 | AssertIf(width <= 0.0f || height <= 0.0f, "can not grab a node with size [{}x{}].", width, height); |
| 1668 | |
| 1669 | size_t rtCount = 1; |
| 1670 | if (_effect) { |
| 1671 | for (Pass* pass : _effect->getPasses()) { |
| 1672 | if (pass->isGrabPass()) { |
| 1673 | rtCount = 2; |
| 1674 | break; |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | if (rtCount < _renderTargets.size()) { |
| 1679 | for (size_t i = rtCount; i < _renderTargets.size(); i++) { |
| 1680 | _renderTargets.pop_back(); |
| 1681 | } |
| 1682 | } else { |
| 1683 | for (size_t i = _renderTargets.size(); i < rtCount; i++) { |
| 1684 | _renderTargets.push_back(newRenderPair(width, height)); |
| 1685 | } |
| 1686 | } |
| 1687 | for (size_t i = 0; i < _renderTargets.size(); i++) { |
| 1688 | const auto& rt = _renderTargets[i]; |
| 1689 | if (rt.surface->getWidth() != width || rt.surface->getHeight() != height) { |
| 1690 | _renderTargets[i] = newRenderPair(width, height); |
| 1691 | } |
| 1692 | _renderTargets[i].surface->getEffect()->clear(); |
| 1693 | } |
| 1694 | |
| 1695 | SharedView.pushInsertionMode(true, [&]() { |
| 1696 | target->markDirty(); |
| 1697 | target->_flags.setOn(Node::IgnoreLocalTransform); |
| 1698 | _renderTargets[0].rt->setCamera(_camera); |
| 1699 | _renderTargets[0].rt->renderWithClear(target, _clearColor); |
| 1700 | _renderTargets[0].rt->setCamera(nullptr); |
| 1701 | target->_flags.setOff(Node::IgnoreLocalTransform); |
| 1702 | target->markDirty(); |
| 1703 | |
| 1704 | size_t rtIndex = 0; |
| 1705 | if (_effect) { |
| 1706 | for (Pass* pass : _effect->getPasses()) { |
| 1707 | Effect* effect = _renderTargets[rtIndex].surface->getEffect(); |
| 1708 | effect->add(pass); |
| 1709 | if (pass->isGrabPass()) { |
| 1710 | Sprite* surface = _renderTargets[rtIndex].surface; |
| 1711 | rtIndex = (rtIndex + 1) % 2; |
| 1712 | surface->setPosition({width / 2.0f, height / 2.0f}); |
| 1713 | surface->setBlendFunc({BlendFunc::One, BlendFunc::Zero}); |
| 1714 | _renderTargets[rtIndex].rt->render(surface); |
| 1715 | surface->getEffect()->clear(); |
| 1716 | _renderTargets[rtIndex].surface->getEffect()->clear(); |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 |
no test coverage detected