VTK
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  this->VTKWindow = nullptr; this->Releasing = false; }
31 
32  // Called when the event is invoked
33  virtual void Release() = 0;
34 
36 
37  bool IsReleasing() {
38  return this->Releasing; }
39 
40  protected:
42  bool Releasing;
43 };
44 
45 // Description:
46 // Templated member callback.
47 template <class T>
49 {
50 public:
51  vtkOpenGLResourceFreeCallback(T* handler, void (T::*method)(vtkWindow *))
52  {
53  this->Handler = handler;
54  this->Method = method;
55  }
56 
58 
60  if (this->VTKWindow == rw)
61  {
62  return;
63  }
64  if (this->VTKWindow)
65  {
66  this->Release();
67  }
68  this->VTKWindow = rw;
69  if (this->VTKWindow)
70  {
72  }
73  }
74 
75  // Called when the event is invoked
76  void Release() override
77  {
78  if (this->VTKWindow && this->Handler && !this->Releasing)
79  {
80  this->Releasing = true;
81  this->VTKWindow->PushContext();
82  (this->Handler->*this->Method)(this->VTKWindow);
84  this->VTKWindow->PopContext();
85  this->VTKWindow = nullptr;
86  this->Releasing = false;
87  }
88  }
89 protected:
90  T* Handler;
91  void (T::*Method)(vtkWindow *);
92 };
93 
94 #endif
95 // 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:37
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void PushContext()
Ability to push and pop this window&#39;s context as the current context.
vtkOpenGLResourceFreeCallback(T *handler, void(T::*method)(vtkWindow *))