diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 29fbbb90e..7d82e8e30 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -64,6 +64,7 @@ void Machine::setup_output() "uint texValue = texture(sampler, coordinate).r;" "texValue >>= 4 - (int(icoordinate.x * 2) & 1)*4;" "return vec4(texValue & 4u, texValue & 2u, texValue & 1u, 1.0);" +// "return vec4(1.0);" "}"); _crt->set_output_device(Outputs::CRT::Monitor); diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index b3407d69e..d7bf891c0 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -132,7 +132,7 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi uint8_t *next_run = nullptr; if(is_output_segment) { - next_run = _openGL_output_builder->get_next_output_run(); + next_run = (_openGL_output_builder->get_output_device() == Monitor) ? _openGL_output_builder->get_next_output_run() : _openGL_output_builder->get_next_source_run(); } // Vertex output is arranged for triangle strips, as: @@ -195,18 +195,22 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi output_position_y(3) = output_position_y(4) = output_position_y(5) = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider); output_timestamp(3) = output_timestamp(4) = output_timestamp(5) = _openGL_output_builder->get_current_field_time(); output_tex_x(3) = output_tex_x(4) = output_tex_x(5) = tex_x; + + _openGL_output_builder->complete_output_run(6); } else { source_input_position_x(1) = tex_x; source_output_position_x(1) = (uint16_t)_horizontal_flywheel->get_current_output_position(); + + _openGL_output_builder->complete_source_run(); } } - if(is_output_segment) - { - _openGL_output_builder->complete_output_run(); - } +// if(is_output_segment) +// { +// _openGL_output_builder->complete_output_run(6); +// } // if this is horizontal retrace then advance the output line counter and bookend an output run if(_openGL_output_builder->get_output_device() == Television) @@ -230,8 +234,9 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi output_lateral(0) = 0; output_lateral(1) = _is_writing_composite_run ? 1 : 0; output_lateral(2) = 1; + output_frame_id(0) = output_frame_id(1) = output_frame_id(2) = (uint8_t)_openGL_output_builder->get_current_field(); - _openGL_output_builder->complete_output_run(); + _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 c82540243..d14e7aee5 100644 --- a/Outputs/CRT/Internals/CRTConstants.hpp +++ b/Outputs/CRT/Internals/CRTConstants.hpp @@ -43,7 +43,7 @@ const int IntermediateBufferWidth = 2048; const int IntermediateBufferHeight = 2048; // Some internal -const GLsizeiptr InputVertexBufferDataSize = 262080; // a multiple of 6 * OutputVertexSize +const GLsizeiptr OutputVertexBufferDataSize = 262080; // a multiple of 6 * OutputVertexSize // Runs are divided discretely by vertical syncs in order to put a usable bounds on the uniform used to track diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index 0afd28d18..acd334fc5 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -112,7 +112,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer); - glBufferData(GL_ARRAY_BUFFER, InputVertexBufferDataSize, NULL, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, OutputVertexBufferDataSize, NULL, GL_STREAM_DRAW); _output_buffer_data_pointer = 0; glBindVertexArray(output_vertex_array); @@ -216,7 +216,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out { // draw GLsizei primitive_count = (GLsizei)(count / OutputVertexSize); - GLsizei max_count = (GLsizei)((InputVertexBufferDataSize - start) / OutputVertexSize); + GLsizei max_count = (GLsizei)((OutputVertexBufferDataSize - start) / OutputVertexSize); if(primitive_count < max_count) { glDrawArrays(GL_TRIANGLE_STRIP, (GLint)(start / OutputVertexSize), primitive_count); @@ -231,7 +231,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out // drawing commands having been issued, reclaim the array buffer pointer // _buffer_builder->move_to_new_line(); - _output_buffer_data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, InputVertexBufferDataSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); + _output_buffer_data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, OutputVertexBufferDataSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); _input_texture_data = (uint8_t *)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, _input_texture_array_size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); _output_mutex->unlock(); } diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index a2086d4f8..1144bd4ea 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -117,13 +117,13 @@ class OpenGLOutputBuilder { { _output_mutex->lock(); uint8_t *pointer = &_output_buffer_data[_output_buffer_data_pointer]; - _output_buffer_data_pointer = (_output_buffer_data_pointer + 6 * OutputVertexSize) % InputVertexBufferDataSize; return pointer; } - inline void complete_output_run() + inline void complete_output_run(size_t vertices_written) { - _run_builders[_run_write_pointer]->amount_of_data += 6 * OutputVertexSize; + _run_builders[_run_write_pointer]->amount_of_data += vertices_written * OutputVertexSize; + _output_buffer_data_pointer = (_output_buffer_data_pointer + vertices_written * OutputVertexSize) % OutputVertexBufferDataSize; _output_mutex->unlock(); }