From 7580d192d5b8275076f0c4dbe01cba8d87360245 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 14 Feb 2016 19:28:02 -0500 Subject: [PATCH] Fixes: now setting correct frame time estimate, properly enabling the timestamp attribute, and ensuring that the Electron flushes screen work at least once per host frame update. --- Machines/Electron/Electron.cpp | 6 ++++++ Machines/Electron/Electron.hpp | 2 ++ OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm | 1 + Outputs/CRT/CRTOpenGL.cpp | 14 ++++++++------ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 27b27ed79..df7578a3c 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -318,6 +318,12 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin return cycles; } +void Machine::update_output() +{ + update_display(); + update_audio(); +} + void Machine::set_tape(std::shared_ptr tape) { _tape.set_tape(tape); diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 4f9193e8d..6a2cb074e 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -151,6 +151,8 @@ class Machine: public CPU6502::Processor, Tape::Delegate { virtual void tape_did_change_interrupt_status(Tape *tape); + void update_output(); + private: inline void update_display(); diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index 4d0de1122..cc17d6ae4 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -18,6 +18,7 @@ - (void)doRunForNumberOfCycles:(int)numberOfCycles { _electron.run_for_cycles(numberOfCycles); + _electron.update_output(); } - (void)setOSROM:(nonnull NSData *)rom { diff --git a/Outputs/CRT/CRTOpenGL.cpp b/Outputs/CRT/CRTOpenGL.cpp index a6b9b070d..871c847a9 100644 --- a/Outputs/CRT/CRTOpenGL.cpp +++ b/Outputs/CRT/CRTOpenGL.cpp @@ -150,8 +150,9 @@ void CRT::draw_frame(unsigned int output_width, unsigned int output_height, bool glBindBuffer(GL_ARRAY_BUFFER, _openGL_state->arrayBuffers[run]); if(_run_builders[run]->uploaded_vertices != _run_builders[run]->number_of_vertices) { - // buffersubdata can only replace existing data, not grow the pool, so we'll just have to take this hit - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(_run_builders[run]->number_of_vertices * kCRTSizeOfVertex), &_run_builders[run]->_input_runs[0], GL_DYNAMIC_DRAW); + // glBufferSubData can only replace existing data, not grow the pool, so for now we'll just take this hit + uint8_t *data = &_run_builders[run]->_input_runs[0]; + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(_run_builders[run]->number_of_vertices * kCRTSizeOfVertex), data, GL_DYNAMIC_DRAW); _run_builders[run]->uploaded_vertices = _run_builders[run]->number_of_vertices; } @@ -299,17 +300,18 @@ char *CRT::get_fragment_shader() "in float lateralVarying;" "in float age;" "in vec2 shadowMaskCoordinates;" + "in vec2 srcCoordinatesVarying;" + "out vec4 fragColour;" "uniform sampler2D texID;" "uniform sampler2D shadowMaskTexID;" - "in vec2 srcCoordinatesVarying;" "\n%s\n" "void main(void)" "{" - "fragColour = vec4(rgb_sample(srcCoordinatesVarying).rgb, 1.3 - age);" + "fragColour = vec4(rgb_sample(srcCoordinatesVarying).rgb, 2.0 - age);" "}" , _rgb_shader); } @@ -348,7 +350,7 @@ void CRT::prepare_shader() glUniform1i(texIDUniform, 0); glUniform1i(shadowMaskTexIDUniform, 1); glUniform2f(textureSizeUniform, CRTInputBufferBuilderWidth, CRTInputBufferBuilderHeight); - glUniform1f(ticksPerFrameUniform, (GLfloat)(_cycles_per_line * _height_of_display * _time_multiplier)); + glUniform1f(ticksPerFrameUniform, (GLfloat)(_cycles_per_line * _height_of_display)); } void CRT::prepare_vertex_array() @@ -356,7 +358,7 @@ void CRT::prepare_vertex_array() glEnableVertexAttribArray((GLuint)_openGL_state->positionAttribute); glEnableVertexAttribArray((GLuint)_openGL_state->textureCoordinatesAttribute); glEnableVertexAttribArray((GLuint)_openGL_state->lateralAttribute); - glEnableVertexAttribArray((GLuint)_openGL_state->timestampBaseUniform); + glEnableVertexAttribArray((GLuint)_openGL_state->timestampAttribute); const GLsizei vertexStride = kCRTSizeOfVertex; glVertexAttribPointer((GLuint)_openGL_state->positionAttribute, 2, GL_UNSIGNED_SHORT, GL_TRUE, vertexStride, (void *)kCRTVertexOffsetOfPosition);