[Development] OpenGL Support in Qt5

Sean Harmer sean.harmer at kdab.com
Fri Jul 13 16:00:23 CEST 2012


Hi,

I have pushed the following WIP patch for review:

https://codereview.qt-project.org/#change,30554

The idea of this is to provide a set of classes that expose the OpenGL 
functions specific to the version and profile of the corresponding 
QOpenGLContext.

This means that it is no longer necessary to use GLEW or similar or to 
manually resolve OpenGL entry points by hand. This allows developers using 
these classes to get per-context entry points easily and to also get compiler 
errors rather than runtime errors if they try to use a function not supported 
by that {version, profile} of OpenGL.

The set of QOpenGLFunctions_<Major>_<Minor>_<Profile> classes are generated 
directly from the official OpenGL spec files as published by the Khronos 
group. As such we could potentially make the generation of these classes part 
of the qtbase bootstrap process. This would require importing the OpenGL spec 
files into the qtbase repo along with the code generator.

The current WIP patch exposes the version specific functions via 
QOpenGLContext::versionFunctions() at present as there already exists a 
function QOpenGLContext::functions() which returns a pointer to a 
QOpenGLFunctions object.

QOpenGLFunctions provides basically the same as the new classes but for the 
common subset of Desktop OpenGL 2 and OpenGL ES 2 as this is what is required 
by Qt itself (e.g. in QQ2).

Another motivation for these new classes is that the existing QOpenGLFunctions 
is not enough to support modern OpenGL on the desktop. It cannot answer 
questions such as "are geometry shaders supported?". Geometry shaders are 
available in Qt4's QGLShaderProgram but are disabled in Qt 5's 
QOpenGLShaderProgram at present.

If we combine these proposed classes with the extension resolved (which should 
be improved and made public) then we would able to easily check for support 
(either as a core feature or via an extension) and also be able to easily get 
access to resolved function entry points in the implementation.

It would be a fairly simple job to extend the code generator to create classes 
for OpenGL extensions too (they are also in the spec files). I am currently 
thinking that the extension matcher can be used to query the available 
extensions and then as a factory to a family of classes that each represent 
one extension.

I would like to seek opinion on whether people are happy with this general 
approach and how it should be placed in relation to the existing 
QOpenGLFunctions::functions(). Alongside it? Replace it?

I do worry about the number of added symbols to QtGui though - OpenGL is not a 
small API. Perhaps adding these classes as plugins would be a good idea?

I believe that such a framework coupled with QWindow would make Qt5 an 
excellent platform for OpenGL development as it would allow us to develop 
additional OpenGL enabler classes easily e.g. QOpenGLVertexArrayObject.

Comments/thoughts/flames?

Cheers,

Sean
--
Dr Sean Harmer | sean.harmer at kdab.com | Senior Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions



More information about the Development mailing list