diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp index 68a103b59d..0b84209eea 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp @@ -366,7 +366,7 @@ void EglBackend::present(Output *output, const std::shared_ptr &fra m_vsyncMonitor->arm(); QRegion effectiveRenderedRegion = m_lastRenderedRegion; - if (!GLPlatform::instance()->isGLES()) { + if (!m_context->isOpenglES()) { const QRect displayRect = workspace()->geometry(); if (!supportsBufferAge() && m_swapStrategy == Options::CopyFrontBuffer && m_lastRenderedRegion != displayRect) { glReadBuffer(GL_FRONT); diff --git a/src/opengl/glframebuffer.cpp b/src/opengl/glframebuffer.cpp index 335a9cdac5..ac96ff0973 100644 --- a/src/opengl/glframebuffer.cpp +++ b/src/opengl/glframebuffer.cpp @@ -153,9 +153,9 @@ void GLFramebuffer::initColorAttachment(GLTexture *colorAttachment) void GLFramebuffer::initDepthStencilAttachment() { GLuint buffer = 0; - + const auto context = OpenGlContext::currentContext(); // Try to attach a depth/stencil combined attachment. - if (OpenGlContext::currentContext()->supportsBlits()) { + if (context->supportsBlits()) { glGenRenderbuffers(1, &buffer); glBindRenderbuffer(GL_RENDERBUFFER, buffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_size.width(), m_size.height()); @@ -173,8 +173,8 @@ void GLFramebuffer::initDepthStencilAttachment() // Try to attach a depth attachment separately. GLenum depthFormat; - if (GLPlatform::instance()->isGLES()) { - if (OpenGlContext::currentContext()->supportsGLES24BitDepthBuffers()) { + if (context->isOpenglES()) { + if (context->supportsGLES24BitDepthBuffers()) { depthFormat = GL_DEPTH_COMPONENT24; } else { depthFormat = GL_DEPTH_COMPONENT16; @@ -195,7 +195,7 @@ void GLFramebuffer::initDepthStencilAttachment() // Try to attach a stencil attachment separately. GLenum stencilFormat; - if (GLPlatform::instance()->isGLES()) { + if (context->isOpenglES()) { stencilFormat = GL_STENCIL_INDEX8; } else { stencilFormat = GL_STENCIL_INDEX; diff --git a/src/opengl/glshader.cpp b/src/opengl/glshader.cpp index 98ec166c58..bf4b497ec4 100644 --- a/src/opengl/glshader.cpp +++ b/src/opengl/glshader.cpp @@ -95,11 +95,12 @@ const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &so { // Prepare the source code QByteArray ba; - if (GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() < Version(3, 0)) { + const auto context = OpenGlContext::currentContext(); + if (context->isOpenglES() && GLPlatform::instance()->glslVersion() < Version(3, 0)) { ba.append("precision highp float;\n"); } ba.append(source); - if (GLPlatform::instance()->isGLES() && GLPlatform::instance()->glslVersion() >= Version(3, 0)) { + if (context->isOpenglES() && GLPlatform::instance()->glslVersion() >= Version(3, 0)) { ba.replace("#version 140", "#version 300 es\n\nprecision highp float;\n"); } diff --git a/src/opengl/glshadermanager.cpp b/src/opengl/glshadermanager.cpp index d04d9d46ec..2c37839ae7 100644 --- a/src/opengl/glshadermanager.cpp +++ b/src/opengl/glshadermanager.cpp @@ -42,9 +42,10 @@ QByteArray ShaderManager::generateVertexSource(ShaderTraits traits) const QTextStream stream(&source); GLPlatform *const gl = GLPlatform::instance(); + const auto context = OpenGlContext::currentContext(); QByteArray attribute, varying; - if (!gl->isGLES()) { + if (!context->isOpenglES()) { const bool glsl_140 = gl->glslVersion() >= Version(1, 40); attribute = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute"); @@ -92,9 +93,10 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const QTextStream stream(&source); GLPlatform *const gl = GLPlatform::instance(); + const auto context = OpenGlContext::currentContext(); QByteArray varying, output, textureLookup; - if (!gl->isGLES()) { + if (!context->isOpenglES()) { const bool glsl_140 = gl->glslVersion() >= Version(1, 40); if (glsl_140) { @@ -256,7 +258,8 @@ static QString resolveShaderFilePath(const QString &filePath) QString suffix; QString extension; - const Version coreVersionNumber = GLPlatform::instance()->isGLES() ? Version(3, 0) : Version(1, 40); + const auto context = OpenGlContext::currentContext(); + const Version coreVersionNumber = context->isOpenglES() ? Version(3, 0) : Version(1, 40); if (GLPlatform::instance()->glslVersion() >= coreVersionNumber) { suffix = QStringLiteral("_core"); } diff --git a/src/opengl/gltexture.cpp b/src/opengl/gltexture.cpp index 99ad1d95f9..b116d23a44 100644 --- a/src/opengl/gltexture.cpp +++ b/src/opengl/gltexture.cpp @@ -155,14 +155,15 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s Q_ASSERT(d->m_owning); + const auto context = OpenGlContext::currentContext(); GLenum glFormat; GLenum type; QImage::Format uploadFormat; - if (!GLPlatform::instance()->isGLES()) { + if (!context->isOpenglES()) { const QImage::Format index = image.format(); if (index < sizeof(formatTable) / sizeof(formatTable[0]) && formatTable[index].internalFormat - && !(formatTable[index].type == GL_UNSIGNED_SHORT && !OpenGlContext::currentContext()->supports16BitTextures())) { + && !(formatTable[index].type == GL_UNSIGNED_SHORT && !context->supports16BitTextures())) { glFormat = formatTable[index].format; type = formatTable[index].type; uploadFormat = index; @@ -172,7 +173,7 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s uploadFormat = QImage::Format_ARGB32_Premultiplied; } } else { - if (OpenGlContext::currentContext()->supportsARGB32Textures()) { + if (context->supportsARGB32Textures()) { glFormat = GL_BGRA_EXT; type = GL_UNSIGNED_BYTE; uploadFormat = QImage::Format_ARGB32_Premultiplied; @@ -182,7 +183,7 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s uploadFormat = QImage::Format_RGBA8888_Premultiplied; } } - bool useUnpack = OpenGlContext::currentContext()->supportsTextureUnpack() && image.format() == uploadFormat && !src.isNull(); + bool useUnpack = context->supportsTextureUnpack() && image.format() == uploadFormat && !src.isNull(); QImage im; if (useUnpack) { @@ -451,7 +452,7 @@ OutputTransform GLTexture::contentTransform() const void GLTexture::setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha) { - if (!GLPlatform::instance()->isGLES()) { + if (!OpenGlContext::currentContext()->isOpenglES()) { const GLuint swizzle[] = {red, green, blue, alpha}; glTexParameteriv(d->m_target, GL_TEXTURE_SWIZZLE_RGBA, (const GLint *)swizzle); } else { @@ -494,7 +495,7 @@ QImage GLTexture::toImage() } QImage ret(size(), QImage::Format_RGBA8888_Premultiplied); - if (GLPlatform::instance()->isGLES()) { + if (OpenGlContext::currentContext()->isOpenglES()) { GLFramebuffer fbo(this); GLFramebuffer::pushFramebuffer(&fbo); glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ret.bits()); @@ -528,8 +529,9 @@ std::unique_ptr GLTexture::allocate(GLenum internalFormat, const QSiz } glBindTexture(GL_TEXTURE_2D, texture); - if (!GLPlatform::instance()->isGLES()) { - if (OpenGlContext::currentContext()->supportsTextureStorage()) { + const auto context = OpenGlContext::currentContext(); + if (!context->isOpenglES()) { + if (context->supportsTextureStorage()) { glTexStorage2D(GL_TEXTURE_2D, levels, internalFormat, size.width(), size.height()); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1); @@ -540,7 +542,7 @@ std::unique_ptr GLTexture::allocate(GLenum internalFormat, const QSiz // The format parameter in glTexSubImage() must match the internal format // of the texture, so it's important that we allocate the texture with // the format that will be used in update() and clear(). - const GLenum format = OpenGlContext::currentContext()->supportsARGB32Textures() ? GL_BGRA_EXT : GL_RGBA; + const GLenum format = context->supportsARGB32Textures() ? GL_BGRA_EXT : GL_RGBA; glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GL_UNSIGNED_BYTE, nullptr); @@ -564,8 +566,9 @@ std::unique_ptr GLTexture::upload(const QImage &image) } glBindTexture(GL_TEXTURE_2D, texture); + const auto context = OpenGlContext::currentContext(); GLenum internalFormat; - if (!GLPlatform::instance()->isGLES()) { + if (!context->isOpenglES()) { QImage im; GLenum format; GLenum type; @@ -573,7 +576,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) const QImage::Format index = image.format(); if (index < sizeof(formatTable) / sizeof(formatTable[0]) && formatTable[index].internalFormat - && !(formatTable[index].type == GL_UNSIGNED_SHORT && !OpenGlContext::currentContext()->supports16BitTextures())) { + && !(formatTable[index].type == GL_UNSIGNED_SHORT && !context->supports16BitTextures())) { internalFormat = formatTable[index].internalFormat; format = formatTable[index].format; type = formatTable[index].type; @@ -585,7 +588,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) type = GL_UNSIGNED_INT_8_8_8_8_REV; } - if (OpenGlContext::currentContext()->supportsARGB32Textures()) { + if (context->supportsARGB32Textures()) { glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height()); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im.width(), im.height(), format, type, im.constBits()); @@ -597,7 +600,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) } else { internalFormat = GL_RGBA8; - if (OpenGlContext::currentContext()->supportsARGB32Textures()) { + if (context->supportsARGB32Textures()) { const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, im.width(), im.height(), 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.constBits()); diff --git a/src/plugins/backgroundcontrast/contrastshader.cpp b/src/plugins/backgroundcontrast/contrastshader.cpp index 826f9c6649..39e32b5e4c 100644 --- a/src/plugins/backgroundcontrast/contrastshader.cpp +++ b/src/plugins/backgroundcontrast/contrastshader.cpp @@ -95,7 +95,8 @@ void ContrastShader::init() { reset(); - const bool gles = GLPlatform::instance()->isGLES(); + const auto context = OpenGlContext::currentContext(); + const bool gles = context->isOpenglES(); const bool glsl_140 = !gles && GLPlatform::instance()->glslVersion() >= Version(1, 40); const bool core = glsl_140 || (gles && GLPlatform::instance()->glslVersion() >= Version(3, 0)); diff --git a/src/plugins/mousemark/mousemark.cpp b/src/plugins/mousemark/mousemark.cpp index 855b56c112..f7754c1285 100644 --- a/src/plugins/mousemark/mousemark.cpp +++ b/src/plugins/mousemark/mousemark.cpp @@ -106,8 +106,8 @@ void MouseMarkEffect::paintScreen(const RenderTarget &renderTarget, const Render if (marks.isEmpty() && drawing.isEmpty()) { return; } - if (effects->isOpenGLCompositing()) { - if (!GLPlatform::instance()->isGLES()) { + if (const auto context = effects->openglContext()) { + if (!context->isOpenglES()) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -142,7 +142,7 @@ void MouseMarkEffect::paintScreen(const RenderTarget &renderTarget, const Render vbo->render(GL_LINE_STRIP); } glLineWidth(1.0); - if (!GLPlatform::instance()->isGLES()) { + if (!context->isOpenglES()) { glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); } diff --git a/src/scene/workspacescene_opengl.cpp b/src/scene/workspacescene_opengl.cpp index 886410c44f..43d9932d44 100644 --- a/src/scene/workspacescene_opengl.cpp +++ b/src/scene/workspacescene_opengl.cpp @@ -233,7 +233,8 @@ void OpenGLShadowTextureProvider::update() p.end(); // Check if the image is alpha-only in practice, and if so convert it to an 8-bpp format - if (!GLPlatform::instance()->isGLES() && GLTexture::supportsSwizzle() && GLTexture::supportsFormatRG()) { + const auto context = OpenGlContext::currentContext(); + if (!context->isOpenglES() && context->supportsTextureSwizzle() && context->supportsRGTextures()) { QImage alphaImage(image.size(), QImage::Format_Alpha8); bool alphaOnly = true;