Skip to content

Commit d0ca613

Browse files
authored
Unit test improvements + fixes (#2211)
* Fix 3d_cube_with_cubes * Fix 3d_cube * Fix 3d_sphere * Fix basic_renderer * resources list_built_in_assets * Fix bindless_texture * Fix examples + improve example tests * Exclude bindless texture example * Properly ignore example names * Remove unused imports
1 parent 76add53 commit d0ca613

23 files changed

Lines changed: 186 additions & 114 deletions

arcade/examples/gl/3d_cube.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
python -m arcade.examples.gl.3d_cube
66
"""
77

8-
from pyglet.math import Mat4
8+
from pyglet.math import Mat4, Vec3
99
import arcade
1010
from arcade.gl import geometry
1111

@@ -55,23 +55,19 @@ def __init__(self, width, height, title):
5555
""",
5656
)
5757
self.on_resize(*self.get_size())
58-
self.time = 0
5958

6059
def on_draw(self):
6160
self.clear()
6261
self.ctx.enable_only(self.ctx.CULL_FACE, self.ctx.DEPTH_TEST)
6362

64-
translate = Mat4.from_translation((0, 0, -1.75))
65-
rx = Mat4.from_rotation(self.time, (1, 0, 0))
66-
ry = Mat4.from_rotation(self.time * 0.77, (0, 1, 0))
63+
translate = Mat4.from_translation(Vec3(0, 0, -1.75))
64+
rx = Mat4.from_rotation(self.time, Vec3(1, 0, 0))
65+
ry = Mat4.from_rotation(self.time * 0.77, Vec3(0, 1, 0))
6766
modelview = translate @ rx @ ry
6867
self.program["modelview"] = modelview
6968

7069
self.cube.render(self.program)
7170

72-
def on_update(self, dt):
73-
self.time += dt
74-
7571
def on_resize(self, width, height):
7672
"""Set up viewport and projection"""
7773
self.ctx.viewport = 0, 0, width, height

arcade/examples/gl/3d_cube_with_cubes.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
python -m arcade.examples.gl.3d_cube_with_cubes
66
"""
77

8-
from pyglet.math import Mat4
8+
from pyglet.math import Mat4, Vec3
99

1010
import arcade
1111
from arcade.gl import geometry
@@ -94,7 +94,6 @@ def __init__(self, width, height, title):
9494
self.quad_fs = geometry.quad_2d_fs()
9595

9696
self.on_resize(*self.get_size())
97-
self.time = 0
9897
self.frame = 0
9998

10099
self.fbo1 = self.ctx.framebuffer(
@@ -113,14 +112,14 @@ def on_draw(self):
113112
self.fbo1.use()
114113
self.fbo1.clear(color_normalized=(1.0, 1.0, 1.0, 1.0))
115114

116-
translate = Mat4.from_translation((0, 0, -1.75))
117-
rx = Mat4.from_rotation(self.time, (1, 0, 0))
118-
ry = Mat4.from_rotation(self.time, (0, 1, 0))
115+
translate = Mat4.from_translation(Vec3(0, 0, -1.75))
116+
rx = Mat4.from_rotation(self.time, Vec3(1, 0, 0))
117+
ry = Mat4.from_rotation(self.time, Vec3(0, 1, 0))
119118
modelview = translate @ rx @ ry
120119

121-
if self.frame > 0:
122-
self.program["use_texture"] = 1
123-
self.fbo2.color_attachments[0].use()
120+
self.program["use_texture"] = 1
121+
self.fbo2.color_attachments[0].use()
122+
124123
self.program["modelview"] = modelview
125124
self.cube.render(self.program)
126125

@@ -136,15 +135,11 @@ def on_draw(self):
136135
self.fbo1, self.fbo2 = self.fbo2, self.fbo1
137136
self.frame += 1
138137

139-
def on_update(self, dt):
140-
self.time += dt
141-
142138
def on_resize(self, width, height):
143139
"""Set up viewport and projection"""
144140
self.ctx.viewport = 0, 0, width, height
145141
self.program["projection"] = Mat4.perspective_projection(self.aspect_ratio, 0.1, 100, fov=60)
146142

147143

148144
if __name__ == "__main__":
149-
MyGame(720, 720, "3D Cube")
150-
arcade.run()
145+
MyGame(720, 720, "3D Cube").run()

arcade/examples/gl/3d_sphere.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import arcade
1212
from arcade.math import clamp
1313
from arcade.gl import geometry
14-
from pyglet.math import Mat4
14+
from pyglet.math import Mat4, Vec3
1515
from pyglet.graphics import Batch
1616

1717

@@ -98,19 +98,19 @@ def __init__(self, width, height, title):
9898
self.rot_y = 0
9999
self.wireframe = True
100100
self.vert_count = 0.5
101-
self.drag = False
102-
self.time = 0
101+
self.drag_time = None
103102
self.flags = set([self.ctx.DEPTH_TEST])
104103

105104
def on_draw(self):
106105
self.clear()
107106
self.ctx.enable_only(*self.flags)
108107
self.ctx.wireframe = self.wireframe
108+
time = self.drag_time or self.time
109109

110110
# Position and rotate the sphere
111-
translate = Mat4.from_translation((0, 0, -2.5))
112-
rx = Mat4.from_rotation(self.time + self.rot_x, (0, 1, 0))
113-
ry = Mat4.from_rotation(self.time + self.rot_y, (1, 0, 0))
111+
translate = Mat4.from_translation(Vec3(0, 0, -2.5))
112+
rx = Mat4.from_rotation(time + self.rot_x, Vec3(0, 1, 0))
113+
ry = Mat4.from_rotation(time + self.rot_y, Vec3(1, 0, 0))
114114
# Set matrices and draw
115115
self.view = translate @ rx @ ry
116116
self.projection = Mat4.perspective_projection(self.aspect_ratio, 0.1, 100, fov=60)
@@ -125,10 +125,6 @@ def on_draw(self):
125125
with self.ctx.enabled_only():
126126
self.text_batch.draw()
127127

128-
def on_update(self, dt):
129-
if not self.drag:
130-
self.time += dt / 2
131-
132128
def on_key_press(self, key, modifiers):
133129
if key == arcade.key.ESCAPE:
134130
self.close()
@@ -157,12 +153,12 @@ def on_key_press(self, key, modifiers):
157153
self.text_cull.text = f"F2: Toggle cull face ({self.ctx.CULL_FACE in self.flags})"
158154

159155
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
160-
self.drag = True
156+
self.drag_time = self.time
161157
self.rot_x += dx / 100
162158
self.rot_y -= dy / 100
163159

164160
def on_mouse_release(self, x, y, button, modifiers):
165-
self.drag = False
161+
self.drag_time = None
166162

167163
def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
168164
self.vert_count = clamp(self.vert_count + scroll_y / 500, 0.0, 1.0)

arcade/examples/gl/basic_renderer.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def __init__(self, width, height, title):
2121
"""
2222
Set up the application.
2323
"""
24-
self.time = 0
2524
super().__init__(width, height, title)
2625
self.color_program = self.ctx.program(
2726
vertex_shader="""
@@ -82,9 +81,6 @@ def on_draw(self):
8281
self.quad_1.render(self.color_program)
8382
self.quad_2.render(self.uv_program)
8483

85-
def on_update(self, dt):
86-
self.time += dt
87-
8884

8985
if __name__ == "__main__":
9086
MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

arcade/examples/gl/bindless_texture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ def __init__(self):
146146
self.handles = []
147147
self.textures: List[Texture2D] = []
148148
# Make a cycle iterator from arcade's resources (images)
149-
resources = [
150-
getattr(arcade.resources, resource) for resource in dir(arcade.resources) if resource.startswith("image_")
151-
]
149+
resources = arcade.resources.list_built_in_assets(name="female", extensions=(".png",))
152150
resource_cycle = cycle(resources)
153151

154152
# Load enough textures to cover for each point/sprite
@@ -179,6 +177,8 @@ def __init__(self):
179177
)
180178

181179
def on_draw(self):
180+
self.clear()
181+
self.ctx.enable(self.ctx.BLEND)
182182
# Bind the SSBO with texture handles to binding point 0
183183
# matching the binding point in the shader.
184184
self.texture_ssbo.bind_to_storage_buffer(binding=0)

arcade/examples/gl/geometry_shader.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(self, width, height, title):
2626
"""
2727
Set up the application.
2828
"""
29-
self.time = 0
3029
super().__init__(width, height, title, resizable=True)
3130
self.program = self.ctx.program(
3231
vertex_shader="""
@@ -106,19 +105,9 @@ def __init__(self, width, height, title):
106105

107106
def on_draw(self):
108107
self.clear()
109-
110108
self.ctx.enable(self.ctx.BLEND)
111-
try:
112-
self.program["time"] = self.time
113-
self.points.render(self.program, mode=self.ctx.POINTS)
114-
except Exception:
115-
import traceback
116-
117-
traceback.print_exc()
118-
exit(1)
119-
120-
def on_update(self, dt):
121-
self.time += dt
109+
self.program["time"] = self.time
110+
self.points.render(self.program, mode=self.ctx.POINTS)
122111

123112

124113
if __name__ == "__main__":

arcade/examples/gl/instancing.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(self, width, height, title):
2626
"""
2727
Set up the application.
2828
"""
29-
self.time = 0
3029
super().__init__(width, height, title)
3130
self.program = self.ctx.program(
3231
vertex_shader="""
@@ -120,9 +119,6 @@ def on_draw(self):
120119
self.program["time"] = self.time
121120
self.geometry.render(self.program, instances=self.instances)
122121

123-
def on_update(self, dt):
124-
self.time += dt
125-
126122

127123
if __name__ == "__main__":
128124
MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

arcade/examples/gl/multisample_fbo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import math
1313
import arcade
14+
from arcade.color import WHITE
1415

1516
SAMPLES = 8
1617

@@ -29,19 +30,19 @@ def on_draw(self):
2930
# Draw to MSAA framebuffer
3031
self.fbo.use()
3132
self.fbo.clear()
32-
arcade.draw_line(0, 0, self.width, self.height, (255, 255, 255))
33-
arcade.draw_line(0, self.height, self.width, 0, (255, 255, 255))
33+
arcade.draw_line(0, 0, self.width, self.height, WHITE)
34+
arcade.draw_line(0, self.height, self.width, 0, WHITE)
3435
arcade.draw_circle_outline(
3536
self.width / 2,
3637
self.height / 2,
3738
100 + math.sin(self.time) * 50,
38-
(255, 255, 255),
39+
WHITE,
3940
)
4041
arcade.draw_circle_outline(
4142
self.width / 2,
4243
self.height / 2,
4344
200 + math.sin(self.time) * 50,
44-
(255, 255, 255),
45+
WHITE,
4546
)
4647

4748
# Activate screen and copy the MSAA framebuffer to it

arcade/examples/gl/render_indirect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def on_draw(self):
226226
)
227227

228228
# We want to prove by using a query that the following
229-
# is identical for all the redering methods:
229+
# is identical for all the rendering methods:
230230
# * The number of pixels written (rgba / 4)
231231
# * The number of primitives generate
232232
# We also compare the nanoseconds each methods is using

arcade/examples/gl/shader_setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class ShaderSetup(arcade.Window):
1818

1919
def __init__(self, width, height, title):
2020
super().__init__(width, height, title, resizable=True)
21-
self.time = 0
2221
self.program = self.ctx.program(
2322
vertex_shader="""
2423
#version 330
@@ -93,8 +92,5 @@ def on_draw(self):
9392
# Draw the geometry using the program
9493
self.quad.render(self.program)
9594

96-
def on_update(self, dt):
97-
self.time += dt
98-
9995

10096
ShaderSetup(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE).run()

0 commit comments

Comments
 (0)