VTK  9.3.20240418
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 
11 VTK_ABI_NAMESPACE_BEGIN
13 class vtkWindow;
14 
16 {
17 public:
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 
32 protected:
34  bool Releasing;
35 };
36 
37 // Description:
38 // Templated member callback.
39 template <class T>
41 {
42 public:
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 
83 protected:
84  T* Handler;
85  void (T::*Method)(vtkWindow*);
86 };
87 
88 VTK_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