VTK  9.7.1
vtkWebGPUComputeTexture.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 #ifndef vtkWebGPUComputeTexture_h
5 #define vtkWebGPUComputeTexture_h
6 
7 #include "vtkDataArray.h" // for vtkDataArray used in SetData
8 #include "vtkLogger.h" // for the logger
9 #include "vtkRenderingWebGPUModule.h" // For export macro
11 #include "vtk_wgpu.h" // for dawn classes
12 
13 VTK_ABI_NAMESPACE_BEGIN
14 
15 class vtkWebGPURenderer;
16 
28 class VTKRENDERINGWEBGPU_EXPORT vtkWebGPUComputeTexture : public vtkWebGPUTextureDeviceResource
29 {
30 public:
32  static vtkWebGPUComputeTexture* New();
33 
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
37 
40  vtkGetMacro(ByteSize, vtkIdType);
41  vtkSetMacro(ByteSize, vtkIdType);
43 
51  template <typename T>
52  void SetData(const std::vector<T>& data)
53  {
54  this->DataPointer = data.data();
55  this->ByteSize = data.size() * sizeof(T);
56  }
57 
65  void SetData(vtkDataArray* data);
66 
68 
71  vtkGetMacro(DataType, TextureDataType);
72  vtkSetMacro(DataType, TextureDataType);
74 
81  const void* GetDataPointer() { return this->DataPointer; }
82 
89  vtkDataArray* GetDataArray() { return this->DataArray; }
90 
92 
95  const std::string& GetLabel() const { return this->Label; }
96  vtkGetMacro(Label, std::string&);
97  vtkSetMacro(Label, std::string);
99 
100 protected:
102  ~vtkWebGPUComputeTexture() override;
103 
104 private:
106  void operator=(const vtkWebGPUComputeTexture&) = delete;
107 
108  // Total size of the texture in bytes
109  vtkIdType ByteSize = -1;
110 
111  // The type of data that will be uploaded to the GPU
112  TextureDataType DataType = TextureDataType::STD_VECTOR;
113 
114  // Pointer to the data that this buffer will contain. This variable DataPointer is only used when
115  // the user set the buffer data (with SetData()) using an std::vector.
116  const void* DataPointer = nullptr;
117  // Data array containing the data that will be uploaded to the buffer. Only relevant if the user
118  // called SetData(vtkDataArray).
119  vtkDataArray* DataArray = nullptr;
120 
121  // Label used for debugging if something goes wrong.
122  std::string Label = "Compute texture";
123 };
124 
125 VTK_ABI_NAMESPACE_END
126 
127 #endif
const void * GetDataPointer()
The pointer to the std::vector<> data passed with SetData(std::vector)
abstract base class for most VTK objects
Definition: vtkObject.h:52
int vtkIdType
Definition: vtkType.h:363
const std::string & GetLabel() const
Get/set the label used for debugging in case of errors.
vtkDataArray * GetDataArray()
The pointer to the vtkDataArray passed with SetData(vtkDataArray)
void SetData(const std::vector< T > &data)
Sets the data that will be used by the texture.
a simple class to control print indentation
Definition: vtkIndent.h:28
Abstraction class for WebGPU textures.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
static vtkWebGPUTextureDeviceResource * New()
Represents the set of parameters that will be used to create a compute shader texture on the device w...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.