]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Initial checkin.
[nageru] / pbo_frame_allocator.h
1 #ifndef _PBO_FRAME_ALLOCATOR 
2 #define _PBO_FRAME_ALLOCATOR 1
3
4 #include <mutex>
5 #include <queue>
6 #include <epoxy/gl.h>
7
8 #include "bmusb.h"
9
10 // An allocator that allocates straight into OpenGL pinned memory.
11 // Meant for video frames only. We use a queue rather than a stack,
12 // since we want to maximize pipelineability.
13 class PBOFrameAllocator : public FrameAllocator {
14 public:
15         // Note: You need to have an OpenGL context when calling
16         // the constructor.
17         PBOFrameAllocator(size_t frame_size,
18                           size_t num_queued_frames = 16,  // FIXME: should be 6
19                           GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
20                           GLenum permissions = GL_MAP_WRITE_BIT,
21                           GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
22         ~PBOFrameAllocator() override;
23         Frame alloc_frame() override;
24         void release_frame(Frame frame) override;
25
26 private:
27         size_t frame_size;
28
29         std::mutex freelist_mutex;
30         std::queue<Frame> freelist;
31         GLenum buffer;
32 };
33
34 #endif  // !defined(_PBO_FRAME_ALLOCATOR)