From 16f031df4d83bd4e096e7db82f638d8c08e43318 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 29 Nov 2025 21:57:01 -0500 Subject: [PATCH] After further diagnosis, work around Qt6 GL crash. --- OSBindings/Qt/clksignal.pro | 5 ++--- Outputs/OpenGL/Primitives/Shader.cpp | 19 +++++++++++++++++-- Outputs/OpenGL/Primitives/TextureTarget.cpp | 4 +--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/OSBindings/Qt/clksignal.pro b/OSBindings/Qt/clksignal.pro index d1837f1bc..a73103c92 100644 --- a/OSBindings/Qt/clksignal.pro +++ b/OSBindings/Qt/clksignal.pro @@ -1,7 +1,6 @@ -QT += core gui multimedia widgets -greaterThan(5, QT_MAJOR_VERSION) QT += openglwidgets +QT += core gui multimedia widgets openglwidgets -# Be specific about C++17 but also try the vaguer C++1z for older +# Be specific about C++20 but also try the vaguer C++2a for older # versions of Qt. CONFIG += c++20 CONFIG += c++2a diff --git a/Outputs/OpenGL/Primitives/Shader.cpp b/Outputs/OpenGL/Primitives/Shader.cpp index ee862c338..7d34d1ed8 100644 --- a/Outputs/OpenGL/Primitives/Shader.cpp +++ b/Outputs/OpenGL/Primitives/Shader.cpp @@ -14,7 +14,9 @@ using namespace Outputs::Display::OpenGL; namespace { +#ifndef TARGET_QT thread_local const Shader *bound_shader = nullptr; +#endif using Logger = Log::Logger; } @@ -106,20 +108,30 @@ void Shader::init(const std::string &vertex_shader, const std::string &fragment_ } Shader::~Shader() { +#ifndef TARGET_QT if(bound_shader == this) Shader::unbind(); +#endif glDeleteProgram(shader_program_); } void Shader::bind() const { +#ifndef TARGET_QT + // Qt workaround: it's doing something to interfere with the currently-bound program. + // So assume that the driver has a check similar to the below. if(bound_shader != this) { test_gl(glUseProgram, shader_program_); bound_shader = this; } +#else + test_gl(glUseProgram, shader_program_); +#endif flush_functions(); } void Shader::unbind() { +#ifndef TARGET_QT bound_shader = nullptr; +#endif test_gl(glUseProgram, 0); } @@ -128,7 +140,9 @@ GLint Shader::get_attrib_location(const std::string &name) const { } GLint Shader::get_uniform_location(const std::string &name) const { - return glGetUniformLocation(shader_program_, name.c_str()); + const auto location = glGetUniformLocation(shader_program_, name.c_str()); + test_gl_error(); + return location; } void Shader::enable_vertex_attribute_with_pointer(const std::string &name, GLint size, GLenum type, GLboolean normalised, GLsizei stride, const GLvoid *pointer, GLuint divisor) { @@ -293,8 +307,9 @@ void Shader::enqueue_function(std::function function) { void Shader::flush_functions() const { std::lock_guard function_guard(function_mutex_); - for(std::function function : enqueued_functions_) { + for(std::function &function : enqueued_functions_) { function(); + test_gl_error(); } enqueued_functions_.clear(); } diff --git a/Outputs/OpenGL/Primitives/TextureTarget.cpp b/Outputs/OpenGL/Primitives/TextureTarget.cpp index a65b791a3..ff19971fc 100644 --- a/Outputs/OpenGL/Primitives/TextureTarget.cpp +++ b/Outputs/OpenGL/Primitives/TextureTarget.cpp @@ -8,8 +8,6 @@ #include "TextureTarget.hpp" -#include -#include #include using namespace Outputs::Display::OpenGL; @@ -93,7 +91,7 @@ void TextureTarget::bind_texture() const { test_gl(glBindTexture, GL_TEXTURE_2D, texture_); } -void TextureTarget::draw(float aspect_ratio, float colour_threshold) const { +void TextureTarget::draw(const float aspect_ratio, const float colour_threshold) const { if(!pixel_shader_) { const char *vertex_shader = "#version 150\n"