VTK  9.4.20250130
vtkOpenGLResourceFreeCallback.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
4#ifndef vtkOpenGLResourceFreeCallback_h
5#define vtkOpenGLResourceFreeCallback_h
6
7// Description:
8// Provide a mechanism for making sure graphics resources are
9// freed properly.
10
11VTK_ABI_NAMESPACE_BEGIN
13class vtkWindow;
14
16{
17public:
19 {
20 this->VTKWindow = nullptr;
21 this->Releasing = false;
22 }
24
25 // Called when the event is invoked
26 virtual void Release() = 0;
27
29
30 bool IsWindowRegistered(vtkOpenGLRenderWindow* rw) { return (rw == this->VTKWindow); }
31
32 bool IsReleasing() { return this->Releasing; }
33
34protected:
37};
38
39// Description:
40// Templated member callback.
41template <class T>
43{
44public:
45 vtkOpenGLResourceFreeCallback(T* handler, void (T::*method)(vtkWindow*))
46 {
47 this->Handler = handler;
48 this->Method = method;
49 }
50
51 ~vtkOpenGLResourceFreeCallback() override = default;
52
54 {
55 if (this->VTKWindow == rw)
56 {
57 return;
58 }
59 if (this->VTKWindow)
60 {
61 this->Release();
62 }
63 this->VTKWindow = rw;
64 if (this->VTKWindow)
65 {
67 }
68 }
69
70 // Called when the event is invoked
71 void Release() override
72 {
73 if (this->VTKWindow && this->Handler && !this->Releasing)
74 {
75 this->Releasing = true;
76 this->VTKWindow->PushContext();
77 (this->Handler->*this->Method)(this->VTKWindow);
79 this->VTKWindow->PopContext();
80 this->VTKWindow = nullptr;
81 this->Releasing = false;
82 }
83 }
84
85protected:
87 void (T::*Method)(vtkWindow*);
88};
89
90VTK_ABI_NAMESPACE_END
91#endif
92// VTK-HeaderTest-Exclude: vtkOpenGLResourceFreeCallback.h
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)=0
virtual ~vtkGenericOpenGLResourceFreeCallback()=default
bool IsWindowRegistered(vtkOpenGLRenderWindow *rw)
OpenGL rendering window.
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void PushContext()
Ability to push and pop this window's context as the current context.
void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw) override
vtkOpenGLResourceFreeCallback(T *handler, void(T::*method)(vtkWindow *))
~vtkOpenGLResourceFreeCallback() override=default
window superclass for vtkRenderWindow
Definition vtkWindow.h:48