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
\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
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
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