diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index 21e606fd9..a7bc9c96e 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -80,9 +80,9 @@ static int getCircularRanges(GLsizei *start_pointer, GLsizei *end_pointer, GLsiz } } -static GLsizei submitArrayData(GLuint buffer, uint8_t *source, GLsizei *length_pointer) +static GLsizei submitArrayData(GLuint buffer, uint8_t *source, size_t *length_pointer) { - GLsizei length = *length_pointer; + GLsizei length = (GLsizei)*length_pointer; glBindBuffer(GL_ARRAY_BUFFER, buffer); uint8_t *data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, length, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); @@ -114,16 +114,15 @@ OpenGLOutputBuilder::OpenGLOutputBuilder(unsigned int buffer_depth) : _cleared_composite_output_y(0), _composite_shader(nullptr), _rgb_shader(nullptr), - _output_buffer_data(new uint8_t[OutputVertexBufferDataSize]), - _source_buffer_data(new uint8_t[SourceVertexBufferDataSize]), - _output_buffer_data_pointer(0), - _source_buffer_data_pointer(0), _last_output_width(0), _last_output_height(0), _fence(nullptr) { _buffer_builder.reset(new CRTInputBufferBuilder(buffer_depth)); + _output_buffer.data.resize(OutputVertexBufferDataSize); + _source_buffer.data.resize(OutputVertexBufferDataSize); + glBlendFunc(GL_SRC_ALPHA, GL_CONSTANT_COLOR); glBlendColor(0.6f, 0.6f, 0.6f, 1.0f); @@ -224,10 +223,10 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out _output_mutex->lock(); // release the mapping, giving up on trying to draw if data has been lost - GLsizei submitted_output_data = submitArrayData(output_array_buffer, _output_buffer_data.get(), &_output_buffer_data_pointer); + GLsizei submitted_output_data = submitArrayData(output_array_buffer, _output_buffer.data.data(), &_output_buffer.pointer); // bind and flush the source array buffer - GLsizei submitted_source_data = submitArrayData(source_array_buffer, _source_buffer_data.get(), &_source_buffer_data_pointer); + GLsizei submitted_source_data = submitArrayData(source_array_buffer, _source_buffer.data.data(), &_source_buffer.pointer); // determine how many lines are newly reclaimed; they'll need to be cleared Range clearing_zones[2]; diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index 4f0a79a32..65a0b7423 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -20,6 +20,7 @@ #include "Shaders/IntermediateShader.hpp" #include +#include namespace Outputs { namespace CRT { @@ -93,6 +94,28 @@ class OpenGLOutputBuilder { OpenGLOutputBuilder(unsigned int buffer_depth); ~OpenGLOutputBuilder(); + inline uint8_t *get_next_source_run() + { + if(_source_buffer.pointer == SourceVertexBufferDataSize) return nullptr; + return &_source_buffer.data[_source_buffer.pointer]; + } + + inline void complete_source_run() + { + _source_buffer.pointer += SourceVertexSize; + } + + inline uint8_t *get_next_output_run() + { + if(_output_buffer.pointer == OutputVertexBufferDataSize) return nullptr; + return &_output_buffer.data[_output_buffer.pointer]; + } + + inline void complete_output_run() + { + _output_buffer.pointer += OutputVertexSize; + } + inline void set_colour_format(ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator) { _output_mutex->lock(); @@ -108,31 +131,9 @@ class OpenGLOutputBuilder { _visible_area = visible_area; } - inline uint8_t *get_next_source_run() - { - if(_source_buffer_data_pointer == SourceVertexBufferDataSize) return nullptr; - return &_source_buffer_data.get()[_source_buffer_data_pointer]; - } - - inline void complete_source_run() - { - _source_buffer_data_pointer += SourceVertexSize; - } - inline bool composite_output_run_has_room_for_vertex() { - return _output_buffer_data_pointer < OutputVertexBufferDataSize; - } - - inline uint8_t *get_next_output_run() - { - if(_output_buffer_data_pointer == OutputVertexBufferDataSize) return nullptr; - return &_output_buffer_data.get()[_output_buffer_data_pointer]; - } - - inline void complete_output_run() - { - _output_buffer_data_pointer += OutputVertexSize; + return _output_buffer.pointer < OutputVertexBufferDataSize; } inline void lock_output() @@ -199,11 +200,11 @@ class OpenGLOutputBuilder { void set_output_device(OutputDevice output_device); void set_timing(unsigned int input_frequency, unsigned int cycles_per_line, unsigned int height_of_display, unsigned int horizontal_scan_period, unsigned int vertical_scan_period, unsigned int vertical_period_divider); - std::unique_ptr _source_buffer_data; - GLsizei _source_buffer_data_pointer; - - std::unique_ptr _output_buffer_data; - GLsizei _output_buffer_data_pointer; + struct Buffer { + std::vector data; + size_t pointer; + Buffer() : pointer(0) {} + } _line_buffer, _source_buffer, _output_buffer; GLsync _fence; };