7

QOpenGLFunctions seems to be missing important functions such as glInvalidateFramebuffer and glMapBuffer. From what I understand QOpenGLFunctions loads the intersection of both desktop OpenGL functions and ES functions. If that's the case, why aren't these two functions present? From what I can tell glMapBuffer is in both.

Am I misunderstanding QOpenGLFunctions, or are they actually missing functions(unlikely)?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Ben
  • 1,816
  • 1
  • 20
  • 29

2 Answers2

10

QOpenGLFunctions just exposes the common subset of OpenGL 2 (+FBO) and OpenGL ES 2. That's why your functions are not there. glMapBuffer is in OpenGL 2 but not in ES 2 (but there's an OES extension); glInvalidateFramebuffer is in OpenGL 4.3.


If you need any other function apart from those of the common subset you can:

  • Starting with Qt 5.6, use QOpenGLExtraFunctions, which aims at the OpenGL ES 3.0 / 3.1 API (and the rough equivalent functionality on desktop OpenGL). As such, it does have both glMapBuffer and glInvalidateFramebuffer.

  • resolve it yourself via QOpenGLContext::getProcAddress

  • use QOpenGLContext::versionFunctions<T>() to get a function object containing all the functions for a given OpenGL version, for instance

    auto functions = context->versionFunctions<QOpenGLFunctions_4_3_Core>();
    if (!functions) error();
    functions->initializeOpenGLFunctions();
    functions->glInvalidateFramebuffer(...);
    
  • #include <QOpenGLExtensions> and use the class(es) wrapping the extensions you need, for instance

    auto functions = new QOpenGLExtension_ARB_invalidate_subdata;
    if (!functions->initializeOpenGLFunctions()) error();
    functions->glInvalidateFramebuffer(...)
    
  • wrap a combination of the above in a class that will use the resolved calls given a suitable GL version, or fall back to extensions, or fail (e.g.: QOpenGLTexture).

For glMapBuffer, it is actually exposed somehow wrapped by QOpenGLBuffer.

peppe
  • 21,934
  • 4
  • 55
  • 70
  • Brilliant! I find OpenGL in Qt5 to be confusing at best, this certainly helped me. But one big Q remains, in my existing codebase I have lots of opengl code that I am now trying to bring into my Qt5 app. Is there any way to use QOpenGLContext::versionFunctions() method to get the correct functions object without having to prefix each and every opengl call with functions-> ? – Mr. Developerdude Sep 21 '16 at 22:30
  • When you say "correct functions", are you referring to a specific GL version? – peppe Sep 22 '16 at 05:22
4

There are multiple reasons for those two cases and the one in the comment:

1) As far as I am aware, the addition process was selective. Only those functions got added that you would need to resolve manually.

In the aforementioned glDrawArrays case, that function have been available for a while, both in desktop OpenGL as well as ES where Qt is supported, so there is not much need to resolve anything there manually.

You can just use them right away the regular opengl way, including gl.h and all that.

2) For the time being, Qt does not support OpenGL ES 3 through this interface. Your aforementioned functions, glMapBuffer and glInvalidateFramebuffer are likely to fall into this category. They are not available in OpenGL ES 2 "by default".

If there is any function not being exposed and not covered by the aforementioned reasons, it is likely to be an overlook or so.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • You mean by including gl.h? Those functions aren't available in windows, though. – Ben May 26 '14 at 09:36
  • I'm still confused. The opengl headers provided on some systems don't include the functions I mentioned in my question. How do you obtain those? – Ben May 26 '14 at 09:53
  • Ah, I didn't realise they weren't available in ES 2. Thanks. – Ben May 26 '14 at 10:07