------------------------------------------------------------------------------
| 1724 | |
| 1725 | //------------------------------------------------------------------------------ |
| 1726 | void vtkWebGPUPolyDataMapper::UpdateClippingPlanesBuffer( |
| 1727 | vtkWebGPUConfiguration* wgpuConfiguration, vtkActor* actor) |
| 1728 | { |
| 1729 | if (this->GetNumberOfClippingPlanes() == 0) |
| 1730 | { |
| 1731 | // Release any previously allocated buffer |
| 1732 | if (this->ClippingPlanesBuffer) |
| 1733 | { |
| 1734 | this->ClippingPlanesBuffer.Destroy(); |
| 1735 | this->ClippingPlanesBuffer = nullptr; |
| 1736 | } |
| 1737 | return; |
| 1738 | } |
| 1739 | if (this->GetNumberOfClippingPlanes() > 6) |
| 1740 | { |
| 1741 | // we only support up to 6 clipping planes. |
| 1742 | // this is a limitation of the shader code and the way we handle clipping planes. |
| 1743 | // if more than 6 clipping planes are needed, then we need to use a different approach. |
| 1744 | // for now, we just log a warning. |
| 1745 | vtkWarningMacro(<< "Too many clipping planes: " << this->GetNumberOfClippingPlanes() |
| 1746 | << ", maximum is " << 6); |
| 1747 | } |
| 1748 | this->ClippingPlanesData.PlaneCount = std::min(this->GetNumberOfClippingPlanes(), 6); |
| 1749 | vtkMTimeType planesMTime = 0; |
| 1750 | for (vtkTypeUInt32 i = 0; i < this->ClippingPlanesData.PlaneCount; i++) |
| 1751 | { |
| 1752 | planesMTime = std::max(planesMTime, this->ClippingPlanes->GetItem(i)->GetMTime()); |
| 1753 | } |
| 1754 | if (planesMTime < this->ClippingPlanesBuildTimestamp) |
| 1755 | { |
| 1756 | // no need to update the clipping planes buffer, it is already up to date. |
| 1757 | return; |
| 1758 | } |
| 1759 | // create a wgpu buffer for clipping planes if not already created. |
| 1760 | if (this->ClippingPlanesBuffer == nullptr) |
| 1761 | { |
| 1762 | const auto label = this->GetObjectDescription() + "-ClippingPlanesBuffer"; |
| 1763 | wgpu::BufferDescriptor desc = {}; |
| 1764 | desc.label = label.c_str(); |
| 1765 | desc.mappedAtCreation = false; |
| 1766 | desc.size = vtkWebGPUConfiguration::Align(sizeof(this->ClippingPlanesData), 16); |
| 1767 | desc.usage = wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst; |
| 1768 | this->ClippingPlanesBuffer = wgpuConfiguration->CreateBuffer(desc); |
| 1769 | } |
| 1770 | vtkNew<vtkMatrix4x4> modelToWorldMatrix; |
| 1771 | std::array<double, 3> scale = { 1, 1, 1 }; |
| 1772 | std::array<double, 3> shift = { 0, 0, 0 }; |
| 1773 | for (vtkTypeUInt32 i = 0; i < this->ClippingPlanesData.PlaneCount; i++) |
| 1774 | { |
| 1775 | double planeEquation[4]; |
| 1776 | actor->GetModelToWorldMatrix(modelToWorldMatrix); |
| 1777 | this->GetClippingPlaneInDataCoords(modelToWorldMatrix, i, planeEquation); |
| 1778 | |
| 1779 | // multiply by shift scale if set |
| 1780 | this->ClippingPlanesData.PlaneEquations[i][0] = planeEquation[0] / scale[0]; |
| 1781 | this->ClippingPlanesData.PlaneEquations[i][1] = planeEquation[1] / scale[1]; |
| 1782 | this->ClippingPlanesData.PlaneEquations[i][2] = planeEquation[2] / scale[2]; |
| 1783 | this->ClippingPlanesData.PlaneEquations[i][3] = planeEquation[3] + planeEquation[0] * shift[0] + |
no test coverage detected