Skip to content

Commit 3ed9e52

Browse files
committed
cubes examples supports new shader system
1 parent 8e64061 commit 3ed9e52

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

examples/cubes/effects.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def draw(self, time, frametime, target):
4242
m_mv = self.create_transformation(rotation=(time * 1.2, time * 2.1, time * 0.25),
4343
translation=(-7.0, 0.0, -12.0))
4444

45-
self.program.uniform("m_proj", self.sys_camera.projection.tobytes())
46-
self.program.uniform("m_mv", m_mv.astype('f4').tobytes())
45+
self.program["m_proj"].write(self.sys_camera.projection.tobytes())
46+
self.program["m_mv"].write(m_mv.astype('f4').tobytes())
4747
self.cube.draw(self.program)
4848

4949

@@ -56,14 +56,22 @@ def __init__(self, cube):
5656
self.cube = cube
5757
self.program = self.get_program("light")
5858

59+
# Pre-fetch the uniforms
60+
self.m_proj = self.program["m_proj"]
61+
self.m_mv = self.program["m_mv"]
62+
self.m_normal = self.program["m_normal"]
63+
5964
def draw(self, time, frametime, target):
6065
m_mv = self.create_transformation(rotation=(time * 1.2, time * 2.1, time * 0.25),
6166
translation=(0.0, 0.0, -12.0))
6267
m_normal = self.create_normal_matrix(m_mv)
6368

64-
self.program.uniform("m_proj", self.sys_camera.projection.tobytes())
65-
self.program.uniform("m_mv", m_mv.astype('f4').tobytes())
66-
self.program.uniform("m_normal", m_normal.astype('f4').tobytes())
69+
# Write to uniforms
70+
self.m_proj.write(self.sys_camera.projection.tobytes())
71+
self.m_mv.write(m_mv.astype('f4').tobytes())
72+
self.m_normal.write(m_normal.astype('f4').tobytes())
73+
74+
# Draw the cube
6775
self.cube.draw(self.program)
6876

6977

@@ -77,14 +85,22 @@ def __init__(self, cube):
7785
self.program = self.get_program("textured")
7886
self.texture = self.get_texture("crate")
7987

88+
# pre-fetch the uniform buffers
89+
self.m_proj = self.program["m_proj"]
90+
self.m_mv = self.program["m_mv"]
91+
self.m_normal = self.program["m_normal"]
92+
self.wood = self.program["wood"]
93+
8094
def draw(self, time, frametime, target):
8195
m_mv = self.create_transformation(rotation=(time * 1.2, time * 2.1, time * 0.25),
8296
translation=(7.0, 0.0, -12.0))
8397
m_normal = self.create_normal_matrix(m_mv)
8498

85-
self.program.uniform("m_proj", self.sys_camera.projection.tobytes())
86-
self.program.uniform("m_mv", m_mv.astype('f4').tobytes())
87-
self.program.uniform("m_normal", m_normal.astype('f4').tobytes())
99+
self.m_proj.write(self.sys_camera.projection.tobytes())
100+
self.m_mv.write(m_mv.astype('f4').tobytes())
101+
self.m_normal.write(m_normal.astype('f4').tobytes())
102+
88103
self.texture.use(location=0)
89-
self.program.uniform("wood", 0)
104+
self.wood.value = 0
105+
90106
self.cube.draw(self.program)

0 commit comments

Comments
 (0)