Multi-texturing using QOpenGLTexture and QOpenGLFrameBufferObject

informer2000

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.

To clarify, the main problem I'm having with the new API 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.

peppe

Yes, QOpenGLFrameBufferObject predates QOpenGLTexture and as such, it doesn't use or expose QOpenGLTexture. It should be added, but actually, QOpenGLFBO should be just rewritten to support multiple attachments.

Apart from this, what's the problem at manually using GL calls?

GLuint textureId = fbo->texture();
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, textureId);

glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_3D, anotherTexture);

QOpenGLTexture *yetAnother = getTexture();
yetAnother->bind(2);

program->setUniformValue("samplerForTheFBOTexture", GL_TEXTURE4 - GL_TEXTURE0);
program->setUniformValue("my3dSampler", GL_TEXTURE9 - GL_TEXTURE0);
program->setUniformValue("anotherSampler", 2);
// or use layout (binding = ) in GLSL

etc.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related