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 = NULL; 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;
70  }
71 
72  // Called when the event is invoked
73  virtual void Release()
74  {
75  if (this->VTKWindow && this->Handler && !this->Releasing)
76  {
77  this->Releasing = true;
78  this->VTKWindow->PushContext();
79  (this->Handler->*this->Method)(this->VTKWindow);
81  this->VTKWindow->PopContext();
82  this->VTKWindow = NULL;
83  this->Releasing = false;
84  }
85  }
86 protected:
87  T* Handler;
88  void (T::*Method)(vtkWindow *);
89 };
90 
91 #endif
92 // VTK-HeaderTest-Exclude: vtkOpenGLResourceFreeCallback.h
OpenGL rendering window.
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)=0
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's context as the current context.
vtkOpenGLResourceFreeCallback(T *handler, void(T::*method)(vtkWindow *))
virtual void RegisterGraphicsResources(vtkOpenGLRenderWindow *rw)