mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 01:31:42 +00:00
Fixed off-by-one error on texture upload.
This commit is contained in:
parent
f621cc8523
commit
e9a9cfb09f
@ -33,7 +33,7 @@ const GLsizei SourceVertexSize = 16;
|
||||
|
||||
// These constants hold the size of the rolling buffer to which the CPU writes
|
||||
const GLsizei InputBufferBuilderWidth = 2048;
|
||||
const GLsizei InputBufferBuilderHeight = 8;
|
||||
const GLsizei InputBufferBuilderHeight = 8192;
|
||||
|
||||
// This is the size of the intermediate buffers used during composite to RGB conversion
|
||||
const GLsizei IntermediateBufferWidth = 2048;
|
||||
|
@ -16,8 +16,6 @@ CRTInputBufferBuilder::CRTInputBufferBuilder(size_t bytes_per_pixel) :
|
||||
_bytes_per_pixel(bytes_per_pixel),
|
||||
_next_write_x_position(0),
|
||||
_next_write_y_position(0),
|
||||
_last_uploaded_line(0),
|
||||
_is_full(false),
|
||||
_image(new uint8_t[bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight])
|
||||
{}
|
||||
|
||||
@ -28,7 +26,7 @@ CRTInputBufferBuilder::~CRTInputBufferBuilder()
|
||||
|
||||
void CRTInputBufferBuilder::allocate_write_area(size_t required_length)
|
||||
{
|
||||
if(!_is_full)
|
||||
if(_next_write_y_position != InputBufferBuilderHeight)
|
||||
{
|
||||
_last_allocation_amount = required_length;
|
||||
|
||||
@ -37,8 +35,7 @@ void CRTInputBufferBuilder::allocate_write_area(size_t required_length)
|
||||
_next_write_x_position = 0;
|
||||
_next_write_y_position++;
|
||||
|
||||
_is_full = (_next_write_y_position == _last_uploaded_line + InputBufferBuilderHeight);
|
||||
if(_is_full)
|
||||
if(_next_write_y_position == InputBufferBuilderHeight)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -46,12 +43,17 @@ void CRTInputBufferBuilder::allocate_write_area(size_t required_length)
|
||||
_write_y_position = _next_write_y_position;
|
||||
_write_target_pointer = (_write_y_position * InputBufferBuilderWidth) + _write_x_position;
|
||||
_next_write_x_position += required_length + 2;
|
||||
|
||||
if(_write_y_position == 0 && _write_x_position == 0)
|
||||
{
|
||||
memset(_image, 0, _bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CRTInputBufferBuilder::reduce_previous_allocation_to(size_t actual_length)
|
||||
{
|
||||
if(_is_full) return false;
|
||||
if(_next_write_y_position == InputBufferBuilderHeight) return false;
|
||||
|
||||
// book end the allocation with duplicates of the first and last pixel, to protect
|
||||
// against rounding errors when this run is drawn
|
||||
@ -76,15 +78,14 @@ uint8_t *CRTInputBufferBuilder::get_image_pointer()
|
||||
|
||||
uint16_t CRTInputBufferBuilder::get_and_finalise_current_line()
|
||||
{
|
||||
uint16_t result = _write_y_position;
|
||||
uint16_t result = _write_y_position + (_next_write_x_position ? 1 : 0);
|
||||
_next_write_x_position = _next_write_y_position = 0;
|
||||
_is_full = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t *CRTInputBufferBuilder::get_write_target()
|
||||
{
|
||||
return _is_full ? nullptr : &_image[_write_target_pointer * _bytes_per_pixel];
|
||||
return (_next_write_y_position == InputBufferBuilderHeight) ? nullptr : &_image[_write_target_pointer * _bytes_per_pixel];
|
||||
}
|
||||
|
||||
uint16_t CRTInputBufferBuilder::get_last_write_x_position()
|
||||
@ -94,7 +95,7 @@ uint16_t CRTInputBufferBuilder::get_last_write_x_position()
|
||||
|
||||
uint16_t CRTInputBufferBuilder::get_last_write_y_position()
|
||||
{
|
||||
return _write_y_position % InputBufferBuilderHeight;
|
||||
return _write_y_position;
|
||||
}
|
||||
|
||||
size_t CRTInputBufferBuilder::get_bytes_per_pixel()
|
||||
|
@ -51,11 +51,7 @@ struct CRTInputBufferBuilder {
|
||||
// the buffer size
|
||||
size_t _bytes_per_pixel;
|
||||
|
||||
// Storage for the amount of buffer uploaded so far; initialised correctly by the buffer
|
||||
// builder but otherwise entrusted to the CRT to update.
|
||||
unsigned int _last_uploaded_line;
|
||||
bool _is_full;
|
||||
|
||||
// the buffer
|
||||
uint8_t *_image;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user