VTK
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 "vtkRenderingOpenGL2Module.h" // for export macro
18 #include "vtkObject.h"
19 #include <vector> // used for method args
20 
21 class vtkCellArray;
22 class vtkDataArray;
23 class vtkPoints;
24 
32 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
33 {
34 public:
35  static vtkOpenGLBufferObject *New();
37  void PrintSelf(ostream& os, vtkIndent indent);
38 
40  {
43  TextureBuffer
44  };
45 
47  ObjectType GetType() const;
48 
50  void SetType(ObjectType value);
51 
53  int GetHandle() const;
54 
56  bool IsReady() const { return this->Dirty == false; }
57 
59  bool GenerateBuffer(ObjectType type);
60 
70  template <class T>
71  bool Upload(const T &array, ObjectType type);
72 
73  // non vector version
74  template <class T>
75  bool Upload(const T *array, size_t numElements, ObjectType type);
76 
82  bool Bind();
83 
87  bool Release();
88 
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:
102  bool Dirty;
104 
105  bool UploadInternal(const void *buffer, size_t size, ObjectType objectType);
106 
107 private:
108  vtkOpenGLBufferObject(const vtkOpenGLBufferObject&) VTK_DELETE_FUNCTION;
109  void operator=(const vtkOpenGLBufferObject&) VTK_DELETE_FUNCTION;
110  struct Private;
111  Private *Internal;
112 };
113 
114 template <class T>
115 inline bool vtkOpenGLBufferObject::Upload(
116  const T &array,
117  vtkOpenGLBufferObject::ObjectType objectType)
118 {
119  if (array.empty())
120  {
121  this->Error = "Refusing to upload empty array.";
122  return false;
123  }
124 
125  return this->UploadInternal(&array[0],
126  array.size() * sizeof(typename T::value_type),
127  objectType);
128 }
129 
130 template <class T>
132  const T *array, size_t numElements,
134 {
135  if (!array)
136  {
137  this->Error = "Refusing to upload empty array.";
138  return false;
139  }
140  return this->UploadInternal(array,
141  numElements * sizeof(T),
142  objectType);
143 }
144 
145 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:39
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
object to represent cell connectivity
Definition: vtkCellArray.h:50
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...
represent and manipulate 3D points
Definition: vtkPoints.h:39