| 271 | } |
| 272 | |
| 273 | void UpdateInstanceAttributeBuffers(vtkSmartPointer<vtkWebGPUConfiguration> wgpuConfiguration) |
| 274 | { |
| 275 | const char* instanceAttribLabels[InstanceDataAttributes::NUM_INSTANCE_ATTRIBUTES] = { |
| 276 | "instance_colors", "instanceNormals", "instance_normal_transforms" |
| 277 | }; |
| 278 | for (int attributeIndex = 0; attributeIndex < InstanceDataAttributes::NUM_INSTANCE_ATTRIBUTES; |
| 279 | ++attributeIndex) |
| 280 | { |
| 281 | uint64_t currentBufferSize = 0; |
| 282 | const uint64_t requiredBufferSize = |
| 283 | this->GetExactInstanceBufferSize(static_cast<InstanceDataAttributes>(attributeIndex)); |
| 284 | if (this->InstanceAttributesBuffers[attributeIndex].Buffer) |
| 285 | { |
| 286 | currentBufferSize = this->InstanceAttributesBuffers[attributeIndex].Size; |
| 287 | } |
| 288 | if (currentBufferSize != requiredBufferSize) |
| 289 | { |
| 290 | if (this->InstanceAttributesBuffers[attributeIndex].Buffer) |
| 291 | { |
| 292 | this->InstanceAttributesBuffers[attributeIndex].Buffer.Destroy(); |
| 293 | this->InstanceAttributesBuffers[attributeIndex].Size = 0; |
| 294 | } |
| 295 | wgpu::BufferDescriptor descriptor{}; |
| 296 | descriptor.size = requiredBufferSize; |
| 297 | const auto label = instanceAttribLabels[attributeIndex] + std::string("-") + |
| 298 | this->CurrentInput->GetObjectDescription(); |
| 299 | descriptor.label = label.c_str(); |
| 300 | descriptor.mappedAtCreation = false; |
| 301 | descriptor.usage = wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst; |
| 302 | this->InstanceAttributesBuffers[attributeIndex].Buffer = |
| 303 | wgpuConfiguration->CreateBuffer(descriptor); |
| 304 | this->InstanceAttributesBuffers[attributeIndex].Size = requiredBufferSize; |
| 305 | // invalidate timestamp |
| 306 | this->InstanceAttributesBuildTimestamp[attributeIndex] = vtkTimeStamp(); |
| 307 | this->RebuildGraphicsPipelines = true; |
| 308 | } |
| 309 | switch (InstanceDataAttributesOrder[attributeIndex]) |
| 310 | { |
| 311 | case INSTANCE_COLORS: |
| 312 | if (this->InstanceColors && |
| 313 | this->GlyphStructuresBuildTime > this->InstanceAttributesBuildTimestamp[attributeIndex]) |
| 314 | { |
| 315 | wgpuConfiguration->WriteBuffer(this->InstanceAttributesBuffers[attributeIndex].Buffer, |
| 316 | 0, this->InstanceColors->data(), |
| 317 | this->InstanceColors->size() * sizeof(vtkTypeFloat32), |
| 318 | instanceAttribLabels[attributeIndex]); |
| 319 | this->InstanceAttributesBuildTimestamp[attributeIndex].Modified(); |
| 320 | } |
| 321 | break; |
| 322 | case INSTANCE_TRANSFORMS: |
| 323 | if (this->InstanceTransforms && |
| 324 | this->GlyphStructuresBuildTime > this->InstanceAttributesBuildTimestamp[attributeIndex]) |
| 325 | { |
| 326 | wgpuConfiguration->WriteBuffer(this->InstanceAttributesBuffers[attributeIndex].Buffer, |
| 327 | 0, this->InstanceTransforms->data(), |
| 328 | this->InstanceTransforms->size() * sizeof(vtkTypeFloat32), |
| 329 | instanceAttribLabels[attributeIndex]); |
| 330 | this->InstanceAttributesBuildTimestamp[attributeIndex].Modified(); |
nothing calls this directly
no test coverage detected