]> git.sesse.net Git - casparcg/blob - core/mixer/gpu/ogl_device.h
2.0.0.2: Some restructuring. Removed gpu_frame_x and moved them into write/read-frame...
[casparcg] / core / mixer / gpu / ogl_device.h
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\r
6 *    CasparCG is free software: you can redistribute it and/or modify\r
7 *    it under the terms of the GNU General Public License as published by\r
8 *    the Free Software Foundation, either version 3 of the License, or\r
9 *    (at your option) any later version.\r
10 *\r
11 *    CasparCG is distributed in the hope that it will be useful,\r
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 *    GNU General Public License for more details.\r
15 \r
16 *    You should have received a copy of the GNU General Public License\r
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 */\r
20 #pragma once\r
21 \r
22 #include "host_buffer.h"\r
23 #include "device_buffer.h"\r
24 \r
25 #include <common/concurrency/executor.h>\r
26 #include <common/memory/safe_ptr.h>\r
27 \r
28 #include <tbb/concurrent_unordered_map.h>\r
29 #include <tbb/concurrent_queue.h>\r
30 \r
31 #include <boost/thread/future.hpp>\r
32 \r
33 #include <array>\r
34 \r
35 #include "../../dependencies\SFML-1.6\include\SFML/Window/Context.hpp"\r
36 \r
37 namespace caspar { namespace core {\r
38 \r
39 class ogl_device\r
40 {       \r
41         std::unique_ptr<sf::Context> context_;\r
42         \r
43         std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<device_buffer>>>, 4> device_pools_;\r
44         std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<host_buffer>>>, 2> host_pools_;\r
45         \r
46         unsigned int fbo_;\r
47 \r
48         executor executor_;\r
49 \r
50         ogl_device();\r
51         ~ogl_device();\r
52 \r
53         static ogl_device& get_instance()\r
54         {\r
55                 static ogl_device device;\r
56                 return device;\r
57         }\r
58         \r
59         template<typename Func>\r
60         auto do_begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
61         {                       \r
62                 return executor_.begin_invoke(std::forward<Func>(func));\r
63         }\r
64         \r
65         template<typename Func>\r
66         auto do_invoke(Func&& func) -> decltype(func())\r
67         {\r
68                 return executor_.invoke(std::forward<Func>(func));\r
69         }\r
70                 \r
71         safe_ptr<device_buffer> do_create_device_buffer(size_t width, size_t height, size_t stride);\r
72         safe_ptr<host_buffer> do_create_host_buffer(size_t size, host_buffer::usage_t usage);\r
73 public:         \r
74         \r
75         template<typename Func>\r
76         static auto begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
77         {                       \r
78                 return get_instance().do_begin_invoke(std::forward<Func>(func));\r
79         }\r
80         \r
81         template<typename Func>\r
82         static auto invoke(Func&& func) -> decltype(func())\r
83         {\r
84                 return get_instance().do_invoke(std::forward<Func>(func));\r
85         }\r
86                 \r
87         static safe_ptr<device_buffer> create_device_buffer(size_t width, size_t height, size_t stride)\r
88         {\r
89                 return get_instance().do_create_device_buffer(width, height, stride);\r
90         }\r
91 \r
92         static safe_ptr<host_buffer> create_host_buffer(size_t size, host_buffer::usage_t usage)\r
93         {\r
94                 return get_instance().do_create_host_buffer(size, usage);\r
95         }\r
96 \r
97         static std::wstring get_version();\r
98 };\r
99 \r
100 }}