Debian Codegraph @

3rdparty/osgXR/src/FrameStore.h

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-only
2 // Copyright (C) 2021 James Hogan <[email protected]>
3
4 #ifndef OSGXR_FRAME_STORE
5 #define OSGXR_FRAME_STORE 1
6
7 #include "OpenXR/Session.h"
8
9 #include <osg/ref_ptr>
10 #include <OpenThreads/Mutex>
11
12 #include <vector>
13
14 namespace osg {
15 class FrameStamp;
16 }
17
18 namespace osgXR {
19
20 /**
21 * Manages concurrent frames.
22 * A FrameStore stores any concurrent OpenXR frames and allows them to be
23 * created and retrieved in a thread-safe way based on an osg::FrameStamp.
24 */
25 class FrameStore
26 {
27 public:
28
29 typedef OpenXR::Session::Frame Frame;
30 typedef const osg::FrameStamp *Stamp;
31
32 FrameStore();
33
34 /// Get a frame by FrameStamp.
35 osg::ref_ptr<Frame> getFrame(Stamp stamp);
36
37 /// Get or wait for a frame by FrameStamp.
38 osg::ref_ptr<Frame> getFrame(Stamp stamp, OpenXR::Session *session);
39
40 /**
41 * End a frame by FrameStamp.
42 * @return true on success, false otherwise.
43 */
44 bool endFrame(Stamp stamp);
45
46 /**
47 * Kill (without ending) a frame by FrameStamp.
48 * @return true on success, false otherwise.
49 */
50 bool killFrame(Stamp stamp);
51
52 /// Count the number of frames.
53 unsigned int countFrames() const;
54
55 protected:
56
57 // These return cache index or -1
58 int lookupFrame(Stamp stamp) const;
59 int blankFrame() const;
60
61 // 2 allows work to start on next frame before the prior one has ended
62 static constexpr unsigned int maxFrames = 2;
63 // Protected by _mutex
64 osg::ref_ptr<Frame> _store[maxFrames];
65
66 // For access to _store
67 OpenThreads::Mutex _mutex;
68 };
69
70 }
71
72 #endif