def test_buffer(self): # Some data that we need data = np.zeros(100, np.uint16) im2 = np.zeros((50, 50), np.uint16) im3 = np.zeros((20, 20, 20), np.uint16) shaders = gloo.VertexShader("x"), gloo.FragmentShader("x") items = [ # Buffers (gloo.buffer.Buffer(target=gl.GL_ARRAY_BUFFER), 'set_data', data), (gloo.buffer.VertexBuffer(np.uint16), 'set_data', data), (gloo.buffer.ElementBuffer(np.uint16), 'set_data', data), # Textures (gloo.Texture2D(), 'set_data', im2), (gloo.Texture3D(), 'set_data', im3), # FBO stuff (gloo.RenderBuffer(), 'set_shape', (1, 1)), (gloo.FrameBuffer(), 'attach_color', gloo.RenderBuffer((1, 1))), # Shader stuff (gloo.VertexShader(), 'set_code', "x"), (gloo.FragmentShader(), 'set_code', "x"), (gloo.Program(), 'attach', shaders), ] for ob, funcname, value in items: self._fix_ob(ob) #print('Testing GLObject compliance for %s' % ob.__class__.__name__) # Initially a clear state self.assertEqual(ob._need_update, False) # Set value, now we should have a "dirty" state x = ob for part in funcname.split('.'): x = getattr(x, part) x(value) self.assertEqual(ob._need_update, True) # Activate the object ob.activate() # Now we should be activated self.assertEqual(len(ob._actions), 3) self.assertEqual(ob._actions[0], 'create') self.assertEqual(ob._actions.count('update'), 1) self.assertEqual(ob._actions.count('activate'), 1) # Deactivate ob.deactivate() # Now we should be deactivated self.assertEqual(len(ob._actions), 4) self.assertEqual(ob._actions[-1], 'deactivate') # Activate some more for i in range(10): ob.activate() # Create and update should not have been called self.assertEqual(ob._actions.count('create'), 1) self.assertEqual(ob._actions.count('update'), 1)
def __init__(self): app.Canvas.__init__(self) self.size = 560, 420 # Create texture to render to self._rendertex = gloo.Texture2D() # Create FBO, attach the color buffer and depth buffer self._fbo = gloo.FrameBuffer(self._rendertex, gloo.RenderBuffer()) # Create program to render a shape self._program1 = gloo.Program( gloo.VertexShader(VERT_SHADER1), gloo.FragmentShader(FRAG_SHADER1) ) self._program1['u_color'] = 0.9, 1.0, 0.4, 1 self._program1['a_position'] = gloo.VertexBuffer(vPosition) # Create program to render FBO result self._program2 = gloo.Program( gloo.VertexShader(VERT_SHADER2), gloo.FragmentShader(FRAG_SHADER2) ) self._program2['a_position'] = gloo.VertexBuffer(vPosition) self._program2['a_texcoord'] = gloo.VertexBuffer(vTexcoord) self._program2['u_texture1'] = self._rendertex
def __init__(self): app.Canvas.__init__(self, keys='interactive') self.size = 560, 420 # Create texture to render to shape = self.size[1], self.size[0] self._rendertex = gloo.Texture2D(shape=(shape + (3, )), dtype=np.float32) # Create FBO, attach the color buffer and depth buffer self._fbo = gloo.FrameBuffer(self._rendertex, gloo.DepthBuffer(shape)) # Create program to render a shape self._program1 = gloo.Program(gloo.VertexShader(VERT_SHADER1), gloo.FragmentShader(FRAG_SHADER1)) self._program1['u_color'] = 0.9, 1.0, 0.4, 1 self._program1['a_position'] = gloo.VertexBuffer(vPosition) # Create program to render FBO result self._program2 = gloo.Program(gloo.VertexShader(VERT_SHADER2), gloo.FragmentShader(FRAG_SHADER2)) self._program2['a_position'] = gloo.VertexBuffer(vPosition) self._program2['a_texcoord'] = gloo.VertexBuffer(vTexcoord) self._program2['u_texture1'] = self._rendertex
def __init__(self): self.program = gloo.Program( gloo.VertexShader(vertex_shader), gloo.FragmentShader(fragment_shader), ) # prepare data as numpy record array data = np.empty(len(pos), dtype=[('pos', np.float32, 3), ('color', np.float32, 4)]) data['pos'] = pos data['color'] = color # create vertex buffer from data self.vbo = gloo.VertexBuffer(data) # assign buffer fields to program variables self.program['in_position'] = self.vbo['pos'] self.program['in_color'] = self.vbo['color'] vispy.app.Canvas.__init__(self) self.size = (800, 800) self.show()