VTK  9.0.1
vtkOpenGLResourceFreeCallback.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4 
5  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 
15 #ifndef vtkOpenGLResourceFreeCallback_h
16 #define vtkOpenGLResourceFreeCallback_h
17 
18 // Description:
19 // Provide a mechanism for making sure graphics resources are
20 // freed properly.
21 
23 class vtkWindow;
24 
26 {
27 public:
29  {
30  this->VTKWindow = nullptr;
31  this->Releasing = false;
32  }
34 
35  // Called when the event is invoked
36  virtual void Release() = 0;
37 
39 
40  bool IsReleasing() { return this->Releasing; }
41 
42 protected:
44  bool Releasing;
45 };
46 
47 // Description:
48 // Templated member callback.
49 template <class T>
51 {
52 public:
53  vtkOpenGLResourceFreeCallback(T* handler, void (T::*method)(vtkWindow*))
54  {
55  this->Handler = handler;
56  this->Method = method;
57  }
58 
60 
62  {
63  if (this->VTKWindow == rw)
64  {
65  return;
66  }
67  if (this->VTKWindow)
68  {
69  this->Release();
70  }
71  this->VTKWindow = rw;
72  if (this->VTKWindow)
73  {
75  }
76  }
77 
78  // Called when the event is invoked
79  void Release() override
80  {
81  if (this->VTKWindow && this->Handler && !this->Releasing)
82  {
83  this->Releasing = true;
84  this->VTKWindow->PushContext();
85  (this->Handler->*this->Method)(this->VTKWindow);
87  this->VTKWindow->PopContext();
88  this->VTKWindow = nullptr;
89  this->Releasing = false;
90  }
91  }
92 
93 protected:
94  T* Handler;
95  void (T::*Method)(vtkWindow*);
96 };
97 
98 #endif
99 // VTK-HeaderTest-Exclude: vtkOpenGLResourceFreeCallback.h
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)=0
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 *))
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38