From 8db8dd24bfe7bb397b67aa7f9fb9487a60dcbfb8 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 22 Jan 2024 15:21:46 +0100 Subject: [PATCH] move vao from WorkspaceSceneOpenGL to GlxContext EglContext already had a vao, and it makes more sense for the context to take care of this than the scene --- src/backends/x11/standalone/glxcontext.cpp | 10 ++++++++++ src/backends/x11/standalone/glxcontext.h | 1 + src/scene/workspacescene_opengl.cpp | 5 ----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backends/x11/standalone/glxcontext.cpp b/src/backends/x11/standalone/glxcontext.cpp index 5d5467012f..b3a5164ad1 100644 --- a/src/backends/x11/standalone/glxcontext.cpp +++ b/src/backends/x11/standalone/glxcontext.cpp @@ -21,10 +21,20 @@ GlxContext::GlxContext(::Display *display, GLXWindow window, GLXContext handle) , m_window(window) , m_handle(handle) { + // It is not legal to not have a vertex array object bound in a core context + // to make code handling old and new OpenGL versions easier, bind a dummy vao that's used for everything + if (!isOpenglES() && hasOpenglExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { + glGenVertexArrays(1, &m_vao); + glBindVertexArray(m_vao); + } } GlxContext::~GlxContext() { + if (m_vao) { + makeCurrent(); + glDeleteVertexArrays(1, &m_vao); + } glXDestroyContext(m_display, m_handle); } diff --git a/src/backends/x11/standalone/glxcontext.h b/src/backends/x11/standalone/glxcontext.h index 9241151c9a..ac323ff92e 100644 --- a/src/backends/x11/standalone/glxcontext.h +++ b/src/backends/x11/standalone/glxcontext.h @@ -30,6 +30,7 @@ private: ::Display *const m_display; const GLXWindow m_window; const GLXContext m_handle; + uint32_t m_vao = 0; }; } diff --git a/src/scene/workspacescene_opengl.cpp b/src/scene/workspacescene_opengl.cpp index 4b68d32c39..3a024f56bd 100644 --- a/src/scene/workspacescene_opengl.cpp +++ b/src/scene/workspacescene_opengl.cpp @@ -43,11 +43,6 @@ WorkspaceSceneOpenGL::WorkspaceSceneOpenGL(OpenGLBackend *backend) : WorkspaceScene(std::make_unique()) , m_backend(backend) { - // It is not legal to not have a vertex array object bound in a core context - if (!GLPlatform::instance()->isGLES() && hasGLExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - } } WorkspaceSceneOpenGL::~WorkspaceSceneOpenGL()