[英]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.