Overte C++ Documentation
FboCache.h
1 //
2 // OffscreenGlCanvas.h
3 // interface/src/renderer
4 //
5 // Created by Bradley Austin Davis on 2014/04/09.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 #pragma once
12 #ifndef hifi_FboCache_h
13 #define hifi_FboCache_h
14 
15 #include <QOffscreenSurface>
16 #include <QQueue>
17 #include <QMap>
18 #include <QtCore/QSharedPointer>
19 #include <QMutex>
20 
21 class QOpenGLFramebufferObject;
22 
23 class FboCache : public QObject {
24 public:
25  FboCache();
26 
27  // setSize() and getReadyFbo() must consitently be called from only a single
28  // thread. Additionally, it is the caller's responsibility to ensure that
29  // the appropriate OpenGL context is active when doing so.
30 
31  // Important.... textures are sharable resources, but FBOs ARE NOT.
32  void setSize(const QSize& newSize);
33  QOpenGLFramebufferObject* getReadyFbo();
34 
35  // These operations are thread safe and require no OpenGL context. They manipulate the
36  // internal locks and pointers but execute no OpenGL opreations.
37  void lockTexture(int texture);
38  void releaseTexture(int texture);
39 
40  const QSize& getSize();
41 
42 protected:
43  QMap<int, QSharedPointer<QOpenGLFramebufferObject>> _fboMap;
44  QMap<int, int> _fboLocks;
45  QQueue<QOpenGLFramebufferObject*> _readyFboQueue;
46  QQueue<QSharedPointer<QOpenGLFramebufferObject>> _destroyFboQueue;
47  QMutex _lock;
48  QSize _size;
49 
50 };
51 
52 #endif // hifi_FboCache_h