VTK  9.3.0
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:
28  void PrintSelf(ostream& os, vtkIndent indent) override;
29 
31  {
34  TextureBuffer
35  };
36 
39 
42 
44  int GetHandle() const;
45 
47  bool IsReady() const { return this->Dirty == false; }
48 
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.
83 
87  std::string GetError() const { return Error; }
88 
89 protected:
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
object to represent cell connectivity
Definition: vtkCellArray.h:176
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:45
a simple class to control print indentation
Definition: vtkIndent.h:29
abstract base class for most VTK objects
Definition: vtkObject.h:52
OpenGL buffer object.
void SetType(ObjectType value)
Set the type of the buffer object.
bool IsReady() const
Determine if the buffer object is ready to be used.
bool Release()
Release the buffer.
ObjectType GetType() const
Get the type of the buffer object.
~vtkOpenGLBufferObject() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool Bind()
Bind the buffer object ready for rendering.
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
bool Upload(const T &array, ObjectType type)
Upload data to the buffer object.
bool GenerateBuffer(ObjectType type)
Generate the opengl buffer for this Handle.
int GetHandle() const
Get the handle of the buffer object.
std::string GetError() const
Return a string describing errors.
static vtkOpenGLBufferObject * New()
represent and manipulate 3D points
Definition: vtkPoints.h:29
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ size
Definition: vtkX3D.h:253
@ string
Definition: vtkX3D.h:490