Back to Blog home

Graphics on Windows from a different angle

Published on Wednesday October 24, 2012 by Jason Barron in Graphics OpenGL Qt Windows | Comments

With Qt 5 we are making the bold move of making OpenGL 2.0 a requirement for using  QtQuick2. There are several challenges with this new requirement, many of which have been discussed on the blogs and mailing lists already, but today I want to talk about one issue in particular and that's OpenGL on Windows.

Microsoft has included OpenGL in Windows since Windows 98 (or earlier?), however the initial version was a software implementation and only supported version 1.1 of the API. Over time, the implementation has been improved so that today it is implemented as a wrapper on top of Direct3D. This is great, but unfortunately the version of the API that is supported has remained the same and that means it is not sufficient for running QtQuick2 or even Qt's GL paint engine. You can insert your own conspiracy theory about why Microsoft has let OpenGL stagnate on Windows, but every theory will likely involve Direct3D. D3D is a component of DirectX that offers similar functionality to OpenGL. It is most commonly used by game developers to target desktop Windows and also XBox, but is also used by CAD applications.

Typically when a developer wants to run or develop something that requires OpenGL on Windows, the first place they go is to their hardware vendor's website and download the latest drivers from Intel, NVidia, AMD or whoever.. This is fine, but can be somewhat inconvenient for end users of OpenGL applications. We wanted to avoid this problem with Qt applications so deployment would essentially be the same as with Qt 4 (but with possibly more DLLs). Luckily for us, we weren't the first people to experience this problem. Most browsers these days (except IE) are supporting WebGL out of the box. WebGL is a 3D canvas API available through Javascript. The API is based on OpenGL ES 2.0 and the shader language is GLSL ES. So how can browsers offer an OpenGL 2 API without requiring new drivers? The solution is called the ANGLE (Almost Native Graphics Layer Engine) project.

ANGLE is a BSD licensed project that implements the OpenGL ES 2.0 API on top of DirectX 9.0c. In addition to this, it also implements the EGL API and contains a shader cross compiler that takes GLSL ES code and converts it to HLSL which is the shader language used in DirectX. So ANGLE allows us to essentially run the Qt Scene Graph on top of DirectX without modifying any of our code. Friedemann has already done most of the hard work by adding support for GLES2 and EGL into the Windows platform plugin and as a result it has been possible to use Qt 5 with ANGLE for quite some time now. However, to make this experience more painless, we are including ANGLE in Qt's 3rdparty directory and making it the default OpenGL configuration on Windows.

For QML applications and lightweight OpenGL apps, you can use this new configuration to deploy your apps without requiring your end users to install new graphics drivers. On the other hand if your application requires full desktop OpenGL, then it's simply a matter of configuring Qt with "-opengl desktop" and you get the same behavior as before.

One additional benefit of using ANGLE on Windows is that our graphics pipeline and multimedia pipeline are now based on the same underlying technology (DirectX) so we can take some shortcuts to get video frames into the Scene Graph more efficiently. Taking this one step further, Windows Vista introduced a new driver model called WDDM and one of the features here is that DirectX surfaces can now be shared across processes. This little feature will come in handy for our WebKit2 work which has seperate processes for the web renderer and the ui. All of this goodness might not make it into the 5.0 release, but it's  all in progress so hopefully it makes an appearance soon!

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.