]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Switch to getting bmusb from a submodule.
[nageru] / pbo_frame_allocator.h
1 #ifndef _PBO_FRAME_ALLOCATOR 
2 #define _PBO_FRAME_ALLOCATOR 1
3
4 #include <epoxy/gl.h>
5 #include <mutex>
6 #include <queue>
7
8 #include "bmusb/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                           GLuint width, GLuint height,
19                           size_t num_queued_frames = 16,  // FIXME: should be 6
20                           GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
21                           GLenum permissions = GL_MAP_WRITE_BIT,
22                           GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
23         ~PBOFrameAllocator() override;
24         Frame alloc_frame() override;
25         void release_frame(Frame frame) override;
26
27         struct Userdata {
28                 GLuint pbo;
29                 GLuint tex_y, tex_cbcr;
30         };
31
32 private:
33         size_t frame_size;
34
35         std::mutex freelist_mutex;
36         std::queue<Frame> freelist;
37         GLenum buffer;
38         std::unique_ptr<Userdata[]> userdata;
39 };
40
41 #endif  // !defined(_PBO_FRAME_ALLOCATOR)