繁体   English   中英

QtOpenGL-共享的OpenGL上下文

[英]QtOpenGL - shared OpenGL context

我有一个Qt4 + OpenGL + Python应用程序,它可以生成几何图形,然后将其绘制在QGLWidget

class GLWidget(QtOpenGL.QGLWidget):

   def initializeGL(self):
       (...)
       self.scene.buildScene() #this generates geometry and creates OpenGL Lists

   def paintGL(self):
       (...)
       self.scene.renderScene() # this calls glCallList on every object

这很好。 问题在于,根据输入的不同,几何图形生成可能需要几秒钟甚至几分钟的时间。 这一次没有Qt窗口出现,因为应用程序卡在initializeGL()

我试图通过使用共享资源的其他OpenGL上下文创建另一个线程来避免这种“滞后”:

class GLWidget(QtOpenGL.QGLWidget):
   def __init__(self, parent):
      (...)
      self.buildingThread = threading.Thread(target=self.buildingThreadFunc)

   def buildingThreadFunc(self):
      self.buildFormat = QtOpenGL.QGLFormat()
      self.buildingContext = QtOpenGL.QGLContext(self.buildFormat)
      self.buildingContext.create(self.context()) #This returns False
      self.buildingContext.device() #This returns None
      self.buildingContext.initialized() #This returns False

      self.scene.buildScene() #And finnally this fails because 
                              #there is no context to call `glGenLists`

   def initializeGL(self):
      (...)
      self.buildingThread.start()

   def paintGL(self):
      (...)
      self.scene.renderScene() #Here, every element on scene shall successively appears during geometry creation

核心问题是QGLContext::create返回False,但我不知道为什么。

此外:我关于其他线程和上下文的想法正确吗? 能行吗 我想glGenLists和同时在QGLWidget上绘画可能存在问题,但我希望至少其他小部件能够“响应”。

多年前, 我读了这篇博客文章 ,解释了如何使用多个渲染线程。 我有一个在后台显示的GL加载小部件,另一个QGLWidget正在启动。 根据博客文章,我做了一个演示,展示了我的数十个加载小部件,所有这些部件都是同时启动的。

还要看看这个例子:

http://doc.qt.io/archives/qt-4.8/qt-demos-glhypnotizer-example.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM