MCPcopy Create free account
hub / github.com/Kitware/VTK / SetRGBAPixelData

Method SetRGBAPixelData

Rendering/WebGPU/vtkWebGPURenderWindow.cxx:1524–1612  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1522
1523//------------------------------------------------------------------------------
1524int vtkWebGPURenderWindow::SetRGBAPixelData(
1525 int x, int y, int x2, int y2, float* data, int front, int blend /*=0*/, int right /*=0*/)
1526{
1527 vtkWebGPUCheckUnconfiguredWithReturn(this, 0);
1528 auto device = this->WGPUConfiguration->GetDevice();
1529 if (device == nullptr)
1530 {
1531 vtkErrorMacro(<< "Cannot set RGBA pixel data because WebGPU device is not ready!");
1532 return 0;
1533 }
1534 (void)front;
1535 (void)blend;
1536 (void)right;
1537 const int nComp = 4;
1538 int width = (x2 - x) + 1;
1539 int height = (y2 - y) + 1;
1540 int bytesPerRow = vtkWebGPUConfiguration::Align(width * nComp, 256);
1541 int size = bytesPerRow * height;
1542
1543 const std::string label = "StagingRGBAPixelData-" + this->GetObjectDescription();
1544 wgpu::BufferDescriptor desc;
1545 desc.mappedAtCreation = true;
1546 desc.label = label.c_str();
1547 desc.size = size;
1548 desc.usage = wgpu::BufferUsage::CopySrc;
1549
1550 this->StagingPixelData.Buffer = this->WGPUConfiguration->CreateBuffer(desc);
1551 if (this->StagingPixelData.Buffer == nullptr)
1552 {
1553 vtkErrorMacro(<< "Failed to create buffer for staging pixel data using device "
1554 << device.Get());
1555 return 0;
1556 }
1557 auto mapped =
1558 reinterpret_cast<unsigned char*>(this->StagingPixelData.Buffer.GetMappedRange(0, size));
1559 if (mapped == nullptr)
1560 {
1561 vtkErrorMacro(<< "Failed to map staging pixel data!");
1562 return 0;
1563 }
1564 unsigned long dstIdx = 0;
1565 unsigned long srcIdx = 0;
1566 const unsigned long nPad = bytesPerRow - width * nComp;
1567 int componentMap[4] = {};
1568 if (this->ColorAttachment.Format == wgpu::TextureFormat::BGRA8Unorm)
1569 {
1570 componentMap[0] = 2;
1571 componentMap[1] = 1;
1572 componentMap[2] = 0;
1573 componentMap[3] = 3;
1574 }
1575 else if (this->ColorAttachment.Format == wgpu::TextureFormat::RGBA8Unorm)
1576 {
1577 componentMap[0] = 0;
1578 componentMap[1] = 1;
1579 componentMap[2] = 2;
1580 componentMap[3] = 3;
1581 }

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
EndMethod · 0.95
FrameMethod · 0.95
GetDeviceMethod · 0.45
GetObjectDescriptionMethod · 0.45
c_strMethod · 0.45
CreateBufferMethod · 0.45
GetMethod · 0.45
GetPointerMethod · 0.45

Tested by

no test coverage detected