1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 // File: vogl_framebuffer_capturer.h
27 #ifndef VOGL_FRAMEBUFFER_CAPTURER_H
28 #define VOGL_FRAMEBUFFER_CAPTURER_H
30 #include "vogl_common.h"
31 #include "vogl_dynamic_string.h"
33 typedef bool (*vogl_write_image_callback_func_ptr)(uint width, uint height, uint pitch, size_t size, GLenum pixel_format, GLenum pixel_type, const void *pImage, void *pOpaque, uint64_t frame_index);
35 class vogl_framebuffer_capturer
43 vogl_framebuffer_capturer();
45 ~vogl_framebuffer_capturer();
47 bool init(uint num_buffers, vogl_write_image_callback_func_ptr pWrite_func, void *pWrite_opaque, GLenum pixel_format, GLenum pixel_type);
48 void deinit(bool ok_to_make_gl_calls);
50 bool is_initialized() const
55 uint get_num_buffers() const
59 uint get_num_busy_buffers() const
61 return m_num_busy_pbos;
64 bool did_any_write_fail() const
66 return m_did_any_write_fail;
68 void clear_did_any_write_fail_flag()
70 m_did_any_write_fail = false;
75 bool capture(uint width, uint height, GLuint framebuffer = 0, GLuint read_buffer = GL_BACK, uint64_t frame_index = 0);
77 vogl::vector<GLuint> get_buffer_handles() const;
81 bool m_did_any_write_fail;
83 vogl_write_image_callback_func_ptr m_pWrite_func;
84 void *m_pWrite_opaque;
86 GLenum m_pixel_format;
92 : m_width(0), m_height(0), m_pitch(0), m_buffer(0), m_busy(false)
98 utils::zero_object(*this);
101 uint64_t m_frame_index;
113 uint m_num_busy_pbos;
114 pbo m_pbos[cMaxBufs];
119 bool flush_pbo(pbo &buf);
120 void delete_all_bufs();
121 bool recreate_buffers(uint new_width, uint new_height);
124 #endif // VOGL_FRAMEBUFFER_CAPTURER_H