opengl: remove the global shadermanager instance
This commit is contained in:
parent
1b21b08130
commit
e763cd9eec
9 changed files with 33 additions and 27 deletions
|
@ -41,18 +41,23 @@ GlxContext::~GlxContext()
|
|||
glXDestroyContext(m_display, m_handle);
|
||||
}
|
||||
|
||||
bool GlxContext::makeCurrent() const
|
||||
bool GlxContext::makeCurrent()
|
||||
{
|
||||
if (QOpenGLContext *context = QOpenGLContext::currentContext()) {
|
||||
// Workaround to tell Qt that no QOpenGLContext is current
|
||||
context->doneCurrent();
|
||||
}
|
||||
return glXMakeCurrent(m_display, m_window, m_handle);
|
||||
const bool ret = glXMakeCurrent(m_display, m_window, m_handle);
|
||||
if (ret) {
|
||||
s_currentContext = this;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool GlxContext::doneCurrent() const
|
||||
void GlxContext::doneCurrent() const
|
||||
{
|
||||
return glXMakeCurrent(m_display, None, nullptr);
|
||||
glXMakeCurrent(m_display, None, nullptr);
|
||||
s_currentContext = nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<GlxContext> GlxContext::create(GlxBackend *backend, GLXFBConfig fbconfig, GLXWindow glxWindow)
|
||||
|
@ -139,6 +144,7 @@ std::unique_ptr<GlxContext> GlxContext::create(GlxBackend *backend, GLXFBConfig
|
|||
return nullptr;
|
||||
}
|
||||
auto ret = std::make_unique<GlxContext>(backend->display(), glxWindow, handle);
|
||||
s_currentContext = ret.get();
|
||||
if (!ret->checkSupported()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ public:
|
|||
GlxContext(::Display *display, GLXWindow window, GLXContext handle);
|
||||
~GlxContext() override;
|
||||
|
||||
bool makeCurrent() const;
|
||||
bool doneCurrent() const;
|
||||
bool makeCurrent();
|
||||
void doneCurrent() const;
|
||||
|
||||
static std::unique_ptr<GlxContext> create(GlxBackend *backend, GLXFBConfig fbconfig, GLXWindow glxWindow);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ std::unique_ptr<EglContext> EglContext::create(EglDisplay *display, EGLConfig co
|
|||
return nullptr;
|
||||
}
|
||||
auto ret = std::make_unique<EglContext>(display, config, handle);
|
||||
s_currentContext = ret.get();
|
||||
if (!ret->checkSupported()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -65,18 +66,23 @@ EglContext::~EglContext()
|
|||
eglDestroyContext(m_display->handle(), m_handle);
|
||||
}
|
||||
|
||||
bool EglContext::makeCurrent(EGLSurface surface) const
|
||||
bool EglContext::makeCurrent(EGLSurface surface)
|
||||
{
|
||||
if (QOpenGLContext *context = QOpenGLContext::currentContext()) {
|
||||
// Workaround to tell Qt that no QOpenGLContext is current
|
||||
context->doneCurrent();
|
||||
}
|
||||
return eglMakeCurrent(m_display->handle(), surface, surface, m_handle) == EGL_TRUE;
|
||||
const bool ret = eglMakeCurrent(m_display->handle(), surface, surface, m_handle) == EGL_TRUE;
|
||||
if (ret) {
|
||||
s_currentContext = this;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EglContext::doneCurrent() const
|
||||
{
|
||||
eglMakeCurrent(m_display->handle(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
s_currentContext = nullptr;
|
||||
}
|
||||
|
||||
EglDisplay *EglContext::displayObject() const
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
EglContext(EglDisplay *display, EGLConfig config, ::EGLContext context);
|
||||
~EglContext() override;
|
||||
|
||||
bool makeCurrent(EGLSurface surface = EGL_NO_SURFACE) const;
|
||||
bool makeCurrent(EGLSurface surface = EGL_NO_SURFACE);
|
||||
void doneCurrent() const;
|
||||
std::shared_ptr<GLTexture> importDmaBufAsTexture(const DmaBufAttributes &attributes) const;
|
||||
|
||||
|
|
|
@ -20,19 +20,9 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
std::unique_ptr<ShaderManager> ShaderManager::s_shaderManager;
|
||||
|
||||
ShaderManager *ShaderManager::instance()
|
||||
{
|
||||
if (!s_shaderManager) {
|
||||
s_shaderManager = std::make_unique<ShaderManager>();
|
||||
}
|
||||
return s_shaderManager.get();
|
||||
}
|
||||
|
||||
void ShaderManager::cleanup()
|
||||
{
|
||||
s_shaderManager.reset();
|
||||
return OpenGlContext::currentContext()->shaderManager();
|
||||
}
|
||||
|
||||
ShaderManager::ShaderManager()
|
||||
|
|
|
@ -143,11 +143,6 @@ public:
|
|||
*/
|
||||
static ShaderManager *instance();
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static void cleanup();
|
||||
|
||||
private:
|
||||
void bindFragDataLocations(GLShader *shader);
|
||||
void bindAttributeLocations(GLShader *shader) const;
|
||||
|
@ -159,7 +154,6 @@ private:
|
|||
|
||||
QStack<GLShader *> m_boundShaders;
|
||||
std::map<ShaderTraits, std::unique_ptr<GLShader>> m_shaderHash;
|
||||
static std::unique_ptr<ShaderManager> s_shaderManager;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,7 +121,6 @@ void initGL(const std::function<resolveFuncPtr(const char *)> &resolveFunction)
|
|||
|
||||
void cleanupGL()
|
||||
{
|
||||
ShaderManager::cleanup();
|
||||
GLTexturePrivate::cleanup();
|
||||
GLFramebuffer::cleanup();
|
||||
GLVertexBuffer::cleanup();
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
OpenGlContext *OpenGlContext::s_currentContext = nullptr;
|
||||
|
||||
static QSet<QByteArray> getExtensions(OpenGlContext *context)
|
||||
{
|
||||
QSet<QByteArray> ret;
|
||||
|
@ -124,4 +126,9 @@ void OpenGlContext::setShaderManager(ShaderManager *manager)
|
|||
{
|
||||
m_shaderManager = manager;
|
||||
}
|
||||
|
||||
OpenGlContext *OpenGlContext::currentContext()
|
||||
{
|
||||
return s_currentContext;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,10 +44,14 @@ public:
|
|||
*/
|
||||
bool checkSupported() const;
|
||||
|
||||
static OpenGlContext *currentContext();
|
||||
|
||||
protected:
|
||||
bool checkTimerQuerySupport() const;
|
||||
void setShaderManager(ShaderManager *manager);
|
||||
|
||||
static OpenGlContext *s_currentContext;
|
||||
|
||||
const QByteArrayView m_versionString;
|
||||
const Version m_version;
|
||||
const QByteArrayView m_vendor;
|
||||
|
|
Loading…
Reference in a new issue