From 727f2e2ba0e5efc5d26cc20d5e57d99f5b29b1e9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 17 Jan 2019 22:28:02 -0500 Subject: [PATCH] Updates to the ScanTarget world. --- OSBindings/SDL/main.cpp | 16 ++++++++-------- Outputs/OpenGL/ScanTarget.cpp | 6 ++++++ Outputs/OpenGL/ScanTarget.hpp | 5 ++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 80e541bfa..385199373 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -26,7 +26,8 @@ #include "../../Concurrency/BestEffortUpdater.hpp" #include "../../Activity/Observer.hpp" -#include "../../Outputs/CRT/Internals/Rectangle.hpp" +#include "../../Outputs/OpenGL/Primitives/Rectangle.hpp" +#include "../../Outputs/OpenGL/ScanTarget.hpp" namespace { @@ -109,7 +110,7 @@ class ActivityObserver: public Activity::Observer { float y = 1.0f - 2.0f * height; for(const auto &drive: drives_) { // TODO: use std::make_unique as below, if/when formally embracing C++14. - lights_.emplace(std::make_pair(drive, std::unique_ptr(new OpenGL::Rectangle(right_x, y, width, height)))); + lights_.emplace(std::make_pair(drive, std::unique_ptr(new Outputs::Display::OpenGL::Rectangle(right_x, y, width, height)))); y -= height * 2.0f; } @@ -154,7 +155,7 @@ class ActivityObserver: public Activity::Observer { blinking_leds_.insert(name); } - std::map> lights_; + std::map> lights_; std::set lit_leds_; std::set blinking_leds_; }; @@ -467,9 +468,8 @@ int main(int argc, char *argv[]) { glGetIntegerv(GL_FRAMEBUFFER_BINDING, &target_framebuffer); // Setup output, assuming a CRT machine for now, and prepare a best-effort updater. - machine->crt_machine()->setup_output(4.0 / 3.0); - machine->crt_machine()->get_crt()->set_output_gamma(2.2f); - machine->crt_machine()->get_crt()->set_target_framebuffer(target_framebuffer); + Outputs::Display::OpenGL::ScanTarget scan_target(target_framebuffer); + machine->crt_machine()->set_scan_target(&scan_target); // For now, lie about audio output intentions. auto speaker = machine->crt_machine()->get_speaker(); @@ -593,7 +593,7 @@ int main(int argc, char *argv[]) { case SDL_WINDOWEVENT_RESIZED: { GLint target_framebuffer = 0; glGetIntegerv(GL_FRAMEBUFFER_BINDING, &target_framebuffer); - machine->crt_machine()->get_crt()->set_target_framebuffer(target_framebuffer); + scan_target.set_target_framebuffer(target_framebuffer); SDL_GetWindowSize(window, &window_width, &window_height); if(activity_observer) activity_observer->set_aspect_ratio(static_cast(window_width) / static_cast(window_height)); } break; @@ -785,7 +785,7 @@ int main(int argc, char *argv[]) { // Display a new frame and wait for vsync. updater.update(); - machine->crt_machine()->get_crt()->draw_frame(static_cast(window_width), static_cast(window_height), false); + scan_target.draw(true, int(window_width), int(window_height)); if(activity_observer) activity_observer->draw(); SDL_GL_SwapWindow(window); } diff --git a/Outputs/OpenGL/ScanTarget.cpp b/Outputs/OpenGL/ScanTarget.cpp index 091df6360..63fee54c5 100644 --- a/Outputs/OpenGL/ScanTarget.cpp +++ b/Outputs/OpenGL/ScanTarget.cpp @@ -93,6 +93,12 @@ ScanTarget::~ScanTarget() { glDeleteVertexArrays(1, &scan_vertex_array_); } +void ScanTarget::set_target_framebuffer(GLuint target_framebuffer) { + while(is_drawing_.test_and_set()); + target_framebuffer_ = target_framebuffer; + is_drawing_.clear(); +} + void ScanTarget::set_modals(Modals modals) { // Don't change the modals while drawing is ongoing; a previous set might be // in the process of being established. diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index 36c6967e4..e1021d0a7 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -37,6 +37,9 @@ class ScanTarget: public Outputs::Display::ScanTarget { public: ScanTarget(GLuint target_framebuffer = 0, float output_gamma = 2.2f); ~ScanTarget(); + + void set_target_framebuffer(GLuint); + void draw(bool synchronous, int output_width, int output_height); private: @@ -46,7 +49,7 @@ class ScanTarget: public Outputs::Display::ScanTarget { static constexpr int LineBufferWidth = 2048; static constexpr int LineBufferHeight = 2048; - const GLuint target_framebuffer_; + GLuint target_framebuffer_; const float output_gamma_; // Outputs::Display::ScanTarget overrides.