Jump to content
  • Advertisement
Sign in to follow this  
antimouse

OpenGL Qt+OpenGL texture issue

This topic is 3300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all! I'm having a weird (at least to me) problem with textures using OpenGL through Qt. I made a user interface in Qt and I'm using OpenGL to show the images captured from two different cameras. For this purpose, I created a GLCamWidget, which inherits from QGLWidget, and a GLStereoWidget, which also inherits from QGLWidget. In the preview window, I instantiate two objects of GLCamWidget. Each object shows a different camera image through a 2D texture. As I have two instances of the class, I suppose (I'm not sure about it) that I have two different OpenGL contexts. The reason for this line of thought is that I use glGenTextures() in the constructor of the class, and the function returns the same ID (ID = 1) for each texture. And it all works fine. When I choose "Stereo Mode" in my program, I create an instance of GLStereoWidget and it shows the images of both cameras side by side, using 2 textures, one for each image. Again, I suppose it's a different context, because the ID's returned are 1 and 2. If it was the same context, it could not return 1, right? Ok, that works fine too. The problem occurs when I close the stereo window. I delete the GLStereoWidget object, and, in his destructor, I use glDeleteTextures() to delete these 2 textures (I suppose from THIS CONTEXT). Although, this function is misteriously affecting one of my GLCamWidget objects, because one of them stops exhibiting the image from the camera, while the other one remains normal. I can see no reason for that happening. If anyone can help me get through this, I would really appreciate. I didn't post any code here because it's split in several modules, but if you think it's really necessary, I'll do it. Screenshots: 1) Before stereo (GLCamWidget objects) 2) During stereo (GLStereoWidget object) 3) After stereo (GLCamWidget objects, the one on the right not working anymore) Thank you!!

Share this post


Link to post
Share on other sites
Advertisement
You should either make sure that the corresponding context is the current one (there is some QGLWidget::getContext ()->makeCurrent function) or you can just share a context between all GL widgets. I think the QGLWidget constructor can accept a context to share. The latter option seems to be better suited because it enables you to avoid context switches as well as it allows you to possibly use all textures in all of your GL widgets no matter in which one you have created the texture.

Share this post


Link to post
Share on other sites
Waterwalker, thanks for replying. I'll try your suggestion, it seems better than what I'm doing. Still, I'm curious about why deleting those 2 textures are interfering with the GLCamWidget one. Do you have any clue?

Share this post


Link to post
Share on other sites
I think Waterwalker hit the nail on the head. My guess is the widget that loses a texture is always simply going to be the last one you drew to before deleting the texture, because that's the one with the active context. Remember, the gl___ commands are totally naive about context; they just assume it's set up and ready to go. Also keep in mind that GL's object naming is very simple for most drivers; every context starts with object 1 as the first object allocated, and just increments it for further objects, meaning that GL has no way to tell which context the texture you're referring to is supposed to belong to. That means that when you ask it to delete texture 1, it's just deleting texture 1 in whatever happens to be the current context.

I would strongly recommend following Waterwalker's advice and sharing a context among all your widgets, for a number of reasons. First, you'll consume less memory only having a single copy of each texture loaded at once. Second, context switching can be a VERY expensive operation, so you should always avoid multiple contexts whenever possible. Third, you won't have to concern yourself with the active context.

Share this post


Link to post
Share on other sites
Quote:
Original post by antimouse
Waterwalker, thanks for replying. I'll try your suggestion, it seems better than what I'm doing. Still, I'm curious about why deleting those 2 textures are interfering with the GLCamWidget one. Do you have any clue?

Just as Shinkage said I would assume that the GLCamWidget's context is active when you call delete on the textures of the other widget. Hence the texture id's 1 and 2 in the GLCamWidget get deleted, not the ones of the other widget you are closing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!