From 3a689d14cc8cccc234839a414c8ade7fd8155e70 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 7 Feb 2016 20:29:32 -0500 Subject: [PATCH] Added padding of supplied data to correct for any potential rounding errors when rendering. --- Outputs/CRT/CRT.hpp | 6 +++--- Outputs/CRT/CRTFrameBuilder.cpp | 21 ++++++++++++++++----- Outputs/CRT/CRTOpenGL.cpp | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Outputs/CRT/CRT.hpp b/Outputs/CRT/CRT.hpp index bb4c4ddb0..c66574438 100644 --- a/Outputs/CRT/CRT.hpp +++ b/Outputs/CRT/CRT.hpp @@ -283,8 +283,8 @@ class CRT { uint8_t *get_next_run(); - void allocate_write_area(int required_length); - void reduce_previous_allocation_to(int actual_length); + void allocate_write_area(size_t required_length); + void reduce_previous_allocation_to(size_t actual_length); uint8_t *get_write_target_for_buffer(int buffer); // a pointer to the section of content buffer currently being @@ -292,7 +292,7 @@ class CRT { uint16_t _next_write_x_position, _next_write_y_position; uint16_t _write_x_position, _write_y_position; size_t _write_target_pointer; - int _last_allocation_amount; + size_t _last_allocation_amount; }; static const int kCRTNumberOfFrames = 4; diff --git a/Outputs/CRT/CRTFrameBuilder.cpp b/Outputs/CRT/CRTFrameBuilder.cpp index a229500ae..930beaad2 100644 --- a/Outputs/CRT/CRTFrameBuilder.cpp +++ b/Outputs/CRT/CRTFrameBuilder.cpp @@ -64,26 +64,37 @@ uint8_t *CRT::CRTFrameBuilder::get_next_run() return next_run; } -void CRT::CRTFrameBuilder::allocate_write_area(int required_length) +void CRT::CRTFrameBuilder::allocate_write_area(size_t required_length) { _last_allocation_amount = required_length; - if (_next_write_x_position + required_length > frame.size.width) + if(_next_write_x_position + required_length + 2 > frame.size.width) { _next_write_x_position = 0; _next_write_y_position = (_next_write_y_position+1)&(frame.size.height-1); frame.dirty_size.height++; } - _write_x_position = _next_write_x_position; + _write_x_position = _next_write_x_position + 1; _write_y_position = _next_write_y_position; _write_target_pointer = (_write_y_position * frame.size.width) + _write_x_position; - _next_write_x_position += required_length; + _next_write_x_position += required_length + 2; frame.dirty_size.width = std::max(frame.dirty_size.width, _next_write_x_position); } -void CRT::CRTFrameBuilder::reduce_previous_allocation_to(int actual_length) +void CRT::CRTFrameBuilder::reduce_previous_allocation_to(size_t actual_length) { + for(int c = 0; c < frame.number_of_buffers; c++) + { + memcpy( &frame.buffers[c].data[(_write_target_pointer - 1) * frame.buffers[c].depth], + &frame.buffers[c].data[_write_target_pointer * frame.buffers[c].depth], + frame.buffers[c].depth); + + memcpy( &frame.buffers[c].data[(_write_target_pointer + actual_length) * frame.buffers[c].depth], + &frame.buffers[c].data[(_write_target_pointer + actual_length - 1) * frame.buffers[c].depth], + frame.buffers[c].depth); + } + _next_write_x_position -= (_last_allocation_amount - actual_length); } diff --git a/Outputs/CRT/CRTOpenGL.cpp b/Outputs/CRT/CRTOpenGL.cpp index e1522e9bc..fba197fa8 100644 --- a/Outputs/CRT/CRTOpenGL.cpp +++ b/Outputs/CRT/CRTOpenGL.cpp @@ -312,4 +312,5 @@ void CRT::prepare_shader() void CRT::set_output_device(OutputDevice output_device) { + _output_device = output_device; }