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 
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.
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
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
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)
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:112
vtkOpenGLBufferObject::UploadInternal
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkOpenGLBufferObject::Error
std::string Error
Definition: vtkOpenGLBufferObject.h:100
vtkOpenGLBufferObject::Bind
bool Bind()
Bind the buffer object ready for rendering.
vtkgl::value
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
vtkOpenGLBufferObject::ElementArrayBuffer
@ ElementArrayBuffer
Definition: vtkOpenGLBufferObject.h:42
vtkOpenGLBufferObject::~vtkOpenGLBufferObject
~vtkOpenGLBufferObject()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkOpenGLBufferObject::Release
bool Release()
Release the buffer.
vtkOpenGLBufferObject::Dirty
bool Dirty
Definition: vtkOpenGLBufferObject.h:99
vtkOpenGLBufferObject::GetError
std::string GetError() const
Return a string describing errors.
Definition: vtkOpenGLBufferObject.h:94
vtkObject.h
vtkOpenGLBufferObject::GetHandle
int GetHandle() const
Get the handle of the buffer object.
vtkOpenGLBufferObject::vtkOpenGLBufferObject
vtkOpenGLBufferObject()
vtkgl::buffer
GLuint buffer
Definition: vtkgl.h:11839
vtkOpenGLBufferObject::GetType
ObjectType GetType() const
Get the type of the buffer object.
vtkOpenGLBufferObject::ArrayBuffer
@ ArrayBuffer
Definition: vtkOpenGLBufferObject.h:41
vtkgl::type
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
vtkOpenGLBufferObject::SetType
void SetType(ObjectType value)
Set the type of the buffer object.
vtkgl::string
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
vtkgl::size
GLsizeiptr size
Definition: vtkgl.h:11843
vtkOpenGLBufferObject::ObjectType
ObjectType
Definition: vtkOpenGLBufferObject.h:40