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 
67  template <class T>
68  bool Upload(const T &array, ObjectType type);
69 
70  // non vector version
71  template <class T>
72  bool Upload(const T *array, size_t numElements, ObjectType type);
73 
79  bool Bind();
80 
84  bool Release();
85 
86 
87  // Description:
88  // Release any graphics resources that are being consumed by this class.
89  void ReleaseGraphicsResources();
90 
94  std::string GetError() const { return Error; }
95 
96 protected:
99  bool Dirty;
101 
102  bool UploadInternal(const void *buffer, size_t size, ObjectType objectType);
103 
104 private:
105  vtkOpenGLBufferObject(const vtkOpenGLBufferObject&); // Not implemented
106  void operator=(const vtkOpenGLBufferObject&); // Not implemented
107  struct Private;
108  Private *Internal;
109 };
110 
111 template <class T>
113  const T &array,
115 {
116  if (array.empty())
117  {
118  this->Error = "Refusing to upload empty array.";
119  return false;
120  }
121 
122  return this->UploadInternal(&array[0],
123  array.size() * sizeof(typename T::value_type),
124  objectType);
125 }
126 
127 template <class T>
129  const T *array, size_t numElements,
131 {
132  if (!array)
133  {
134  this->Error = "Refusing to upload empty array.";
135  return false;
136  }
137  return this->UploadInternal(array,
138  numElements * sizeof(T),
139  objectType);
140 }
141 
142 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:61
std::string GetError() const
Return a string describing errors.
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
object to represent cell connectivity
Definition: vtkCellArray.h:49
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()
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
represent and manipulate 3D points
Definition: vtkPoints.h:38