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
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:40
vtkOpenGLBufferObject::IsReady
bool IsReady() const
Determine if the buffer object is ready to be used.
Definition: vtkOpenGLBufferObject.h:56
vtkOpenGLBufferObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkOpenGLBufferObject::New
static vtkOpenGLBufferObject * New()
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkOpenGLBufferObject::ReleaseGraphicsResources
void ReleaseGraphicsResources()
vtkOpenGLBufferObject::Upload
bool Upload(const T &array, ObjectType type)
Upload data to the buffer object.
Definition: vtkOpenGLBufferObject.h:115
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkOpenGLBufferObject::UploadInternal
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkOpenGLBufferObject::Error
std::string Error
Definition: vtkOpenGLBufferObject.h:103
vtkOpenGLBufferObject::GenerateBuffer
bool GenerateBuffer(ObjectType type)
Generate the the opengl buffer for this Handle.
vtkOpenGLBufferObject::Bind
bool Bind()
Bind the buffer object ready for rendering.
vtkOpenGLBufferObject::ElementArrayBuffer
@ ElementArrayBuffer
Definition: vtkOpenGLBufferObject.h:42
vtkOpenGLBufferObject::~vtkOpenGLBufferObject
~vtkOpenGLBufferObject()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:51
vtkOpenGLBufferObject::Release
bool Release()
Release the buffer.
vtkOpenGLBufferObject::Dirty
bool Dirty
Definition: vtkOpenGLBufferObject.h:102
vtkOpenGLBufferObject::GetError
std::string GetError() const
Return a string describing errors.
Definition: vtkOpenGLBufferObject.h:97
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkObject.h
vtkOpenGLBufferObject::GetHandle
int GetHandle() const
Get the handle of the buffer object.
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkOpenGLBufferObject::vtkOpenGLBufferObject
vtkOpenGLBufferObject()
vtkOpenGLBufferObject::GetType
ObjectType GetType() const
Get the type of the buffer object.
vtkOpenGLBufferObject::ArrayBuffer
@ ArrayBuffer
Definition: vtkOpenGLBufferObject.h:41
vtkOpenGLBufferObject::SetType
void SetType(ObjectType value)
Set the type of the buffer object.
vtkOpenGLBufferObject::ObjectType
ObjectType
Definition: vtkOpenGLBufferObject.h:40