From 284b3100743b057e024a81401da99f537a4a8a6d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 5 May 2016 19:52:05 -0400 Subject: [PATCH] Attempted to implement end-of-buffer tests for all stages. --- OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m | 10 ++++++++-- Outputs/CRT/CRT.cpp | 15 +++++++++------ Outputs/CRT/Internals/CRTConstants.hpp | 4 ++-- Outputs/CRT/Internals/CRTInputBufferBuilder.cpp | 2 +- Outputs/CRT/Internals/CRTOpenGL.cpp | 1 + Outputs/CRT/Internals/CRTOpenGL.hpp | 7 +++++++ 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index 8e41cc50e..240b63f22 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -43,8 +43,14 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) { - CSOpenGLView *const view = (__bridge CSOpenGLView *)displayLinkContext; - [view drawAtTime:now frequency:CVDisplayLinkGetActualOutputVideoRefreshPeriod(displayLink)]; + static int d = 0; + d++; + if(d == 10) + { + d = 0; + CSOpenGLView *const view = (__bridge CSOpenGLView *)displayLinkContext; + [view drawAtTime:now frequency:CVDisplayLinkGetActualOutputVideoRefreshPeriod(displayLink)]; + } return kCVReturnSuccess; } diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 9a1ef52a5..a14f6a29d 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -130,7 +130,7 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi 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) + if(is_output_segment && !_openGL_output_builder->composite_output_buffer_is_full()) { next_run = _openGL_output_builder->get_next_source_run(); } @@ -190,12 +190,15 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi { uint8_t *next_run = _openGL_output_builder->get_next_output_run(); - output_position_x(0) = output_position_x(1) = output_position_x(2) = (uint16_t)_horizontal_flywheel->get_current_output_position(); - output_position_y(0) = output_position_y(1) = output_position_y(2) = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider); - output_tex_x(0) = output_tex_x(1) = output_tex_x(2) = (uint16_t)_horizontal_flywheel->get_current_output_position(); - output_tex_y(0) = output_tex_y(1) = output_tex_y(2) = _openGL_output_builder->get_composite_output_y(); + if(next_run) + { + output_position_x(0) = output_position_x(1) = output_position_x(2) = (uint16_t)_horizontal_flywheel->get_current_output_position(); + output_position_y(0) = output_position_y(1) = output_position_y(2) = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider); + output_tex_x(0) = output_tex_x(1) = output_tex_x(2) = (uint16_t)_horizontal_flywheel->get_current_output_position(); + output_tex_y(0) = output_tex_y(1) = output_tex_y(2) = _openGL_output_builder->get_composite_output_y(); - _openGL_output_builder->complete_output_run(3); + _openGL_output_builder->complete_output_run(3); + } _is_writing_composite_run ^= true; } diff --git a/Outputs/CRT/Internals/CRTConstants.hpp b/Outputs/CRT/Internals/CRTConstants.hpp index 5d17b5ad3..65fc45f12 100644 --- a/Outputs/CRT/Internals/CRTConstants.hpp +++ b/Outputs/CRT/Internals/CRTConstants.hpp @@ -33,11 +33,11 @@ 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 = 8192; +const GLsizei InputBufferBuilderHeight = 1024; // This is the size of the intermediate buffers used during composite to RGB conversion const GLsizei IntermediateBufferWidth = 2048; -const GLsizei IntermediateBufferHeight = 2048; +const GLsizei IntermediateBufferHeight = 1024; // Some internal buffer sizes const GLsizeiptr OutputVertexBufferDataSize = 5990400; // a multiple of 6 * OutputVertexSize diff --git a/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp b/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp index c4d6784c3..15ad5e617 100644 --- a/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp +++ b/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp @@ -30,7 +30,7 @@ void CRTInputBufferBuilder::allocate_write_area(size_t required_length) { _last_allocation_amount = required_length; - if(_next_write_x_position + required_length + 2 > InputBufferBuilderWidth) +// if(_next_write_x_position + required_length + 2 > InputBufferBuilderWidth) { _next_write_x_position = 0; _next_write_y_position++; diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index d81893c37..4b8afc1dd 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -375,6 +375,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height); glClear(GL_COLOR_BUFFER_BIT); framebuffer->draw((float)output_width / (float)output_height); +// compositeTexture->draw((float)output_width / (float)output_height); // drawing commands having been issued, reclaim the array buffer pointer glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer); diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index 8c5a5a11a..8812abcc0 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -106,6 +106,7 @@ class OpenGLOutputBuilder { inline uint8_t *get_next_source_run() { + if(_source_buffer_data_pointer == _drawn_source_buffer_data_pointer + SourceVertexBufferDataSize) return nullptr; _output_mutex->lock(); return &_source_buffer_data[_source_buffer_data_pointer % SourceVertexBufferDataSize]; } @@ -118,6 +119,7 @@ class OpenGLOutputBuilder { inline uint8_t *get_next_output_run() { + if(_output_buffer_data_pointer == _drawn_output_buffer_data_pointer + OutputVertexBufferDataSize) return nullptr; _output_mutex->lock(); return &_output_buffer_data[_output_buffer_data_pointer % OutputVertexBufferDataSize]; } @@ -133,6 +135,11 @@ class OpenGLOutputBuilder { return _output_device; } + inline bool composite_output_buffer_is_full() + { + return _composite_src_output_y == _cleared_composite_output_y + IntermediateBufferHeight; + } + inline uint16_t get_composite_output_y() { return _composite_src_output_y % IntermediateBufferHeight;