std::fill(binded_textures_.begin(), binded_textures_.end(), 0);\r
std::fill(viewport_.begin(), viewport_.end(), 0);\r
std::fill(scissor_.begin(), scissor_.end(), 0);\r
+ std::fill(blend_func_.begin(), blend_func_.end(), 0);\r
\r
invoke([=]\r
{\r
glDeleteFramebuffersEXT(1, &fbo_);\r
});\r
}\r
+\r
+safe_ptr<device_buffer> ogl_device::allocate_device_buffer(size_t width, size_t height, size_t stride)\r
+{\r
+ std::shared_ptr<device_buffer> buffer;\r
+ try\r
+ {\r
+ buffer.reset(new device_buffer(width, height, stride));\r
+ }\r
+ catch(...)\r
+ {\r
+ try\r
+ {\r
+ yield();\r
+ gc().wait();\r
+ \r
+ // Try again\r
+ buffer.reset(new device_buffer(width, height, stride));\r
+ }\r
+ catch(...)\r
+ {\r
+ CASPAR_LOG(error) << L"ogl: create_device_buffer failed!";\r
+ throw;\r
+ }\r
+ }\r
+ return make_safe(buffer);\r
+}\r
\r
safe_ptr<device_buffer> ogl_device::create_device_buffer(size_t width, size_t height, size_t stride)\r
{\r
auto& pool = device_pools_[stride-1][((width << 16) & 0xFFFF0000) | (height & 0x0000FFFF)];\r
std::shared_ptr<device_buffer> buffer;\r
if(!pool->items.try_pop(buffer)) \r
- {\r
- ++pool->total_count;\r
- executor_.invoke([&]\r
- { \r
- try\r
- {\r
- buffer.reset(new device_buffer(width, height, stride));\r
- }\r
- catch(...)\r
- {\r
- try\r
- {\r
- yield();\r
- gc().wait();\r
- \r
- // Try again\r
- buffer.reset(new device_buffer(width, height, stride));\r
- }\r
- catch(...)\r
- {\r
- CASPAR_LOG(error) << L"ogl: create_device_buffer failed!";\r
- --pool->total_count;\r
- throw;\r
- }\r
- }\r
- }, high_priority); \r
- }\r
+ buffer = executor_.invoke([&]{return allocate_device_buffer(width, height, stride);}, high_priority); \r
\r
- ++pool->usage_count;\r
+ //++pool->usage_count;\r
\r
return safe_ptr<device_buffer>(buffer.get(), [=](device_buffer*) mutable\r
{ \r
pool->items.push(buffer); \r
});\r
}\r
+\r
+safe_ptr<host_buffer> ogl_device::allocate_host_buffer(size_t size, host_buffer::usage_t usage)\r
+{\r
+ std::shared_ptr<host_buffer> buffer;\r
+\r
+ try\r
+ {\r
+ buffer.reset(new host_buffer(size, usage));\r
+ if(usage == host_buffer::write_only)\r
+ buffer->map();\r
+ else\r
+ buffer->unmap(); \r
+ }\r
+ catch(...)\r
+ {\r
+ try\r
+ {\r
+ yield();\r
+ gc().wait();\r
+\r
+ // Try again\r
+ buffer.reset(new host_buffer(size, usage));\r
+ if(usage == host_buffer::write_only)\r
+ buffer->map();\r
+ else\r
+ buffer->unmap(); \r
+ }\r
+ catch(...)\r
+ {\r
+ CASPAR_LOG(error) << L"ogl: create_host_buffer failed!";\r
+ throw; \r
+ }\r
+ }\r
+\r
+ return make_safe(buffer);\r
+}\r
\r
safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::usage_t usage)\r
{\r
CASPAR_VERIFY(size > 0);\r
auto& pool = host_pools_[usage][size];\r
std::shared_ptr<host_buffer> buffer;\r
- if(!pool->items.try_pop(buffer))\r
- {\r
- ++pool->total_count;\r
- executor_.invoke([&]\r
- {\r
- try\r
- {\r
- buffer.reset(new host_buffer(size, usage));\r
- if(usage == host_buffer::write_only)\r
- buffer->map();\r
- else\r
- buffer->unmap(); \r
- }\r
- catch(...)\r
- {\r
- try\r
- {\r
- yield();\r
- gc().wait();\r
-\r
- // Try again\r
- buffer.reset(new host_buffer(size, usage));\r
- if(usage == host_buffer::write_only)\r
- buffer->map();\r
- else\r
- buffer->unmap(); \r
- }\r
- catch(...)\r
- {\r
- CASPAR_LOG(error) << L"ogl: create_host_buffer failed!";\r
- --pool->total_count;\r
- throw; \r
- }\r
- }\r
- }, high_priority); \r
- }\r
+ if(!pool->items.try_pop(buffer)) \r
+ buffer = executor_.invoke([=]{return allocate_host_buffer(size, usage);}, high_priority); \r
\r
- ++pool->usage_count;\r
+ //++pool->usage_count;\r
\r
return safe_ptr<host_buffer>(buffer.get(), [=](host_buffer*) mutable\r
{\r
});\r
}\r
\r
-template<typename T>\r
-void flush_pool(buffer_pool<T>& pool)\r
-{ \r
- if(pool.flush_count.fetch_and_increment() < 3)\r
- return;\r
-\r
- if(pool.usage_count.fetch_and_store(0) < pool.items.size())\r
- {\r
- std::shared_ptr<T> buffer;\r
- if(pool.items.try_pop(buffer))\r
- --pool.total_count;\r
- }\r
-\r
- pool.flush_count = 0;\r
- pool.usage_count = 0;\r
-}\r
+//template<typename T>\r
+//void flush_pool(buffer_pool<T>& pool)\r
+//{ \r
+// if(pool.flush_count.fetch_and_increment() < 16)\r
+// return;\r
+//\r
+// if(pool.usage_count.fetch_and_store(0) < pool.items.size())\r
+// {\r
+// std::shared_ptr<T> buffer;\r
+// pool.items.try_pop(buffer);\r
+// }\r
+//\r
+// pool.flush_count = 0;\r
+// pool.usage_count = 0;\r
+//}\r
\r
void ogl_device::flush()\r
{\r
GL(glFlush()); \r
\r
- try\r
- {\r
- BOOST_FOREACH(auto& pools, device_pools_)\r
- {\r
- BOOST_FOREACH(auto& pool, pools)\r
- flush_pool(*pool.second);\r
- }\r
- BOOST_FOREACH(auto& pools, host_pools_)\r
- {\r
- BOOST_FOREACH(auto& pool, pools)\r
- flush_pool(*pool.second);\r
- }\r
- }\r
- catch(...)\r
- {\r
- CASPAR_LOG_CURRENT_EXCEPTION();\r
- }\r
+ //try\r
+ //{\r
+ // BOOST_FOREACH(auto& pools, device_pools_)\r
+ // {\r
+ // BOOST_FOREACH(auto& pool, pools)\r
+ // flush_pool(*pool.second);\r
+ // }\r
+ // BOOST_FOREACH(auto& pools, host_pools_)\r
+ // {\r
+ // BOOST_FOREACH(auto& pool, pools)\r
+ // flush_pool(*pool.second);\r
+ // }\r
+ //}\r
+ //catch(...)\r
+ //{\r
+ // CASPAR_LOG_CURRENT_EXCEPTION();\r
+ //}\r
}\r
\r
void ogl_device::yield()\r
BOOST_FOREACH(auto& pools, device_pools_)\r
{\r
BOOST_FOREACH(auto& pool, pools)\r
- {\r
- auto size = pool.second->items.size();\r
- std::shared_ptr<device_buffer> buffer;\r
- for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n)\r
- --pool.second->total_count;\r
- }\r
+ pool.second->items.clear();\r
}\r
BOOST_FOREACH(auto& pools, host_pools_)\r
{\r
BOOST_FOREACH(auto& pool, pools)\r
- {\r
- auto size = pool.second->items.size();\r
- std::shared_ptr<host_buffer> buffer;\r
- for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n)\r
- --pool.second->total_count;\r
- }\r
+ pool.second->items.clear();\r
}\r
}\r
catch(...)\r
}\r
}\r
\r
+void ogl_device::blend_func(int c1, int c2, int a1, int a2)\r
+{\r
+ std::array<int, 4> func = {c1, c2, a1, a2};\r
+\r
+ if(blend_func_ != func)\r
+ {\r
+ blend_func_ = func;\r
+ GL(glBlendFuncSeparate(c1, c2, a1, a2));\r
+ }\r
+}\r
+\r
+void ogl_device::blend_func(int c1, int c2)\r
+{\r
+ blend_func(c1, c2, c1, c2);\r
+}\r
+\r
}}\r
\r