VTK  9.1.0
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 "vtkObject.h"
18#include "vtkRenderingOpenGL2Module.h" // for export macro
19#include <string> // used for std::string
20#include <vector> // used for method args
21
22class vtkCellArray;
23class vtkDataArray;
24class vtkPoints;
25
33class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
34{
35public:
38 void PrintSelf(ostream& os, vtkIndent indent) override;
39
41 {
44 TextureBuffer
45 };
46
49
52
54 int GetHandle() const;
55
57 bool IsReady() const { return this->Dirty == false; }
58
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 // Description:
91 // Release any graphics resources that are being consumed by this class.
93
97 std::string GetError() const { return Error; }
98
99protected:
102 bool Dirty;
104
105 bool UploadInternal(const void* buffer, size_t size, ObjectType objectType);
106
107private:
109 void operator=(const vtkOpenGLBufferObject&) = delete;
110 struct Private;
111 Private* Internal;
112};
113
114template <class T>
116 const T& array, vtkOpenGLBufferObject::ObjectType objectType)
117{
118 if (array.empty())
119 {
120 this->Error = "Refusing to upload empty array.";
121 return false;
122 }
123
124 return this->UploadInternal(&array[0], array.size() * sizeof(typename T::value_type), objectType);
125}
126
127template <class T>
129 const T* array, size_t numElements, vtkOpenGLBufferObject::ObjectType objectType)
130{
131 if (!array)
132 {
133 this->Error = "Refusing to upload empty array.";
134 return false;
135 }
136 return this->UploadInternal(array, numElements * sizeof(T), objectType);
137}
138
139#endif
object to represent cell connectivity
Definition: vtkCellArray.h:290
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73
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.
ObjectType GetType() const
Get the type of the buffer object.
~vtkOpenGLBufferObject() override
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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 opengl buffer for this Handle.
int GetHandle() const
Get the handle of the buffer object.
static vtkOpenGLBufferObject * New()
std::string GetError() const
Return a string describing errors.
represent and manipulate 3D points
Definition: vtkPoints.h:143
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
@ size
Definition: vtkX3D.h:259
@ string
Definition: vtkX3D.h:496