From 1b21b08130754f0793dbe78db1271c40154e420d Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 27 Feb 2024 19:16:34 +0100 Subject: [PATCH] opengl: move shader manager getter to OpenGlContext --- src/backends/x11/standalone/glxcontext.cpp | 5 ++++- src/backends/x11/standalone/glxcontext.h | 1 + src/opengl/eglcontext.cpp | 6 +----- src/opengl/eglcontext.h | 1 - src/opengl/openglcontext.cpp | 10 ++++++++++ src/opengl/openglcontext.h | 5 +++++ 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/backends/x11/standalone/glxcontext.cpp b/src/backends/x11/standalone/glxcontext.cpp index b3a5164ad1..0576598b59 100644 --- a/src/backends/x11/standalone/glxcontext.cpp +++ b/src/backends/x11/standalone/glxcontext.cpp @@ -20,7 +20,9 @@ GlxContext::GlxContext(::Display *display, GLXWindow window, GLXContext handle) : m_display(display) , m_window(window) , m_handle(handle) + , m_shaderManager(std::make_unique()) { + setShaderManager(m_shaderManager.get()); // 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"))) { @@ -31,10 +33,11 @@ GlxContext::GlxContext(::Display *display, GLXWindow window, GLXContext handle) GlxContext::~GlxContext() { + makeCurrent(); if (m_vao) { - makeCurrent(); glDeleteVertexArrays(1, &m_vao); } + m_shaderManager.reset(); glXDestroyContext(m_display, m_handle); } diff --git a/src/backends/x11/standalone/glxcontext.h b/src/backends/x11/standalone/glxcontext.h index ac323ff92e..93c2ecba16 100644 --- a/src/backends/x11/standalone/glxcontext.h +++ b/src/backends/x11/standalone/glxcontext.h @@ -31,6 +31,7 @@ private: const GLXWindow m_window; const GLXContext m_handle; uint32_t m_vao = 0; + std::unique_ptr m_shaderManager; }; } diff --git a/src/opengl/eglcontext.cpp b/src/opengl/eglcontext.cpp index 085a198a15..022bddad63 100644 --- a/src/opengl/eglcontext.cpp +++ b/src/opengl/eglcontext.cpp @@ -45,6 +45,7 @@ EglContext::EglContext(EglDisplay *display, EGLConfig config, ::EGLContext conte , m_config(config) , m_shaderManager(std::make_unique()) { + setShaderManager(m_shaderManager.get()); // 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"))) { @@ -208,9 +209,4 @@ std::shared_ptr EglContext::importDmaBufAsTexture(const DmaBufAttribu return nullptr; } } - -ShaderManager *EglContext::shaderManager() const -{ - return m_shaderManager.get(); -} } diff --git a/src/opengl/eglcontext.h b/src/opengl/eglcontext.h index 1f65acde5e..d39961f145 100644 --- a/src/opengl/eglcontext.h +++ b/src/opengl/eglcontext.h @@ -36,7 +36,6 @@ public: ::EGLContext handle() const; EGLConfig config() const; bool isValid() const; - ShaderManager *shaderManager() const; static std::unique_ptr create(EglDisplay *display, EGLConfig config, ::EGLContext sharedContext); diff --git a/src/opengl/openglcontext.cpp b/src/opengl/openglcontext.cpp index 41f2fdb9c8..e717351d9c 100644 --- a/src/opengl/openglcontext.cpp +++ b/src/opengl/openglcontext.cpp @@ -107,6 +107,11 @@ bool OpenGlContext::supportsTimerQueries() const return m_supportsTimerQueries; } +ShaderManager *OpenGlContext::shaderManager() const +{ + return m_shaderManager; +} + bool OpenGlContext::checkSupported() const { const bool supportsGLSL = m_isOpenglES || (hasOpenglExtension("GL_ARB_shader_objects") && hasOpenglExtension("GL_ARB_fragment_shader") && hasOpenglExtension("GL_ARB_vertex_shader")); @@ -114,4 +119,9 @@ bool OpenGlContext::checkSupported() const const bool supports3DTextures = !m_isOpenglES || hasVersion(Version(3, 0)) || hasOpenglExtension("GL_OES_texture_3D"); return supportsGLSL && supportsNonPowerOfTwoTextures && supports3DTextures; } + +void OpenGlContext::setShaderManager(ShaderManager *manager) +{ + m_shaderManager = manager; +} } diff --git a/src/opengl/openglcontext.h b/src/opengl/openglcontext.h index 8e81c1a229..e30660077e 100644 --- a/src/opengl/openglcontext.h +++ b/src/opengl/openglcontext.h @@ -19,6 +19,8 @@ namespace KWin { +class ShaderManager; + class KWIN_EXPORT OpenGlContext { public: @@ -35,6 +37,7 @@ public: bool hasOpenglExtension(QByteArrayView name) const; bool isSoftwareRenderer() const; bool supportsTimerQueries() const; + ShaderManager *shaderManager() const; /** * checks whether or not this context supports all the features that KWin requires @@ -43,6 +46,7 @@ public: protected: bool checkTimerQuerySupport() const; + void setShaderManager(ShaderManager *manager); const QByteArrayView m_versionString; const Version m_version; @@ -51,6 +55,7 @@ protected: const bool m_isOpenglES; const QSet m_extensions; const bool m_supportsTimerQueries; + ShaderManager *m_shaderManager = nullptr; }; }