1 #include "pbo_frame_allocator.h"
6 PBOFrameAllocator::PBOFrameAllocator(size_t frame_size, size_t num_queued_frames, GLenum buffer, GLenum permissions, GLenum map_bits)
7 : frame_size(frame_size), buffer(buffer)
9 for (size_t i = 0; i < num_queued_frames; ++i) {
11 glGenBuffers(1, &pbo);
13 glBindBuffer(buffer, pbo);
15 glBufferStorage(buffer, frame_size, NULL, permissions | GL_MAP_PERSISTENT_BIT);
19 frame.data = (uint8_t *)glMapBufferRange(buffer, 0, frame_size, permissions | map_bits | GL_MAP_PERSISTENT_BIT);
20 frame.data2 = frame.data + frame_size / 2;
22 frame.size = frame_size;
23 frame.userdata = (void *)(intptr_t)pbo;
25 frame.interleaved = true;
28 glBindBuffer(buffer, 0);
32 PBOFrameAllocator::~PBOFrameAllocator()
34 while (!freelist.empty()) {
35 Frame frame = freelist.front();
37 GLuint pbo = (intptr_t)frame.userdata;
38 glBindBuffer(buffer, pbo);
40 glUnmapBuffer(buffer);
42 glBindBuffer(buffer, 0);
44 glDeleteBuffers(1, &pbo);
47 //static int sumsum = 0;
49 FrameAllocator::Frame PBOFrameAllocator::alloc_frame()
53 std::unique_lock<std::mutex> lock(freelist_mutex); // Meh.
54 if (freelist.empty()) {
55 printf("Frame overrun (no more spare PBO frames), dropping frame!\n");
57 //fprintf(stderr, "freelist has %d allocated\n", ++sumsum);
58 vf = freelist.front();
59 freelist.pop(); // Meh.
65 void PBOFrameAllocator::release_frame(Frame frame)
67 std::unique_lock<std::mutex> lock(freelist_mutex);