VTK  9.3.1
vtkOpenGLBufferObject.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 #ifndef vtkOpenGLBufferObject_h
4 #define vtkOpenGLBufferObject_h
5 
6 #include "vtkObject.h"
7 #include "vtkRenderingOpenGL2Module.h" // for export macro
8 #include <string> // used for std::string
9 #include <vector> // used for method args
10 
11 VTK_ABI_NAMESPACE_BEGIN
12 class vtkCellArray;
13 class vtkDataArray;
14 class vtkPoints;
15 
23 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
24 {
25 public:
26  static vtkOpenGLBufferObject* New();
28  void PrintSelf(ostream& os, vtkIndent indent) override;
29 
31  {
34  TextureBuffer
35  };
36 
38  ObjectType GetType() const;
39 
41  void SetType(ObjectType value);
42 
44  int GetHandle() const;
45 
47  bool IsReady() const { return this->Dirty == false; }
48 
50  bool GenerateBuffer(ObjectType type);
51 
61  template <class T>
62  bool Upload(const T& array, ObjectType type);
63 
64  // non vector version
65  template <class T>
66  bool Upload(const T* array, size_t numElements, ObjectType type);
67 
73  bool Bind();
74 
78  bool Release();
79 
80  // Description:
81  // Release any graphics resources that are being consumed by this class.
82  void ReleaseGraphicsResources();
83 
87  std::string GetError() const { return Error; }
88 
89 protected:
91  ~vtkOpenGLBufferObject() override;
92  bool Dirty;
94 
95  bool UploadInternal(const void* buffer, size_t size, ObjectType objectType);
96 
97 private:
99  void operator=(const vtkOpenGLBufferObject&) = delete;
100  struct Private;
101  Private* Internal;
102 };
103 
104 template <class T>
106  const T& array, vtkOpenGLBufferObject::ObjectType objectType)
107 {
108  if (array.empty())
109  {
110  this->Error = "Refusing to upload empty array.";
111  return false;
112  }
113 
114  return this->UploadInternal(&array[0], array.size() * sizeof(typename T::value_type), objectType);
115 }
116 
117 template <class T>
119  const T* array, size_t numElements, vtkOpenGLBufferObject::ObjectType objectType)
120 {
121  if (!array)
122  {
123  this->Error = "Refusing to upload empty array.";
124  return false;
125  }
126  return this->UploadInternal(array, numElements * sizeof(T), objectType);
127 }
128 
129 VTK_ABI_NAMESPACE_END
130 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::string GetError() const
Return a string describing errors.
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
object to represent cell connectivity
Definition: vtkCellArray.h:175
bool IsReady() const
Determine if the buffer object is ready to be used.
OpenGL buffer object.
bool Upload(const T &array, ObjectType type)
Upload data to the buffer object.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
represent and manipulate 3D points
Definition: vtkPoints.h:28