VTK  9.4.20241222
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 IsReleasing() { return this->Releasing; }
31
32protected:
35};
36
37// Description:
38// Templated member callback.
39template <class T>
41{
42public:
43 vtkOpenGLResourceFreeCallback(T* handler, void (T::*method)(vtkWindow*))
44 {
45 this->Handler = handler;
46 this->Method = method;
47 }
48
49 ~vtkOpenGLResourceFreeCallback() override = default;
50
52 {
53 if (this->VTKWindow == rw)
54 {
55 return;
56 }
57 if (this->VTKWindow)
58 {
59 this->Release();
60 }
61 this->VTKWindow = rw;
62 if (this->VTKWindow)
63 {
65 }
66 }
67
68 // Called when the event is invoked
69 void Release() override
70 {
71 if (this->VTKWindow && this->Handler && !this->Releasing)
72 {
73 this->Releasing = true;
74 this->VTKWindow->PushContext();
75 (this->Handler->*this->Method)(this->VTKWindow);
77 this->VTKWindow->PopContext();
78 this->VTKWindow = nullptr;
79 this->Releasing = false;
80 }
81 }
82
83protected:
85 void (T::*Method)(vtkWindow*);
86};
87
88VTK_ABI_NAMESPACE_END
89#endif
90// VTK-HeaderTest-Exclude: vtkOpenGLResourceFreeCallback.h
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)=0
virtual ~vtkGenericOpenGLResourceFreeCallback()=default
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