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(); m_vsyncMonitor->arm();
QRegion effectiveRenderedRegion = m_lastRenderedRegion; QRegion effectiveRenderedRegion = m_lastRenderedRegion;
if (!GLPlatform::instance()->isGLES()) { if (!m_context->isOpenglES()) {
const QRect displayRect = workspace()->geometry(); const QRect displayRect = workspace()->geometry();
if (!supportsBufferAge() && m_swapStrategy == Options::CopyFrontBuffer && m_lastRenderedRegion != displayRect) { if (!supportsBufferAge() && m_swapStrategy == Options::CopyFrontBuffer && m_lastRenderedRegion != displayRect) {
glReadBuffer(GL_FRONT); glReadBuffer(GL_FRONT);

View file

@ -153,9 +153,9 @@ void GLFramebuffer::initColorAttachment(GLTexture *colorAttachment)
void GLFramebuffer::initDepthStencilAttachment() void GLFramebuffer::initDepthStencilAttachment()
{ {
GLuint buffer = 0; GLuint buffer = 0;
const auto context = OpenGlContext::currentContext();
// Try to attach a depth/stencil combined attachment. // Try to attach a depth/stencil combined attachment.
if (OpenGlContext::currentContext()->supportsBlits()) { if (context->supportsBlits()) {
glGenRenderbuffers(1, &buffer); glGenRenderbuffers(1, &buffer);
glBindRenderbuffer(GL_RENDERBUFFER, buffer); glBindRenderbuffer(GL_RENDERBUFFER, buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_size.width(), m_size.height()); 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. // Try to attach a depth attachment separately.
GLenum depthFormat; GLenum depthFormat;
if (GLPlatform::instance()->isGLES()) { if (context->isOpenglES()) {
if (OpenGlContext::currentContext()->supportsGLES24BitDepthBuffers()) { if (context->supportsGLES24BitDepthBuffers()) {
depthFormat = GL_DEPTH_COMPONENT24; depthFormat = GL_DEPTH_COMPONENT24;
} else { } else {
depthFormat = GL_DEPTH_COMPONENT16; depthFormat = GL_DEPTH_COMPONENT16;
@ -195,7 +195,7 @@ void GLFramebuffer::initDepthStencilAttachment()
// Try to attach a stencil attachment separately. // Try to attach a stencil attachment separately.
GLenum stencilFormat; GLenum stencilFormat;
if (GLPlatform::instance()->isGLES()) { if (context->isOpenglES()) {
stencilFormat = GL_STENCIL_INDEX8; stencilFormat = GL_STENCIL_INDEX8;
} else { } else {
stencilFormat = GL_STENCIL_INDEX; stencilFormat = GL_STENCIL_INDEX;

View file

@ -95,11 +95,12 @@ const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &so
{ {
// Prepare the source code // Prepare the source code
QByteArray ba; 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("precision highp float;\n");
} }
ba.append(source); 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"); 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); QTextStream stream(&source);
GLPlatform *const gl = GLPlatform::instance(); GLPlatform *const gl = GLPlatform::instance();
const auto context = OpenGlContext::currentContext();
QByteArray attribute, varying; QByteArray attribute, varying;
if (!gl->isGLES()) { if (!context->isOpenglES()) {
const bool glsl_140 = gl->glslVersion() >= Version(1, 40); const bool glsl_140 = gl->glslVersion() >= Version(1, 40);
attribute = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute"); attribute = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute");
@ -92,9 +93,10 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
QTextStream stream(&source); QTextStream stream(&source);
GLPlatform *const gl = GLPlatform::instance(); GLPlatform *const gl = GLPlatform::instance();
const auto context = OpenGlContext::currentContext();
QByteArray varying, output, textureLookup; QByteArray varying, output, textureLookup;
if (!gl->isGLES()) { if (!context->isOpenglES()) {
const bool glsl_140 = gl->glslVersion() >= Version(1, 40); const bool glsl_140 = gl->glslVersion() >= Version(1, 40);
if (glsl_140) { if (glsl_140) {
@ -256,7 +258,8 @@ static QString resolveShaderFilePath(const QString &filePath)
QString suffix; QString suffix;
QString extension; 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) { if (GLPlatform::instance()->glslVersion() >= coreVersionNumber) {
suffix = QStringLiteral("_core"); 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); Q_ASSERT(d->m_owning);
const auto context = OpenGlContext::currentContext();
GLenum glFormat; GLenum glFormat;
GLenum type; GLenum type;
QImage::Format uploadFormat; QImage::Format uploadFormat;
if (!GLPlatform::instance()->isGLES()) { if (!context->isOpenglES()) {
const QImage::Format index = image.format(); const QImage::Format index = image.format();
if (index < sizeof(formatTable) / sizeof(formatTable[0]) && formatTable[index].internalFormat 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; glFormat = formatTable[index].format;
type = formatTable[index].type; type = formatTable[index].type;
uploadFormat = index; uploadFormat = index;
@ -172,7 +173,7 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s
uploadFormat = QImage::Format_ARGB32_Premultiplied; uploadFormat = QImage::Format_ARGB32_Premultiplied;
} }
} else { } else {
if (OpenGlContext::currentContext()->supportsARGB32Textures()) { if (context->supportsARGB32Textures()) {
glFormat = GL_BGRA_EXT; glFormat = GL_BGRA_EXT;
type = GL_UNSIGNED_BYTE; type = GL_UNSIGNED_BYTE;
uploadFormat = QImage::Format_ARGB32_Premultiplied; 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; 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; QImage im;
if (useUnpack) { if (useUnpack) {
@ -451,7 +452,7 @@ OutputTransform GLTexture::contentTransform() const
void GLTexture::setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha) 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}; const GLuint swizzle[] = {red, green, blue, alpha};
glTexParameteriv(d->m_target, GL_TEXTURE_SWIZZLE_RGBA, (const GLint *)swizzle); glTexParameteriv(d->m_target, GL_TEXTURE_SWIZZLE_RGBA, (const GLint *)swizzle);
} else { } else {
@ -494,7 +495,7 @@ QImage GLTexture::toImage()
} }
QImage ret(size(), QImage::Format_RGBA8888_Premultiplied); QImage ret(size(), QImage::Format_RGBA8888_Premultiplied);
if (GLPlatform::instance()->isGLES()) { if (OpenGlContext::currentContext()->isOpenglES()) {
GLFramebuffer fbo(this); GLFramebuffer fbo(this);
GLFramebuffer::pushFramebuffer(&fbo); GLFramebuffer::pushFramebuffer(&fbo);
glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ret.bits()); 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); glBindTexture(GL_TEXTURE_2D, texture);
if (!GLPlatform::instance()->isGLES()) { const auto context = OpenGlContext::currentContext();
if (OpenGlContext::currentContext()->supportsTextureStorage()) { if (!context->isOpenglES()) {
if (context->supportsTextureStorage()) {
glTexStorage2D(GL_TEXTURE_2D, levels, internalFormat, size.width(), size.height()); glTexStorage2D(GL_TEXTURE_2D, levels, internalFormat, size.width(), size.height());
} else { } else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1); 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 // The format parameter in glTexSubImage() must match the internal format
// of the texture, so it's important that we allocate the texture with // of the texture, so it's important that we allocate the texture with
// the format that will be used in update() and clear(). // 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, glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0,
format, GL_UNSIGNED_BYTE, nullptr); format, GL_UNSIGNED_BYTE, nullptr);
@ -564,8 +566,9 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
} }
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
const auto context = OpenGlContext::currentContext();
GLenum internalFormat; GLenum internalFormat;
if (!GLPlatform::instance()->isGLES()) { if (!context->isOpenglES()) {
QImage im; QImage im;
GLenum format; GLenum format;
GLenum type; GLenum type;
@ -573,7 +576,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
const QImage::Format index = image.format(); const QImage::Format index = image.format();
if (index < sizeof(formatTable) / sizeof(formatTable[0]) && formatTable[index].internalFormat 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; internalFormat = formatTable[index].internalFormat;
format = formatTable[index].format; format = formatTable[index].format;
type = formatTable[index].type; 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; 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()); glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im.width(), im.height(), glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im.width(), im.height(),
format, type, im.constBits()); format, type, im.constBits());
@ -597,7 +600,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
} else { } else {
internalFormat = GL_RGBA8; internalFormat = GL_RGBA8;
if (OpenGlContext::currentContext()->supportsARGB32Textures()) { if (context->supportsARGB32Textures()) {
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, im.width(), im.height(), glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, im.width(), im.height(),
0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.constBits()); 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.constBits());

View file

@ -95,7 +95,8 @@ void ContrastShader::init()
{ {
reset(); 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 glsl_140 = !gles && GLPlatform::instance()->glslVersion() >= Version(1, 40);
const bool core = glsl_140 || (gles && GLPlatform::instance()->glslVersion() >= Version(3, 0)); 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()) { if (marks.isEmpty() && drawing.isEmpty()) {
return; return;
} }
if (effects->isOpenGLCompositing()) { if (const auto context = effects->openglContext()) {
if (!GLPlatform::instance()->isGLES()) { if (!context->isOpenglES()) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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); vbo->render(GL_LINE_STRIP);
} }
glLineWidth(1.0); glLineWidth(1.0);
if (!GLPlatform::instance()->isGLES()) { if (!context->isOpenglES()) {
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }

View file

@ -233,7 +233,8 @@ void OpenGLShadowTextureProvider::update()
p.end(); p.end();
// Check if the image is alpha-only in practice, and if so convert it to an 8-bpp format // 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); QImage alphaImage(image.size(), QImage::Format_Alpha8);
bool alphaOnly = true; bool alphaOnly = true;