VTK  9.0.1
vtkOpenGLBufferObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4 
5  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkOpenGLBufferObject_h
15 #define vtkOpenGLBufferObject_h
16 
17 #include "vtkObject.h"
18 #include "vtkRenderingOpenGL2Module.h" // for export macro
19 #include <string> // used for std::string
20 #include <vector> // used for method args
21 
22 class vtkCellArray;
23 class vtkDataArray;
24 class vtkPoints;
25 
33 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
34 {
35 public:
36  static vtkOpenGLBufferObject* New();
38  void PrintSelf(ostream& os, vtkIndent indent) override;
39 
41  {
44  TextureBuffer
45  };
46 
48  ObjectType GetType() const;
49 
51  void SetType(ObjectType value);
52 
54  int GetHandle() const;
55 
57  bool IsReady() const { return this->Dirty == false; }
58 
60  bool GenerateBuffer(ObjectType type);
61 
71  template <class T>
72  bool Upload(const T& array, ObjectType type);
73 
74  // non vector version
75  template <class T>
76  bool Upload(const T* array, size_t numElements, ObjectType type);
77 
83  bool Bind();
84 
88  bool Release();
89 
90  // Description:
91  // Release any graphics resources that are being consumed by this class.
92  void ReleaseGraphicsResources();
93 
97  std::string GetError() const { return Error; }
98 
99 protected:
101  ~vtkOpenGLBufferObject() override;
102  bool Dirty;
104 
105  bool UploadInternal(const void* buffer, size_t size, ObjectType objectType);
106 
107 private:
109  void operator=(const vtkOpenGLBufferObject&) = delete;
110  struct Private;
111  Private* Internal;
112 };
113 
114 template <class T>
116  const T& array, vtkOpenGLBufferObject::ObjectType objectType)
117 {
118  if (array.empty())
119  {
120  this->Error = "Refusing to upload empty array.";
121  return false;
122  }
123 
124  return this->UploadInternal(&array[0], array.size() * sizeof(typename T::value_type), objectType);
125 }
126 
127 template <class T>
129  const T* array, size_t numElements, vtkOpenGLBufferObject::ObjectType objectType)
130 {
131  if (!array)
132  {
133  this->Error = "Refusing to upload empty array.";
134  return false;
135  }
136  return this->UploadInternal(array, numElements * sizeof(T), objectType);
137 }
138 
139 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool IsReady() const
Determine if the buffer object is ready to be used.
a simple class to control print indentation
Definition: vtkIndent.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
object to represent cell connectivity
Definition: vtkCellArray.h:179
OpenGL buffer object.
bool Upload(const T &array, ObjectType type)
Upload data to the buffer object.
std::string GetError() const
Return a string describing errors.
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:33