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:
37  void PrintSelf(ostream& os, vtkIndent indent);
38 
40  {
43  TextureBuffer
44  };
45 
48 
51 
53  int GetHandle() const;
54 
56  bool IsReady() const { return this->Dirty == false; }
57 
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.
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>
116  const T &array,
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
object to represent cell connectivity
Definition: vtkCellArray.h:51
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
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.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
ObjectType GetType() const
Get the type of the buffer object.
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 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:40
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ size
Definition: vtkX3D.h:253
@ string
Definition: vtkX3D.h:490