本文整理汇总了Python中vispy.gloo.program.Program.set_shaders方法的典型用法代码示例。如果您正苦于以下问题:Python Program.set_shaders方法的具体用法?Python Program.set_shaders怎么用?Python Program.set_shaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vispy.gloo.program.Program
的用法示例。
在下文中一共展示了Program.set_shaders方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setting_shaders
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import set_shaders [as 别名]
def test_setting_shaders(self):
program = Program("A", "B")
assert program.shaders[0] == "A"
assert program.shaders[1] == "B"
program.set_shaders('C', 'D')
assert program.shaders[0] == "C"
assert program.shaders[1] == "D"
示例2: test_setting_shaders
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import set_shaders [as 别名]
def test_setting_shaders(self):
from vispy.gloo.program import VertexShader, FragmentShader
program = Program("A", "B")
assert isinstance(program.shaders[0], VertexShader)
assert program.shaders[0].code == 'A'
assert isinstance(program.shaders[1], FragmentShader)
assert program.shaders[1].code == 'B'
program.set_shaders('C', 'D')
assert program.shaders[0].code == "C"
assert program.shaders[1].code == "D"
示例3: test_attributes
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import set_shaders [as 别名]
def test_attributes(self):
program = Program("attribute float A; attribute vec4 B;", "foo")
assert ('attribute', 'float', 'A') in program.variables
assert ('attribute', 'vec4', 'B') in program.variables
assert len(program.variables) == 2
from vispy.gloo import VertexBuffer
vbo = VertexBuffer()
# Set existing uniforms
program['A'] = vbo
assert program['A'] == vbo
assert 'A' in program._user_variables
assert program._user_variables['A'] is vbo
# Set data - update existing vbp
program['A'] = np.zeros((10,), np.float32)
assert program._user_variables['A'] is vbo
# Set data - create new vbo
program['B'] = np.zeros((10, 4), np.float32)
assert isinstance(program._user_variables['B'], VertexBuffer)
# Set non-exisint uniforms
program['C'] = vbo
assert program['C'] == vbo
assert 'C' not in program._user_variables
assert 'C' in program._pending_variables
# C should be taken up when code comes along that mentions it
program.set_shaders("attribute float A; attribute vec2 C;", "foo")
assert program['C'] == vbo
assert 'C' in program._user_variables
assert 'C' not in program._pending_variables
# Set wrong values
self.assertRaises(ValueError, program.__setitem__, 'A', 'asddas')
# Set wrong values beforehand
program['D'] = ""
self.assertRaises(ValueError, program.set_shaders,
'attribute vec3 D;', '')
# Set to one value per vertex
program.set_shaders("attribute float A; attribute vec2 C;", "foo")
program['A'] = 1.0
assert program['A'] == 1.0
program['C'] = 1.0, 2.0
assert all(program['C'] == np.array((1.0, 2.0), np.float32))
#
self.assertRaises(ValueError, program.__setitem__, 'A', (1.0, 2.0))
self.assertRaises(ValueError, program.__setitem__, 'C', 1.0)
self.assertRaises(ValueError, program.bind, 'notavertexbuffer')
示例4: test_uniform
# 需要导入模块: from vispy.gloo.program import Program [as 别名]
# 或者: from vispy.gloo.program.Program import set_shaders [as 别名]
def test_uniform(self):
# Text array unoforms
program = Program("uniform float A[10];", "foo")
assert ('uniform', 'float', 'A[0]') in program.variables
assert len(program.variables) == 10
# Init program
program = Program("uniform float A;",
"uniform float A; uniform vec4 B;")
assert ('uniform', 'float', 'A') in program.variables
assert ('uniform', 'vec4', 'B') in program.variables
assert len(program.variables) == 2
# Set existing uniforms
program['A'] = 3.0
assert isinstance(program['A'], np.ndarray)
assert program['A'] == 3.0
assert 'A' in program._user_variables
#
program['B'] = 1.0, 2.0, 3.0, 4.0
assert isinstance(program['B'], np.ndarray)
assert all(program['B'] == np.array((1.0, 2.0, 3.0, 4.0), np.float32))
assert 'B' in program._user_variables
# Set non-exisint uniforms
program['C'] = 1.0, 2.0
assert program['C'] == (1.0, 2.0)
assert 'C' not in program._user_variables
assert 'C' in program._pending_variables
# Set samplers
program.set_shaders("uniform sampler2D T2; uniform sampler3D T3;", "f")
program['T2'] = np.zeros((10, 10), np.float32)
program['T3'] = np.zeros((10, 10, 10), np.float32)
assert isinstance(program['T2'], gloo.Texture2D)
assert isinstance(program['T3'], gloo.Texture3D)
# Set samplers with textures
tex = gloo.Texture2D((10, 10))
program['T2'] = tex
assert program['T2'] is tex
program['T2'] = np.zeros((10, 10), np.float32) # Update texture
assert program['T2'] is tex
# C should be taken up when code comes along that mentions it
program.set_shaders("uniform float A; uniform vec2 C;",
"uniform float A; uniform vec4 B;")
assert isinstance(program['C'], np.ndarray)
assert all(program['C'] == np.array((1.0, 2.0), np.float32))
assert 'C' in program._user_variables
assert 'C' not in program._pending_variables
# Set wrong values
self.assertRaises(ValueError, program.__setitem__, 'A', (1.0, 2.0))
self.assertRaises(ValueError, program.__setitem__, 'B', (1.0, 2.0))
self.assertRaises(ValueError, program.__setitem__, 'C', 1.0)
# Set wrong values beforehand
program['D'] = 1.0, 2.0
self.assertRaises(ValueError, program.set_shaders,
'', 'uniform vec3 D;')