From 4f1ef3cbee2100956607634d0847e370c09a7d9e Mon Sep 17 00:00:00 2001 From: ronag Date: Sat, 21 Jan 2012 03:55:53 +0000 Subject: [PATCH] git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2142 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- core/mixer/gpu/ogl_device.cpp | 28 ++++++++++++---------------- core/mixer/gpu/ogl_device.h | 6 +++--- core/mixer/image/image_mixer.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/core/mixer/gpu/ogl_device.cpp b/core/mixer/gpu/ogl_device.cpp index 584038fbc..2699f50a0 100644 --- a/core/mixer/gpu/ogl_device.cpp +++ b/core/mixer/gpu/ogl_device.cpp @@ -113,7 +113,7 @@ safe_ptr ogl_device::allocate_device_buffer(int width, int height return make_safe_ptr(buffer); } -safe_ptr ogl_device::create_device_buffer(int width, int height, int stride, bool zero) +safe_ptr ogl_device::create_device_buffer(int width, int height, int stride) { CASPAR_VERIFY(stride > 0 && stride < 5); CASPAR_VERIFY(width > 0 && height > 0); @@ -121,23 +121,17 @@ safe_ptr ogl_device::create_device_buffer(int width, int height, std::shared_ptr buffer; if(!pool->items.try_pop(buffer)) - buffer = executor_.invoke([&]{return allocate_device_buffer(width, height, stride);}); - - if(zero) + buffer = executor_.invoke([&]{return allocate_device_buffer(width, height, stride);}); + + return safe_ptr(buffer.get(), [=](device_buffer*) mutable { - executor_.invoke([&] + executor_.begin_invoke([=] { - scoped_state scope(*this); - attach(*buffer); + auto prev = attach(buffer->id()); glClear(GL_COLOR_BUFFER_BIT); - }, high_priority); - } - - //++pool->usage_count; - - return safe_ptr(buffer.get(), [=](device_buffer*) mutable - { - pool->items.push(buffer); + attach(prev); + pool->items.push(buffer); + }, high_priority); }); } @@ -391,8 +385,9 @@ void ogl_device::stipple_pattern(const std::array& pattern) } } -void ogl_device::attach(GLint id) +GLint ogl_device::attach(GLint id) { + auto prev = state_.attached_texture; if(id != state_.attached_texture) { GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0, GL_TEXTURE_2D, id, 0)); @@ -400,6 +395,7 @@ void ogl_device::attach(GLint id) state_.attached_texture = id; } + return prev; } void ogl_device::attach(const device_buffer& texture) diff --git a/core/mixer/gpu/ogl_device.h b/core/mixer/gpu/ogl_device.h index 75de06991..0a6a7980f 100644 --- a/core/mixer/gpu/ogl_device.h +++ b/core/mixer/gpu/ogl_device.h @@ -99,11 +99,12 @@ class ogl_device : public std::enable_shared_from_this ogl_device(); void use(GLint id); - void attach(GLint id); + GLint attach(GLint id); void bind(GLint id, int index); void flush(); friend class scoped_state; + public: void push_state(); state pop_state(); @@ -128,7 +129,6 @@ public: void bind(const device_buffer& texture, int index); - // thread-afe template auto begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future // noexcept @@ -142,7 +142,7 @@ public: return executor_.invoke(std::forward(func), priority); } - safe_ptr create_device_buffer(int width, int height, int stride, bool zero = false); + safe_ptr create_device_buffer(int width, int height, int stride); safe_ptr create_host_buffer(int size, host_buffer::usage_t usage); boost::unique_future> transfer(const safe_ptr& source); diff --git a/core/mixer/image/image_mixer.cpp b/core/mixer/image/image_mixer.cpp index 7164330fe..b514dafb0 100644 --- a/core/mixer/image/image_mixer.cpp +++ b/core/mixer/image/image_mixer.cpp @@ -68,7 +68,7 @@ public: boost::unique_future> operator()(std::vector&& layers, const video_format_desc& format_desc) { - auto draw_buffer = ogl_->create_device_buffer(format_desc.width, format_desc.height, 4, true); + auto draw_buffer = ogl_->create_device_buffer(format_desc.width, format_desc.height, 4); if(format_desc.field_mode != field_mode::progressive) { @@ -125,7 +125,7 @@ private: if(layer.first != blend_mode::normal) { - auto layer_draw_buffer = ogl_->create_device_buffer(format_desc.width, format_desc.height, 4, true); + auto layer_draw_buffer = ogl_->create_device_buffer(format_desc.width, format_desc.height, 4); BOOST_FOREACH(auto& item, layer.second) draw_item(std::move(item), layer_draw_buffer, layer_key_buffer, local_key_buffer, local_mix_buffer, format_desc); @@ -161,7 +161,7 @@ private: if(item.transform.is_key) { - local_key_buffer = local_key_buffer ? local_key_buffer : ogl_->create_device_buffer(format_desc.width, format_desc.height, 4, true); + local_key_buffer = local_key_buffer ? local_key_buffer : ogl_->create_device_buffer(format_desc.width, format_desc.height, 4); draw_params.background = local_key_buffer; draw_params.local_key = nullptr; @@ -171,7 +171,7 @@ private: } else if(item.transform.is_mix) { - local_mix_buffer = local_mix_buffer ? local_mix_buffer : ogl_->create_device_buffer(format_desc.width, format_desc.height, 4, true); + local_mix_buffer = local_mix_buffer ? local_mix_buffer : ogl_->create_device_buffer(format_desc.width, format_desc.height, 4); draw_params.background = local_mix_buffer; draw_params.local_key = std::move(local_key_buffer); -- 2.39.5