2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
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
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
22 #include "host_buffer.h"
\r
23 #include "device_buffer.h"
\r
25 #include <common/concurrency/executor.h>
\r
26 #include <common/memory/safe_ptr.h>
\r
28 #include <tbb/concurrent_unordered_map.h>
\r
29 #include <tbb/concurrent_queue.h>
\r
31 #include <boost/noncopyable.hpp>
\r
32 #include <boost/thread/future.hpp>
\r
35 #include <unordered_map>
\r
37 #include <gl/glew.h>
\r
39 #include "../../dependencies\SFML-1.6\include\SFML/Window/Context.hpp"
\r
41 namespace caspar { namespace core {
\r
45 class ogl_device : boost::noncopyable
\r
47 std::unordered_map<GLenum, bool> caps_;
\r
48 std::array<size_t, 4> viewport_;
\r
49 std::array<size_t, 4> scissor_;
\r
50 const GLubyte* pattern_;
\r
51 GLint attached_texture_;
\r
52 GLint active_shader_;
\r
53 std::array<GLint, 16> binded_textures_;
\r
55 std::unique_ptr<sf::Context> context_;
\r
57 std::array<tbb::concurrent_unordered_map<size_t, safe_ptr<tbb::concurrent_bounded_queue<std::shared_ptr<device_buffer>>>>, 4> device_pools_;
\r
58 std::array<tbb::concurrent_unordered_map<size_t, safe_ptr<tbb::concurrent_bounded_queue<std::shared_ptr<host_buffer>>>>, 2> host_pools_;
\r
68 // Not thread-safe, must be called inside of context
\r
69 void enable(GLenum cap);
\r
70 void disable(GLenum cap);
\r
71 void viewport(size_t x, size_t y, size_t width, size_t height);
\r
72 void scissor(size_t x, size_t y, size_t width, size_t height);
\r
73 void stipple_pattern(const GLubyte* pattern);
\r
75 void attach(device_buffer& texture);
\r
76 void clear(device_buffer& texture);
\r
78 void begin_read(host_buffer& dest, device_buffer& source);
\r
79 void begin_read(device_buffer& dest, host_buffer& source);
\r
81 void use(shader& shader);
\r
84 template<typename Func>
\r
85 auto begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future<decltype(func())> // noexcept
\r
87 return executor_.begin_invoke(std::forward<Func>(func), priority);
\r
90 template<typename Func>
\r
91 auto invoke(Func&& func, task_priority priority = normal_priority) -> decltype(func())
\r
93 return executor_.invoke(std::forward<Func>(func), priority);
\r
96 safe_ptr<device_buffer> create_device_buffer(size_t width, size_t height, size_t stride);
\r
97 safe_ptr<host_buffer> create_host_buffer(size_t size, host_buffer::usage_t usage);
\r
99 boost::unique_future<void> gc();
\r
101 static std::wstring get_version();
\r