1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Switched to postfix underscores and gave this class ownership of a texture builder and an array builder, though it presently uses neither.

This commit is contained in:
Thomas Harte 2016-11-17 11:00:11 +08:00
parent 57f0648742
commit 0f3b02edb7
2 changed files with 117 additions and 117 deletions

View File

@ -16,7 +16,7 @@ using namespace Outputs::CRT;
void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator)
{
_openGL_output_builder->set_colour_format(colour_space, colour_cycle_numerator, colour_cycle_denominator);
openGL_output_builder_.set_colour_format(colour_space, colour_cycle_numerator, colour_cycle_denominator);
const unsigned int syncCapacityLineChargeThreshold = 2;
const unsigned int millisecondsHorizontalRetraceTime = 7; // source: Dictionary of Video and Television Technology, p. 234
@ -28,24 +28,21 @@ void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_di
// a TV picture tube or camera tube to the starting point of a line or field. It is about 7 µs
// for horizontal retrace and 500 to 750 µs for vertical retrace in NTSC and PAL TV."
_time_multiplier = IntermediateBufferWidth / cycles_per_line;
// store fundamental display configuration properties
_height_of_display = height_of_display;
_cycles_per_line = cycles_per_line * _time_multiplier;
time_multiplier_ = IntermediateBufferWidth / cycles_per_line;
unsigned int multiplied_cycles_per_line = cycles_per_line * time_multiplier_;
// generate timing values implied by the given arbuments
_sync_capacitor_charge_threshold = (int)(syncCapacityLineChargeThreshold * _cycles_per_line);
sync_capacitor_charge_threshold_ = (int)(syncCapacityLineChargeThreshold * multiplied_cycles_per_line);
// create the two flywheels
_horizontal_flywheel.reset(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6, _cycles_per_line >> 6));
_vertical_flywheel.reset(new Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line, (_cycles_per_line * height_of_display) >> 3));
horizontal_flywheel_.reset(new Flywheel(multiplied_cycles_per_line, (millisecondsHorizontalRetraceTime * multiplied_cycles_per_line) >> 6, multiplied_cycles_per_line >> 6));
vertical_flywheel_.reset(new Flywheel(multiplied_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * multiplied_cycles_per_line, (multiplied_cycles_per_line * height_of_display) >> 3));
// figure out the divisor necessary to get the horizontal flywheel into a 16-bit range
unsigned int real_clock_scan_period = (_cycles_per_line * height_of_display) / (_time_multiplier * _common_output_divisor);
_vertical_flywheel_output_divider = (uint16_t)(ceilf(real_clock_scan_period / 65536.0f) * (_time_multiplier * _common_output_divisor));
unsigned int real_clock_scan_period = (multiplied_cycles_per_line * height_of_display) / (time_multiplier_ * common_output_divisor_);
vertical_flywheel_output_divider_ = (uint16_t)(ceilf(real_clock_scan_period / 65536.0f) * (time_multiplier_ * common_output_divisor_));
_openGL_output_builder->set_timing(cycles_per_line, _cycles_per_line, _height_of_display, _horizontal_flywheel->get_scan_period(), _vertical_flywheel->get_scan_period(), _vertical_flywheel_output_divider);
openGL_output_builder_.set_timing(cycles_per_line, multiplied_cycles_per_line, height_of_display, horizontal_flywheel_->get_scan_period(), vertical_flywheel_->get_scan_period(), vertical_flywheel_output_divider_);
}
void CRT::set_new_display_type(unsigned int cycles_per_line, DisplayType displayType)
@ -62,24 +59,27 @@ void CRT::set_new_display_type(unsigned int cycles_per_line, DisplayType display
}
}
CRT::CRT(unsigned int common_output_divisor) :
_sync_capacitor_charge_level(0),
_is_receiving_sync(false),
_sync_period(0),
_common_output_divisor(common_output_divisor),
_is_writing_composite_run(false),
_delegate(nullptr),
_frames_since_last_delegate_call(0) {}
CRT::CRT(unsigned int common_output_divisor, unsigned int buffer_depth) :
sync_capacitor_charge_level_(0),
is_receiving_sync_(false),
sync_period_(0),
common_output_divisor_(common_output_divisor),
is_writing_composite_run_(false),
delegate_(nullptr),
frames_since_last_delegate_call_(0),
openGL_output_builder_(buffer_depth),
array_builder_(SourceVertexBufferDataSize, OutputVertexBufferDataSize),
texture_builder_(buffer_depth) {}
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int buffer_depth) : CRT(common_output_divisor)
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int buffer_depth) :
CRT(common_output_divisor, buffer_depth)
{
_openGL_output_builder.reset(new OpenGLOutputBuilder(buffer_depth));
set_new_timing(cycles_per_line, height_of_display, colour_space, colour_cycle_numerator, colour_cycle_denominator);
}
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, DisplayType displayType, unsigned int buffer_depth) : CRT(common_output_divisor)
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, DisplayType displayType, unsigned int buffer_depth) :
CRT(common_output_divisor, buffer_depth)
{
_openGL_output_builder.reset(new OpenGLOutputBuilder(buffer_depth));
set_new_display_type(cycles_per_line, displayType);
}
@ -87,12 +87,12 @@ CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, Displ
Flywheel::SyncEvent CRT::get_next_vertical_sync_event(bool vsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced)
{
return _vertical_flywheel->get_next_event_in_period(vsync_is_requested, cycles_to_run_for, cycles_advanced);
return vertical_flywheel_->get_next_event_in_period(vsync_is_requested, cycles_to_run_for, cycles_advanced);
}
Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced)
{
return _horizontal_flywheel->get_next_event_in_period(hsync_is_requested, cycles_to_run_for, cycles_advanced);
return horizontal_flywheel_->get_next_event_in_period(hsync_is_requested, cycles_to_run_for, cycles_advanced);
}
#define output_x1() (*(uint16_t *)&next_run[OutputVertexOffsetOfHorizontal + 0])
@ -112,7 +112,7 @@ Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested,
void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divider, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Scan::Type type, uint16_t tex_x, uint16_t tex_y)
{
number_of_cycles *= _time_multiplier;
number_of_cycles *= time_multiplier_;
bool is_output_run = ((type == Scan::Type::Level) || (type == Scan::Type::Data));
@ -129,23 +129,23 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
hsync_requested = false;
vsync_requested = false;
bool is_output_segment = ((is_output_run && next_run_length) && !_horizontal_flywheel->is_in_retrace() && !_vertical_flywheel->is_in_retrace());
bool is_output_segment = ((is_output_run && next_run_length) && !horizontal_flywheel_->is_in_retrace() && !vertical_flywheel_->is_in_retrace());
uint8_t *next_run = nullptr;
if(is_output_segment && !_openGL_output_builder->composite_output_buffer_is_full())
if(is_output_segment && !openGL_output_builder_.composite_output_buffer_is_full())
{
next_run = _openGL_output_builder->get_next_source_run();
next_run = openGL_output_builder_.get_next_source_run();
}
if(next_run)
{
source_input_position_x1() = tex_x;
source_input_position_y() = tex_y;
source_output_position_x1() = (uint16_t)_horizontal_flywheel->get_current_output_position();
source_output_position_x1() = (uint16_t)horizontal_flywheel_->get_current_output_position();
// Don't write output_y now, write it later; we won't necessarily know what it is outside of the locked region
// source_output_position_y() = _openGL_output_builder->get_composite_output_y();
source_phase() = _colour_burst_phase;
source_amplitude() = _colour_burst_amplitude;
source_phase_time() = (uint8_t)_colour_burst_time; // assumption: burst was within the first 1/16 of the line
// source_output_position_y() = openGL_output_builder_->get_composite_output_y();
source_phase() = colour_burst_phase_;
source_amplitude() = colour_burst_amplitude_;
source_phase_time() = (uint8_t)colour_burst_time_; // assumption: burst was within the first 1/16 of the line
}
// decrement the number of cycles left to run for and increment the
@ -154,23 +154,23 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
// either charge or deplete the vertical retrace capacitor (making sure it stops at 0)
if(vsync_charging)
_sync_capacitor_charge_level += next_run_length;
sync_capacitor_charge_level_ += next_run_length;
else
_sync_capacitor_charge_level = std::max(_sync_capacitor_charge_level - (int)next_run_length, 0);
sync_capacitor_charge_level_ = std::max(sync_capacitor_charge_level_ - (int)next_run_length, 0);
// react to the incoming event...
_horizontal_flywheel->apply_event(next_run_length, (next_run_length == time_until_horizontal_sync_event) ? next_horizontal_sync_event : Flywheel::SyncEvent::None);
_vertical_flywheel->apply_event(next_run_length, (next_run_length == time_until_vertical_sync_event) ? next_vertical_sync_event : Flywheel::SyncEvent::None);
horizontal_flywheel_->apply_event(next_run_length, (next_run_length == time_until_horizontal_sync_event) ? next_horizontal_sync_event : Flywheel::SyncEvent::None);
vertical_flywheel_->apply_event(next_run_length, (next_run_length == time_until_vertical_sync_event) ? next_vertical_sync_event : Flywheel::SyncEvent::None);
if(next_run)
{
// if this is a data run then advance the buffer pointer
if(type == Scan::Type::Data && source_divider) tex_x += next_run_length / (_time_multiplier * source_divider);
if(type == Scan::Type::Data && source_divider) tex_x += next_run_length / (time_multiplier_ * source_divider);
source_input_position_x2() = tex_x;
source_output_position_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position();
source_output_position_x2() = (uint16_t)horizontal_flywheel_->get_current_output_position();
_openGL_output_builder->complete_source_run();
openGL_output_builder_.complete_source_run();
}
// if this is horizontal retrace then advance the output line counter and bookend an output run
@ -178,62 +178,62 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
if(next_run_length == time_until_vertical_sync_event && next_vertical_sync_event != Flywheel::SyncEvent::None) honoured_event = next_vertical_sync_event;
if(next_run_length == time_until_horizontal_sync_event && next_horizontal_sync_event != Flywheel::SyncEvent::None) honoured_event = next_horizontal_sync_event;
bool needs_endpoint =
(honoured_event == Flywheel::SyncEvent::StartRetrace && _is_writing_composite_run) ||
(honoured_event == Flywheel::SyncEvent::EndRetrace && !_horizontal_flywheel->is_in_retrace() && !_vertical_flywheel->is_in_retrace());
(honoured_event == Flywheel::SyncEvent::StartRetrace && is_writing_composite_run_) ||
(honoured_event == Flywheel::SyncEvent::EndRetrace && !horizontal_flywheel_->is_in_retrace() && !vertical_flywheel_->is_in_retrace());
if(needs_endpoint)
{
if(
_openGL_output_builder->composite_output_run_has_room_for_vertex() &&
!_openGL_output_builder->composite_output_buffer_is_full())
openGL_output_builder_.composite_output_run_has_room_for_vertex() &&
!openGL_output_builder_.composite_output_buffer_is_full())
{
if(!_is_writing_composite_run)
if(!is_writing_composite_run_)
{
_output_run.x1 = (uint16_t)_horizontal_flywheel->get_current_output_position();
_output_run.y = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider);
output_run_.x1 = (uint16_t)horizontal_flywheel_->get_current_output_position();
output_run_.y = (uint16_t)(vertical_flywheel_->get_current_output_position() / vertical_flywheel_output_divider_);
}
else
{
_openGL_output_builder->lock_output();
openGL_output_builder_.lock_output();
// Get and write all those previously unwritten output ys
uint16_t output_y = _openGL_output_builder->get_composite_output_y();
uint16_t output_y = openGL_output_builder_.get_composite_output_y();
size_t size;
uint8_t *buffered_lines = _openGL_output_builder->get_buffered_source_runs(size);
uint8_t *buffered_lines = openGL_output_builder_.get_buffered_source_runs(size);
for(size_t position = 0; position < size; position += SourceVertexSize)
{
(*(uint16_t *)&buffered_lines[position + SourceVertexOffsetOfOutputStart + 2]) = output_y;
}
// Construct the output run
uint8_t *next_run = _openGL_output_builder->get_next_output_run();
output_x1() = _output_run.x1;
output_position_y() = _output_run.y;
uint8_t *next_run = openGL_output_builder_.get_next_output_run();
output_x1() = output_run_.x1;
output_position_y() = output_run_.y;
output_tex_y() = output_y;
output_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position();
_openGL_output_builder->complete_output_run();
output_x2() = (uint16_t)horizontal_flywheel_->get_current_output_position();
openGL_output_builder_.complete_output_run();
_openGL_output_builder->unlock_output();
openGL_output_builder_.unlock_output();
}
_is_writing_composite_run ^= true;
is_writing_composite_run_ ^= true;
}
}
if(next_run_length == time_until_horizontal_sync_event && next_horizontal_sync_event == Flywheel::SyncEvent::StartRetrace)
{
_openGL_output_builder->increment_composite_output_y();
openGL_output_builder_.increment_composite_output_y();
}
// if this is vertical retrace then adcance a field
if(next_run_length == time_until_vertical_sync_event && next_vertical_sync_event == Flywheel::SyncEvent::EndRetrace)
{
if(_delegate)
if(delegate_)
{
_frames_since_last_delegate_call++;
if(_frames_since_last_delegate_call == 20)
frames_since_last_delegate_call_++;
if(frames_since_last_delegate_call_ == 20)
{
_delegate->crt_did_end_batch_of_frames(this, _frames_since_last_delegate_call, _vertical_flywheel->get_and_reset_number_of_surprises());
_frames_since_last_delegate_call = 0;
delegate_->crt_did_end_batch_of_frames(this, frames_since_last_delegate_call_, vertical_flywheel_->get_and_reset_number_of_surprises());
frames_since_last_delegate_call_ = 0;
}
}
}
@ -260,31 +260,31 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
void CRT::output_scan(const Scan *const scan)
{
const bool this_is_sync = (scan->type == Scan::Type::Sync);
const bool is_trailing_edge = (_is_receiving_sync && !this_is_sync);
const bool is_leading_edge = (!_is_receiving_sync && this_is_sync);
_is_receiving_sync = this_is_sync;
const bool is_trailing_edge = (is_receiving_sync_ && !this_is_sync);
const bool is_leading_edge = (!is_receiving_sync_ && this_is_sync);
is_receiving_sync_ = this_is_sync;
// This introduces a blackout period close to the expected vertical sync point in which horizontal syncs are not
// recognised, effectively causing the horizontal flywheel to freewheel during that period. This attempts to seek
// the problem that vertical sync otherwise often starts halfway through a scanline, which confuses the horizontal
// flywheel. I'm currently unclear whether this is an accurate solution to this problem.
const bool hsync_requested = is_leading_edge && !_vertical_flywheel->is_near_expected_sync();
const bool vsync_requested = is_trailing_edge && (_sync_capacitor_charge_level >= _sync_capacitor_charge_threshold);
const bool hsync_requested = is_leading_edge && !vertical_flywheel_->is_near_expected_sync();
const bool vsync_requested = is_trailing_edge && (sync_capacitor_charge_level_ >= sync_capacitor_charge_threshold_);
// simplified colour burst logic: if it's within the back porch we'll take it
if(scan->type == Scan::Type::ColourBurst)
{
if(_horizontal_flywheel->get_current_time() < (_horizontal_flywheel->get_standard_period() * 12) >> 6)
if(horizontal_flywheel_->get_current_time() < (horizontal_flywheel_->get_standard_period() * 12) >> 6)
{
_colour_burst_time = (uint16_t)_horizontal_flywheel->get_current_time();
_colour_burst_phase = scan->phase;
_colour_burst_amplitude = scan->amplitude;
colour_burst_time_ = (uint16_t)horizontal_flywheel_->get_current_time();
colour_burst_phase_ = scan->phase;
colour_burst_amplitude_ = scan->amplitude;
}
}
// TODO: inspect raw data for potential colour burst if required
_sync_period = _is_receiving_sync ? (_sync_period + scan->number_of_cycles) : 0;
sync_period_ = is_receiving_sync_ ? (sync_period_ + scan->number_of_cycles) : 0;
advance_cycles(scan->number_of_cycles, scan->source_divider, hsync_requested, vsync_requested, this_is_sync, scan->type, scan->tex_x, scan->tex_y);
}
@ -311,13 +311,13 @@ void CRT::output_blank(unsigned int number_of_cycles)
void CRT::output_level(unsigned int number_of_cycles)
{
if(!_openGL_output_builder->input_buffer_is_full())
if(!openGL_output_builder_.input_buffer_is_full())
{
Scan scan {
.type = Scan::Type::Level,
.number_of_cycles = number_of_cycles,
.tex_x = _openGL_output_builder->get_last_write_x_posititon(),
.tex_y = _openGL_output_builder->get_last_write_y_posititon()
.tex_x = openGL_output_builder_.get_last_write_x_posititon(),
.tex_y = openGL_output_builder_.get_last_write_y_posititon()
};
output_scan(&scan);
}
@ -344,14 +344,14 @@ void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint
void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider)
{
if(!_openGL_output_builder->input_buffer_is_full())
if(!openGL_output_builder_.input_buffer_is_full())
{
_openGL_output_builder->reduce_previous_allocation_to(number_of_cycles / source_divider);
openGL_output_builder_.reduce_previous_allocation_to(number_of_cycles / source_divider);
Scan scan {
.type = Scan::Type::Data,
.number_of_cycles = number_of_cycles,
.tex_x = _openGL_output_builder->get_last_write_x_posititon(),
.tex_y = _openGL_output_builder->get_last_write_y_posititon(),
.tex_x = openGL_output_builder_.get_last_write_x_posititon(),
.tex_y = openGL_output_builder_.get_last_write_y_posititon(),
.source_divider = source_divider
};
output_scan(&scan);
@ -368,15 +368,15 @@ void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider
Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio)
{
first_cycle_after_sync *= _time_multiplier;
number_of_cycles *= _time_multiplier;
first_cycle_after_sync *= time_multiplier_;
number_of_cycles *= time_multiplier_;
first_line_after_sync -= 2;
number_of_lines += 4;
// determine prima facie x extent
unsigned int horizontal_period = _horizontal_flywheel->get_standard_period();
unsigned int horizontal_scan_period = _horizontal_flywheel->get_scan_period();
unsigned int horizontal_period = horizontal_flywheel_->get_standard_period();
unsigned int horizontal_scan_period = horizontal_flywheel_->get_scan_period();
unsigned int horizontal_retrace_period = horizontal_period - horizontal_scan_period;
// make sure that the requested range is visible
@ -387,8 +387,8 @@ Outputs::CRT::Rect CRT::get_rect_for_area(int first_line_after_sync, int number_
float width = (float)number_of_cycles / (float)horizontal_scan_period;
// determine prima facie y extent
unsigned int vertical_period = _vertical_flywheel->get_standard_period();
unsigned int vertical_scan_period = _vertical_flywheel->get_scan_period();
unsigned int vertical_period = vertical_flywheel_->get_standard_period();
unsigned int vertical_scan_period = vertical_flywheel_->get_scan_period();
unsigned int vertical_retrace_period = vertical_period - vertical_scan_period;
// make sure that the requested range is visible

View File

@ -14,6 +14,8 @@
#include "CRTTypes.hpp"
#include "Internals/Flywheel.hpp"
#include "Internals/CRTOpenGL.hpp"
#include "Internals/ArrayBuilder.hpp"
#include "Internals/TextureBuilder.hpp"
namespace Outputs {
namespace CRT {
@ -27,26 +29,22 @@ class Delegate {
class CRT {
private:
CRT(unsigned int common_output_divisor);
CRT(unsigned int common_output_divisor, unsigned int buffer_depth);
// the incoming clock lengths will be multiplied by something to give at least 1000
// sample points per line
unsigned int _time_multiplier;
const unsigned int _common_output_divisor;
// fundamental creator-specified properties
unsigned int _cycles_per_line;
unsigned int _height_of_display;
unsigned int time_multiplier_;
const unsigned int common_output_divisor_;
// the two flywheels regulating scanning
std::unique_ptr<Flywheel> _horizontal_flywheel, _vertical_flywheel;
uint16_t _vertical_flywheel_output_divider;
std::unique_ptr<Flywheel> horizontal_flywheel_, vertical_flywheel_;
uint16_t vertical_flywheel_output_divider_;
// elements of sync separation
bool _is_receiving_sync; // true if the CRT is currently receiving sync (i.e. this is for edge triggering of horizontal sync)
int _sync_capacitor_charge_level; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
int _sync_capacitor_charge_threshold; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
unsigned int _sync_period;
bool is_receiving_sync_; // true if the CRT is currently receiving sync (i.e. this is for edge triggering of horizontal sync)
int sync_capacitor_charge_level_; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
int sync_capacitor_charge_threshold_; // this charges up during times of sync and depletes otherwise; needs to hit a required threshold to trigger a vertical sync
unsigned int sync_period_;
// each call to output_* generates a scan. A two-slot queue for scans allows edge extensions.
struct Scan {
@ -66,9 +64,9 @@ class CRT {
};
void output_scan(const Scan *scan);
uint8_t _colour_burst_phase, _colour_burst_amplitude;
uint16_t _colour_burst_time;
bool _is_writing_composite_run;
uint8_t colour_burst_phase_, colour_burst_amplitude_;
uint16_t colour_burst_time_;
bool is_writing_composite_run_;
// the outer entry point for dispatching output_sync, output_blank, output_level and output_data
void advance_cycles(unsigned int number_of_cycles, unsigned int source_divider, bool hsync_requested, bool vsync_requested, const bool vsync_charging, const Scan::Type type, uint16_t tex_x, uint16_t tex_y);
@ -78,17 +76,19 @@ class CRT {
Flywheel::SyncEvent get_next_vertical_sync_event(bool vsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced);
Flywheel::SyncEvent get_next_horizontal_sync_event(bool hsync_is_requested, unsigned int cycles_to_run_for, unsigned int *cycles_advanced);
// OpenGL state, kept behind an opaque pointer to avoid inclusion of the GL headers here.
std::unique_ptr<OpenGLOutputBuilder> _openGL_output_builder;
// OpenGL state
OpenGLOutputBuilder openGL_output_builder_;
ArrayBuilder array_builder_;
TextureBuilder texture_builder_;
// temporary storage used during the construction of output runs
struct {
uint16_t x1, y;
} _output_run;
} output_run_;
// The delegate
Delegate *_delegate;
unsigned int _frames_since_last_delegate_call;
Delegate *delegate_;
unsigned int frames_since_last_delegate_call_;
public:
/*! Constructs the CRT with a specified clock rate, height and colour subcarrier frequency.
@ -194,7 +194,7 @@ class CRT {
*/
inline uint8_t *allocate_write_area(size_t required_length)
{
return _openGL_output_builder->allocate_write_area(required_length);
return openGL_output_builder_.allocate_write_area(required_length);
}
/*! Causes appropriate OpenGL or OpenGL ES calls to be issued in order to draw the current CRT state.
@ -202,7 +202,7 @@ class CRT {
*/
inline void draw_frame(unsigned int output_width, unsigned int output_height, bool only_if_dirty)
{
_openGL_output_builder->draw_frame(output_width, output_height, only_if_dirty);
openGL_output_builder_.draw_frame(output_width, output_height, only_if_dirty);
}
/*! Tells the CRT that the next call to draw_frame will occur on a different OpenGL context than
@ -214,7 +214,7 @@ class CRT {
*/
inline void set_openGL_context_will_change(bool should_delete_resources)
{
_openGL_output_builder->set_openGL_context_will_change(should_delete_resources);
openGL_output_builder_.set_openGL_context_will_change(should_delete_resources);
}
/*! Sets a function that will map from whatever data the machine provided to a composite signal.
@ -226,7 +226,7 @@ class CRT {
*/
inline void set_composite_sampling_function(const char *shader)
{
_openGL_output_builder->set_composite_sampling_function(shader);
openGL_output_builder_.set_composite_sampling_function(shader);
}
/*! Sets a function that will map from whatever data the machine provided to an RGB signal.
@ -244,24 +244,24 @@ class CRT {
*/
inline void set_rgb_sampling_function(const char *shader)
{
_openGL_output_builder->set_rgb_sampling_function(shader);
openGL_output_builder_.set_rgb_sampling_function(shader);
}
inline void set_output_device(OutputDevice output_device)
{
_openGL_output_builder->set_output_device(output_device);
openGL_output_builder_.set_output_device(output_device);
}
inline void set_visible_area(Rect visible_area)
{
_openGL_output_builder->set_visible_area(visible_area);
openGL_output_builder_.set_visible_area(visible_area);
}
Rect get_rect_for_area(int first_line_after_sync, int number_of_lines, int first_cycle_after_sync, int number_of_cycles, float aspect_ratio);
inline void set_delegate(Delegate *delegate)
{
_delegate = delegate;
delegate_ = delegate;
}
};