def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 300) # for some reason Windows wants a tall window... data = np.random.rand(*shape).astype(np.float32) use_shape = shape + (3, ) with Canvas(size=shape[::-1]) as c: orig_tex = Texture2D(data) fbo_tex = Texture2D(use_shape, format='rgb') rbo = RenderBuffer(shape, 'color') fbo = FrameBuffer(color=fbo_tex) c._glir.set_verbose(True) assert_equal(c.size, shape[::-1]) set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert_equal(out_tex.shape, c.size[::-1]) assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = RenderBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 300) # for some reason Windows wants a tall window... data = np.random.rand(*shape).astype(np.float32) use_shape = shape + (3,) with Canvas(size=shape[::-1]) as c: orig_tex = Texture2D(data) fbo_tex = Texture2D(use_shape, format='rgb') rbo = RenderBuffer(shape, 'color') fbo = FrameBuffer(color=fbo_tex) c.context.glir.set_verbose(True) assert_equal(c.size, shape[::-1]) set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert_equal(out_tex.shape, c.size[::-1]) assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = RenderBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 100) data = np.random.rand(*shape).astype(np.float32) orig_tex = Texture2D(data) use_shape = shape + (3,) fbo_tex = Texture2D(shape=use_shape, dtype=np.ubyte, format='rgb') rbo = ColorBuffer(shape=shape) fbo = FrameBuffer(color=fbo_tex) with Canvas(size=(100, 100)) as c: set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = DepthBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_renderbuffer(): # Set with no args assert_raises(ValueError, RenderBuffer) # Set shape only R = RenderBuffer((10, 20)) assert R.shape == (10, 20) assert R.format is None # Set both shape and format gloo.get_a_context().glir.clear() R = RenderBuffer((10, 20), 'color') assert R.shape == (10, 20) assert R.format is 'color' # glir_cmds = R._context.glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'CREATE' assert glir_cmds[1][0] == 'SIZE' # Orther formats assert RenderBuffer((10, 20), 'depth').format == 'depth' assert RenderBuffer((10, 20), 'stencil').format == 'stencil' # Test reset size and format R.resize((9, 9), 'depth') assert R.shape == (9, 9) assert R.format == 'depth' R.resize((8, 8), 'stencil') assert R.shape == (8, 8) assert R.format == 'stencil' # Wrong formats assert_raises(ValueError, R.resize, (9, 9), 'no_format') assert_raises(ValueError, R.resize, (9, 9), []) # Resizable R = RenderBuffer((10, 20), 'color', False) assert_raises(RuntimeError, R.resize, (9, 9), 'color') # Attaching sets the format F = FrameBuffer() # R = RenderBuffer((9, 9)) F.color_buffer = R assert F.color_buffer is R assert R.format == 'color' # F.depth_buffer = RenderBuffer((9, 9)) assert F.depth_buffer.format == 'depth' # F.stencil_buffer = RenderBuffer((9, 9)) assert F.stencil_buffer.format == 'stencil'
def test_renderbuffer(): # Set with no args assert_raises(ValueError, RenderBuffer) # Set shape only R = RenderBuffer((10, 20)) assert R.shape == (10, 20) assert R.format is None # Set both shape and format gloo.context.get_current_glir_queue().clear() R = RenderBuffer((10, 20), 'color') assert R.shape == (10, 20) assert R.format is 'color' # glir_cmds = R._glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'CREATE' assert glir_cmds[1][0] == 'SIZE' # Orther formats assert RenderBuffer((10, 20), 'depth').format == 'depth' assert RenderBuffer((10, 20), 'stencil').format == 'stencil' # Test reset size and format R.resize((9, 9), 'depth') assert R.shape == (9, 9) assert R.format == 'depth' R.resize((8, 8), 'stencil') assert R.shape == (8, 8) assert R.format == 'stencil' # Wrong formats assert_raises(ValueError, R.resize, (9, 9), 'no_format') assert_raises(ValueError, R.resize, (9, 9), []) # Resizable R = RenderBuffer((10, 20), 'color', False) assert_raises(RuntimeError, R.resize, (9, 9), 'color') # Attaching sets the format F = FrameBuffer() # R = RenderBuffer((9, 9)) F.color_buffer = R assert F.color_buffer is R assert R.format == 'color' # F.depth_buffer = RenderBuffer((9, 9)) assert F.depth_buffer.format == 'depth' # F.stencil_buffer = RenderBuffer((9, 9)) assert F.stencil_buffer.format == 'stencil'
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 300) # for some reason Windows wants a tall window... data = np.random.rand(*shape).astype(np.float32) use_shape = shape + (3, ) with Canvas(size=shape[::-1]) as c: c.app.process_events() c.set_current() if c.app.backend_name.lower() == 'pyqt5': # PyQt5 on OSX for some reason sets this to 1024x768... c.size = shape[::-1] c.app.process_events() orig_tex = Texture2D(data) fbo_tex = Texture2D(use_shape, format='rgb') rbo = RenderBuffer(shape, 'color') fbo = FrameBuffer(color=fbo_tex) c.context.glir.set_verbose(True) assert c.size == shape[::-1] c.set_current() set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert out_tex.shape == c.size[::-1] assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = RenderBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_use_framebuffer(): """Test drawing to a framebuffer""" shape = (100, 300) # for some reason Windows wants a tall window... data = np.random.rand(*shape).astype(np.float32) use_shape = shape + (3,) with Canvas(size=shape[::-1]) as c: c.app.process_events() c.set_current() if c.app.backend_name.lower() == 'pyqt5': # PyQt5 on OSX for some reason sets this to 1024x768... c.size = shape[::-1] c.app.process_events() orig_tex = Texture2D(data) fbo_tex = Texture2D(use_shape, format='rgb') rbo = RenderBuffer(shape, 'color') fbo = FrameBuffer(color=fbo_tex) c.context.glir.set_verbose(True) assert c.size == shape[::-1] c.set_current() set_viewport((0, 0) + c.size) with fbo: draw_texture(orig_tex) draw_texture(fbo_tex) out_tex = _screenshot()[::-1, :, 0].astype(np.float32) assert out_tex.shape == c.size[::-1] assert_raises(TypeError, FrameBuffer.color_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, fbo, 1.) assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, fbo, 1.) fbo.color_buffer = rbo fbo.depth_buffer = RenderBuffer(shape) fbo.stencil_buffer = None print((fbo.color_buffer, fbo.depth_buffer, fbo.stencil_buffer)) clear(color='black') with fbo: clear(color='black') draw_texture(orig_tex) out_rbo = _screenshot()[:, :, 0].astype(np.float32) assert_allclose(data * 255., out_tex, atol=1) assert_allclose(data * 255., out_rbo, atol=1)
def test_framebuffer(): # Test init with no args gloo.get_a_context().glir.clear() F = FrameBuffer() glir_cmds = F._context.glir.clear() assert len(glir_cmds) == 1 glir_cmds[0][0] == 'CREATE' # Activate / deactivate F.activate() glir_cmd = F._context.glir.clear()[-1] assert glir_cmd[0] == 'FRAMEBUFFER' assert glir_cmd[2] is True # F.deactivate() glir_cmd = F._context.glir.clear()[-1] assert glir_cmd[0] == 'FRAMEBUFFER' assert glir_cmd[2] is False # with F: pass glir_cmds = F._context.glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'FRAMEBUFFER' assert glir_cmds[1][0] == 'FRAMEBUFFER' assert glir_cmds[0][2] is True and glir_cmds[1][2] is False # Init with args R = RenderBuffer((3, 3)) F = FrameBuffer(R) assert F.color_buffer is R # R2 = RenderBuffer((3, 3)) F.color_buffer = R2 assert F.color_buffer is R2 # Wrong buffers F = FrameBuffer() assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, 'FOO') assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, []) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, F, 'FOO') assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, F, 'FOO') color_buffer = RenderBuffer((9, 9), 'color') assert_raises(ValueError, FrameBuffer.depth_buffer.fset, F, color_buffer) # But None is allowed! F.color_buffer = None # Shape R1 = RenderBuffer((3, 3)) R2 = RenderBuffer((3, 3)) R3 = RenderBuffer((3, 3)) F = FrameBuffer(R1, R2, R3) assert F.shape == R1.shape assert R1.format == 'color' assert R2.format == 'depth' assert R3.format == 'stencil' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert F.shape == R1.shape assert F.shape == R2.shape assert F.shape == R3.shape assert R1.format == 'color' assert R2.format == 'depth' assert R3.format == 'stencil' # Shape from any buffer F.color_buffer = None assert F.shape == (10, 10) F.depth_buffer = None assert F.shape == (10, 10) F.stencil_buffer = None assert_raises(RuntimeError, FrameBuffer.shape.fget, F) # Also with Texture luminance T = gloo.Texture2D((20, 30)) R = RenderBuffer(T.shape) assert T.format == 'luminance' F = FrameBuffer(T, R) assert F.shape == T.shape[:2] assert F.shape == R.shape assert T.format == 'luminance' assert R.format == 'depth' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert T.shape == (10, 10, 1) assert F.shape == R.shape assert T.format == 'luminance' assert R.format == 'depth' # Also with Texture RGB T = gloo.Texture2D((20, 30, 3)) R = RenderBuffer(T.shape) assert T.format == 'rgb' F = FrameBuffer(T, R) assert F.shape == T.shape[:2] assert F.shape == R.shape assert T.format == 'rgb' assert R.format == 'depth' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert T.shape == (10, 10, 3) assert F.shape == R.shape assert T.format == 'rgb' assert R.format == 'depth' # Wrong shape in resize assert_raises(ValueError, F. resize, (9, 9, 1)) assert_raises(ValueError, F. resize, (9,)) assert_raises(ValueError, F. resize, 'FOO')
def test_framebuffer(): # Test init with no args F = FrameBuffer() glir_cmds = F._glir.clear() assert len(glir_cmds) == 1 glir_cmds[0][0] == 'CREATE' # Activate / deactivate F.activate() glir_cmd = F._glir.clear()[-1] assert glir_cmd[0] == 'FRAMEBUFFER' assert glir_cmd[2] is True # F.deactivate() glir_cmd = F._glir.clear()[-1] assert glir_cmd[0] == 'FRAMEBUFFER' assert glir_cmd[2] is False # with F: pass glir_cmds = F._glir.clear() assert len(glir_cmds) == 2 assert glir_cmds[0][0] == 'FRAMEBUFFER' assert glir_cmds[1][0] == 'FRAMEBUFFER' assert glir_cmds[0][2] is True and glir_cmds[1][2] is False # Init with args R = RenderBuffer((3, 3)) F = FrameBuffer(R) assert F.color_buffer is R # R2 = RenderBuffer((3, 3)) F.color_buffer = R2 assert F.color_buffer is R2 # Wrong buffers F = FrameBuffer() assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, 'FOO') assert_raises(TypeError, FrameBuffer.color_buffer.fset, F, []) assert_raises(TypeError, FrameBuffer.depth_buffer.fset, F, 'FOO') assert_raises(TypeError, FrameBuffer.stencil_buffer.fset, F, 'FOO') color_buffer = RenderBuffer((9, 9), 'color') assert_raises(ValueError, FrameBuffer.depth_buffer.fset, F, color_buffer) # But None is allowed! F.color_buffer = None # Shape R1 = RenderBuffer((3, 3)) R2 = RenderBuffer((3, 3)) R3 = RenderBuffer((3, 3)) F = FrameBuffer(R1, R2, R3) assert F.shape == R1.shape assert R1.format == 'color' assert R2.format == 'depth' assert R3.format == 'stencil' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert F.shape == R1.shape assert F.shape == R2.shape assert F.shape == R3.shape assert R1.format == 'color' assert R2.format == 'depth' assert R3.format == 'stencil' # Shape from any buffer F.color_buffer = None assert F.shape == (10, 10) F.depth_buffer = None assert F.shape == (10, 10) F.stencil_buffer = None assert_raises(RuntimeError, FrameBuffer.shape.fget, F) # Also with Texture luminance T = gloo.Texture2D((20, 30)) R = RenderBuffer(T.shape) assert T.format == 'luminance' F = FrameBuffer(T, R) assert F.shape == T.shape[:2] assert F.shape == R.shape assert T.format == 'luminance' assert R.format == 'depth' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert T.shape == (10, 10, 1) assert F.shape == R.shape assert T.format == 'luminance' assert R.format == 'depth' # Also with Texture RGB T = gloo.Texture2D((20, 30, 3)) R = RenderBuffer(T.shape) assert T.format == 'rgb' F = FrameBuffer(T, R) assert F.shape == T.shape[:2] assert F.shape == R.shape assert T.format == 'rgb' assert R.format == 'depth' # Resize F.resize((10, 10)) assert F.shape == (10, 10) assert T.shape == (10, 10, 3) assert F.shape == R.shape assert T.format == 'rgb' assert R.format == 'depth' # Wrong shape in resize assert_raises(ValueError, F.resize, (9, 9, 1)) assert_raises(ValueError, F.resize, (9, )) assert_raises(ValueError, F.resize, 'FOO')