Update OpenGL-related config and handling for ANGLE
Closed, ResolvedPublic

Description

Though ANGLE does expose an OpenGL ES 3.0 interface to Krita, it isn't actually using OpenGL under the hood. So certain places within Krita needs to be updated to reflect the addition of ANGLE on the Windows build.

  1. Differences due to -opengl dynamic configure option:
  2. If the environment variable QT_OPENGL is set, Qt will use the specified OpenGL type, unless it is software and the software fallback is not available then it will use the desktop OpenGL.
  3. If the environment variable QT_OPENGL is not set, Qt decides the OpenGL driver to use during first creation of an OpenGL context by these checks (that's when QApplication is constructed):
    1. It gets the graphics driver information (by utilizing D3D9 API)
    2. It tests the native desktop OpenGL version (targets for OpenGL 2.0)
    3. It checks the OpenGL bug list (either built-in or external) to see what features to disable
    4. It decides whether to use desktop OpenGL, ANGLE or the software renderer

Possible OpenGL choices:

Assuming OpenGL software renderer fallback is present:

  • Krita OpenGL off, doesn't matter what Qt's choice is
  • Krita OpenGL on, Qt auto detect, Qt uses desktop OpenGL
  • Krita OpenGL on, Qt auto detect, Qt uses ANGLE D3D11
  • Krita OpenGL on, Qt auto detect, Qt uses ANGLE WARP (D3D11 software renderer)
  • Krita OpenGL on, Qt auto detect, Qt uses ANGLE D3D9 (and then crash in Krita)
  • Krita OpenGL on, Qt auto detect, Qt uses OpenGL software renderer fallback
  • Krita OpenGL on, Qt force desktop OpenGL
  • Krita OpenGL on, Qt force ANGLE D3D11
  • Krita OpenGL on, Qt force ANGLE WARP
  • Krita OpenGL on, Qt force ANGLE D3D9 (and then crash in Krita)
  • Krita OpenGL on, Qt force OpenGL software renderer fallback

Quirks:

  • ANGLE D3D9 will crash Krita somewhere, because the current code only works with OpenGL ES 3.0 and OpenGL ES 3.0 requires using D3D11 in ANGLE.
    • Auto choosing this should really only be possible when disabled in the OpenGL bug list, so we can ship our own bug list and make sure this will not happen.
    • We should hijack QT_ANGLE_PLATFORM to make sure it doesn't get specified.
    • We don't care about XP
    • We should still add a check and disable OpenGL whenever this happens.
  • ANGLE WARP: when using the ANGLE compiled from the Qt source it would crash, but if I use the ANGLE libraries from Chrome it doesn't.
    • Try compiling updated ANGLE version from source instead?
  • Desktop OpenGL means OpenGL 2.0. While Krita might still work, would it be better to choose ANGLE instead?
    • It might be possible to re-initialize the OpenGL choice by some trickery, I'll check.

Configuration/UI changes needed:

  • OpenGL: Change to Graphics Rendering choices:
    • Detect Automatically - Krita OpenGL
    • Use Software Rendering - Krita OpenGL off
    • Hardware-accelerated Rendering - Detect Automatically - Krita OpenGL on with Qt detection (possibly slightly modified)
    • Use OpenGL - Krita OpenGL on, force desktop OpenGL?
    • Use Direct3D 11 (via ANGLE) - Krita OpenGL on, force ANGLE D3D11
    • Use Software Direct3D 11 (via ANGLE) - Krita OpenGL on, force ANGLE WARP check later
  • Scaling mode: Need to check...
  • Use texture buffer: Need to check what difference it makes with ANGLE...
  • Add information about the renderer in use (esp. for use in bug reports)

Krita startup steps:

  1. Read values of QT_OPENGL and QT_ANGLE_PLATFORM and unset them
  2. If QT_OPENGL was set, set the appropriate Qt::AA_UseDesktopOpenGL/Qt::AA_UseOpenGLES/Qt::AA_UseSoftwareOpenGL flag
  3. Otherwise check config; if OpenGL or ANGLE is specified set the appropriate flag
  4. Set QT_ANGLE_PLATFORM to d3d11

Possible way to check the Qt OpenGL detection:

  1. Unset QT_OPENGL
  2. Set QT_ANGLE_PLATFORM to d3d11
  3. Create QGuiApplication
  4. Initialize an OpenGL context
    • OpenGL context invalid => no Krita OpenGL
    • OpenGL is GLES => desktop OpenGL probably doesn't work
    • OpenGL is desktop OpenGL => desktop OpenGL might work
  5. Tear down OpenGL context and QGuiApplication
  6. set AA_UseDesktopOpenGL
  7. Create QGuiApplication
  8. Initialize an OpenGL context
    • OpenGL context invalid => desktop OpenGL doesn't work
  9. Tear down OpenGL context and QGuiApplication

(TODO)