VTK  9.7.1
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  }
23  virtual ~vtkGenericOpenGLResourceFreeCallback() = default;
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 
34 protected:
36  bool Releasing;
37 };
38 
39 // Description:
40 // Templated member callback.
41 template <class T>
43 {
44 public:
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 
85 protected:
86  T* Handler;
87  void (T::*Method)(vtkWindow*);
88 };
89 
90 VTK_ABI_NAMESPACE_END
91 #endif
92 // VTK-HeaderTest-Exclude: vtkOpenGLResourceFreeCallback.h
OpenGL rendering window.
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)=0
void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw) override
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
bool IsWindowRegistered(vtkOpenGLRenderWindow *rw)
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void PushContext()
Ability to push and pop this window's context as the current context.
vtkOpenGLResourceFreeCallback(T *handler, void(T::*method)(vtkWindow *))
~vtkOpenGLResourceFreeCallback() override=default
virtual ~vtkGenericOpenGLResourceFreeCallback()=default