2016-03-09 01:59:16 +00:00
|
|
|
//
|
|
|
|
// CRTInputBufferBuilder.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 08/03/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CRTInputBufferBuilder_hpp
|
|
|
|
#define CRTInputBufferBuilder_hpp
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2016-03-19 21:07:05 +00:00
|
|
|
#include "CRTConstants.hpp"
|
2016-03-20 02:46:17 +00:00
|
|
|
#include "OpenGL.hpp"
|
2016-05-05 01:08:38 +00:00
|
|
|
#include <memory.h>
|
2016-03-09 01:59:16 +00:00
|
|
|
|
|
|
|
namespace Outputs {
|
|
|
|
namespace CRT {
|
|
|
|
|
|
|
|
struct CRTInputBufferBuilder {
|
2016-03-19 21:37:55 +00:00
|
|
|
CRTInputBufferBuilder(size_t bytes_per_pixel);
|
2016-03-09 01:59:16 +00:00
|
|
|
|
|
|
|
void allocate_write_area(size_t required_length);
|
2016-05-04 11:39:45 +00:00
|
|
|
bool reduce_previous_allocation_to(size_t actual_length, uint8_t *buffer);
|
2016-03-09 01:59:16 +00:00
|
|
|
|
2016-05-04 00:56:47 +00:00
|
|
|
inline uint16_t get_and_finalise_current_line()
|
2016-03-19 21:07:05 +00:00
|
|
|
{
|
2016-05-04 00:56:47 +00:00
|
|
|
uint16_t result = _write_y_position;
|
2016-05-04 11:39:45 +00:00
|
|
|
if(!_is_full)
|
|
|
|
{
|
|
|
|
_next_write_x_position = 0;
|
|
|
|
_next_write_y_position++;
|
|
|
|
}
|
2016-05-04 00:56:47 +00:00
|
|
|
_next_write_y_position %= InputBufferBuilderHeight;
|
2016-05-05 01:08:38 +00:00
|
|
|
_last_uploaded_line = _next_write_y_position;
|
2016-05-04 11:39:45 +00:00
|
|
|
_is_full = false;
|
2016-05-04 00:56:47 +00:00
|
|
|
return result;
|
2016-03-19 21:07:05 +00:00
|
|
|
}
|
2016-03-19 21:37:55 +00:00
|
|
|
|
|
|
|
inline uint8_t *get_write_target(uint8_t *buffer)
|
|
|
|
{
|
2016-05-05 01:08:38 +00:00
|
|
|
if(!_is_full)
|
|
|
|
{
|
|
|
|
memset(&buffer[_write_target_pointer * _bytes_per_pixel], 0, _last_allocation_amount * _bytes_per_pixel);
|
|
|
|
}
|
2016-05-04 11:39:45 +00:00
|
|
|
return _is_full ? nullptr : &buffer[_write_target_pointer * _bytes_per_pixel];
|
2016-03-19 21:37:55 +00:00
|
|
|
}
|
2016-05-04 00:56:47 +00:00
|
|
|
|
|
|
|
inline uint16_t get_last_write_x_position()
|
|
|
|
{
|
|
|
|
return _write_x_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t get_last_write_y_position()
|
|
|
|
{
|
2016-05-04 02:22:12 +00:00
|
|
|
return _write_y_position % InputBufferBuilderHeight;
|
2016-05-04 00:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t get_bytes_per_pixel()
|
|
|
|
{
|
2016-05-04 11:39:45 +00:00
|
|
|
return _bytes_per_pixel;
|
2016-05-04 00:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// where pixel data will be put to the next time a write is requested
|
|
|
|
uint16_t _next_write_x_position, _next_write_y_position;
|
|
|
|
|
|
|
|
// the most recent position returned for pixel data writing
|
|
|
|
uint16_t _write_x_position, _write_y_position;
|
|
|
|
|
|
|
|
// details of the most recent allocation
|
|
|
|
size_t _write_target_pointer;
|
|
|
|
size_t _last_allocation_amount;
|
|
|
|
|
|
|
|
// the buffer size
|
2016-05-04 11:39:45 +00:00
|
|
|
size_t _bytes_per_pixel;
|
2016-05-04 00:56:47 +00:00
|
|
|
|
|
|
|
// Storage for the amount of buffer uploaded so far; initialised correctly by the buffer
|
|
|
|
// builder but otherwise entrusted to the CRT to update.
|
2016-05-04 11:39:45 +00:00
|
|
|
unsigned int _last_uploaded_line;
|
|
|
|
bool _is_full;
|
2016-03-09 01:59:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CRTInputBufferBuilder_hpp */
|