From 9ee11d7765c81ac6c949796a4df0dba39d5198d6 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 16 Nov 2016 11:34:05 +0800 Subject: [PATCH] At the expense of API simplicity, at least for now, resolved the most glaring cause of dirty lines. --- Outputs/CRT/CRT.cpp | 18 +++++++++++++++--- Outputs/CRT/CRT.hpp | 2 +- Outputs/CRT/Internals/CRTOpenGL.hpp | 8 +++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 05ca75550..b722fab26 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -141,7 +141,8 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi source_input_position_x1() = tex_x; source_input_position_y() = tex_y; source_output_position_x1() = (uint16_t)_horizontal_flywheel->get_current_output_position(); - source_output_position_y() = _openGL_output_builder->get_composite_output_y(); + // Don't write output_y now, write it later; we won't necessarily know what it is outside of the locked region +// source_output_position_y() = _openGL_output_builder->get_composite_output_y(); source_phase() = _colour_burst_phase; source_amplitude() = _colour_burst_amplitude; source_phase_time() = (uint8_t)_colour_burst_time; // assumption: burst was within the first 1/16 of the line @@ -190,17 +191,28 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi { _output_run.x1 = (uint16_t)_horizontal_flywheel->get_current_output_position(); _output_run.y = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider); - _output_run.tex_y = _openGL_output_builder->get_composite_output_y(); } else { _openGL_output_builder->lock_output(); + + // Get and write all those previously unwritten output ys + uint16_t output_y = _openGL_output_builder->get_composite_output_y(); + size_t size; + uint8_t *buffered_lines = _openGL_output_builder->get_buffered_source_runs(size); + for(size_t position = 0; position < size; position += SourceVertexSize) + { + (*(uint16_t *)&buffered_lines[position + SourceVertexOffsetOfOutputStart + 2]) = output_y; + } + + // Construct the output run uint8_t *next_run = _openGL_output_builder->get_next_output_run(); output_x1() = _output_run.x1; output_position_y() = _output_run.y; - output_tex_y() = _output_run.tex_y; + output_tex_y() = output_y; output_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position(); _openGL_output_builder->complete_output_run(); + _openGL_output_builder->unlock_output(); } _is_writing_composite_run ^= true; diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index 59d4ca962..78bc4ec1a 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -83,7 +83,7 @@ class CRT { // temporary storage used during the construction of output runs struct { - uint16_t x1, y, tex_y; + uint16_t x1, y; } _output_run; // The delegate diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index fca1e6532..baab3a33e 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -105,6 +105,12 @@ class OpenGLOutputBuilder { _line_buffer.pointer += SourceVertexSize; } + inline uint8_t *get_buffered_source_runs(size_t &size) + { + size = _line_buffer.pointer; + return _line_buffer.data.data(); + } + inline uint8_t *get_next_output_run() { if(_output_buffer.pointer == OutputVertexBufferDataSize) return nullptr; @@ -161,7 +167,7 @@ class OpenGLOutputBuilder { inline uint16_t get_composite_output_y() { - return _composite_src_output_y % IntermediateBufferHeight; + return (uint16_t)_composite_src_output_y; } inline bool composite_output_buffer_is_full()