From dce52d740dbd3ca259c5fc59308fab50aae0c42b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 11 Nov 2018 23:23:42 -0500 Subject: [PATCH] Finally gets some pixels back on screen. For now, just the raw scans, direct to the framebuffer, with no intermediate processing. But it seems to prove that at least some of the proper data is reaching the GPU. --- .../Clock Signal.xcodeproj/project.pbxproj | 12 ++++---- Outputs/OpenGL/ScanTarget.cpp | 28 +++++++++++++++++-- Outputs/OpenGL/ScanTarget.hpp | 5 +++- ...pp => ScanTargetVertexArrayAttributes.cpp} | 17 ++++++++++- 4 files changed, 51 insertions(+), 11 deletions(-) rename Outputs/OpenGL/{ScanTargetVertexArrayAttributs.cpp => ScanTargetVertexArrayAttributes.cpp} (85%) diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 58d69b723..f29712c67 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -624,8 +624,8 @@ 4BD424E82193B5830097291A /* Rectangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD424E22193B5820097291A /* Rectangle.cpp */; }; 4BD468F71D8DF41D0084958B /* 1770.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD468F51D8DF41D0084958B /* 1770.cpp */; }; 4BD4A8D01E077FD20020D856 /* PCMTrackTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BD4A8CF1E077FD20020D856 /* PCMTrackTests.mm */; }; - 4BD5D2682199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp */; }; - 4BD5D2692199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp */; }; + 4BD5D2682199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp */; }; + 4BD5D2692199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp */; }; 4BD5F1951D13528900631CD1 /* CSBestEffortUpdater.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5F1941D13528900631CD1 /* CSBestEffortUpdater.mm */; }; 4BD61664206B2AC800236112 /* QuickLoadOptions.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4BD61662206B2AC700236112 /* QuickLoadOptions.xib */; }; 4BD67DCB209BE4D700AB2146 /* StaticAnalyser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD67DCA209BE4D600AB2146 /* StaticAnalyser.cpp */; }; @@ -1387,7 +1387,7 @@ 4BD468F51D8DF41D0084958B /* 1770.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = 1770.cpp; path = 1770/1770.cpp; sourceTree = ""; }; 4BD468F61D8DF41D0084958B /* 1770.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = 1770.hpp; path = 1770/1770.hpp; sourceTree = ""; }; 4BD4A8CF1E077FD20020D856 /* PCMTrackTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PCMTrackTests.mm; sourceTree = ""; }; - 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScanTargetVertexArrayAttributs.cpp; sourceTree = ""; }; + 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScanTargetVertexArrayAttributes.cpp; sourceTree = ""; }; 4BD5F1931D13528900631CD1 /* CSBestEffortUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSBestEffortUpdater.h; path = Updater/CSBestEffortUpdater.h; sourceTree = ""; }; 4BD5F1941D13528900631CD1 /* CSBestEffortUpdater.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CSBestEffortUpdater.mm; path = Updater/CSBestEffortUpdater.mm; sourceTree = ""; }; 4BD601A920D89F2A00CBCE57 /* Log.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Log.hpp; path = ../../Outputs/Log.hpp; sourceTree = ""; }; @@ -3027,7 +3027,7 @@ children = ( 4BD191DC219113B80042E144 /* CRTOpenGL.cpp */, 4BD191F22191180E0042E144 /* ScanTarget.cpp */, - 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp */, + 4BD5D2672199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp */, 4BD191D8219113B80042E144 /* TextureBuilder.cpp */, 4BD191D9219113B80042E144 /* OpenGL.hpp */, 4BD191F32191180E0042E144 /* ScanTarget.hpp */, @@ -3672,7 +3672,7 @@ 4B894521201967B4007DE474 /* StaticAnalyser.cpp in Sources */, 4B7F188F2154825E00388727 /* MasterSystem.cpp in Sources */, 4B055AA51FAE85EF0060FFFF /* Encoder.cpp in Sources */, - 4BD5D2692199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp in Sources */, + 4BD5D2692199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp in Sources */, 4B894529201967B4007DE474 /* Disk.cpp in Sources */, 4B055AEA1FAE9B990060FFFF /* 6502Storage.cpp in Sources */, 4B055AA71FAE85EF0060FFFF /* SegmentParser.cpp in Sources */, @@ -3862,7 +3862,7 @@ 4B0333AF2094081A0050B93D /* AppleDSK.cpp in Sources */, 4B894518201967B4007DE474 /* ConfidenceCounter.cpp in Sources */, 4B89452E201967B4007DE474 /* StaticAnalyser.cpp in Sources */, - 4BD5D2682199148100DDF17D /* ScanTargetVertexArrayAttributs.cpp in Sources */, + 4BD5D2682199148100DDF17D /* ScanTargetVertexArrayAttributes.cpp in Sources */, 4B38F3481F2EC11D00D9235D /* AmstradCPC.cpp in Sources */, 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */, 4B4518A41F75FD1C00926311 /* OricMFMDSK.cpp in Sources */, diff --git a/Outputs/OpenGL/ScanTarget.cpp b/Outputs/OpenGL/ScanTarget.cpp index 291efcddf..b9e7d323f 100644 --- a/Outputs/OpenGL/ScanTarget.cpp +++ b/Outputs/OpenGL/ScanTarget.cpp @@ -81,6 +81,18 @@ ScanTarget::ScanTarget() : glGenTextures(1, &write_area_texture_name_); glGenVertexArrays(1, &scan_vertex_array_); + + glBindVertexArray(scan_vertex_array_); + glBindBuffer(GL_ARRAY_BUFFER, scan_buffer_name_); + test_shader_.reset(new Shader( + globals(ShaderType::Scan), + "#version 150\n" + "out vec4 fragColour;" + "void main(void) {" + "fragColour = vec4(1.0);" + "}" + )); + enable_vertex_attributes(ShaderType::Scan, *test_shader_); } ScanTarget::~ScanTarget() { @@ -104,6 +116,10 @@ void ScanTarget::set_modals(Modals modals) { write_pointers_.scan_buffer = 0; write_pointers_.write_area = 0; } + + // TODO: this, but not to the test shader. + test_shader_->set_uniform("scale", GLfloat(modals.output_scale.x), GLfloat(modals.output_scale.y)); + test_shader_->set_uniform("rowHeight", GLfloat(1.0f / modals.expected_vertical_lines)); } Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() { @@ -228,17 +244,19 @@ void ScanTarget::announce(Event event, uint16_t x, uint16_t y) { } void ScanTarget::draw() { + glClear(GL_COLOR_BUFFER_BIT); + // Grab the current read and submit pointers. const auto submit_pointers = submit_pointers_.load(); const auto read_pointers = read_pointers_.load(); // Submit scans. if(submit_pointers.scan_buffer != read_pointers.scan_buffer) { - const auto buffer_size = scan_buffer_.size() * sizeof(Scan); uint8_t *destination = static_cast( glMapBufferRange(GL_ARRAY_BUFFER, 0, GLsizeiptr(buffer_size), GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT) ); + assert(destination); if(submit_pointers.scan_buffer > read_pointers.scan_buffer) { // Submit the direct region from the submit pointer to the read pointer. @@ -323,7 +341,11 @@ void ScanTarget::draw() { // the submit pointer location. read_pointers_.store(submit_pointers); - glClear(GL_COLOR_BUFFER_BIT); -// ::OpenGL::Rectangle rect(-0.8f, -0.8f, 1.6f, 1.6f); + // TEST: draw all scans. + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindVertexArray(scan_vertex_array_); + test_shader_->bind(); + glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, GLsizei(scan_buffer_.size())); +// Rectangle rect(-0.8f, -0.8f, 1.6f, 1.6f); // rect.draw(1, 1, 0); } diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index 8b0b521cf..897f129b0 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -110,7 +110,8 @@ class ScanTarget: public Outputs::Display::ScanTarget { /*! @returns A string containing GLSL code describing the standard set of @c in and @c uniform variables to bind to the relevant struct - from [...]OpenGL::ScanTarget. + from [...]OpenGL::ScanTarget and a vertex function to provide + the standard varyings. */ std::string globals(ShaderType type); @@ -119,6 +120,8 @@ class ScanTarget: public Outputs::Display::ScanTarget { globals for shaders of @c type to @c target. */ void enable_vertex_attributes(ShaderType type, Shader &target); + + std::unique_ptr test_shader_; }; } diff --git a/Outputs/OpenGL/ScanTargetVertexArrayAttributs.cpp b/Outputs/OpenGL/ScanTargetVertexArrayAttributes.cpp similarity index 85% rename from Outputs/OpenGL/ScanTargetVertexArrayAttributs.cpp rename to Outputs/OpenGL/ScanTargetVertexArrayAttributes.cpp index 41aa86324..9c59f689c 100644 --- a/Outputs/OpenGL/ScanTargetVertexArrayAttributs.cpp +++ b/Outputs/OpenGL/ScanTargetVertexArrayAttributes.cpp @@ -14,6 +14,8 @@ std::string ScanTarget::globals(ShaderType type) { switch(type) { case ShaderType::Scan: return + "#version 150\n" + "uniform vec2 scale;" "uniform float rowHeight;" "uniform mat3 lumaChromaToRGB;" @@ -28,10 +30,23 @@ std::string ScanTarget::globals(ShaderType type) { "in float endCompositeAngle;" "in float dataY;" - "in float lineY;"; + "in float lineY;" + + "void main(void) {" + "float lateral = float(gl_VertexID & 1);" + "float longitudinal = float((gl_VertexID & 2) >> 1);" + + "vec2 vPosition = vec2(" + "mix(startPoint.x, endPoint.x, lateral)," + "mix(startPoint.y, endPoint.y, longitudinal)" + ") / scale;" + "gl_Position = vec4(vPosition, 0.0, 1.0);" + "}"; case ShaderType::Line: return + "#version 150\n" + "in vec2 startPoint;" "in vec2 endPoint;"; }