2016-02-14 01:52:23 +00:00
|
|
|
//
|
2016-03-09 01:59:16 +00:00
|
|
|
// CRTInputBufferBuilder.cpp
|
2016-02-14 01:52:23 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
2016-03-09 01:59:16 +00:00
|
|
|
// Created by Thomas Harte on 08/03/2016.
|
2016-02-14 01:52:23 +00:00
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
#include "CRTInputBufferBuilder.hpp"
|
2016-02-14 01:52:23 +00:00
|
|
|
#include "CRTOpenGL.hpp"
|
2016-03-09 01:59:16 +00:00
|
|
|
#include <string.h>
|
2016-02-14 01:52:23 +00:00
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
using namespace Outputs::CRT;
|
2016-02-14 01:52:23 +00:00
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
CRTInputBufferBuilder::CRTInputBufferBuilder(unsigned int number_of_buffers, va_list buffer_sizes)
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
this->number_of_buffers = number_of_buffers;
|
|
|
|
buffers = new CRTInputBufferBuilder::Buffer[number_of_buffers];
|
|
|
|
|
|
|
|
for(int buffer = 0; buffer < number_of_buffers; buffer++)
|
|
|
|
{
|
|
|
|
buffers[buffer].bytes_per_pixel = va_arg(buffer_sizes, unsigned int);
|
2016-03-09 01:49:07 +00:00
|
|
|
buffers[buffer].data = new uint8_t[InputBufferBuilderWidth * InputBufferBuilderHeight * buffers[buffer].bytes_per_pixel];
|
2016-02-14 01:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_next_write_x_position = _next_write_y_position = 0;
|
|
|
|
last_uploaded_line = 0;
|
|
|
|
}
|
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
CRTInputBufferBuilder::~CRTInputBufferBuilder()
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
for(int buffer = 0; buffer < number_of_buffers; buffer++)
|
|
|
|
delete[] buffers[buffer].data;
|
|
|
|
delete buffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
void CRTInputBufferBuilder::allocate_write_area(size_t required_length)
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
_last_allocation_amount = required_length;
|
|
|
|
|
2016-03-09 01:49:07 +00:00
|
|
|
if(_next_write_x_position + required_length + 2 > InputBufferBuilderWidth)
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
_next_write_x_position = 0;
|
2016-03-09 01:49:07 +00:00
|
|
|
_next_write_y_position = (_next_write_y_position+1)%InputBufferBuilderHeight;
|
2016-02-14 01:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_write_x_position = _next_write_x_position + 1;
|
|
|
|
_write_y_position = _next_write_y_position;
|
2016-03-09 01:49:07 +00:00
|
|
|
_write_target_pointer = (_write_y_position * InputBufferBuilderWidth) + _write_x_position;
|
2016-02-14 01:52:23 +00:00
|
|
|
_next_write_x_position += required_length + 2;
|
|
|
|
}
|
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
void CRTInputBufferBuilder::reduce_previous_allocation_to(size_t actual_length)
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
for(int c = 0; c < number_of_buffers; c++)
|
|
|
|
{
|
|
|
|
memcpy( &buffers[c].data[(_write_target_pointer - 1) * buffers[c].bytes_per_pixel],
|
|
|
|
&buffers[c].data[_write_target_pointer * buffers[c].bytes_per_pixel],
|
|
|
|
buffers[c].bytes_per_pixel);
|
|
|
|
|
|
|
|
memcpy( &buffers[c].data[(_write_target_pointer + actual_length) * buffers[c].bytes_per_pixel],
|
|
|
|
&buffers[c].data[(_write_target_pointer + actual_length - 1) * buffers[c].bytes_per_pixel],
|
|
|
|
buffers[c].bytes_per_pixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
_next_write_x_position -= (_last_allocation_amount - actual_length);
|
|
|
|
}
|
|
|
|
|
2016-03-09 01:59:16 +00:00
|
|
|
uint8_t *CRTInputBufferBuilder::get_write_target_for_buffer(int buffer)
|
2016-02-14 01:52:23 +00:00
|
|
|
{
|
|
|
|
return &buffers[buffer].data[_write_target_pointer * buffers[buffer].bytes_per_pixel];
|
|
|
|
}
|