QOpenGLTexture and QOpenGLFrameBufferObject
I'm trying to port a previous project to the new Qt5 OpenGL classes. I want to render to a texture using an FBO. The previous code utilized multiple textures which I attaching to the FBO on-demand. So, I would attach a certain texture object, perform the rendering, attach another texture and perform a different operation and have the output rendered to the newly attached texture, and so on.
I was wondering how would I go about doing this using the Qt5 OpenGL classes. For example, I can't figure out how to attach a certain QOpenGLTexture object to a QOpenGLFrameBufferObject so that I can render to it. I can see that there is a texture() method and a takeTexture() method. But they both just return the texture id. Also, how can I change the active texture unit? For example, I want to sample from two textures in my shader program. So, I need to bind two textures to different texture units.
Thanks in advance..
Regarding the second question: There is an overload of the bind() method in QOpenGLTexture that takes an argument for the desired texture unit:
Don't know about the first question, sorry.
Thanks Cmdr. That is helpful. The main problem I have now is that I don't see any method in QOpenGLFrameBufferObject that would return a QOpenGLTexture object. There is only the toImage() method and the texture() and takeTexture() methods.
I guess I could just construct a QOpenGLTexture using the QImage returned from toImage(). But I'm not sure if that would be efficient. As for texture() and takeTexture(), I don't see how their return values can be used using the new classes.
No, the QImage won't help here. I suggest you use vanilla OpenGL functions on the texture id returned by QOpenGLFramebufferObject::texture() and don't use QOpenGLTexture for this purpose at all. This shouldn't be too difficult: use glActiveTexture to set the texture unit you want to bind the texture to, and then glBindTexture to bind it. I don't know which parameters QOpenGLFrameBufferObject sets on the texture, so you might need to disable mip mapping with glTexParameteri.