]> git.sesse.net Git - nageru/blobdiff - nageru/pbo_frame_allocator.h
Fix some issues with cards changing pixel format on-the-fly.
[nageru] / nageru / pbo_frame_allocator.h
index 0080dd0e97fe3ce729d37aa960895d04ffedc12e..5ea0ffee8f43f72a0abc4b0dcf3be01d8e998112 100644 (file)
@@ -36,6 +36,17 @@ public:
        Frame create_frame(size_t width, size_t height, size_t stride) override;
        void release_frame(Frame frame) override;
 
+       // NOTE: Does not check the buffer types; they are just assumed to be compatible.
+       void reconfigure(bmusb::PixelFormat pixel_format,
+                        size_t frame_size,
+                        GLuint width, GLuint height,
+                        unsigned card_index,
+                        MJPEGEncoder *mjpeg_encoder = nullptr,
+                        size_t num_queued_frames = 16,
+                        GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
+                        GLenum permissions = GL_MAP_WRITE_BIT,
+                        GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
+
        struct Userdata {
                GLuint pbo;
 
@@ -80,10 +91,12 @@ public:
                uint8_t *data_copy_malloc;
                MJPEGEncoder::VAResources va_resources;
                MJPEGEncoder::ReleaseVAResources va_resources_release;
+
+               int generation;
        };
 
 private:
-       void init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits);
+       void init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits, int generation);
        void destroy_frame(Frame *frame);
 
        unsigned card_index;
@@ -93,6 +106,14 @@ private:
        std::queue<Frame> freelist;
        GLenum buffer;
        std::unique_ptr<Userdata[]> userdata;
+
+       // Used only for reconfigure(), to check whether we can do without.
+       size_t frame_size;
+       size_t num_queued_frames;
+       GLuint width, height;
+       GLenum permissions;
+       GLenum map_bits;
+       int generation = 0;  // Under freelist_mutex.
 };
 
 #endif  // !defined(_PBO_FRAME_ALLOCATOR)