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

Method ReadTextureFromGPU

Rendering/WebGPU/vtkWebGPURenderWindow.cxx:768–876  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

766
767//------------------------------------------------------------------------------
768void vtkWebGPURenderWindow::ReadTextureFromGPU(wgpu::Texture& wgpuTexture,
769 wgpu::TextureFormat format, std::size_t mipLevel, wgpu::TextureAspect aspect,
770 wgpu::Origin3D offsets, wgpu::Extent3D extents, TextureMapCallback callback, void* userData)
771{
772 int bytesPerPixel = 0;
773 switch (format)
774 {
775 case wgpu::TextureFormat::RGBA8Unorm:
776 case wgpu::TextureFormat::BGRA8Unorm:
777 bytesPerPixel = 4;
778 break;
779 case wgpu::TextureFormat::RGBA32Uint:
780 bytesPerPixel = 16;
781 break;
782 case wgpu::TextureFormat::Depth24Plus:
783 bytesPerPixel = 3;
784 break;
785 case wgpu::TextureFormat::Depth24PlusStencil8:
786 bytesPerPixel = 4;
787 break;
788 case wgpu::TextureFormat::R32Uint:
789 bytesPerPixel = 4;
790 break;
791 default:
792 vtkErrorMacro(
793 << "Unhandled texture format in vtkWebGPUTextureDeviceResource::GetBytesPerPixel: "
794 << int(format));
795 }
796
797 // Bytes needs to be a multiple of 256
798 vtkIdType bytesPerRow = vtkWebGPUConfiguration::Align(extents.width * bytesPerPixel, 256);
799
800 // Creating the buffer that will hold the data of the texture
801 wgpu::BufferDescriptor bufferDescriptor;
802 bufferDescriptor.label = "Buffer descriptor for mapping texture";
803 bufferDescriptor.mappedAtCreation = false;
804 bufferDescriptor.nextInChain = nullptr;
805 bufferDescriptor.size = bytesPerRow * extents.height;
806 bufferDescriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
807
808 wgpu::Buffer buffer = this->WGPUConfiguration->CreateBuffer(bufferDescriptor);
809
810 // Parameters for copying the texture
811 wgpu::TexelCopyTextureInfo texelCopyTexture;
812 texelCopyTexture.mipLevel = mipLevel;
813 texelCopyTexture.origin = offsets;
814 texelCopyTexture.texture = wgpuTexture;
815 texelCopyTexture.aspect = aspect;
816
817 // Parameters for copying the buffer
818 unsigned int mipLevelWidth = std::floor(extents.width / std::pow(2, mipLevel));
819 unsigned int mipLevelHeight = std::floor(extents.height / std::pow(2, mipLevel));
820 wgpu::TexelCopyBufferInfo texelCopyBuffer;
821 texelCopyBuffer.buffer = buffer;
822 texelCopyBuffer.layout.offset = 0;
823 texelCopyBuffer.layout.rowsPerImage = mipLevelHeight;
824 texelCopyBuffer.layout.bytesPerRow = bytesPerRow;
825

Callers 4

GetIdsDataMethod · 0.95
GetPixelDataMethod · 0.95
GetRGBAPixelDataMethod · 0.95
GetRGBACharPixelDataMethod · 0.95

Calls 11

floorFunction · 0.50
powFunction · 0.50
CreateBufferMethod · 0.45
CreateCommandEncoderMethod · 0.45
GetDeviceMethod · 0.45
FinishMethod · 0.45
emptyMethod · 0.45
GetMethod · 0.45
GetObjectDescriptionMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected