Answer the question
In order to leave comments, you need to log in
How to properly manage OpenGL resources in a Qt application?
Before that, I used the QPainter API, and there were no such issues. Allocate resources in the constructor, delete them in the destructor. I decided to switch to OpenGL and faced the fact that working with resources is possible only in the rendering thread. I draw under QML, by event
QQuickWindow::beforeRenderingNow all objects that own resources have an init method and an isReady flag, and on each draw call it has to check whether it has already been initialized or not. Either create objects in the desired thread, and each time check whether it has already been created. With the removal has not yet decided what to do. When clicking the button responsible for changing the style, I used to be able to simply replace all the bitmaps with others, directly in the click handler. And now we need to cock the isDirty flag and wait for the draw call to update / delete the textures, and the flag needs to be checked every frame. We have to check whether the buffer has already been initialized, or is just waiting for the right thread to be initialized. There is a lot of overhead and somehow everything looks uncomfortable and illogical. Am I missing something and is there really no other way? I really want to manage resources when it's convenient for me, instead of waiting for the desired flow. Is it even possible? Is there any practice?
void SquircleRenderer::paint()
{
if (!m_program) {
initializeOpenGLFunctions();
m_program = new QOpenGLShaderProgram();
...
...
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question