1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Added padding of supplied data to correct for any potential rounding errors when rendering.

This commit is contained in:
Thomas Harte 2016-02-07 20:29:32 -05:00
parent 3a9ea66f8b
commit 3a689d14cc
3 changed files with 20 additions and 8 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -312,4 +312,5 @@ void CRT::prepare_shader()
void CRT::set_output_device(OutputDevice output_device)
{
_output_device = output_device;
}