------------------------------------------------------------------------------
| 1422 | |
| 1423 | //------------------------------------------------------------------------------ |
| 1424 | float* vtkWebGPURenderWindow::GetRGBAPixelData( |
| 1425 | int x1, int y1, int x2, int y2, int front, int right /*=0*/) |
| 1426 | { |
| 1427 | (void)front; |
| 1428 | (void)right; |
| 1429 | |
| 1430 | int width = x2 - x1 + 1; |
| 1431 | int height = y2 - y1 + 1; |
| 1432 | const int outNumberOfComponents = 4; |
| 1433 | int inNumberOfComponents = 0; |
| 1434 | |
| 1435 | struct CallbackData |
| 1436 | { |
| 1437 | float* outputValues; |
| 1438 | int xMin; |
| 1439 | int xMax; |
| 1440 | int yMin; |
| 1441 | int yMax; |
| 1442 | int componentMap[4] = {}; |
| 1443 | }; |
| 1444 | auto* pixels = new float[width * height * outNumberOfComponents]; |
| 1445 | auto* callbackData = new CallbackData(); |
| 1446 | callbackData->outputValues = pixels; |
| 1447 | callbackData->xMin = x1; |
| 1448 | callbackData->xMax = x2; |
| 1449 | callbackData->yMin = y1; |
| 1450 | callbackData->yMax = y2; |
| 1451 | if (this->ColorAttachment.Format == wgpu::TextureFormat::BGRA8Unorm) |
| 1452 | { |
| 1453 | callbackData->componentMap[0] = 2; |
| 1454 | callbackData->componentMap[1] = 1; |
| 1455 | callbackData->componentMap[2] = 0; |
| 1456 | callbackData->componentMap[3] = 3; |
| 1457 | inNumberOfComponents = 4; |
| 1458 | } |
| 1459 | else if (this->ColorAttachment.Format == wgpu::TextureFormat::RGBA8Unorm) |
| 1460 | { |
| 1461 | callbackData->componentMap[0] = 0; |
| 1462 | callbackData->componentMap[1] = 1; |
| 1463 | callbackData->componentMap[2] = 2; |
| 1464 | callbackData->componentMap[3] = 3; |
| 1465 | inNumberOfComponents = 4; |
| 1466 | } |
| 1467 | else |
| 1468 | { |
| 1469 | // TODO: Handle other formats. |
| 1470 | vtkErrorMacro(<< "Unsupported offscreen texture format!"); |
| 1471 | delete callbackData; |
| 1472 | return pixels; |
| 1473 | } |
| 1474 | |
| 1475 | auto onTextureMapped = [inNumberOfComponents]( |
| 1476 | const void* mappedData, int bytesPerRow, void* userData) |
| 1477 | { |
| 1478 | CallbackData* callbackDataPtr = reinterpret_cast<CallbackData*>(userData); |
| 1479 | float* outputValues = callbackDataPtr->outputValues; |
| 1480 | const unsigned char* mappedDataChar = reinterpret_cast<const unsigned char*>(mappedData); |
| 1481 |