Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
QGlBufferManager.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef Tulip_QGLBUFFERMANAGER_H
22 #define Tulip_QGLBUFFERMANAGER_H
23 
24 #include <map>
25 
26 #include <tulip/tulipconf.h>
27 
28 #include <QtOpenGL/QGLPixelBuffer>
29 #include <QtOpenGL/QGLFramebufferObject>
30 
31 namespace tlp {
32 
33 /** \brief Class to manage QGlPixelBuffer and QGlFramebufferObject
34  * Singleton class to manager QGlPixelBuffer and QGlFramebufferObject
35  */
36 class TLP_QT_SCOPE QGlBufferManager {
37 
38 public:
39 
40  /**
41  * Return the QGlBuffer manager singleton, il singleton doesn't exist this function create it
42  */
43  static QGlBufferManager &getInst() {
44  if(!inst)
45  inst=new QGlBufferManager();
46 
47  return *inst;
48  }
49 
50  static void clearBuffers() {
51  if(!inst)
52  return;
53 
54  for(std::map<std::pair<int,int>,QGLPixelBuffer*>::iterator it=inst->widthHeightToBuffer.begin(); it!=inst->widthHeightToBuffer.end(); ++it)
55  delete (*it).second;
56 
57  for(std::map<std::pair<int,int>,QGLFramebufferObject*>::iterator it=inst->widthHeightToFramebuffer.begin(); it!=inst->widthHeightToFramebuffer.end(); ++it)
58  delete (*it).second;
59 
60  inst->widthHeightToBuffer.clear();
61  inst->bufferToWidthHeight.clear();
62  inst->widthHeightToFramebuffer.clear();
63  inst->framebufferToWidthHeight.clear();
64  }
65 
66  /**
67  * Return if QGlPixelBuffer can be used
68  */
69  bool canUsePixelBuffer() {
70  return pixelBufferWork;
71  }
72 
73  /**
74  * Return if QGlFramebufferObject can be used
75  */
76  bool canUseFramebufferObject() {
77  return framebufferObjectWork;
78  }
79 
80  /**
81  * Return a QGlPixelBuffer with given size
82  */
83  QGLPixelBuffer *getPixelBuffer(int width, int height);
84 
85  /**
86  * Return a QGLFramebufferObject with given size
87  */
88  QGLFramebufferObject *getFramebufferObject(int width, int height);
89 
90 private:
91 
92  /**
93  * empty private constructor for singleton
94  */
95  QGlBufferManager();
96 
97  static QGlBufferManager* inst;
98 
99  std::map<std::pair<int,int>,QGLPixelBuffer*> widthHeightToBuffer;
100  std::map<QGLPixelBuffer*,std::pair<int,int> > bufferToWidthHeight;
101  std::map<std::pair<int,int>,QGLFramebufferObject*> widthHeightToFramebuffer;
102  std::map<QGLFramebufferObject*,std::pair<int,int> > framebufferToWidthHeight;
103 
104  bool pixelBufferWork;
105  bool framebufferObjectWork;
106 
107 };
108 
109 }
110 
111 #endif // Tulip_QGLBUFFERMANAGER_H
112 ///@endcond