Skip to content

Commit 6c6c115

Browse files
committed
Lazy update vertices + left/bottom fix
1 parent b48e20c commit 6c6c115

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arcade/gui/surface.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
self._pos = position
4040
self._pixel_ratio = pixel_ratio
4141
self._pixelated = False
42+
self._area = None # Cached area for the last draw call
4243

4344
self.texture = self.ctx.texture(self.size_scaled, components=4)
4445
self.fbo: Framebuffer = self.ctx.framebuffer(color_attachments=[self.texture])
@@ -278,19 +279,24 @@ def _update_geometry(self, area: Rect | None = None) -> None:
278279
"""
279280
Update the internal geometry of the surface mesh.
280281
281-
The geometry is a triangle strip with 4 verties.
282+
The geometry is a triangle strip with 4 vertices.
282283
"""
283284
if area is None:
284285
area = LBWH(0, 0, *self.size)
285286

287+
if self._area == area:
288+
return
289+
self._area = area
290+
286291
# Clamp the area inside the surface
287292
# This is the local area inside the surface
288293
_size = Vec2(*self.size)
289-
_pos = Vec2(area.left, area.bottom)
294+
_pos = Vec2(*self.position)
295+
_area_pos = Vec2(area.left, area.bottom)
290296
_area_size = Vec2(area.width, area.height)
291297

292-
b1 = _pos.clamp(Vec2(0.0), _size)
293-
end_point = _pos + _area_size
298+
b1 = _area_pos.clamp(Vec2(0.0), _size)
299+
end_point = _area_pos + _area_size
294300
b2 = end_point.clamp(Vec2(0.0), _size)
295301
b = b2 - b1
296302
l_area = Vec4(b1.x, b1.y, b.x, b.y)

0 commit comments

Comments
 (0)