VTK: Rendering/OpenGL2/vtkOpenGLBufferObject.h Source File

| VTK 9.3.1

vtkOpenGLBufferObject.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkOpenGLBufferObject_h
4 #define vtkOpenGLBufferObject_h
5
6 #include "vtkObject.h"
7 #include "vtkRenderingOpenGL2Module.h" // for export macro
8 #include <string> // used for std::string
9 #include <vector> // used for method args
10
11 VTK_ABI_NAMESPACE_BEGIN
12 class vtkCellArray;
13 class vtkDataArray;
14 class vtkPoints;
15
23 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
24 {
25 public:
26 static vtkOpenGLBufferObject* New();
27 vtkTypeMacro(vtkOpenGLBufferObject, vtkObject);
28 void PrintSelf(ostream& os, vtkIndent indent) override;
29
30 enum ObjectType
31 {
32 ArrayBuffer,
33 ElementArrayBuffer,
34 TextureBuffer
35 };
36
38 ObjectType GetType() const;
39
41 void SetType(ObjectType value);
42
44 int GetHandle() const;
45
47 bool IsReady() const { return this->Dirty == false; }
48
50 bool GenerateBuffer(ObjectType type);
51
61 template <class T>
62 bool Upload(const T& array, ObjectType type);
63
64 // non vector version
65 template <class T>
66 bool Upload(const T* array, size_t numElements, ObjectType type);
67
73 bool Bind();
74
78 bool Release();
79
80 // Description:
81 // Release any graphics resources that are being consumed by this class.
82 void ReleaseGraphicsResources();
83
87 std::string GetError() const { return Error; }
88
89 protected:
90 vtkOpenGLBufferObject();
91 ~vtkOpenGLBufferObject() override;
92 bool Dirty;
93 std::string Error;
94
95 bool UploadInternal(const void* buffer, size_t size, ObjectType objectType);
96
97 private:
98 vtkOpenGLBufferObject(const vtkOpenGLBufferObject&) = delete;
99 void operator=(const vtkOpenGLBufferObject&) = delete;
100 struct Private;
101 Private* Internal;
102 };
103
104 template <class T>
105 inline bool vtkOpenGLBufferObject::Upload(
106 const T& array, vtkOpenGLBufferObject::ObjectType objectType)
107 {
108 if (array.empty())
109 {
110 this->Error = "Refusing to upload empty array.";
111 return false;
112 }
113
114 return this->UploadInternal(&array[0], array.size() * sizeof(typename T::value_type), objectType);
115 }
116
117 template <class T>
118 inline bool vtkOpenGLBufferObject::Upload(
119 const T* array, size_t numElements, vtkOpenGLBufferObject::ObjectType objectType)
120 {
121 if (!array)
122 {
123 this->Error = "Refusing to upload empty array.";
124 return false;
125 }
126 return this->UploadInternal(array, numElements * sizeof(T), objectType);
127 }
128
129 VTK_ABI_NAMESPACE_END
130 #endif
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:185
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:24
vtkOpenGLBufferObject::SetType
void SetType(ObjectType value)
Set the type of the buffer object.
vtkOpenGLBufferObject::ReleaseGraphicsResources
void ReleaseGraphicsResources()
vtkOpenGLBufferObject::IsReady
bool IsReady() const
Determine if the buffer object is ready to be used.
Definition: vtkOpenGLBufferObject.h:47
vtkOpenGLBufferObject::Release
bool Release()
Release the buffer.
vtkOpenGLBufferObject::GetType
ObjectType GetType() const
Get the type of the buffer object.
vtkOpenGLBufferObject::~vtkOpenGLBufferObject
~vtkOpenGLBufferObject() override
vtkOpenGLBufferObject::Error
std::string Error
Definition: vtkOpenGLBufferObject.h:93
vtkOpenGLBufferObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkOpenGLBufferObject::Bind
bool Bind()
Bind the buffer object ready for rendering.
vtkOpenGLBufferObject::UploadInternal
bool UploadInternal(const void *buffer, size_t size, ObjectType objectType)
vtkOpenGLBufferObject::Upload
bool Upload(const T &array, ObjectType type)
Upload data to the buffer object.
Definition: vtkOpenGLBufferObject.h:105
vtkOpenGLBufferObject::GenerateBuffer
bool GenerateBuffer(ObjectType type)
Generate the opengl buffer for this Handle.
vtkOpenGLBufferObject::Dirty
bool Dirty
Definition: vtkOpenGLBufferObject.h:92
vtkOpenGLBufferObject::GetHandle
int GetHandle() const
Get the handle of the buffer object.
vtkOpenGLBufferObject::GetError
std::string GetError() const
Return a string describing errors.
Definition: vtkOpenGLBufferObject.h:87
vtkOpenGLBufferObject::vtkOpenGLBufferObject
vtkOpenGLBufferObject()
vtkOpenGLBufferObject::New
static vtkOpenGLBufferObject * New()
vtkOpenGLBufferObject::ObjectType
ObjectType
Definition: vtkOpenGLBufferObject.h:31
vtkOpenGLBufferObject::ElementArrayBuffer
@ ElementArrayBuffer
Definition: vtkOpenGLBufferObject.h:33
vtkOpenGLBufferObject::ArrayBuffer
@ ArrayBuffer
Definition: vtkOpenGLBufferObject.h:32
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:38
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkObject.h
vtkParseResult::Error
@ Error