From d979a822ac3dc043d61c2d79da3833c0f9ec0d6e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Feb 2017 21:46:07 -0500 Subject: [PATCH] Introduced a deferred task list for the OpenGL thread. --- Outputs/CRT/CRT.hpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index af06af273..df78efe56 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -81,10 +81,19 @@ class CRT { uint16_t x1, y; } output_run_; - // The delegate + // the delegate Delegate *delegate_; unsigned int frames_since_last_delegate_call_; + // queued tasks for the OpenGL queue; performed before the next draw + std::mutex function_mutex_; + std::vector> enqueued_openGL_functions_; + inline void enqueue_openGL_function(const std::function &function) + { + std::lock_guard function_guard(function_mutex_); + enqueued_openGL_functions_.push_back(function); + } + public: /*! Constructs the CRT with a specified clock rate, height and colour subcarrier frequency. The requested number of buffers, each with the requested number of bytes per pixel, @@ -204,6 +213,14 @@ class CRT { */ inline void draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty) { + { + std::lock_guard function_guard(function_mutex_); + for(std::function function : enqueued_openGL_functions_) + { + function(); + } + enqueued_openGL_functions_.clear(); + } openGL_output_builder_.draw_frame(output_width, output_height, only_if_dirty); }