------------------------------------------------------------------------------
| 1330 | |
| 1331 | //------------------------------------------------------------------------------ |
| 1332 | int vtkWebGPURenderWindow::SetPixelData( |
| 1333 | int x, int y, int x2, int y2, unsigned char* data, int front, int right) |
| 1334 | { |
| 1335 | vtkWebGPUCheckUnconfiguredWithReturn(this, 0); |
| 1336 | auto device = this->WGPUConfiguration->GetDevice(); |
| 1337 | if (device == nullptr) |
| 1338 | { |
| 1339 | vtkErrorMacro(<< "Cannot set pixel data because WebGPU device is not ready!"); |
| 1340 | return 0; |
| 1341 | } |
| 1342 | (void)front; |
| 1343 | (void)right; |
| 1344 | const int nComp = 3; |
| 1345 | int width = (x2 - x) + 1; |
| 1346 | int height = (y2 - y) + 1; |
| 1347 | int bytesPerRow = vtkWebGPUConfiguration::Align(width * nComp, 256); |
| 1348 | int size = bytesPerRow * height; |
| 1349 | |
| 1350 | const std::string label = "StagingRGBPixelData-" + this->GetObjectDescription(); |
| 1351 | wgpu::BufferDescriptor desc; |
| 1352 | desc.mappedAtCreation = true; |
| 1353 | desc.label = label.c_str(); |
| 1354 | desc.size = size; |
| 1355 | desc.usage = wgpu::BufferUsage::CopySrc; |
| 1356 | |
| 1357 | this->StagingPixelData.Buffer = this->WGPUConfiguration->CreateBuffer(desc); |
| 1358 | if (this->StagingPixelData.Buffer == nullptr) |
| 1359 | { |
| 1360 | vtkErrorMacro(<< "Failed to create buffer for staging pixel data using device " |
| 1361 | << device.Get()); |
| 1362 | return 0; |
| 1363 | } |
| 1364 | auto mapped = |
| 1365 | reinterpret_cast<unsigned char*>(this->StagingPixelData.Buffer.GetMappedRange(0, size)); |
| 1366 | if (mapped == nullptr) |
| 1367 | { |
| 1368 | vtkErrorMacro(<< "Failed to map staging pixel data!"); |
| 1369 | return 0; |
| 1370 | } |
| 1371 | unsigned long dstIdx = 0; |
| 1372 | unsigned long srcIdx = 0; |
| 1373 | const unsigned long nPad = bytesPerRow - width * nComp; |
| 1374 | int componentMap[3] = {}; |
| 1375 | if (this->ColorAttachment.Format == wgpu::TextureFormat::BGRA8Unorm) |
| 1376 | { |
| 1377 | componentMap[0] = 2; |
| 1378 | componentMap[1] = 1; |
| 1379 | componentMap[2] = 0; |
| 1380 | } |
| 1381 | else if (this->ColorAttachment.Format == wgpu::TextureFormat::RGBA8Unorm) |
| 1382 | { |
| 1383 | componentMap[0] = 0; |
| 1384 | componentMap[1] = 1; |
| 1385 | componentMap[2] = 2; |
| 1386 | } |
| 1387 | for (int j = 0; j < height; ++j) |
| 1388 | { |
| 1389 | for (int i = 0; i < width; ++i) |
no test coverage detected