1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-01-22 08:26:48 +00:00

After further diagnosis, work around Qt6 GL crash.

This commit is contained in:
Thomas Harte
2025-11-29 21:57:01 -05:00
parent 73eb5d9a04
commit 16f031df4d
3 changed files with 20 additions and 8 deletions

View File

@@ -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

View File

@@ -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<Log::Source::OpenGL>;
}
@@ -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<void(void)> function) {
void Shader::flush_functions() const {
std::lock_guard function_guard(function_mutex_);
for(std::function<void(void)> function : enqueued_functions_) {
for(std::function<void(void)> &function : enqueued_functions_) {
function();
test_gl_error();
}
enqueued_functions_.clear();
}

View File

@@ -8,8 +8,6 @@
#include "TextureTarget.hpp"
#include <cstdlib>
#include <vector>
#include <stdexcept>
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"