]> git.sesse.net Git - casparcg/commitdiff
2.1.0: -ogl/device: Supports non-gpu arrays.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sat, 10 Mar 2012 16:31:08 +0000 (16:31 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sat, 10 Mar 2012 16:31:08 +0000 (16:31 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2599 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

accelerator/ogl/util/device.cpp
common/array.h

index d4b1d88f8f418cfc6596b052e1830e481a46d8aa..f26c956ed4d7925b1bd627f7505bd76293abc20a 100644 (file)
@@ -209,9 +209,29 @@ struct device::impl : public std::enable_shared_from_this<impl>
                return array<std::uint8_t>(buf->data(), buf->size(), false, buf);\r
        }\r
 \r
+       template<typename T>\r
+       std::shared_ptr<buffer> copy_to_buf(const T& source)\r
+       {\r
+               std::shared_ptr<buffer> buf;\r
+\r
+               auto tmp = source.storage<spl::shared_ptr<buffer>>();\r
+               if(tmp)\r
+                       buf = *tmp;\r
+               else\r
+               {                       \r
+                       buf = create_buffer(source.size(), buffer::usage::write_only);\r
+                       tbb::parallel_for(tbb::blocked_range<std::size_t>(0, source.size()), [&](const tbb::blocked_range<std::size_t>& r)\r
+                       {\r
+                               A_memcpy(buf->data() + r.begin(), source.data() + r.begin(), r.size());\r
+                       });\r
+               }\r
+\r
+               return buf;\r
+       }\r
+\r
        boost::unique_future<spl::shared_ptr<texture>> copy_async(const array<const std::uint8_t>& source, int width, int height, int stride)\r
        {\r
-               auto buf = source.storage<spl::shared_ptr<buffer>>();\r
+               std::shared_ptr<buffer> buf = copy_to_buf(source);\r
                                \r
                return render_executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
                {\r
@@ -230,20 +250,7 @@ struct device::impl : public std::enable_shared_from_this<impl>
        \r
        boost::unique_future<spl::shared_ptr<texture>> copy_async(const array<std::uint8_t>& source, int width, int height, int stride)\r
        {\r
-               std::shared_ptr<buffer> buf;\r
-\r
-               try\r
-               {\r
-                       buf = source.storage<spl::shared_ptr<buffer>>();\r
-               }\r
-               catch(boost::bad_any_cast&)\r
-               {                       \r
-                       buf = create_buffer(source.size(), buffer::usage::write_only);\r
-                       tbb::parallel_for(tbb::blocked_range<std::size_t>(0, source.size()), [&](const tbb::blocked_range<std::size_t>& r)\r
-                       {\r
-                               A_memcpy(buf->data() + r.begin(), source.data() + r.begin(), r.size());\r
-                       });\r
-               }\r
+               std::shared_ptr<buffer> buf = copy_to_buf(source);\r
 \r
                return render_executor_.begin_invoke([=]() -> spl::shared_ptr<texture>\r
                {\r
index d298705a55288908433ed8e2919c6cbc5dd5c696..dc2cc8bbf9f719922594d651435466ff70fd8b9b 100644 (file)
@@ -65,9 +65,9 @@ public:
        bool cacheable() const          {return cacheable_;}\r
        \r
        template<typename T>\r
-       T storage() const\r
+       T* storage() const\r
        {\r
-               return boost::any_cast<T>(*storage_);\r
+               return boost::any_cast<T>(storage_.get());\r
        }\r
 private:\r
        T*                      ptr_;\r
@@ -138,9 +138,9 @@ public:
        bool cacheable() const          {return cacheable_;}\r
        \r
        template<typename T>\r
-       T storage() const\r
+       T* storage() const\r
        {\r
-               return boost::any_cast<T>(*storage_);\r
+               return boost::any_cast<T>(storage_.get());\r
        }\r
 \r
 private:\r