Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Switching from QOpenGLExtraFunctions to QOpenGLFunctions_4_4_Core broke rendering
I need a function from modern OpenGL, so
QOpenGLExtraFunctionsis no more enough.
I've replaced all
And I've changed
f = context()->extraFunctions(); f->initializeOpenGLFunctions();
f = context()->versionFunctions<QOpenGLFunctions_4_4_Core>();
I can successfully use
QOpenGLFunctions_4_4_Coreto, for example, change the
glClearColorto green, so the functions are initialized.
But my rendering is broken. I was rendering a colored rectangle as a background, for example, but now I see nothing but the empty area of a
QOpenGLWidgetfilled with the background color.
Why did switching from
QOpenGLFunctions_4_4_Corechanged the state of OpenGL so rendering is broken? Or do I miss something?
My OpenGL implementation version is 4.4, and I set 4.4 Core in a
QSurfaceFormatbefore I pass it to
I've found the source of the problem.
I was drawing offscreen into my FBO and then doing post-processing drawing a frame quad into the default framebuffer. And I was calling
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, 0)to set the default framebuffer. However the default framebuffer created by
QOpenGLWidgethas id 4, it is an offsreen FBO. But for some reason everything was working with
QOpenGLExtraFunctions. But when I switched to
QOpenGLFunctions_4_4_Corethe issue revealed itself, and I was seeing nothing but the area filled with the clear color. Now I call
glBindFrameBuffer(GL_DRAW_FRAMEBUFFER, defaultFboId), where defaultFboId is 4, and the issue was fixed.
The only explanation I may suggest is that though
QOpenGLFunctions_4_4_Corehas the same functions as
QOpenGLExtraFunctionsplus some new, these two classes actually have different code for their functions (I have no time to look into the sources) OR they map their function calls to different OpenGL API functions (is it possible?), and so the executed by the driver code of
glBindFrameBufferis different for these two classes.
Though I have no idea why my code was working when I was passing 0 instead of 4 specifying wrong framebuffer. May be
glBindFrameBufferis less restricted and can handle some errors.
Core programming is very different than compatibility mode. You have to program opengl differently than most of the examples on the internet.
This site should help. It covers the basics in depth:
Also search on the differences between core programming and compatibility mode. If you don't have the patience for that then use a non core version of the functions.
@fcarney But I thought I was programming in core mode...
QSurfaceFormat::setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile)and so created a context in core mode, but was I actually using compatibility version of functions with core profile?
Because I actually already was following some of the rules to program in core mode. Like I have to bind VAO always when I call
I guess I made a poor assumption. I was thinking you might be uninformed what core mode was. Not sure on that. I am not sure what QOpenGLExtraFunctions assumes as far as modes. Can you check to see if you were indeed in core mode? I wonder if using those functions makes the assumption you are not. Or if something really is broken.
@fcarney I've tried to switch to
QOpenGLFunctions_4_4_Compatibility, but now
QOpenGLContext::versionFunctions<QOpenGLFunctions_4_4_Compatibility>()returns NULL, what is expected, because I'm creating the context in core mode, because I've set that in
QSurfaceFormat. I'm pretty sure I always was in Core mode... Don't know how to check that exactly, but that would be very surprising, If QT was initializing Compatibility profile.
fcarney last edited by fcarney
Did 4.4 introduce any more shader programs that need to be defined for the pipeline? I seem to remember it adding 2 new shader types to the pipeline, but I was not sure they were required to be defined.
Edit: Versus 3.3
wrosecrans last edited by
@fcarney As far as I know, you aren't required to use any of the new shader types. Just opt-in if they are useful for you. Using 3.3 core profile code under 4.4 should normally Just Work.
Try breaking out the debug logger class and see if it spits out anything useful: https://doc.qt.io/qt-5/qopengldebuglogger.html
@wrosecrans Yes, I'm already monitoring OpenGL errors using
glDebugMessageCallback, but It shows no error, as well as
@fcarney I think that the point is that I already was successfully rendering in 4.4 Core, and now I just have changed the class which provides the OpenGL functions, I didn't change the OpenGL profile, and so I don't use any new features.
QOpenGLFunctions_4_4_Corejust has to give me more functions, but instead it broke already successfully used, may be some function calls don't happen for some reason, and so OpenGL state is broken.
It says here that OpenGLExtraFunctions is for OpenGL ES:
Maybe that is the difference. I have not programmed ES so I am unsure if the calls would be compatible.
@fcarney May be. I guess I have to make a separated project with minimal working code to determine the problem and where is the difference.
@fcarney Hi, I've solved the issue, I've appended explanation into the first post, that is a strange behavior for me, or I may miss something about how does QT work with framebuffers.
fcarney last edited by fcarney
Did you call glGenFramebuffers or where did you get the number for that framebuffer?
Apparently 0 breaks the binding to the GL_DRAW_FRAMEBUFFER
Edit: If its a "magic" number you tried it is likely to break later.
@fcarney No, that is not a magic number, I actually call
QOpenGLWidget::paintGL, it just returns 4 always with current project code. Of course it may change.
@fcarney And well, I've remembered about
QOpenGLWidget::defaultFramebufferObject, it returns the same value as
f->glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &defaultFboId), which I had to use when I was binding the default QT's framebuffer to do final rendering, but I just passed 0 and it was working, so I was thinking about it no more.