]> git.sesse.net Git - casparcg/blobdiff - core/mixer/gpu/host_buffer.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / core / mixer / gpu / host_buffer.cpp
index 125956ef554266ca6d562dbe62fb97ba7945a683..ec65338668de59c759c75fa973ce3ce19ee1a036 100644 (file)
 #include "host_buffer.h"\r
 \r
 #include "fence.h"\r
+#include "device_buffer.h"\r
 #include "ogl_device.h"\r
 \r
+#include <common/exception/exceptions.h>\r
 #include <common/gl/gl_check.h>\r
 \r
+#include <gl/glew.h>\r
+\r
+#include <tbb/atomic.h>\r
+\r
 namespace caspar { namespace core {\r
+\r
+static tbb::atomic<int> g_w_total_count;\r
+static tbb::atomic<int> g_r_total_count;\r
                                                                                                                                                                                                                                                                                                                                \r
 struct host_buffer::implementation : boost::noncopyable\r
 {      \r
@@ -35,7 +44,7 @@ struct host_buffer::implementation : boost::noncopyable
        void*                   data_;\r
        GLenum                  usage_;\r
        GLenum                  target_;\r
-       core::fence             fence_;\r
+       fence                   fence_;\r
 \r
 public:\r
        implementation(size_t size, usage_t usage) \r
@@ -54,7 +63,7 @@ public:
                if(!pbo_)\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
 \r
-               CASPAR_LOG(debug) << "[host_buffer] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
+               CASPAR_LOG(trace) << "[host_buffer] [" << ++(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
        }       \r
 \r
        ~implementation()\r
@@ -62,6 +71,7 @@ public:
                try\r
                {\r
                        GL(glDeleteBuffers(1, &pbo_));\r
+                       //CASPAR_LOG(trace) << "[host_buffer] [" << --(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] deallocated size:" << size_ << " usage: " << (usage_ == write_only ? "write_only" : "read_only");\r
                }\r
                catch(...)\r
                {\r
@@ -84,10 +94,9 @@ public:
                        BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map target_ OpenGL Pixel Buffer Object."));\r
        }\r
 \r
-       void map2(ogl_device& ogl)\r
+       void wait(ogl_device& ogl)\r
        {\r
                fence_.wait(ogl);\r
-               ogl.invoke(std::bind(&implementation::map, this), high_priority);\r
        }\r
 \r
        void unmap()\r
@@ -111,10 +120,18 @@ public:
                GL(glBindBuffer(target_, 0));\r
        }\r
 \r
-       void fence()\r
+       void begin_read(size_t width, size_t height, GLuint format)\r
        {\r
+               unmap();\r
+               bind();\r
+               GL(glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, NULL));\r
+               unbind();\r
                fence_.set();\r
-               GL(glFlush());\r
+       }\r
+\r
+       bool ready() const\r
+       {\r
+               return fence_.ready();\r
        }\r
 };\r
 \r
@@ -122,11 +139,12 @@ host_buffer::host_buffer(size_t size, usage_t usage) : impl_(new implementation(
 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::map(ogl_device& ogl){impl_->map2(ogl);}\r
 void host_buffer::unmap(){impl_->unmap();}\r
 void host_buffer::bind(){impl_->bind();}\r
 void host_buffer::unbind(){impl_->unbind();}\r
-void host_buffer::fence(){impl_->fence();}\r
+void host_buffer::begin_read(size_t width, size_t height, GLuint format){impl_->begin_read(width, height, format);}\r
 size_t host_buffer::size() const { return impl_->size_; }\r
+bool host_buffer::ready() const{return impl_->ready();}\r
+void host_buffer::wait(ogl_device& ogl){impl_->wait(ogl);}\r
 \r
 }}
\ No newline at end of file