1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-30 23:29:08 +00:00

Permitted a wider error window on vertical sync, tidied things up a little and started trying to move towards full implementation of the OpenGL contract.

This commit is contained in:
Thomas Harte 2016-05-11 22:11:01 -04:00
parent 4b3c4082d2
commit 6d65bc9b3a
5 changed files with 32 additions and 10 deletions

View File

@ -33,7 +33,7 @@ void Machine::setup_output(float aspect_ratio)
// this is the NTSC phase offset function; see below for PAL // this is the NTSC phase offset function; see below for PAL
_crt->set_composite_sampling_function( _crt->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)\n" "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
"{" "{"
"uint c = texture(texID, coordinate).r;" "uint c = texture(texID, coordinate).r;"
"uint y = (c >> 1) & 7u;" "uint y = (c >> 1) & 7u;"
@ -49,14 +49,14 @@ void Machine::switch_region()
{ {
// the PAL function // the PAL function
_crt->set_composite_sampling_function( _crt->set_composite_sampling_function(
"float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)\n" "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)"
"{" "{"
"uint c = texture(texID, coordinate).r;" "uint c = texture(texID, coordinate).r;"
"uint y = (c >> 1) & 7u;" "uint y = (c >> 1) & 7u;"
"uint iPhase = (c >> 4);" "uint iPhase = (c >> 4);"
"float phaseOffset = (0.5 + 2.0 * (float(iPhase&1u) - 0.5) * (float((iPhase >> 1) + (iPhase&1u)) / 14.0));" "float phaseOffset = (0.5 + 2.0 * (float(iPhase&1u) - 0.5) * (float((iPhase >> 1) + (iPhase&1u)) / 14.0));"
"return (float(y) / 7.0) * (1.0 - amplitude) + step(2, iPhase) * step(iPhase, 13) * amplitude * cos(phase + 6.283185308 * phaseOffset);" "return (float(y) / 7.0) * (1.0 - amplitude) + step(4, (iPhase + 2u) & 15u) * amplitude * cos(phase + 6.283185308 * phaseOffset);"
"}"); "}");
_crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1); _crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1);
} }

View File

@ -38,8 +38,8 @@ void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_di
_sync_capacitor_charge_threshold = (int)(syncCapacityLineChargeThreshold * _cycles_per_line); _sync_capacitor_charge_threshold = (int)(syncCapacityLineChargeThreshold * _cycles_per_line);
// create the two flywheels // create the two flywheels
_horizontal_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6)); _horizontal_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6, _cycles_per_line >> 6));
_vertical_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line)); _vertical_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line, (_cycles_per_line * height_of_display) >> 3));
// figure out the divisor necessary to get the horizontal flywheel into a 16-bit range // 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); unsigned int real_clock_scan_period = (_cycles_per_line * height_of_display) / (_time_multiplier * _common_output_divisor);

View File

@ -325,28 +325,47 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height); glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glActiveTexture(pixel_accumulation_texture_unit);
framebuffer->bind_texture();
framebuffer->draw((float)output_width / (float)output_height); framebuffer->draw((float)output_width / (float)output_height);
_fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); _fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
_output_mutex->unlock(); _output_mutex->unlock();
} }
void OpenGLOutputBuilder::reset_all_OpenGL_state()
{
composite_input_shader_program = nullptr;
composite_separation_filter_program = nullptr;
composite_y_filter_shader_program = nullptr;
composite_chrominance_filter_shader_program = nullptr;
rgb_input_shader_program = nullptr;
rgb_filter_shader_program = nullptr;
output_shader_program = nullptr;
framebuffer = nullptr;
}
void OpenGLOutputBuilder::set_openGL_context_will_change(bool should_delete_resources) void OpenGLOutputBuilder::set_openGL_context_will_change(bool should_delete_resources)
{ {
_output_mutex->lock();
reset_all_OpenGL_state();
_output_mutex->unlock();
} }
void OpenGLOutputBuilder::set_composite_sampling_function(const char *shader) void OpenGLOutputBuilder::set_composite_sampling_function(const char *shader)
{ {
_output_mutex->lock(); _output_mutex->lock();
_composite_shader = strdup(shader); _composite_shader = strdup(shader);
output_shader_program = nullptr; reset_all_OpenGL_state();
framebuffer = nullptr;
_output_mutex->unlock(); _output_mutex->unlock();
} }
void OpenGLOutputBuilder::set_rgb_sampling_function(const char *shader) void OpenGLOutputBuilder::set_rgb_sampling_function(const char *shader)
{ {
_output_mutex->lock();
_rgb_shader = strdup(shader); _rgb_shader = strdup(shader);
reset_all_OpenGL_state();
_output_mutex->unlock();
} }
#pragma mark - Program compilation #pragma mark - Program compilation

View File

@ -85,6 +85,9 @@ class OpenGLOutputBuilder {
void set_timing_uniforms(); void set_timing_uniforms();
void set_colour_space_uniforms(); void set_colour_space_uniforms();
void establish_OpenGL_state();
void reset_all_OpenGL_state();
public: public:
OpenGLOutputBuilder(unsigned int buffer_depth); OpenGLOutputBuilder(unsigned int buffer_depth);
~OpenGLOutputBuilder(); ~OpenGLOutputBuilder();

View File

@ -27,13 +27,13 @@ struct Flywheel
Constructs an instance of @c Flywheel. Constructs an instance of @c Flywheel.
@param standard_period The expected amount of time between one synchronisation and the next. @param standard_period The expected amount of time between one synchronisation and the next.
@param retrace_time The amount of time it takes to complete a retrace. @param retrace_time The amount of time it takes to complete a retrace.
@param sync_error_window The permitted deviation of sync timings from the norm.
*/ */
Flywheel(unsigned int standard_period, unsigned int retrace_time) : Flywheel(unsigned int standard_period, unsigned int retrace_time, unsigned int sync_error_window) :
_standard_period(standard_period), _standard_period(standard_period),
_retrace_time(retrace_time), _retrace_time(retrace_time),
_sync_error_window(standard_period >> 7), _sync_error_window(sync_error_window),
_counter(0), _counter(0),
_expected_next_sync(standard_period), _expected_next_sync(standard_period),
_counter_before_retrace(standard_period - retrace_time), _counter_before_retrace(standard_period - retrace_time),