[PyOpenGL-Users] glReadPixels not working in thread
Brought to you by:
mcfletch
|
From: Shir G. <shi...@gm...> - 2018-01-21 14:19:11
|
Hi,
My code works just fine without threading, but I’m trying to make it faster by processing the OpenGL data in another thread.
class Cube(app.Canvas):
*
*
*
def finish(self):
im = gl.glReadPixels(0, 0, self.canvas_size[0], self.canvas_size[1], gl.GL_RGB, gl.GL_FLOAT)
rgb = np.copy(np.frombuffer(im, np.float32)).reshape(self.canvas_size + (3,))[::-1, :] # Read buffer and flip Y
im = gl.glReadPixels(0, 0, self.canvas_size[0], self.canvas_size[1], gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT)
dep = np.copy(np.frombuffer(im, np.float32)).reshape(self.canvas_size + (1,))[::-1, :] # Read buffer and flip Y
# Convert z-buffer to depth map
mult = (self.clip_near * self.clip_far) / (self.clip_near - self.clip_far)
addi = self.clip_far / (self.clip_near - self.clip_far)
bg = dep == 1
dep = mult / (dep + addi)
dep[bg] = 0
return rgb, np.squeeze(dep)
def next_batch(self, size):
**** something
self.draw()
col, dep = self.finish()
**** something
def load_data(o, size, q):
while True:
q.put(o.next_batch(size))
cube = Cube()
data_q = Queue()
p = Process(target=load_data, args=(cube, args.nof_load, data_q,))
p.start()
qg = data_q.get()
BUT when it reaches this line:
im = gl.glReadPixels(0, 0, self.canvas_size[0], self.canvas_size[1], gl.GL_RGB, gl.GL_FLOAT)
The program get stuck
Any idea why this happens when i use threading?
Thanks
Shir
|