port most uses of GLPlatform::isGLES to use OpenGlContext directly

This commit is contained in:
Xaver Hugl 2024-02-28 14:30:04 +01:00
parent 5aa2606f04
commit c5cd8d1318
8 changed files with 38 additions and 29 deletions

View file

@ -366,7 +366,7 @@ void EglBackend::present(Output *output, const std::shared_ptr<OutputFrame> &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);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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