kis_opengl.cpp 20.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 *  Copyright (c) 2007 Adrian Page <adrian@pagenet.plus.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

19
#include "opengl/kis_opengl.h"
Halla Rempt's avatar
Halla Rempt committed
20

Halla Rempt's avatar
Halla Rempt committed
21
#include <QOpenGLContext>
22
#include <QOpenGLDebugLogger>
23
#include <QOpenGLFunctions>
Halla Rempt's avatar
Halla Rempt committed
24 25

#include <QApplication>
26 27 28
#include <QDesktopWidget>
#include <QPixmapCache>

Halla Rempt's avatar
Halla Rempt committed
29 30 31
#include <QDir>
#include <QFile>
#include <QDesktopServices>
Halla Rempt's avatar
Halla Rempt committed
32
#include <QMessageBox>
33
#include <QRegularExpression>
34
#include <QStringList>
35
#include <QWindow>
36

37
#include <klocalizedstring.h>
38

39
#include <kis_debug.h>
40
#include <kis_config.h>
41 42 43 44 45 46 47
#include <KisLoggingManager.h>

#include <boost/optional.hpp>

#ifndef GL_RENDERER
#  define GL_RENDERER 0x1F01
#endif
48

49 50
namespace
{
51
    bool defaultFormatIsSet = false;
52 53
    bool isDebugEnabled = false;
    bool isDebugSynchronous = false;
54 55 56 57 58 59 60 61

    struct OpenGLCheckResult {
        // bool contextValid = false;
        int glMajorVersion = 0;
        int glMinorVersion = 0;
        bool supportsDeprecatedFunctions = false;
        bool isOpenGLES = false;
        QString rendererString;
62
        QString driverVersionString;
63 64 65 66 67 68 69 70

        OpenGLCheckResult(QOpenGLContext &context) {
            if (!context.isValid()) {
                return;
            }

            QOpenGLFunctions *funcs = context.functions(); // funcs is ready to be used

71 72
            rendererString = QString(reinterpret_cast<const char *>(funcs->glGetString(GL_RENDERER)));
            driverVersionString = QString(reinterpret_cast<const char *>(funcs->glGetString(GL_VERSION)));
73 74 75 76 77 78 79 80 81
            glMajorVersion = context.format().majorVersion();
            glMinorVersion = context.format().minorVersion();
            supportsDeprecatedFunctions = (context.format().options() & QSurfaceFormat::DeprecatedFunctions);
            isOpenGLES = context.isOpenGLES();
        }

        bool isSupportedVersion() const {
            return
#ifdef Q_OS_OSX
82 83 84
                    ((glMajorVersion * 100 + glMinorVersion) >= 302
                     && !rendererString.toLower().contains("amd")
                     && !rendererString.toLower().contains("radeon"))
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#else
                    (glMajorVersion >= 3 && (supportsDeprecatedFunctions || isOpenGLES)) ||
                    ((glMajorVersion * 100 + glMinorVersion) == 201)
#endif
                    ;
        }

        bool supportsLoD() const {
            return (glMajorVersion * 100 + glMinorVersion) >= 300;
        }

        bool hasOpenGL3() const {
            return (glMajorVersion * 100 + glMinorVersion) >= 302;
        }

        bool supportsFenceSync() const {
            return glMajorVersion >= 3;
        }
#ifdef Q_OS_WIN
        // This is only for detecting whether ANGLE is being used.
        // For detecting generic OpenGL ES please check isOpenGLES
        bool isUsingAngle() const {
            return rendererString.startsWith("ANGLE", Qt::CaseInsensitive);
        }
#endif
    };
    boost::optional<OpenGLCheckResult> openGLCheckResult;

113
    bool NeedsFenceWorkaround = false;
114
    bool NeedsPixmapCacheWorkaround = false;
115

116 117
    QString debugText("OpenGL Info\n  **OpenGL not initialized**");

118 119 120
    void openglOnMessageLogged(const QOpenGLDebugMessage& debugMessage) {
        qDebug() << "OpenGL:" << debugMessage;
    }
Halla Rempt's avatar
Halla Rempt committed
121
}
Halla Rempt's avatar
Halla Rempt committed
122

123 124 125 126 127 128 129
#ifdef Q_OS_WIN
namespace
{
    struct WindowsOpenGLStatus {
        bool supportsDesktopGL = false;
        bool supportsAngleD3D11 = false;
        bool isQtPreferAngle = false;
130
        bool overridePreferAngle = false; // override Qt to force ANGLE to be preferred
131 132 133 134 135 136 137 138 139 140 141 142 143
    };
    WindowsOpenGLStatus windowsOpenGLStatus = {};
    KisOpenGL::OpenGLRenderer userRendererConfig;
    KisOpenGL::OpenGLRenderer nextUserRendererConfig;
    KisOpenGL::OpenGLRenderer currentRenderer;

    QStringList qpaDetectionLog;

    boost::optional<OpenGLCheckResult> checkQpaOpenGLStatus() {
        QWindow surface;
        surface.setSurfaceType(QSurface::OpenGLSurface);
        surface.create();
        QOpenGLContext context;
144 145 146 147
        if (!context.create()) {
            qDebug() << "OpenGL context cannot be created";
            return boost::none;
        }
148
        if (!context.isValid()) {
149 150 151 152 153
            qDebug() << "OpenGL context is not valid while checking Qt's OpenGL status";
            return boost::none;
        }
        if (!context.makeCurrent(&surface)) {
            qDebug() << "OpenGL context cannot be made current";
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
            return boost::none;
        }
        return OpenGLCheckResult(context);
    }

    bool checkIsSupportedDesktopGL(const OpenGLCheckResult &checkResult) {
        if (checkResult.isUsingAngle()) {
            qWarning() << "ANGLE was being used when desktop OpenGL was wanted, assuming no desktop OpenGL support";
            return false;
        }
        if (checkResult.isOpenGLES) {
            qWarning() << "Got OpenGL ES instead of desktop OpenGL, this shouldn't happen!";
            return false;
        }
        return checkResult.isSupportedVersion();
    }

    bool checkIsSupportedAngleD3D11(const OpenGLCheckResult &checkResult) {
        if (!checkResult.isUsingAngle()) {
            qWarning() << "Desktop OpenGL was being used when ANGLE was wanted, assuming no ANGLE support";
            return false;
        }
        if (!checkResult.isOpenGLES) {
            qWarning() << "Got desktop OpenGL instead of OpenGL ES, this shouldn't happen!";
            return false;
        }
        // HACK: Block ANGLE with Direct3D9
        //       Direct3D9 does not give OpenGL ES 3.0
        //       Some versions of ANGLE returns OpenGL version 3.0 incorrectly
        if (checkResult.rendererString.contains("Direct3D9", Qt::CaseInsensitive)) {
            qWarning() << "ANGLE tried to use Direct3D9, Krita won't work with it";
            return false;
        }
        return checkResult.isSupportedVersion();
    }

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    void specialOpenGLVendorFilter(WindowsOpenGLStatus &status, const OpenGLCheckResult &checkResult) {
        if (!status.supportsAngleD3D11) {
            return;
        }
        // HACK: Make ANGLE the preferred renderer for Intel driver versions
        //       between build 4636 and 4729 (exclusive) due to an UI offset bug.
        //       See https://communities.intel.com/thread/116003
        //       (Build 4636 is known to work from some test results)
        if (checkResult.rendererString.startsWith("Intel")) {
            QRegularExpression regex("\\b\\d{2}\\.\\d{2}\\.\\d{2}\\.(\\d{4})\\b");
            QRegularExpressionMatch match = regex.match(checkResult.driverVersionString);
            if (match.hasMatch()) {
                int driverBuild = match.captured(1).toInt();
                if (driverBuild > 4636 && driverBuild < 4729) {
                    qDebug() << "Detected Intel driver build between 4636 and 4729, making ANGLE the preferred renderer";
                    status.overridePreferAngle = true;
                }
            }
        }
    }

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
} // namespace

/**
 * This function probes the Qt Platform Abstraction (QPA) for OpenGL diagnostics
 * information. The code works under the assumption that the bundled Qt is built
 * with `-opengl dynamic` and includes support for ANGLE.
 *
 * This function is written for Qt 5.9.1. On other versions it might not work
 * as well.
 */
void KisOpenGL::probeWindowsQpaOpenGL(int argc, char **argv, QString userRendererConfigString)
{
    KIS_SAFE_ASSERT_RECOVER(defaultFormatIsSet) {
        qWarning() << "Default OpenGL format was not set before calling KisOpenGL::probeWindowsQpaOpenGL. This might be a BUG!";
        setDefaultFormat();
    }

    // Clear env var to prevent affecting tests
    qunsetenv("QT_OPENGL");

    boost::optional<OpenGLCheckResult> qpaDetectionResult;

    qDebug() << "Probing Qt OpenGL detection:";
    {
        KisLoggingManager::ScopedLogCapturer logCapturer(
            "qt.qpa.gl",
            [](QtMsgType type, const QMessageLogContext &context, const QString &msg) {
                Q_UNUSED(type)
                Q_UNUSED(context)
                qpaDetectionLog.append(msg);
            }
        );
        {
            QGuiApplication app(argc, argv);
            qpaDetectionResult = checkQpaOpenGLStatus();
        }
    }
    if (!qpaDetectionResult) {
        qWarning() << "Could not initialize OpenGL context!";
        return;
    }
    qDebug() << "Done probing Qt OpenGL detection";

    windowsOpenGLStatus.isQtPreferAngle = qpaDetectionResult->isUsingAngle();

    boost::optional<OpenGLCheckResult> checkResultAngle, checkResultDesktopGL;
    if (qpaDetectionResult->isUsingAngle()) {
        checkResultAngle = qpaDetectionResult;
        // We already checked ANGLE, now check desktop OpenGL
        qputenv("QT_OPENGL", "desktop");
        qDebug() << "Checking desktop OpenGL...";
        {
            QGuiApplication app(argc, argv);
            checkResultDesktopGL = checkQpaOpenGLStatus();
        }
        if (!checkResultDesktopGL) {
            qWarning() << "Could not initialize OpenGL context!";
        }
        qDebug() << "Done checking desktop OpenGL";
        qunsetenv("QT_OPENGL");
    } else {
        checkResultDesktopGL = qpaDetectionResult;
        // We already checked desktop OpenGL, now check ANGLE
        qputenv("QT_OPENGL", "angle");
        qDebug() << "Checking ANGLE...";
        {
            QGuiApplication app(argc, argv);
            checkResultAngle = checkQpaOpenGLStatus();
        }
        if (!checkResultAngle) {
            qWarning() << "Could not initialize OpenGL context!";
        }
        qDebug() << "Done checking ANGLE";
        qunsetenv("QT_OPENGL");
    }

    windowsOpenGLStatus.supportsDesktopGL =
            checkResultDesktopGL && checkIsSupportedDesktopGL(*checkResultDesktopGL);
    windowsOpenGLStatus.supportsAngleD3D11 =
            checkResultAngle && checkIsSupportedAngleD3D11(*checkResultAngle);

292 293 294 295 296
    // HACK: Filter specific buggy drivers not handled by Qt OpenGL buglist
    if (checkResultDesktopGL) {
        specialOpenGLVendorFilter(windowsOpenGLStatus, *checkResultDesktopGL);
    }

297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
    userRendererConfig = convertConfigToOpenGLRenderer(userRendererConfigString);
    if ((userRendererConfig == RendererDesktopGL && !windowsOpenGLStatus.supportsDesktopGL) ||
            (userRendererConfig == RendererAngle && !windowsOpenGLStatus.supportsAngleD3D11)) {
        // Set it to auto so we won't get stuck
        userRendererConfig = RendererAuto;
    }
    nextUserRendererConfig = userRendererConfig;
    switch (userRendererConfig) {
    case RendererDesktopGL:
        QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL, true);
        currentRenderer = RendererDesktopGL;
        break;
    case RendererAngle:
        QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
        currentRenderer = RendererAngle;
        break;
    default:
        if (windowsOpenGLStatus.isQtPreferAngle && windowsOpenGLStatus.supportsAngleD3D11) {
            currentRenderer = RendererAngle;
316 317 318 319
        } else if (windowsOpenGLStatus.overridePreferAngle && windowsOpenGLStatus.supportsAngleD3D11) {
            QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
            currentRenderer = RendererAngle;
        } else if (!windowsOpenGLStatus.isQtPreferAngle && windowsOpenGLStatus.supportsDesktopGL) {
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
            currentRenderer = RendererDesktopGL;
        } else {
            currentRenderer = RendererNone;
        }
        break;
    }
}

KisOpenGL::OpenGLRenderer KisOpenGL::getCurrentOpenGLRenderer()
{
    return currentRenderer;
}

KisOpenGL::OpenGLRenderer KisOpenGL::getQtPreferredOpenGLRenderer()
{
335 336
    return (windowsOpenGLStatus.isQtPreferAngle || windowsOpenGLStatus.overridePreferAngle)
            ? RendererAngle : RendererDesktopGL;
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
}

KisOpenGL::OpenGLRenderers KisOpenGL::getSupportedOpenGLRenderers()
{
    return RendererAuto |
            (windowsOpenGLStatus.supportsDesktopGL ? RendererDesktopGL : static_cast<OpenGLRenderer>(0)) |
            (windowsOpenGLStatus.supportsAngleD3D11 ? RendererAngle : static_cast<OpenGLRenderers>(0));
}

KisOpenGL::OpenGLRenderer KisOpenGL::getUserOpenGLRendererConfig()
{
    return userRendererConfig;
}

KisOpenGL::OpenGLRenderer KisOpenGL::getNextUserOpenGLRendererConfig()
{
    return nextUserRendererConfig;
}

void KisOpenGL::setNextUserOpenGLRendererConfig(KisOpenGL::OpenGLRenderer renderer)
{
    nextUserRendererConfig = renderer;
}

QString KisOpenGL::convertOpenGLRendererToConfig(KisOpenGL::OpenGLRenderer renderer)
{
    switch (renderer) {
    case RendererDesktopGL:
        return QStringLiteral("desktop");
    case RendererAngle:
        return QStringLiteral("angle");
    default:
        return QStringLiteral("auto");
    }
}

KisOpenGL::OpenGLRenderer KisOpenGL::convertConfigToOpenGLRenderer(QString renderer)
{
    if (renderer == "desktop") {
        return RendererDesktopGL;
    } else if (renderer == "angle") {
        return RendererAngle;
    } else {
        return RendererAuto;
    }
}
#endif

385
void KisOpenGL::initialize()
386
{
387
    if (openGLCheckResult) return;
388

389
    KIS_SAFE_ASSERT_RECOVER(defaultFormatIsSet) {
390 391 392
        qWarning() << "Default OpenGL format was not set before calling KisOpenGL::initialize. This might be a BUG!";
        setDefaultFormat();
    }
393

394 395 396 397 398 399
    // we need a QSurface active to get our GL functions from the context
    QWindow  surface;
    surface.setSurfaceType( QSurface::OpenGLSurface );
    surface.create();

    QOpenGLContext context;
400 401 402 403 404 405 406 407
    if (!context.create()) {
        qDebug() << "OpenGL context cannot be created";
        return;
    }
    if (!context.isValid()) {
        qDebug() << "OpenGL context is not valid";
        return;
    }
408

409 410 411 412
    if (!context.makeCurrent(&surface)) {
        qDebug() << "OpenGL context cannot be made current";
        return;
    }
413 414

    QOpenGLFunctions  *funcs = context.functions();
415

416
    openGLCheckResult = OpenGLCheckResult(context);
Halla Rempt's avatar
Halla Rempt committed
417

418 419 420 421
    debugText.clear();
    QDebug debugOut(&debugText);
    debugOut << "OpenGL Info";
    debugOut << "\n  Vendor: " << reinterpret_cast<const char *>(funcs->glGetString(GL_VENDOR));
422
    debugOut << "\n  Renderer: " << openGLCheckResult->rendererString;
423
    debugOut << "\n  Version: " << openGLCheckResult->driverVersionString;
424 425 426 427
    debugOut << "\n  Shading language: " << reinterpret_cast<const char *>(funcs->glGetString(GL_SHADING_LANGUAGE_VERSION));
    debugOut << "\n  Requested format: " << QSurfaceFormat::defaultFormat();
    debugOut << "\n  Current format:   " << context.format();
    debugOut.nospace();
428
    debugOut << "\n     Version: " << openGLCheckResult->glMajorVersion << "." << openGLCheckResult->glMinorVersion;
429
    debugOut.resetFormat();
430 431 432 433 434 435 436
    debugOut << "\n     Supports deprecated functions" << openGLCheckResult->supportsDeprecatedFunctions;
    debugOut << "\n     is OpenGL ES:" << openGLCheckResult->isOpenGLES;
#ifdef Q_OS_WIN
    debugOut << "\n\nQPA OpenGL Detection Info";
    debugOut << "\n  supportsDesktopGL:" << windowsOpenGLStatus.supportsDesktopGL;
    debugOut << "\n  supportsAngleD3D11:" << windowsOpenGLStatus.supportsAngleD3D11;
    debugOut << "\n  isQtPreferAngle:" << windowsOpenGLStatus.isQtPreferAngle;
437
    debugOut << "\n  overridePreferAngle:" << windowsOpenGLStatus.overridePreferAngle;
438 439 440 441 442 443
    debugOut << "\n== log ==\n";
    debugOut.noquote();
    debugOut << qpaDetectionLog.join('\n');
    debugOut.resetFormat();
    debugOut << "\n== end log ==";
#endif
444 445

    qDebug().noquote() << debugText;
446

447 448
}

449 450
void KisOpenGL::initializeContext(QOpenGLContext *ctx)
{
451
    KisConfig cfg;
452 453
    initialize();

454
    dbgUI << "OpenGL: Opening new context";
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
    if (isDebugEnabled) {
        // Passing ctx for ownership management only, not specifying context.
        // QOpenGLDebugLogger only function on the current active context.
        // FIXME: Do we need to make sure ctx is the active context?
        QOpenGLDebugLogger* openglLogger = new QOpenGLDebugLogger(ctx);
        if (openglLogger->initialize()) {
            qDebug() << "QOpenGLDebugLogger is initialized. Check whether you get a message below.";
            QObject::connect(openglLogger, &QOpenGLDebugLogger::messageLogged, &openglOnMessageLogged);
            openglLogger->startLogging(isDebugSynchronous ? QOpenGLDebugLogger::SynchronousLogging : QOpenGLDebugLogger::AsynchronousLogging);
            openglLogger->logMessage(QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("QOpenGLDebugLogger is logging.")));
        } else {
            qDebug() << "QOpenGLDebugLogger cannot be initialized.";
            delete openglLogger;
        }
    }
470 471

    // Double check we were given the version we requested
472 473 474
    QSurfaceFormat format = ctx->format();
    QOpenGLFunctions *f = ctx->functions();
    f->initializeOpenGLFunctions();
475

476 477 478 479 480
    QFile log(QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/krita-opengl.txt");
    log.open(QFile::WriteOnly);
    QString vendor((const char*)f->glGetString(GL_VENDOR));
    log.write(vendor.toLatin1());
    log.write(", ");
481
    log.write(openGLCheckResult->rendererString.toLatin1());
482 483 484
    log.write(", ");
    QString version((const char*)f->glGetString(GL_VERSION));
    log.write(version.toLatin1());
485
    log.close();
486 487

    // Check if we have a bugged driver that needs fence workaround
488
    bool isOnX11 = false;
489
#ifdef HAVE_X11
490 491
    isOnX11 = true;
#endif
492

493
    if ((isOnX11 && openGLCheckResult->rendererString.startsWith("AMD")) || cfg.forceOpenGLFenceWorkaround()) {
494
        NeedsFenceWorkaround = true;
Stefano Bonicatti's avatar
Stefano Bonicatti committed
495
    }
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521


    /**
     * NVidia + Qt's openGL don't play well together and one cannot
     * draw a pixmap on a widget more than once in one rendering cycle.
     *
     * It can be workarounded by drawing strictly via QPixmapCache and
     * only when the pixmap size in bigger than doubled size of the
     * display framebuffer. That is for 8-bit HD display, you should have
     * a cache bigger than 16 MiB. Don't ask me why. (DK)
     *
     * See bug: https://bugs.kde.org/show_bug.cgi?id=361709
     *
     * TODO: check if this workaround is still needed after merging
     *       Qt5+openGL3 branch.
     */

    if (vendor.toUpper().contains("NVIDIA")) {
        NeedsPixmapCacheWorkaround = true;

        const QRect screenSize = QApplication::desktop()->screenGeometry();
        const int minCacheSize = 20 * 1024;
        const int cacheSize = 2048 + 2 * 4 * screenSize.width() * screenSize.height() / 1024; //KiB

        QPixmapCache::setCacheLimit(qMax(minCacheSize, cacheSize));
    }
522 523


524
}
525

526 527 528 529 530 531
const QString &KisOpenGL::getDebugText()
{
    initialize();
    return debugText;
}

532 533 534 535 536
// XXX Temporary function to allow LoD on OpenGL3 without triggering
// all of the other 3.2 functionality, can be removed once we move to Qt5.7
bool KisOpenGL::supportsLoD()
{
    initialize();
537
    return openGLCheckResult->supportsLoD();
538 539
}

540
bool KisOpenGL::hasOpenGL3()
541 542
{
    initialize();
543 544 545 546 547 548 549
    return openGLCheckResult->hasOpenGL3();
}

bool KisOpenGL::hasOpenGLES()
{
    initialize();
    return openGLCheckResult->isOpenGLES;
550 551
}

552 553
bool KisOpenGL::supportsFenceSync()
{
554
    initialize();
555
    return openGLCheckResult->supportsFenceSync();
556
}
557

558 559
bool KisOpenGL::needsFenceWorkaround()
{
560
    initialize();
561 562 563
    return NeedsFenceWorkaround;
}

564 565 566 567 568 569
bool KisOpenGL::needsPixmapCacheWorkaround()
{
    initialize();
    return NeedsPixmapCacheWorkaround;
}

570
void KisOpenGL::setDefaultFormat(bool enableDebug, bool debugSynchronous)
571
{
572 573 574 575
    if (defaultFormatIsSet) {
        return;
    }
    defaultFormatIsSet = true;
576
    QSurfaceFormat format;
577
#ifdef Q_OS_OSX
578
    format.setVersion(3, 2);
Halla Rempt's avatar
Halla Rempt committed
579 580
    format.setProfile(QSurfaceFormat::CoreProfile);
#else
581
    // XXX This can be removed once we move to Qt5.7
582
    format.setVersion(3, 0);
Halla Rempt's avatar
Halla Rempt committed
583 584 585
    format.setProfile(QSurfaceFormat::CompatibilityProfile);
    format.setOptions(QSurfaceFormat::DeprecatedFunctions);
#endif
586 587 588
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
589
    format.setSwapInterval(0); // Disable vertical refresh syncing
590 591 592 593 594 595
    isDebugEnabled = enableDebug;
    if (enableDebug) {
        format.setOption(QSurfaceFormat::DebugContext, true);
        isDebugSynchronous = debugSynchronous;
        qDebug() << "QOpenGLDebugLogger will be enabled, synchronous:" << debugSynchronous;
    }
596
    QSurfaceFormat::setDefaultFormat(format);
597 598
}

599 600
bool KisOpenGL::hasOpenGL()
{
601
    return openGLCheckResult->isSupportedVersion();
602
}