1 #include "../StdAfx.h"
\r
3 #include "write_frame.h"
\r
5 #include "draw_frame.h"
\r
6 #include "frame_shader.h"
\r
8 #include "../format/pixel_format.h"
\r
9 #include "../../common/gl/utility.h"
\r
10 #include "../../common/gl/pixel_buffer_object.h"
\r
11 #include "../../common/utility/singleton_pool.h"
\r
13 #include <boost/range/algorithm.hpp>
\r
15 namespace caspar { namespace core {
\r
17 struct write_frame::implementation : boost::noncopyable
\r
19 implementation(std::vector<common::gl::pbo_ptr>&& pbos, const pixel_format_desc& desc) : pbos_(std::move(pbos)), desc_(desc){}
\r
23 boost::range::for_each(pbos_, std::mem_fn(&common::gl::pbo::begin_write));
\r
28 boost::range::for_each(pbos_, std::mem_fn(&common::gl::pbo::end_write));
\r
31 void draw(frame_shader& shader)
\r
33 for(size_t n = 0; n < pbos_.size(); ++n)
\r
35 glActiveTexture(GL_TEXTURE0+n);
\r
36 pbos_[n]->bind_texture();
\r
38 shader.render(desc_);
\r
41 boost::iterator_range<unsigned char*> pixel_data(size_t index)
\r
43 auto ptr = static_cast<unsigned char*>(pbos_[index]->data());
\r
44 return boost::iterator_range<unsigned char*>(ptr, ptr+pbos_[index]->size());
\r
46 const boost::iterator_range<const unsigned char*> pixel_data(size_t index) const
\r
48 auto ptr = static_cast<const unsigned char*>(pbos_[index]->data());
\r
49 return boost::iterator_range<const unsigned char*>(ptr, ptr+pbos_[index]->size());
\r
52 std::vector<common::gl::pbo_ptr> pbos_;
\r
53 std::vector<short> audio_data_;
\r
54 const pixel_format_desc desc_;
\r
57 write_frame::write_frame(std::vector<common::gl::pbo_ptr>&& pbos, const pixel_format_desc& desc) : impl_(common::singleton_pool<implementation>::make_shared(std::move(pbos), desc)){}
\r
58 write_frame::write_frame(write_frame&& other) : impl_(std::move(other.impl_)){}
\r
59 void write_frame::swap(write_frame& other){impl_.swap(other.impl_);}
\r
60 write_frame& write_frame::operator=(write_frame&& other)
\r
62 impl_ = std::move(other.impl_);
\r
65 void write_frame::begin_write(){impl_->begin_write();}
\r
66 void write_frame::end_write(){impl_->end_write();}
\r
67 void write_frame::draw(frame_shader& shader){impl_->draw(shader);}
\r
68 boost::iterator_range<unsigned char*> write_frame::pixel_data(size_t index){return impl_->pixel_data(index);}
\r
69 const boost::iterator_range<const unsigned char*> write_frame::pixel_data(size_t index) const {return impl_->pixel_data(index);}
\r
70 std::vector<short>& write_frame::audio_data() { return impl_->audio_data_; }
\r
71 const std::vector<short>& write_frame::audio_data() const { return impl_->audio_data_; }
\r