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 <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 
91  // Description:
92  // Release any graphics resources that are being consumed by this class.
93  void ReleaseGraphicsResources();
94 
98  std::string GetError() const { return Error; }
99 
100 protected:
102  ~vtkOpenGLBufferObject() override;
103  bool Dirty;
105 
106  bool UploadInternal(const void *buffer, size_t size, ObjectType objectType);
107 
108 private:
110  void operator=(const vtkOpenGLBufferObject&) = delete;
111  struct Private;
112  Private *Internal;
113 };
114 
115 template <class T>
117  const T &array,
119 {
120  if (array.empty())
121  {
122  this->Error = "Refusing to upload empty array.";
123  return false;
124  }
125 
126  return this->UploadInternal(&array[0],
127  array.size() * sizeof(typename T::value_type),
128  objectType);
129 }
130 
131 template <class T>
133  const T *array, size_t numElements,
135 {
136  if (!array)
137  {
138  this->Error = "Refusing to upload empty array.";
139  return false;
140  }
141  return this->UploadInternal(array,
142  numElements * sizeof(T),
143  objectType);
144 }
145 
146 #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