Tulip  5.2.1
Large graphs analysis and drawing
QGlBufferManager.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 class QGLPixelBuffer;
29 class 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  * Return the QGlBuffer manager singleton, il singleton doesn't exist this function create it
41  */
42  static QGlBufferManager &getInst() {
43  if (!inst)
44  inst = new QGlBufferManager();
45 
46  return *inst;
47  }
48 
49  static void clearBuffers();
50 
51  /**
52  * Return if QGlPixelBuffer can be used
53  */
54  bool canUsePixelBuffer() {
55  return pixelBufferWork;
56  }
57 
58  /**
59  * Return if QGlFramebufferObject can be used
60  */
61  bool canUseFramebufferObject() {
62  return framebufferObjectWork;
63  }
64 
65  /**
66  * Return a QGlPixelBuffer with given size
67  */
68  QGLPixelBuffer *getPixelBuffer(int width, int height);
69 
70  /**
71  * Return a QGLFramebufferObject with given size
72  */
73  QGLFramebufferObject *getFramebufferObject(int width, int height);
74 
75 private:
76  /**
77  * empty private constructor for singleton
78  */
79  QGlBufferManager();
80 
81  static QGlBufferManager *inst;
82 
83  std::map<std::pair<int, int>, QGLPixelBuffer *> widthHeightToBuffer;
84  std::map<QGLPixelBuffer *, std::pair<int, int>> bufferToWidthHeight;
85  std::map<std::pair<int, int>, QGLFramebufferObject *> widthHeightToFramebuffer;
86  std::map<QGLFramebufferObject *, std::pair<int, int>> framebufferToWidthHeight;
87 
88  bool pixelBufferWork;
89  bool framebufferObjectWork;
90 };
91 } // namespace tlp
92 
93 #endif // Tulip_QGLBUFFERMANAGER_H
94 ///@endcond