From 008f50832c8f00f7ed10a9e498d647214b65aeae Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 10 Feb 2019 22:39:24 -0500 Subject: [PATCH] Fixed: the two shaders that use a common input array should use common bindings. --- Outputs/OpenGL/ScanTarget.cpp | 13 +++-- Outputs/OpenGL/ScanTarget.hpp | 3 +- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 56 +++++++++++----------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Outputs/OpenGL/ScanTarget.cpp b/Outputs/OpenGL/ScanTarget.cpp index 9ea0a6ae4..6c9375a12 100644 --- a/Outputs/OpenGL/ScanTarget.cpp +++ b/Outputs/OpenGL/ScanTarget.cpp @@ -306,6 +306,10 @@ void ScanTarget::setup_pipeline() { write_pointers_.write_area = 0; } + // Prepare to bind line shaders. + glBindVertexArray(line_vertex_array_); + glBindBuffer(GL_ARRAY_BUFFER, line_buffer_name_); + // Destroy or create a QAM buffer and shader, if appropriate. const bool needs_qam_buffer = (modals_.display_type == DisplayType::CompositeColour || modals_.display_type == DisplayType::SVideo); if(needs_qam_buffer) { @@ -314,8 +318,6 @@ void ScanTarget::setup_pipeline() { } qam_separation_shader_ = qam_separation_shader(); - glBindVertexArray(line_vertex_array_); - glBindBuffer(GL_ARRAY_BUFFER, line_buffer_name_); enable_vertex_attributes(ShaderType::QAMSeparation, *qam_separation_shader_); set_uniforms(ShaderType::QAMSeparation, *qam_separation_shader_); qam_separation_shader_->set_uniform("textureName", GLint(UnprocessedLineBufferTextureUnit - GL_TEXTURE0)); @@ -326,8 +328,6 @@ void ScanTarget::setup_pipeline() { // Establish an output shader. output_shader_ = conversion_shader(); - glBindVertexArray(line_vertex_array_); - glBindBuffer(GL_ARRAY_BUFFER, line_buffer_name_); enable_vertex_attributes(ShaderType::Conversion, *output_shader_); set_uniforms(ShaderType::Conversion, *output_shader_); output_shader_->set_uniform("origin", modals_.visible_area.origin.x, modals_.visible_area.origin.y); @@ -577,7 +577,8 @@ void ScanTarget::draw(bool synchronous, int output_width, int output_height) { if(qam_separation_shader_) { qam_separation_shader_->bind(); qam_chroma_texture_->bind_framebuffer(); -// glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); // TODO: this is here as a hint that the old framebuffer doesn't need reloading; + // test whether that's a valid optimisation on desktop OpenGL. glDisable(GL_BLEND); glDisable(GL_STENCIL_TEST); @@ -608,8 +609,6 @@ void ScanTarget::draw(bool synchronous, int output_width, int output_height) { glClear(GL_COLOR_BUFFER_BIT); accumulation_texture_->bind_texture(); accumulation_texture_->draw(float(output_width) / float(output_height), 4.0f / 255.0f); -// qam_chroma_texture_->bind_texture(); -// qam_chroma_texture_->draw(float(output_width) / float(output_height)); // All data now having been spooled to the GPU, update the read pointers to // the submit pointer location. diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index c53ec3ef0..dbd2fe467 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -178,7 +178,8 @@ class ScanTarget: public Outputs::Display::ScanTarget { globals for shaders of @c type to @c target. */ static void enable_vertex_attributes(ShaderType type, Shader &target); - void set_uniforms(ShaderType type, Shader &target); + void set_uniforms(ShaderType type, Shader &target) const; + std::vector bindings(ShaderType type) const; GLsync fence_ = nullptr; std::atomic_flag is_drawing_; diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index c3f224a51..35412ec0f 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -14,7 +14,7 @@ using namespace Outputs::Display::OpenGL; // MARK: - State setup for compiled shaders. -void Outputs::Display::OpenGL::ScanTarget::set_uniforms(ShaderType type, Shader &target) { +void Outputs::Display::OpenGL::ScanTarget::set_uniforms(ShaderType type, Shader &target) const { // Slightly over-amping rowHeight here is a cheap way to make sure that lines // converge even allowing for the fact that they may not be spaced by exactly // the expected distance. Cf. the stencil-powered logic for making sure all @@ -144,6 +144,30 @@ void ScanTarget::enable_vertex_attributes(ShaderType type, Shader &target) { #undef rt_offset_of } +std::vector ScanTarget::bindings(ShaderType type) const { + switch(type) { + case ShaderType::Composition: return { + "startDataX", + "startClock", + "endDataX", + "endClock", + "dataY", + "lineY" + }; + + default: return { + "startPoint", + "endPoint", + "startClock", + "endClock", + "lineY", + "lineCompositeAmplitude", + "startCompositeAngle", + "endCompositeAngle" + }; + } +} + // MARK: - Shader code. std::string ScanTarget::sampling_function() const { @@ -421,16 +445,7 @@ std::unique_ptr ScanTarget::conversion_shader() const { return std::unique_ptr(new Shader( vertex_shader, fragment_shader, - { - "startPoint", - "endPoint", - "startClock", - "endClock", - "lineY", - "lineCompositeAmplitude", - "startCompositeAngle", - "endCompositeAngle" - } + bindings(ShaderType::Conversion) )); } @@ -504,14 +519,7 @@ std::unique_ptr ScanTarget::composition_shader() const { return std::unique_ptr(new Shader( vertex_shader, fragment_shader + "}", - { - "startDataX", - "startClock", - "endDataX", - "endClock", - "dataY", - "lineY", - } + bindings(ShaderType::Composition) )); } @@ -624,14 +632,6 @@ std::unique_ptr ScanTarget::qam_separation_shader() const { return std::unique_ptr(new Shader( vertex_shader, fragment_shader, - { - "startClock", - "startCompositeAngle", - "endClock", - "endCompositeAngle", - - "lineY", - "lineCompositeAmplitude" - } + bindings(ShaderType::QAMSeparation) )); }