]> git.sesse.net Git - casparcg/blob - core/processor/write_frame.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / core / processor / write_frame.cpp
1 #include "../StdAfx.h"\r
2 \r
3 #include "write_frame.h"\r
4 \r
5 #include "draw_frame.h"\r
6 #include "frame_shader.h"\r
7 \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
12 \r
13 #include <boost/range/algorithm.hpp>\r
14 \r
15 namespace caspar { namespace core {\r
16                                                                                                                                                                                                                                                                                                                         \r
17 struct write_frame::implementation : boost::noncopyable\r
18 {\r
19         implementation(std::vector<common::gl::pbo_ptr>&& pbos, const pixel_format_desc& desc) : pbos_(std::move(pbos)), desc_(desc){}\r
20         \r
21         void begin_write()\r
22         {\r
23                 boost::range::for_each(pbos_, std::mem_fn(&common::gl::pbo::begin_write));\r
24         }\r
25 \r
26         void end_write()\r
27         {\r
28                 boost::range::for_each(pbos_, std::mem_fn(&common::gl::pbo::end_write));\r
29         }\r
30 \r
31         void draw(frame_shader& shader)\r
32         {\r
33                 for(size_t n = 0; n < pbos_.size(); ++n)\r
34                 {\r
35                         glActiveTexture(GL_TEXTURE0+n);\r
36                         pbos_[n]->bind_texture();\r
37                 }\r
38                 shader.render(desc_);\r
39         }\r
40 \r
41         boost::iterator_range<unsigned char*> pixel_data(size_t index)\r
42         {\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
45         }\r
46         const boost::iterator_range<const unsigned char*> pixel_data(size_t index) const\r
47         {\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
50         }\r
51                         \r
52         std::vector<common::gl::pbo_ptr> pbos_;\r
53         std::vector<short> audio_data_;\r
54         const pixel_format_desc desc_;\r
55 };\r
56         \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
61 {\r
62         impl_ = std::move(other.impl_);\r
63         return *this;\r
64 }\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
72 }}