VTK  9.7.1
vtkOpenGLArrayTextureBufferAdapter.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
28 #ifndef vtkOpenGLArrayTextureBufferAdapter_h
29 #define vtkOpenGLArrayTextureBufferAdapter_h
30 
31 #include "vtkDataArray.h"
32 #include "vtkOpenGLBufferObject.h"
33 #include "vtkRenderingOpenGL2Module.h"
34 #include "vtkSmartPointer.h"
35 #include "vtkTextureObject.h"
36 #include "vtkWindow.h"
37 
38 #include <cstddef> // for std::size_t
39 #include <vector>
40 
41 VTK_ABI_NAMESPACE_BEGIN
43 
44 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLArrayTextureBufferAdapter
45 {
46 public:
47  std::vector<vtkSmartPointer<vtkDataArray>> Arrays;
54 
57  vtkDataArray* array, bool asScalars, bool* integerTexture = nullptr);
60  const vtkOpenGLArrayTextureBufferAdapter&) = default;
61 
62  void Upload(vtkOpenGLRenderWindow* renderWindow, bool force = false);
63 
64  void ReleaseGraphicsResources(vtkWindow* window);
65 
67 
74  void SetUploaded(bool uploaded) { this->Uploaded = uploaded; }
75  bool GetUploaded() const { return this->Uploaded; }
77 
79 
88  void SetOwnsTexture(bool ownsTexture) { this->OwnsTexture = ownsTexture; }
89  bool GetOwnsTexture() const { return this->OwnsTexture; }
91 
93 
101  void SetPendingReset(bool pendingReset) { this->PendingReset = pendingReset; }
102  bool GetPendingReset() const { return this->PendingReset; }
104 
105 private:
113  void UploadImpl(vtkOpenGLRenderWindow* renderWindow);
114 
116  struct NarrowedArrayInfo
117  {
118  std::size_t ByteLength = 0;
119  vtkIdType TexelCount = 0;
120  int NumComps = 0;
121  int Vtktype = 0;
122  };
123 
128  NarrowedArrayInfo AppendNarrowed(vtkDataArray* array, std::vector<unsigned char>& dest) const;
129 
132  struct SubArrayUpload
133  {
134  const void* SourceId = nullptr;
135  vtkMTimeType MTime = 0;
136  std::size_t ByteOffset = 0;
137  std::size_t ByteLength = 0;
138  vtkIdType TexelOffset = 0;
139  vtkIdType TexelCount = 0;
140  };
141  struct UploadedLayout
142  {
143  std::vector<SubArrayUpload> Subs;
144  std::size_t TotalBytes = 0;
145  vtkIdType TotalTuples = 0;
146  int NumComps = 0;
147  int Vtktype = 0;
148  bool Scalars = false;
149  bool Valid = false;
150  };
151  UploadedLayout LastUpload;
153  bool Uploaded = false;
155  bool OwnsTexture = true;
157  bool PendingReset = false;
158 };
159 
160 VTK_ABI_NAMESPACE_END
161 #endif
162 // Need to skip header testing since we do not inherit vtkObject:
163 // VTK-HeaderTest-Exclude: vtkOpenGLArrayTextureBufferAdapter.h
OpenGL rendering window.
vtkSmartPointer< vtkOpenGLBufferObject > Buffer
bool GetOwnsTexture() const
Get/set who owns this adapter's Texture/Buffer.
void SetPendingReset(bool pendingReset)
Get/set the pending-reset flag used to recycle an adapter across rebuild cycles.
std::vector< vtkSmartPointer< vtkDataArray > > Arrays
Interfaces vtkDataArray to an OpenGL texture buffer.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
vtkSmartPointer< vtkTextureObject > Texture
int vtkIdType
Definition: vtkType.h:363
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
bool GetPendingReset() const
Get/set the pending-reset flag used to recycle an adapter across rebuild cycles.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
bool GetUploaded() const
Get/set the "already uploaded" guard.
void SetOwnsTexture(bool ownsTexture)
Get/set who owns this adapter's Texture/Buffer.
void SetUploaded(bool uploaded)
Get/set the "already uploaded" guard.
vtkOpenGLBufferObject::ObjectUsage BufferUsage
Cell is in a good state.