]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 26 Dec 2010 22:20:29 +0000 (22:20 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 26 Dec 2010 22:20:29 +0000 (22:20 +0000)
22 files changed:
core/consumer/ogl/ogl_consumer.cpp
core/core.vcxproj
core/core.vcxproj.filters
core/processor/buffer/read_buffer.cpp [deleted file]
core/processor/buffer/write_buffer.cpp [deleted file]
core/processor/buffer/write_buffer.h [deleted file]
core/processor/device_buffer.cpp [new file with mode: 0644]
core/processor/device_buffer.h [new file with mode: 0644]
core/processor/draw_frame.cpp
core/processor/draw_frame.h
core/processor/frame_processor_device.cpp
core/processor/gpu_frame.h [deleted file]
core/processor/host_buffer.cpp [new file with mode: 0644]
core/processor/host_buffer.h [moved from core/processor/buffer/read_buffer.h with 59% similarity]
core/processor/image_kernel.cpp [new file with mode: 0644]
core/processor/image_kernel.h [new file with mode: 0644]
core/processor/image_processor.cpp
core/processor/image_processor.h
core/processor/read_frame.cpp
core/processor/read_frame.h
core/processor/write_frame.cpp
core/processor/write_frame.h

index d6921a238eb539056fa2f440eac239b7c63992c1..1f8c102a36b9b55a2042e2a5410fa1fb04132c7c 100644 (file)
@@ -24,9 +24,8 @@
 \r
 #include "../../format/video_format.h"\r
 \r
-#include "../../../common/gl/utility.h"\r
-#include "../../../common/gl/pixel_buffer_object.h"\r
-#include "../../../common/concurrency/executor.h"\r
+#include <common/gl/utility.h>\r
+#include <common/concurrency/executor.h>\r
 \r
 #include <boost/thread.hpp>\r
 \r
@@ -42,7 +41,7 @@ namespace caspar { namespace core { namespace ogl{
 struct consumer::implementation : boost::noncopyable\r
 {      \r
        implementation(const video_format_desc& format_desc, unsigned int screen_index, stretch stretch, bool windowed) \r
-               : format_desc_(format_desc), stretch_(stretch), screen_width_(0), screen_height_(0), windowed_(windowed)\r
+               : format_desc_(format_desc), stretch_(stretch), screen_width_(0), screen_height_(0), windowed_(windowed), texture_(0)\r
        {               \r
 #ifdef _WIN32\r
                DISPLAY_DEVICE d_device;                        \r
@@ -110,9 +109,23 @@ struct consumer::implementation : boost::noncopyable
 \r
                        wSize_ = target_ratio.first;\r
                        hSize_ = target_ratio.second;\r
-                                       \r
-                       pbos_[0].create(format_desc_.width, format_desc_.height);\r
-                       pbos_[1].create(format_desc_.width, format_desc_.height);\r
+                       \r
+                       glGenTextures(1, &texture_);\r
+                       glBindTexture(GL_TEXTURE_2D, texture_);\r
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);\r
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);\r
+                       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, format_desc_.width, format_desc_.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);\r
+                       glBindTexture(GL_TEXTURE_2D, 0);\r
+                       \r
+                       GL(glGenBuffers(2, pbos_.data()));\r
+                       \r
+                       glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[0]);\r
+                       glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW_ARB);\r
+                       glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbos_[1]);\r
+                       glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, format_desc_.size, 0, GL_STREAM_DRAW_ARB);\r
+                       glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);\r
                });\r
        }\r
        \r
@@ -151,20 +164,34 @@ struct consumer::implementation : boost::noncopyable
        }\r
 \r
        void render(const safe_ptr<const read_frame>& frame)\r
-       {                                               \r
-               auto ptr = pbos_.front().map_write();\r
-               std::copy_n(frame->image_data().begin(), frame->image_data().size(), reinterpret_cast<char*>(ptr));\r
+       {                       \r
+               glBindTexture(GL_TEXTURE_2D, texture_);\r
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[0]);\r
 \r
-               GL(glClear(GL_COLOR_BUFFER_BIT));       \r
-               pbos_.back().bind_texture();                            \r
+               glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, format_desc_.width, format_desc_.height, GL_BGRA, GL_UNSIGNED_BYTE, 0);\r
+\r
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbos_[1]);\r
+\r
+               glBufferData(GL_PIXEL_UNPACK_BUFFER, format_desc_.size, 0, GL_STREAM_DRAW);\r
+\r
+               auto ptr = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);\r
+               if(ptr)\r
+               {\r
+                       std::copy_n(frame->image_data().begin(), frame->image_data().size(), reinterpret_cast<char*>(ptr));\r
+                       glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release the mapped buffer\r
+               }\r
+\r
+               glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);\r
+                               \r
+               GL(glClear(GL_COLOR_BUFFER_BIT));                       \r
                glBegin(GL_QUADS);\r
                                glTexCoord2f(0.0f,        hratio_);     glVertex2f(-wSize_, -hSize_);\r
                                glTexCoord2f(wratio_, hratio_); glVertex2f( wSize_, -hSize_);\r
                                glTexCoord2f(wratio_, 0.0f);    glVertex2f( wSize_,  hSize_);\r
                                glTexCoord2f(0.0f,        0.0f);        glVertex2f(-wSize_,  hSize_);\r
                glEnd();\r
-\r
-               pbos_.back().unmap_write();\r
+               \r
+               glBindTexture(GL_TEXTURE_2D, 0);\r
 \r
                std::rotate(pbos_.begin(), pbos_.begin() + 1, pbos_.end());\r
        }\r
@@ -201,7 +228,8 @@ struct consumer::implementation : boost::noncopyable
        float wSize_;\r
        float hSize_;\r
 \r
-       std::array<gl::pixel_buffer_object, 2> pbos_;\r
+       GLuint                            texture_;\r
+       std::array<GLuint, 2> pbos_;\r
 \r
        bool windowed_;\r
        unsigned int screen_width_;\r
@@ -210,7 +238,7 @@ struct consumer::implementation : boost::noncopyable
        unsigned int screen_y_;\r
                                \r
        stretch stretch_;\r
-       video_format_desc format_desc_;\r
+       const video_format_desc format_desc_;\r
        \r
        sf::Window window_;\r
 };\r
index 82555f391de2b0efd075fe300db8a9bca6db7c27..9f1a8c8e31a8af17ea652d02102b8b833045271c 100644 (file)
     <ClInclude Include="format\pixel_format.h" />\r
     <ClInclude Include="format\video_format.h" />\r
     <ClInclude Include="processor\audio_processor.h" />\r
-    <ClInclude Include="processor\buffer\read_buffer.h" />\r
-    <ClInclude Include="processor\buffer\write_buffer.h" />\r
+    <ClInclude Include="processor\device_buffer.h" />\r
     <ClInclude Include="processor\frame_processor_device.h" />\r
+    <ClInclude Include="processor\host_buffer.h" />\r
+    <ClInclude Include="processor\image_kernel.h" />\r
     <ClInclude Include="processor\image_processor.h" />\r
     <ClInclude Include="processor\fwd.h" />\r
     <ClInclude Include="processor\read_frame.h" />\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
-    <ClCompile Include="processor\buffer\read_buffer.cpp">\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-    </ClCompile>\r
-    <ClCompile Include="processor\buffer\write_buffer.cpp">\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    <ClCompile Include="processor\device_buffer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
     <ClCompile Include="processor\frame_processor_device.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
+    <ClCompile Include="processor\host_buffer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="processor\image_kernel.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
     <ClCompile Include="processor\image_processor.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
index aeef32c43bd2092e56dd0e2de8d8a4604382a38d..4dc66af1e34f95bf9baf23ce0e1e4cae81861a4a 100644 (file)
@@ -88,9 +88,6 @@
     <Filter Include="Source\channel\processor\audio">\r
       <UniqueIdentifier>{e3d8bd98-8cb9-4f4a-8cf0-bd455ce9138d}</UniqueIdentifier>\r
     </Filter>\r
-    <Filter Include="Source\channel\processor\buffer">\r
-      <UniqueIdentifier>{d6518ab7-eb0c-4cbe-b83c-a9e32c062b6f}</UniqueIdentifier>\r
-    </Filter>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="StdAfx.h">\r
     <ClInclude Include="processor\draw_frame.h">\r
       <Filter>Source\channel\processor\frame</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="processor\buffer\write_buffer.h">\r
-      <Filter>Source\channel\processor\buffer</Filter>\r
+    <ClInclude Include="processor\image_kernel.h">\r
+      <Filter>Source\channel\processor\image</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="processor\buffer\read_buffer.h">\r
-      <Filter>Source\channel\processor\buffer</Filter>\r
+    <ClInclude Include="processor\device_buffer.h">\r
+      <Filter>Source\channel\processor\image</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="processor\host_buffer.h">\r
+      <Filter>Source\channel\processor\image</Filter>\r
     </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="processor\draw_frame.cpp">\r
       <Filter>Source\channel\processor\frame</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="processor\buffer\read_buffer.cpp">\r
-      <Filter>Source\channel\processor\buffer</Filter>\r
+    <ClCompile Include="processor\image_kernel.cpp">\r
+      <Filter>Source\channel\processor\image</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="processor\device_buffer.cpp">\r
+      <Filter>Source\channel\processor\image</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="processor\buffer\write_buffer.cpp">\r
-      <Filter>Source\channel\processor\buffer</Filter>\r
+    <ClCompile Include="processor\host_buffer.cpp">\r
+      <Filter>Source\channel\processor\image</Filter>\r
     </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
diff --git a/core/processor/buffer/read_buffer.cpp b/core/processor/buffer/read_buffer.cpp
deleted file mode 100644 (file)
index c9c9451..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#include "../../StdAfx.h"\r
-\r
-#include "read_buffer.h"\r
-\r
-#include <common/gl/utility.h>\r
-\r
-namespace caspar { namespace core {\r
-                                                                                                                                                                                                                                                                                                                       \r
-struct read_buffer::implementation : boost::noncopyable\r
-{\r
-       implementation(size_t width, size_t height) : width_(width), height_(height), size_(width*height*4), data_(nullptr), pbo_(0)\r
-       {\r
-               GL(glGenBuffers(1, &pbo_));\r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_));\r
-               GL(glBufferData(GL_PIXEL_PACK_BUFFER, size_, NULL, GL_STREAM_READ));    \r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));\r
-\r
-               if(!pbo_)\r
-                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
-               CASPAR_LOG(trace) << "[read_buffer] Allocated.";\r
-       }       \r
-\r
-       ~implementation()\r
-       {\r
-               glDeleteBuffers(1, &pbo_);\r
-       }\r
-\r
-       void map()\r
-       {\r
-               if(data_)\r
-                       return;\r
-\r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_));\r
-               data_ = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);   \r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));\r
-               if(!data_)\r
-                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map GL_PIXEL_PACK_BUFFER OpenGL Pixel Buffer Object."));\r
-       }\r
-\r
-       void unmap()\r
-       {\r
-               if(!data_)\r
-                       return;\r
-\r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_));\r
-               GL(glUnmapBuffer(GL_PIXEL_PACK_BUFFER));        \r
-               data_ = nullptr;\r
-               GL(glBufferData(GL_PIXEL_PACK_BUFFER, size_, NULL, GL_STREAM_READ));    \r
-               GL(glReadPixels(0, 0, width_, height_, GL_BGRA, GL_UNSIGNED_BYTE, NULL));\r
-               GL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));\r
-       }\r
-       \r
-       GLuint pbo_;\r
-\r
-       const size_t size_;\r
-       const size_t width_;\r
-       const size_t height_;\r
-\r
-       void* data_;\r
-       std::vector<short> audio_data_;\r
-};\r
-\r
-read_buffer::read_buffer(size_t width, size_t height) : impl_(new implementation(width, height)){}\r
-const void* read_buffer::data() const {return impl_->data_;}\r
-void read_buffer::map(){impl_->map();}\r
-void read_buffer::unmap(){impl_->unmap();}\r
-size_t read_buffer::size() const { return impl_->size_; }\r
-size_t read_buffer::width() const { return impl_->width_; }\r
-size_t read_buffer::height() const { return impl_->height_; }\r
-\r
-}}
\ No newline at end of file
diff --git a/core/processor/buffer/write_buffer.cpp b/core/processor/buffer/write_buffer.cpp
deleted file mode 100644 (file)
index 1f3da81..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "../../StdAfx.h"\r
-\r
-#include "write_buffer.h"\r
-\r
-#include <common/exception/exceptions.h>\r
-#include <common/gl/utility.h>\r
-\r
-namespace caspar { namespace core {\r
-\r
-GLenum FORMAT[] = {0, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGR, GL_BGRA};\r
-GLenum INTERNAL_FORMAT[] = {0, GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8};                        \r
-\r
-struct write_buffer::implementation : boost::noncopyable\r
-{\r
-       implementation(size_t width, size_t height, size_t depth) : width_(width), height_(height), size_(width*height*depth), pbo_(0), format_(FORMAT[depth]), data_(nullptr), texture_(0)\r
-       {\r
-               GL(glGenBuffers(1, &pbo_));\r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_));\r
-               GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, size_, NULL, GL_STREAM_DRAW));\r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));\r
-               \r
-               if(!pbo_)\r
-                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
-\r
-               GL(glGenTextures(1, &texture_));\r
-               GL(glBindTexture(GL_TEXTURE_2D, texture_));\r
-               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));\r
-               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));\r
-               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));\r
-               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));\r
-               GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[depth], width_, height_, 0, format_, GL_UNSIGNED_BYTE, NULL));\r
-               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
-                               \r
-               if(!texture_)\r
-                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate texture."));\r
-\r
-               CASPAR_LOG(trace) << "[write_buffer] Allocated.";\r
-       }\r
-\r
-       ~implementation()\r
-       {\r
-               glDeleteBuffers(1, &pbo_);\r
-               glDeleteTextures(1, &texture_);\r
-       }       \r
-               \r
-       void unmap()\r
-       {\r
-               if(!data_)\r
-                       return;\r
-\r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_));\r
-\r
-               GL(glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER));\r
-               data_ = nullptr;\r
-\r
-               GL(glBindTexture(GL_TEXTURE_2D, texture_));\r
-               GL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, format_, GL_UNSIGNED_BYTE, NULL));\r
-\r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));\r
-       }\r
-\r
-       void map()\r
-       {\r
-               if(data_)\r
-                       return;\r
-               \r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_));\r
-\r
-               GL(glBufferData(GL_PIXEL_UNPACK_BUFFER, size_, NULL, GL_STREAM_DRAW));\r
-               data_= glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);\r
-\r
-               GL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));\r
-\r
-               if(!data_)\r
-                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("glMapBuffer failed"));\r
-       }\r
-                               \r
-       GLuint pbo_;\r
-       GLuint texture_;\r
-\r
-       const size_t width_;\r
-       const size_t height_;\r
-       const size_t size_;\r
-       \r
-       GLenum format_;\r
-       void* data_;\r
-};\r
-\r
-write_buffer::write_buffer(write_buffer&& other) : impl_(std::move(other.impl_)){}\r
-write_buffer::write_buffer(size_t width, size_t height, size_t depth) : impl_(new implementation(width, height, depth)){}\r
-write_buffer& write_buffer::operator=(write_buffer&& other)\r
-{\r
-       impl_ = std::move(other.impl_);\r
-       return *this;\r
-}\r
-void* write_buffer::data(){return impl_->data_;}\r
-void write_buffer::unmap() { impl_->unmap();}\r
-void write_buffer::map() {impl_->map();} \r
-size_t write_buffer::size() const {return impl_->size_;}\r
-size_t write_buffer::width() const {return impl_->width_;}\r
-size_t write_buffer::height() const {return impl_->height_;}\r
-}}
\ No newline at end of file
diff --git a/core/processor/buffer/write_buffer.h b/core/processor/buffer/write_buffer.h
deleted file mode 100644 (file)
index aed7c10..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once\r
-\r
-#include <memory>\r
-\r
-#include <boost/noncopyable.hpp>\r
-\r
-#include <Glee.h>\r
-\r
-#include <boost/tuple/tuple.hpp>\r
-#include <boost/thread/future.hpp>\r
-\r
-namespace caspar { namespace core {\r
-       \r
-class write_buffer : boost::noncopyable\r
-{\r
-       friend class image_processor;\r
-public:\r
-\r
-       write_buffer(write_buffer&& other);\r
-       write_buffer(size_t width, size_t height, size_t depth);\r
-       write_buffer& operator=(write_buffer&& other);\r
-       \r
-       void* data();\r
-       size_t size() const;\r
-       size_t width() const;\r
-       size_t height() const;\r
-                               \r
-       void map();\r
-       void unmap();\r
-\r
-private:\r
-       struct implementation;\r
-       std::shared_ptr<implementation> impl_;\r
-};\r
-}}
\ No newline at end of file
diff --git a/core/processor/device_buffer.cpp b/core/processor/device_buffer.cpp
new file mode 100644 (file)
index 0000000..83222a5
--- /dev/null
@@ -0,0 +1,84 @@
+#include "../StdAfx.h"\r
+\r
+#include "device_buffer.h"\r
+\r
+#include <common/gl/utility.h>\r
+\r
+namespace caspar { namespace core {\r
+       \r
+GLenum FORMAT[] = {0, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGR, GL_BGRA};\r
+GLenum INTERNAL_FORMAT[] = {0, GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8};        \r
+\r
+struct device_buffer::implementation : boost::noncopyable\r
+{\r
+       implementation(size_t width, size_t height, size_t stride) : width_(width), height_(height), stride_(stride)\r
+       {       \r
+               GL(glGenTextures(1, &id_));\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));\r
+               GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[stride_], width_, height_, 0, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));    \r
+       }       \r
+\r
+       ~implementation()\r
+       {\r
+               glDeleteTextures(1, &id_);\r
+       }\r
+       \r
+       void bind()\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+       }\r
+\r
+       void unbind()\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+\r
+       void read(host_buffer& source)\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               source.unmap();\r
+               source.bind();\r
+               GL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               source.unbind();\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+       \r
+       void write(host_buffer& target)\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               target.unmap();\r
+               target.bind();\r
+               GL(glReadPixels(0, 0, width_, height_, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               target.unbind();\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+\r
+       void attach(int index)\r
+       {\r
+               GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT + index, GL_TEXTURE_2D, id_, 0));\r
+       }\r
+\r
+       GLuint id_;\r
+\r
+       const size_t width_;\r
+       const size_t height_;\r
+       const size_t stride_;\r
+};\r
+\r
+device_buffer::device_buffer(size_t width, size_t height, size_t stride) : impl_(new implementation(width, height, stride)){}\r
+size_t device_buffer::stride() const { return impl_->stride_; }\r
+size_t device_buffer::width() const { return impl_->width_; }\r
+size_t device_buffer::height() const { return impl_->height_; }\r
+void device_buffer::attach(int index){impl_->attach(index);}\r
+void device_buffer::bind(){impl_->bind();}\r
+void device_buffer::unbind(){impl_->unbind();}\r
+void device_buffer::read(host_buffer& source){impl_->read(source);}\r
+void device_buffer::write(host_buffer& target){impl_->write(target);}\r
+GLuint device_buffer::id() const { return impl_->id_; }\r
+\r
+}}
\ No newline at end of file
diff --git a/core/processor/device_buffer.h b/core/processor/device_buffer.h
new file mode 100644 (file)
index 0000000..e433a29
--- /dev/null
@@ -0,0 +1,34 @@
+#pragma once\r
+\r
+#include "host_buffer.h"\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+#include <memory>\r
+\r
+namespace caspar { namespace core {\r
+       \r
+class device_buffer \r
+{\r
+public:\r
+       device_buffer(size_t width, size_t height, size_t stride);\r
+       \r
+       size_t stride() const;  \r
+       size_t width() const;\r
+       size_t height() const;\r
+               \r
+       void bind();\r
+       void unbind();\r
+\r
+       void attach(int index);\r
+       void read(host_buffer& source);\r
+       void write(host_buffer& target);\r
+\r
+       GLuint id() const;\r
+\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
index 6dc511efbb37f871513a5b47e4bb749c23a5e212..b1e4705170ac53c14ab3ec295d4f0b1adbee2f80 100644 (file)
@@ -2,19 +2,14 @@
 \r
 #include "draw_frame.h"\r
 \r
-#include "draw_frame.h"\r
 #include "image_processor.h"\r
 #include "audio_processor.h"\r
 \r
 #include "../format/pixel_format.h"\r
-#include "../../common/gl/utility.h"\r
-#include "../../common/gl/pixel_buffer_object.h"\r
 #include "../../common/utility/singleton_pool.h"\r
 \r
 #include <boost/range/algorithm.hpp>\r
 \r
-#include <tbb/parallel_for.h>\r
-\r
 namespace caspar { namespace core {\r
                                                                                                                                                                                                                                                                                                                \r
 struct draw_frame::implementation\r
index 75236ca62dcb14ab533c08093fd8178618081da7..66baf2a4fcd40708096e534fd016b2711ece43c9 100644 (file)
@@ -19,7 +19,8 @@ namespace caspar { namespace core {
 class draw_frame\r
 {\r
 public:\r
-       draw_frame();\r
+       draw_frame();   \r
+       draw_frame(safe_ptr<write_frame>&& image, std::vector<short>&& audio);\r
        draw_frame(const safe_ptr<draw_frame>& frame);\r
        draw_frame(safe_ptr<draw_frame>&& frame);\r
        draw_frame(const std::vector<safe_ptr<draw_frame>>& frames);\r
index 0be02648af25f5558c35b52f4eb8ba90fe7e3f54..2b9d41f51eff9edbe5eeb7d365eecc45493353a9 100644 (file)
@@ -65,7 +65,7 @@ struct frame_processor_device::implementation : boost::noncopyable
        audio_processor audio_processor_;\r
        image_processor image_processor_;\r
 \r
-       std::queue<boost::unique_future<safe_ptr<const read_buffer>>> image_buffer_;\r
+       std::queue<boost::unique_future<safe_ptr<const host_buffer>>> image_buffer_;\r
        std::queue<std::vector<short>> audio_buffer_;\r
                                                                                \r
        const video_format_desc fmt_;\r
diff --git a/core/processor/gpu_frame.h b/core/processor/gpu_frame.h
deleted file mode 100644 (file)
index 39a01bf..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once\r
-\r
-#include "fwd.h"\r
-\r
-#include "../../common/exception/exceptions.h"\r
-\r
-#include <boost/noncopyable.hpp>\r
-\r
-#include <memory>\r
-#include <vector>\r
-\r
-namespace caspar { namespace core {\r
-               \r
-class gpu_frame : boost::noncopyable\r
-{      \r
-public:\r
-       virtual const std::vector<short>& audio_data() const = 0;\r
-       virtual std::vector<short>& audio_data() = 0;\r
-       \r
-       virtual void begin_write() = 0;\r
-       virtual void end_write() = 0;\r
-       virtual void draw(frame_shader& shader) = 0;\r
-};\r
-typedef std::shared_ptr<gpu_frame> gpu_frame_ptr;\r
-\r
-\r
-}}
\ No newline at end of file
diff --git a/core/processor/host_buffer.cpp b/core/processor/host_buffer.cpp
new file mode 100644 (file)
index 0000000..af6ef9f
--- /dev/null
@@ -0,0 +1,81 @@
+#include "../StdAfx.h"\r
+\r
+#include "host_buffer.h"\r
+\r
+#include <common/gl/utility.h>\r
+\r
+namespace caspar { namespace core {\r
+                                                                                                                                                                                                                                                                                                                       \r
+struct host_buffer::implementation : boost::noncopyable\r
+{\r
+       implementation(size_t size, usage_t usage) : size_(size), data_(nullptr), pbo_(0),\r
+               target_(usage == write_only ? GL_PIXEL_UNPACK_BUFFER : GL_PIXEL_PACK_BUFFER), usage_(usage == write_only ? GL_STREAM_DRAW : GL_STREAM_READ)\r
+       {\r
+               GL(glGenBuffers(1, &pbo_));\r
+               GL(glBindBuffer(target_, pbo_));\r
+               GL(glBufferData(target_, size_, NULL, usage_)); \r
+               GL(glBindBuffer(target_, 0));\r
+\r
+               if(!pbo_)\r
+                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
+               CASPAR_LOG(trace) << "[host_buffer] Allocated.";\r
+       }       \r
+\r
+       ~implementation()\r
+       {\r
+               glDeleteBuffers(1, &pbo_);\r
+       }\r
+\r
+       void map()\r
+       {\r
+               if(data_)\r
+                       return;\r
+               \r
+               GL(glBindBuffer(target_, pbo_));\r
+               data_ = glMapBuffer(target_, usage_ == GL_STREAM_DRAW ? GL_WRITE_ONLY : GL_READ_ONLY);  \r
+               GL(glBindBuffer(target_, 0)); \r
+               if(!data_)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map target_ OpenGL Pixel Buffer Object."));\r
+       }\r
+\r
+       void unmap()\r
+       {\r
+               if(!data_)\r
+                       return;\r
+               \r
+               GL(glBindBuffer(target_, pbo_));\r
+               GL(glUnmapBuffer(target_));     \r
+               data_ = nullptr;                \r
+               GL(glBindBuffer(target_, 0));\r
+       }\r
+\r
+       void bind()\r
+       {\r
+               GL(glBindBuffer(target_, pbo_));\r
+       }\r
+\r
+       void unbind()\r
+       {\r
+               GL(glBindBuffer(target_, 0));\r
+       }\r
+       \r
+       GLuint pbo_;\r
+\r
+       const size_t size_;\r
+\r
+       void* data_;\r
+       GLenum usage_;\r
+       GLenum target_;\r
+};\r
+\r
+host_buffer::host_buffer(size_t size, usage_t usage) : impl_(new implementation(size, usage)){}\r
+const void* host_buffer::data() const {return impl_->data_;}\r
+void* host_buffer::data() {return impl_->data_;}\r
+void host_buffer::map(){impl_->map();}\r
+void host_buffer::unmap(){impl_->unmap();}\r
+void host_buffer::bind(){impl_->bind();}\r
+void host_buffer::unbind(){impl_->unbind();}\r
+\r
+size_t host_buffer::size() const { return impl_->size_; }\r
+\r
+}}
\ No newline at end of file
similarity index 59%
rename from core/processor/buffer/read_buffer.h
rename to core/processor/host_buffer.h
index e2bbe90562a667c4a262ca3016fd928de4433b3d..1b434b511f9673ab2c56195f528f748b6dd2d7c7 100644 (file)
@@ -5,18 +5,23 @@
 #include <memory>\r
 \r
 namespace caspar { namespace core {\r
-       \r
-class read_buffer \r
+               \r
+class host_buffer \r
 {\r
-       friend class image_processor;\r
 public:\r
-       read_buffer(size_t width, size_t height);\r
+       enum usage_t\r
+       {\r
+               write_only,\r
+               read_only\r
+       };\r
+       host_buffer(size_t size, usage_t usage);\r
        \r
        const void* data() const;\r
+       void* data();\r
        size_t size() const;    \r
-       size_t width() const;\r
-       size_t height() const;\r
-               \r
+       \r
+       void bind();\r
+       void unbind();\r
        void unmap();\r
        void map();\r
 private:\r
diff --git a/core/processor/image_kernel.cpp b/core/processor/image_kernel.cpp
new file mode 100644 (file)
index 0000000..720c57c
--- /dev/null
@@ -0,0 +1,237 @@
+#include "../StdAfx.h"\r
+\r
+#include "image_kernel.h"\r
+\r
+#include <common/exception/exceptions.h>\r
+#include <common/gl/utility.h>\r
+\r
+#include <Glee.h>\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+#include <unordered_map>\r
+\r
+namespace caspar { namespace core {\r
+\r
+class shader_program\r
+{\r
+public:\r
+\r
+       shader_program() : program_(0) {}\r
+       shader_program(const std::string& vertex_source_str, const std::string& fragment_source_str) : program_(0)\r
+       {\r
+               GLint success;\r
+       \r
+               const char* vertex_source = vertex_source_str.c_str();\r
+                                               \r
+               auto vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);\r
+                                       \r
+               GL(glShaderSourceARB(vertex_shader, 1, &vertex_source, NULL));\r
+               GL(glCompileShaderARB(vertex_shader));\r
+\r
+               GL(glGetObjectParameterivARB(vertex_shader, GL_OBJECT_COMPILE_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(vertex_shader, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(vertex_shader));\r
+                       std::stringstream str;\r
+                       str << "Failed to compile vertex shader:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+                       \r
+               const char* fragment_source = fragment_source_str.c_str();\r
+                                               \r
+               auto fragmemt_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);\r
+                                       \r
+               GL(glShaderSourceARB(fragmemt_shader, 1, &fragment_source, NULL));\r
+               GL(glCompileShaderARB(fragmemt_shader));\r
+\r
+               GL(glGetObjectParameterivARB(fragmemt_shader, GL_OBJECT_COMPILE_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(fragmemt_shader, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(fragmemt_shader));\r
+                       std::stringstream str;\r
+                       str << "Failed to compile fragment shader:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+                       \r
+               program_ = glCreateProgramObjectARB();\r
+                       \r
+               GL(glAttachObjectARB(program_, vertex_shader));\r
+               GL(glAttachObjectARB(program_, fragmemt_shader));\r
+\r
+               GL(glLinkProgramARB(program_));\r
+                       \r
+               GL(glDeleteObjectARB(vertex_shader));\r
+               GL(glDeleteObjectARB(fragmemt_shader));\r
+\r
+               GL(glGetObjectParameterivARB(program_, GL_OBJECT_LINK_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(program_, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(program_));\r
+                       std::stringstream str;\r
+                       str << "Failed to link shader program:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+               GL(glUseProgramObjectARB(program_));\r
+               glUniform1i(glGetUniformLocation(program_, "plane[0]"), 0);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[1]"), 1);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[2]"), 2);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[3]"), 3);\r
+       }\r
+\r
+       shader_program& operator=(shader_program&& other) \r
+       {\r
+               program_ = other.program_; \r
+               other.program_ = 0; \r
+               return *this;\r
+       }\r
+\r
+       ~shader_program()\r
+       {\r
+               glDeleteProgram(program_);\r
+       }\r
+\r
+       void use()\r
+       {       \r
+               GL(glUseProgramObjectARB(program_));            \r
+       }\r
+\r
+private:\r
+       GLuint program_;\r
+};\r
+\r
+GLubyte progressive_pattern[] = {\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xFF, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+       \r
+GLubyte upper_pattern[] = {\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};\r
+               \r
+GLubyte lower_pattern[] = {\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, \r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};\r
+\r
+struct image_kernel::implementation\r
+{\r
+       std::unordered_map<pixel_format::type, shader_program>& shaders()\r
+       {\r
+               if(shaders_.empty())\r
+               {\r
+               std::string common_vertex = \r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       gl_TexCoord[0] = gl_MultiTexCoord0;                                                                     "\r
+                       "       gl_FrontColor = gl_Color;                                                                                       "\r
+                       "       gl_Position = ftransform();                                                                                     "\r
+                       "}                                                                                                                                              ";\r
+\r
+               std::string common_fragment = \r
+                       "uniform sampler2D      plane[4];                                                                                       "\r
+                       "uniform vec4           plane_size[2];                                                                          "\r
+                                                                                                                                                               \r
+                       // NOTE: YCbCr, ITU-R, http://www.intersil.com/data/an/an9717.pdf               \r
+                       // TODO: Support for more yuv formats might be needed.                                  \r
+                       "vec4 ycbcra_to_bgra(float y, float cb, float cr, float a)                              "\r
+                       "{                                                                                                                                              "\r
+                       "       cb -= 0.5;                                                                                                                      "\r
+                       "       cr -= 0.5;                                                                                                                      "\r
+                       "       y = 1.164*(y-0.0625);                                                                                           "\r
+                       "                                                                                                                                               "\r
+                       "       vec4 color;                                                                                                                     "\r
+                       "       color.r = y + 1.596 * cr;                                                                                       "\r
+                       "       color.g = y - 0.813 * cr - 0.337633 * cb;                                                       "\r
+                       "       color.b = y + 2.017 * cb;                                                                                       "\r
+                       "       color.a = a;                                                                                                            "\r
+                       "                                                                                                                                               "\r
+                       "       return color;                                                                                                           "\r
+                       "}                                                                                                                                              "                       \r
+                       "                                                                                                                                               ";\r
+                       \r
+               shaders_[pixel_format::abgr] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 abgr = texture2D(plane[0], gl_TexCoord[0].st);"\r
+                       "       gl_FragColor = abgr.argb * gl_Color;                                                            "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[pixel_format::argb]= shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "       \r
+                       "{                                                                                                                                              "\r
+                       "       vec4 argb = texture2D(plane[0], gl_TexCoord[0].st);"\r
+                       "       gl_FragColor = argb.grab * gl_Color;                                                            "       \r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[pixel_format::bgra]= shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 bgra = texture2D(plane[0], gl_TexCoord[0].st);"\r
+                       "       gl_FragColor = bgra.rgba * gl_Color;                                                            "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[pixel_format::rgba] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 rgba = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
+                       "       gl_FragColor = rgba.bgra * gl_Color;                                                            "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[pixel_format::ycbcr] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;"\r
+                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;"\r
+                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;"\r
+                       "       float a = 1.0;                                                                                                          "       \r
+                       "       gl_FragColor = ycbcra_to_bgra(y, cb, cr, a) * gl_Color;                 "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[pixel_format::ycbcra] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;"\r
+                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;"\r
+                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;"\r
+                       "       float a  = texture2D(plane[3], gl_TexCoord[0].st).r;"\r
+                       "       gl_FragColor = ycbcra_to_bgra(y, cb, cr, a) * gl_Color;                         "\r
+                       "}                                                                                                                                              ");\r
+               }\r
+               return shaders_;\r
+       }\r
+       \r
+       std::unordered_map<pixel_format::type, shader_program> shaders_;\r
+};\r
+\r
+image_kernel::image_kernel() : impl_(new implementation()){}\r
+\r
+void image_kernel::use(pixel_format::type pix_fmt, video_mode::type mode)\r
+{\r
+       impl_->shaders()[pix_fmt].use();\r
+\r
+       if(mode == video_mode::upper)\r
+               glPolygonStipple(upper_pattern);\r
+       else if(mode == video_mode::lower)\r
+               glPolygonStipple(lower_pattern);\r
+       else\r
+               glPolygonStipple(progressive_pattern);\r
+}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/processor/image_kernel.h b/core/processor/image_kernel.h
new file mode 100644 (file)
index 0000000..10d403d
--- /dev/null
@@ -0,0 +1,21 @@
+#pragma once\r
+\r
+#include "../format/pixel_format.h"\r
+#include "../format/video_format.h"\r
+\r
+#include <memory>\r
+\r
+namespace caspar { namespace core {\r
+               \r
+class image_kernel\r
+{\r
+public:\r
+       image_kernel();\r
+       void use(pixel_format::type pix_fmt, video_mode::type mode);\r
+\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
index 9f02d61d837cb6b36689e8edf643764186fc93e8..12c0a70f1a595950b911ca62364dfaa941eebf27 100644 (file)
@@ -1,14 +1,13 @@
 #include "../StdAfx.h"\r
 \r
 #include "image_processor.h"\r
+#include "image_kernel.h"\r
 \r
-#include "buffer/read_buffer.h"\r
-#include "buffer/write_buffer.h"\r
+#include "host_buffer.h"\r
+#include "device_buffer.h"\r
 \r
 #include <common/exception/exceptions.h>\r
 #include <common/gl/utility.h>\r
-#include <common/gl/shader_program.h>\r
-#include <common/gl/frame_buffer_object.h>\r
 #include <common/concurrency/executor.h>\r
 \r
 #include <Glee.h>\r
 \r
 #include <unordered_map>\r
 \r
-struct ogl_context\r
-{\r
-       ogl_context(){context_.SetActive(true);};\r
-       sf::Context context_;\r
-};\r
-\r
 namespace caspar { namespace core {\r
                \r
+class ogl_context\r
+{      \r
+public:\r
+       \r
+       ogl_context()\r
+       {\r
+               executor_.start();\r
+               invoke([=]\r
+               {\r
+                       context_.reset(new sf::Context());\r
+                       context_->SetActive(true);\r
+               });\r
+       }\r
+\r
+       template<typename Func>\r
+       auto begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
+       {                       \r
+               return executor_.begin_invoke(std::forward<Func>(func));\r
+       }\r
+       \r
+       template<typename Func>\r
+       auto invoke(Func&& func) -> decltype(func())\r
+       {\r
+               return executor_.invoke(std::forward<Func>(func));\r
+       }\r
+               \r
+       safe_ptr<device_buffer> create_device_buffer(size_t width, size_t height, size_t stride)\r
+       {\r
+               auto pool = &device_pools_[stride][((width << 12) & 0x00FFF000) | ((height << 0) & 0x00000FFF)];\r
+               std::shared_ptr<device_buffer> buffer;\r
+               if(!pool->try_pop(buffer))              \r
+               {\r
+                       executor_.invoke([&]\r
+                       {\r
+                               buffer = std::make_shared<device_buffer>(width, height, stride);\r
+                       });     \r
+               }\r
+               \r
+               return safe_ptr<device_buffer>(buffer.get(), [=](device_buffer*){pool->push(buffer);});\r
+       }\r
+       \r
+       safe_ptr<host_buffer> create_host_buffer(size_t size, host_buffer::usage_t usage)\r
+       {\r
+               auto pool = &host_pools_[usage][size];\r
+               std::shared_ptr<host_buffer> buffer;\r
+               if(!pool->try_pop(buffer))\r
+               {\r
+                       executor_.invoke([&]\r
+                       {\r
+                               buffer = std::make_shared<host_buffer>(size, usage);\r
+                               if(usage == host_buffer::write_only)\r
+                                       buffer->map();\r
+                               else\r
+                                       buffer->unmap();\r
+                       });     \r
+               }\r
+\r
+               return safe_ptr<host_buffer>(buffer.get(), [=](host_buffer*)\r
+               {\r
+                       executor_.begin_invoke([=]\r
+                       {\r
+                               if(usage == host_buffer::write_only)\r
+                                       buffer->map();\r
+                               else\r
+                                       buffer->unmap();\r
+                               pool->push(buffer);\r
+                       });\r
+               });\r
+       }\r
+private:\r
+       executor executor_;\r
+       std::unique_ptr<sf::Context> context_;\r
+       \r
+       std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<device_buffer>>>, 4> device_pools_;\r
+       std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<host_buffer>>>, 2> host_pools_;\r
+};\r
+\r
 image_transform& image_transform::operator*=(const image_transform &other)\r
 {\r
        alpha *= other.alpha;\r
@@ -42,294 +112,142 @@ const image_transform image_transform::operator*(const image_transform &other) c
        return image_transform(*this) *= other;\r
 }\r
 \r
-GLubyte progressive_pattern[] = {\r
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
-       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xFF, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
-       \r
-GLubyte upper_pattern[] = {\r
-       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
-       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
-       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
-       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};\r
-               \r
-GLubyte lower_pattern[] = {\r
-       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, \r
-       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
-       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
-       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};\r
-       \r
-\r
-struct renderer\r
+struct image_processor::implementation\r
 {      \r
-       renderer(const video_format_desc& format_desc) : fbo_(format_desc.width, format_desc.height), reading_(create_reading())\r
+       implementation(const video_format_desc& format_desc) : format_desc_(format_desc)\r
        {\r
-               transform_stack_.push(image_transform());\r
-               transform_stack_.top().mode = video_mode::progressive;\r
-               transform_stack_.top().uv = boost::make_tuple(0.0, 1.0, 1.0, 0.0);\r
-\r
-               GL(glEnable(GL_POLYGON_STIPPLE));\r
-               GL(glEnable(GL_TEXTURE_2D));\r
-               GL(glEnable(GL_BLEND));\r
-               GL(glDisable(GL_DEPTH_TEST));\r
-               GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));                  \r
-               GL(glViewport(0, 0, format_desc.width, format_desc.height));\r
-               reading_->unmap();\r
-\r
-               std::string common_vertex = \r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       gl_TexCoord[0] = gl_MultiTexCoord0;                                                                     "\r
-                       "       gl_FrontColor = gl_Color;                                                                                       "\r
-                       "       gl_Position = ftransform();                                                                                     "\r
-                       "}                                                                                                                                              ";\r
-\r
-               std::string common_fragment = \r
-                       "uniform sampler2D      plane[4];                                                                                       "\r
-                       "uniform vec4           plane_size[2];                                                                          "\r
-                                                                                                                                                               \r
-                       // NOTE: YCbCr, ITU-R, http://www.intersil.com/data/an/an9717.pdf               \r
-                       // TODO: Support for more yuv formats might be needed.                                  \r
-                       "vec4 ycbcra_to_bgra(float y, float cb, float cr, float a)                              "\r
-                       "{                                                                                                                                              "\r
-                       "       cb -= 0.5;                                                                                                                      "\r
-                       "       cr -= 0.5;                                                                                                                      "\r
-                       "       y = 1.164*(y-0.0625);                                                                                           "\r
-                       "                                                                                                                                               "\r
-                       "       vec4 color;                                                                                                                     "\r
-                       "       color.r = y + 1.596 * cr;                                                                                       "\r
-                       "       color.g = y - 0.813 * cr - 0.337633 * cb;                                                       "\r
-                       "       color.b = y + 2.017 * cb;                                                                                       "\r
-                       "       color.a = a;                                                                                                            "\r
-                       "                                                                                                                                               "\r
-                       "       return color;                                                                                                           "\r
-                       "}                                                                                                                                              "                       \r
-                       "                                                                                                                                               ";\r
+               context_.begin_invoke([=]\r
+               {\r
+                       transform_stack_.push(image_transform());\r
+                       transform_stack_.top().mode = video_mode::progressive;\r
+                       transform_stack_.top().uv = boost::make_tuple(0.0, 1.0, 1.0, 0.0);\r
+\r
+                       GL(glEnable(GL_POLYGON_STIPPLE));\r
+                       GL(glEnable(GL_TEXTURE_2D));\r
+                       GL(glEnable(GL_BLEND));\r
+                       GL(glDisable(GL_DEPTH_TEST));\r
+                       GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));                  \r
+\r
+                       render_targets_[0] = context_.create_device_buffer(format_desc.width, format_desc.height, 4);\r
+                       render_targets_[1] = context_.create_device_buffer(format_desc.width, format_desc.height, 4);\r
                        \r
-               shaders_[pixel_format::abgr] = gl::shader_program(common_vertex, common_fragment +\r
-\r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       vec4 abgr = texture2D(plane[0], gl_TexCoord[0].st);"\r
-                       "       gl_FragColor = abgr.argb * gl_Color;                                                            "\r
-                       "}                                                                                                                                              ");\r
-               \r
-               shaders_[pixel_format::argb]= gl::shader_program(common_vertex, common_fragment +\r
+                       GL(glGenFramebuffers(1, &fbo_));                \r
+                       GL(glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo_));\r
+                       GL(glReadBuffer(GL_COLOR_ATTACHMENT0_EXT));\r
 \r
-                       "void main()                                                                                                                    "       \r
-                       "{                                                                                                                                              "\r
-                       "       vec4 argb = texture2D(plane[0], gl_TexCoord[0].st);"\r
-                       "       gl_FragColor = argb.grab * gl_Color;                                                            "       \r
-                       "}                                                                                                                                              ");\r
-               \r
-               shaders_[pixel_format::bgra]= gl::shader_program(common_vertex, common_fragment +\r
-\r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       vec4 bgra = texture2D(plane[0], gl_TexCoord[0].st);"\r
-                       "       gl_FragColor = bgra.rgba * gl_Color;                                                            "\r
-                       "}                                                                                                                                              ");\r
-               \r
-               shaders_[pixel_format::rgba] = gl::shader_program(common_vertex, common_fragment +\r
-\r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       vec4 rgba = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
-                       "       gl_FragColor = rgba.bgra * gl_Color;                                                            "\r
-                       "}                                                                                                                                              ");\r
-               \r
-               shaders_[pixel_format::ycbcr] = gl::shader_program(common_vertex, common_fragment +\r
-\r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;"\r
-                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;"\r
-                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;"\r
-                       "       float a = 1.0;                                                                                                          "       \r
-                       "       gl_FragColor = ycbcra_to_bgra(y, cb, cr, a) * gl_Color;                 "\r
-                       "}                                                                                                                                              ");\r
-               \r
-               shaders_[pixel_format::ycbcra] = gl::shader_program(common_vertex, common_fragment +\r
+                       reading_ = context_.create_host_buffer(format_desc_.size, host_buffer::read_only);\r
+               });\r
+       }\r
 \r
-                       "void main()                                                                                                                    "\r
-                       "{                                                                                                                                              "\r
-                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;"\r
-                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;"\r
-                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;"\r
-                       "       float a  = texture2D(plane[3], gl_TexCoord[0].st).r;"\r
-                       "       gl_FragColor = ycbcra_to_bgra(y, cb, cr, a) * gl_Color;                         "\r
-                       "}                                                                                                                                              ");\r
+       ~implementation()\r
+       {\r
+               glDeleteFramebuffersEXT(1, &fbo_);\r
        }\r
 \r
        void begin(const image_transform& transform)\r
        {\r
-               glPushMatrix();\r
-               transform_stack_.push(transform_stack_.top()*transform);\r
+               context_.begin_invoke([=]\r
+               {\r
+                       glPushMatrix();\r
+                       transform_stack_.push(transform_stack_.top()*transform);\r
 \r
-               glColor4d(1.0, 1.0, 1.0, transform_stack_.top().alpha);\r
-               glTranslated(transform.pos.get<0>()*2.0, transform.pos.get<1>()*2.0, 0.0);\r
-               \r
-               set_mode(transform_stack_.top().mode);\r
+                       glColor4d(1.0, 1.0, 1.0, transform_stack_.top().alpha);\r
+                       glTranslated(transform.pos.get<0>()*2.0, transform.pos.get<1>()*2.0, 0.0);\r
+               });\r
        }\r
                \r
-       void render(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>>& buffers)\r
+       void render(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>>& buffers)\r
        {\r
-               shaders_[desc.pix_fmt].use();\r
-\r
-               for(size_t n = 0; n < buffers.size(); ++n)\r
+               context_.begin_invoke([=]\r
                {\r
-                       auto buffer = buffers[n];\r
-\r
-                       glActiveTexture(GL_TEXTURE0+n);\r
-                       buffer->unmap();\r
-                                               \r
-                       bool fit = buffer->width() == fbo_.width() && buffer->height() == fbo_.height();\r
-                       GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, fit ? GL_NEAREST : GL_LINEAR));\r
-                       GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, fit ? GL_NEAREST : GL_LINEAR));\r
-               }\r
+                       GL(glViewport(0, 0, format_desc_.width, format_desc_.height));\r
+                       kernel_.use(desc.pix_fmt, transform_stack_.top().mode);\r
 \r
-               auto t = transform_stack_.top();\r
-               glBegin(GL_QUADS);\r
-                       glTexCoord2d(t.uv.get<0>(), t.uv.get<3>()); glVertex2d(-1.0, -1.0);\r
-                       glTexCoord2d(t.uv.get<2>(), t.uv.get<3>()); glVertex2d( 1.0, -1.0);\r
-                       glTexCoord2d(t.uv.get<2>(), t.uv.get<1>()); glVertex2d( 1.0,  1.0);\r
-                       glTexCoord2d(t.uv.get<0>(), t.uv.get<1>()); glVertex2d(-1.0,  1.0);\r
-               glEnd();\r
-       }\r
-\r
-       void end()\r
-       {\r
-               transform_stack_.pop();\r
-               set_mode(transform_stack_.top().mode);\r
-               glColor4d(1.0, 1.0, 1.0, transform_stack_.top().alpha);\r
-               glPopMatrix();\r
-       }\r
-\r
-       safe_ptr<const read_buffer> begin_pass()\r
-       {\r
-               reading_->map();\r
-               GL(glClear(GL_COLOR_BUFFER_BIT));\r
-               return reading_;\r
-       }\r
-\r
-       void end_pass()\r
-       {\r
-               reading_ = create_reading();\r
-               reading_->unmap(); // Start transfer from frame buffer to texture. End with map in next tick.\r
-       }\r
-       \r
-       void set_mode(video_mode::type mode)\r
-       {\r
-               if(mode == video_mode::upper)\r
-                       glPolygonStipple(upper_pattern);\r
-               else if(mode == video_mode::lower)\r
-                       glPolygonStipple(lower_pattern);\r
-               else\r
-                       glPolygonStipple(progressive_pattern);\r
-       }\r
-\r
-       safe_ptr<read_buffer> create_reading()\r
-       {\r
-               std::shared_ptr<read_buffer> frame;\r
-               if(!pool_.try_pop(frame))               \r
-                       frame = std::make_shared<read_buffer>(fbo_.width(), fbo_.height());\r
-               return safe_ptr<read_buffer>(frame.get(), [=](read_buffer*){pool_.push(frame);});\r
-       }\r
-\r
-       const ogl_context context_;\r
-                \r
-       tbb::concurrent_bounded_queue<std::shared_ptr<read_buffer>> pool_;\r
-\r
-       std::stack<image_transform> transform_stack_;\r
-\r
-       std::unordered_map<pixel_format::type, gl::shader_program> shaders_;\r
-       gl::fbo fbo_;\r
+                       std::vector<safe_ptr<device_buffer>> device_buffers;\r
+                       for(size_t n = 0; n < buffers.size(); ++n)\r
+                       {\r
+                               auto texture = context_.create_device_buffer(desc.planes[n].width, desc.planes[n].height, desc.planes[n].channels);\r
+                               texture->read(*buffers[n]);\r
+                               device_buffers.push_back(texture);\r
+                       }\r
 \r
-       safe_ptr<read_buffer> reading_;\r
-};\r
+                       for(size_t n = 0; n < buffers.size(); ++n)\r
+                       {\r
+                               glActiveTexture(GL_TEXTURE0+n);\r
+                               device_buffers[n]->bind();\r
+                       }\r
 \r
-struct image_processor::implementation : boost::noncopyable\r
-{\r
-       implementation(const video_format_desc& format_desc) : format_desc_(format_desc)\r
-       {\r
-               executor_.start();\r
-       }\r
-       \r
-       void begin(const image_transform& transform)\r
-       {\r
-               executor_.begin_invoke([=]{get()->begin(transform);});\r
-       }\r
-               \r
-       void render(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>>& buffers)\r
-       {\r
-               executor_.begin_invoke([=]() mutable{get()->render(desc, buffers);});\r
+                       auto t = transform_stack_.top();\r
+                       glBegin(GL_QUADS);\r
+                               glTexCoord2d(t.uv.get<0>(), t.uv.get<3>()); glVertex2d(-1.0, -1.0);\r
+                               glTexCoord2d(t.uv.get<2>(), t.uv.get<3>()); glVertex2d( 1.0, -1.0);\r
+                               glTexCoord2d(t.uv.get<2>(), t.uv.get<1>()); glVertex2d( 1.0,  1.0);\r
+                               glTexCoord2d(t.uv.get<0>(), t.uv.get<1>()); glVertex2d(-1.0,  1.0);\r
+                       glEnd();\r
+               });\r
        }\r
 \r
        void end()\r
        {\r
-               executor_.begin_invoke([=]{get()->end();});\r
+               context_.begin_invoke([=]\r
+               {\r
+                       transform_stack_.pop();\r
+                       glColor4d(1.0, 1.0, 1.0, transform_stack_.top().alpha);\r
+                       glPopMatrix();\r
+               });\r
        }\r
 \r
-       boost::unique_future<safe_ptr<const read_buffer>> begin_pass()\r
+       boost::unique_future<safe_ptr<const host_buffer>> begin_pass()\r
        {\r
-               return executor_.begin_invoke([=]{return get()->begin_pass();});\r
+               return context_.begin_invoke([=]() -> safe_ptr<const host_buffer>\r
+               {\r
+                       reading_->map();\r
+                       render_targets_[0]->attach(0);\r
+                       GL(glClear(GL_COLOR_BUFFER_BIT));\r
+                       return safe_ptr<const host_buffer>(reading_);\r
+               });\r
        }\r
 \r
        void end_pass()\r
        {\r
-               executor_.begin_invoke([=]{get()->end_pass();});\r
-       }\r
-\r
-       std::unique_ptr<renderer>& get()\r
-       {\r
-               if(!renderer_)\r
-                       renderer_.reset(new renderer(format_desc_));\r
-               return renderer_;\r
+               context_.begin_invoke([=]\r
+               {\r
+                       reading_ = context_.create_host_buffer(format_desc_.size, host_buffer::read_only);\r
+                       render_targets_[0]->write(*reading_);\r
+                       std::rotate(render_targets_.begin(), render_targets_.begin() + 1, render_targets_.end());\r
+               });\r
        }\r
-\r
-       std::vector<safe_ptr<write_buffer>> create_buffers(const pixel_format_desc& format)\r
+               \r
+       std::vector<safe_ptr<host_buffer>> create_buffers(const pixel_format_desc& format)\r
        {\r
-               std::vector<safe_ptr<write_buffer>> buffers;\r
-               std::transform(format.planes.begin(), format.planes.end(), std::back_inserter(buffers), [&](const pixel_format_desc::plane& plane) -> safe_ptr<write_buffer>\r
+               std::vector<safe_ptr<host_buffer>> buffers;\r
+               std::transform(format.planes.begin(), format.planes.end(), std::back_inserter(buffers), [&](const pixel_format_desc::plane& plane) -> safe_ptr<host_buffer>\r
                {\r
-                       size_t key = ((plane.channels << 24) & 0x0F000000) | ((plane.width << 12) & 0x00FFF000) | ((plane.height << 0) & 0x00000FFF);\r
-                       auto pool = &write_frames_[key];\r
-                       std::shared_ptr<write_buffer> buffer;\r
-                       if(!pool->try_pop(buffer))\r
-                       {\r
-                               executor_.begin_invoke([&]\r
-                               {\r
-                                       buffer = std::make_shared<write_buffer>(plane.width, plane.height, plane.channels);\r
-                                       buffer->map();\r
-                               }).get();       \r
-                       }\r
-\r
-                       return safe_ptr<write_buffer>(buffer.get(), [=](write_buffer*)\r
-                       {\r
-                               executor_.begin_invoke([=]\r
-                               {\r
-                                       buffer->map();\r
-                                       pool->push(buffer);\r
-                               });\r
-                       });\r
+                       return context_.create_host_buffer(plane.size, host_buffer::write_only);\r
                });\r
                return buffers;\r
        }\r
                \r
-       tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<write_buffer>>> write_frames_;\r
-\r
        const video_format_desc format_desc_;\r
-       std::unique_ptr<renderer> renderer_;\r
-       executor executor_;     \r
+\r
+       ogl_context context_;\r
+\r
+       std::stack<image_transform> transform_stack_;\r
+\r
+       GLuint fbo_;\r
+       std::array<std::shared_ptr<device_buffer>, 2> render_targets_;\r
+\r
+       std::shared_ptr<host_buffer> reading_;\r
+\r
+       image_kernel kernel_;\r
 };\r
 \r
 image_processor::image_processor(const video_format_desc& format_desc) : impl_(new implementation(format_desc)){}\r
 void image_processor::begin(const image_transform& transform) {        impl_->begin(transform);}\r
-void image_processor::process(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>>& buffers){    impl_->render(desc, buffers);}\r
+void image_processor::process(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>>& buffers){     impl_->render(desc, buffers);}\r
 void image_processor::end(){impl_->end();}\r
-boost::unique_future<safe_ptr<const read_buffer>> image_processor::begin_pass(){       return impl_->begin_pass();}\r
+boost::unique_future<safe_ptr<const host_buffer>> image_processor::begin_pass(){       return impl_->begin_pass();}\r
 void image_processor::end_pass(){impl_->end_pass();}\r
-std::vector<safe_ptr<write_buffer>> image_processor::create_buffers(const pixel_format_desc& format){return impl_->create_buffers(format);}\r
+std::vector<safe_ptr<host_buffer>> image_processor::create_buffers(const pixel_format_desc& format){return impl_->create_buffers(format);}\r
 \r
 }}
\ No newline at end of file
index d633f395f607f193db04fe643031759bc559dcab..9e7547394e6e5d2cef2507fa7bd01776d8171761 100644 (file)
@@ -1,7 +1,6 @@
 #pragma once\r
 \r
-#include "buffer/write_buffer.h"\r
-#include "buffer/read_buffer.h"\r
+#include "host_buffer.h"\r
 \r
 #include "../format/video_format.h"\r
 #include "../format/pixel_format.h"\r
@@ -32,18 +31,17 @@ public:
        image_processor(const video_format_desc& format_desc);\r
 \r
        void begin(const image_transform& transform);\r
-       void process(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>>& buffers);\r
+       void process(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>>& buffers);\r
        void end();\r
 \r
-       boost::unique_future<safe_ptr<const read_buffer>> begin_pass();\r
+       boost::unique_future<safe_ptr<const host_buffer>> begin_pass();\r
        void end_pass();\r
 \r
-       std::vector<safe_ptr<write_buffer>> create_buffers(const pixel_format_desc& format);\r
+       std::vector<safe_ptr<host_buffer>> create_buffers(const pixel_format_desc& format);\r
 \r
 private:\r
        struct implementation;\r
        std::shared_ptr<implementation> impl_;\r
 };\r
-typedef std::shared_ptr<image_processor> image_shader_ptr;\r
 \r
 }}
\ No newline at end of file
index 318887260d6c3bf44079f6b9e54a0ed9a6fb2bda..c2ee9d969348b9e8679d3f674dc85dff7e821176 100644 (file)
@@ -2,7 +2,7 @@
 \r
 #include "read_frame.h"\r
 \r
-#include "buffer/read_buffer.h"\r
+#include "host_buffer.h"\r
 \r
 #include <common/gl/utility.h>\r
 #include <common/utility/singleton_pool.h>\r
@@ -11,14 +11,14 @@ namespace caspar { namespace core {
                                                                                                                                                                                                                                                                                                                        \r
 struct read_frame::implementation : boost::noncopyable\r
 {\r
-       implementation(safe_ptr<const read_buffer>&& image_data, std::vector<short>&& audio_data) : image_data_(std::move(image_data)), audio_data_(std::move(audio_data)){}    \r
+       implementation(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data) : image_data_(std::move(image_data)), audio_data_(std::move(audio_data)){}    \r
 \r
-       safe_ptr<const read_buffer> image_data_;\r
+       safe_ptr<const host_buffer> image_data_;\r
        std::vector<short> audio_data_;\r
 };\r
 \r
 read_frame::read_frame(){}\r
-read_frame::read_frame(safe_ptr<const read_buffer>&& image_data, std::vector<short>&& audio_data) : impl_(singleton_pool<implementation>::make_shared(image_data, audio_data)){}\r
+read_frame::read_frame(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data) : impl_(singleton_pool<implementation>::make_shared(image_data, audio_data)){}\r
 \r
 const boost::iterator_range<const unsigned char*> read_frame::image_data() const\r
 {\r
index a7722dcb811b0691c9ab384789bb1bd0f40e830e..7e2b10e5e6a1506632ed617b70fc110ea2a3ad6f 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once\r
 \r
-#include "buffer/read_buffer.h"        \r
+#include "host_buffer.h"       \r
 \r
 #include <boost/noncopyable.hpp>\r
 #include <boost/range/iterator_range.hpp>\r
@@ -16,7 +16,7 @@ class read_frame
 {\r
 public:\r
        read_frame();\r
-       read_frame(safe_ptr<const read_buffer>&& image_data, std::vector<short>&& audio_data);\r
+       read_frame(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data);\r
 \r
        const boost::iterator_range<const unsigned char*> image_data() const;\r
        const boost::iterator_range<const short*> audio_data() const;\r
index 331206e5b5699cfa15a5c3432b385a09c5ad84a0..a51ed3e9fe0d3921423446aac486f21bcebe6947 100644 (file)
@@ -2,7 +2,7 @@
 \r
 #include "write_frame.h"\r
 \r
-#include "buffer/write_buffer.h"\r
+#include "host_buffer.h"\r
 \r
 #include "draw_frame.h"\r
 #include "image_processor.h"\r
@@ -18,7 +18,7 @@ namespace caspar { namespace core {
                                                                                                                                                                                                                                                                                                                        \r
 struct write_frame::implementation : boost::noncopyable\r
 {\r
-       implementation(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>> buffers) : desc_(desc), buffers_(buffers){}\r
+       implementation(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>> buffers) : desc_(desc), buffers_(buffers){}\r
        \r
        void process_image(image_processor& processor)\r
        {\r
@@ -45,12 +45,12 @@ struct write_frame::implementation : boost::noncopyable
                return boost::iterator_range<const unsigned char*>(ptr, ptr+buffers_[index]->size());\r
        }\r
                                \r
-       std::vector<safe_ptr<write_buffer>> buffers_;\r
+       std::vector<safe_ptr<host_buffer>> buffers_;\r
        std::vector<short> audio_data_;\r
        const pixel_format_desc desc_;\r
 };\r
        \r
-write_frame::write_frame(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>> buffers) : impl_(singleton_pool<implementation>::make_shared(desc, buffers)){}\r
+write_frame::write_frame(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>> buffers) : impl_(singleton_pool<implementation>::make_shared(desc, buffers)){}\r
 write_frame::write_frame(write_frame&& other) : impl_(std::move(other.impl_)){}\r
 void write_frame::swap(write_frame& other){impl_.swap(other.impl_);}\r
 write_frame& write_frame::operator=(write_frame&& other)\r
index e8dc4e702d95a916ceb9f147c1777892c12309bf..a32f17dd19a49dbff30a4d53dbad3b903cb5d282 100644 (file)
@@ -2,7 +2,7 @@
 \r
 #include "fwd.h"\r
 \r
-#include "buffer\write_buffer.h"\r
+#include "host_buffer.h"\r
 \r
 #include "draw_frame.h"\r
 \r
@@ -20,7 +20,7 @@ namespace caspar { namespace core {
 class write_frame : public draw_frame, boost::noncopyable\r
 {\r
 public:        \r
-       explicit write_frame(const pixel_format_desc& desc, std::vector<safe_ptr<write_buffer>> buffers);\r
+       explicit write_frame(const pixel_format_desc& desc, std::vector<safe_ptr<host_buffer>> buffers);\r
        write_frame(write_frame&& other);\r
        write_frame& operator=(write_frame&& other);\r
        \r