opengl: move shader manager getter to OpenGlContext

This commit is contained in:
Xaver Hugl 2024-02-27 19:16:34 +01:00
parent 7ff51ba47c
commit 1b21b08130
6 changed files with 21 additions and 7 deletions

View file

@ -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<ShaderManager>())
{
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);
}

View file

@ -31,6 +31,7 @@ private:
const GLXWindow m_window;
const GLXContext m_handle;
uint32_t m_vao = 0;
std::unique_ptr<ShaderManager> m_shaderManager;
};
}

View file

@ -45,6 +45,7 @@ EglContext::EglContext(EglDisplay *display, EGLConfig config, ::EGLContext conte
, m_config(config)
, m_shaderManager(std::make_unique<ShaderManager>())
{
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<GLTexture> EglContext::importDmaBufAsTexture(const DmaBufAttribu
return nullptr;
}
}
ShaderManager *EglContext::shaderManager() const
{
return m_shaderManager.get();
}
}

View file

@ -36,7 +36,6 @@ public:
::EGLContext handle() const;
EGLConfig config() const;
bool isValid() const;
ShaderManager *shaderManager() const;
static std::unique_ptr<EglContext> create(EglDisplay *display, EGLConfig config, ::EGLContext sharedContext);

View file

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

View file

@ -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<QByteArray> m_extensions;
const bool m_supportsTimerQueries;
ShaderManager *m_shaderManager = nullptr;
};
}