@@ -48,6 +48,7 @@ def draw_texture_rect(
4848 # Clamp alpha to 0-255
4949 alpha_normalized = max (0 , min (255 , alpha )) / 255.0
5050
51+ blend_state = ctx .is_enabled (ctx .BLEND )
5152 if blend :
5253 ctx .enable (ctx .BLEND )
5354 else :
@@ -76,7 +77,9 @@ def draw_texture_rect(
7677
7778 geometry .render (program , mode = gl .TRIANGLE_STRIP , vertices = 4 )
7879
79- if blend :
80+ if blend_state :
81+ ctx .enable (ctx .BLEND )
82+ else :
8083 ctx .disable (ctx .BLEND )
8184
8285
@@ -387,17 +390,15 @@ def draw_rect_filled(rect: Rect, color: RGBOrA255, tilt_angle: float = 0) -> Non
387390 # Validate & normalize to a pass the shader an RGBA float uniform
388391 color_normalized = Color .from_iterable (color ).normalized
389392
390- ctx .enable (ctx .BLEND )
391-
392- # Pass data to the shader
393- program ["color" ] = color_normalized
394- program ["shape" ] = rect .width , rect .height , tilt_angle
395- buffer .orphan ()
396- buffer .write (data = array .array ("f" , (rect .x , rect .y )))
397-
398- geometry .render (program , instances = 1 )
393+ # contextmanager will restore state which existed before
394+ with ctx .enabled (ctx .BLEND ):
395+ # Pass data to the shader
396+ program ["color" ] = color_normalized
397+ program ["shape" ] = rect .width , rect .height , tilt_angle
398+ buffer .orphan ()
399+ buffer .write (data = array .array ("f" , (rect .x , rect .y )))
399400
400- ctx . disable ( ctx . BLEND )
401+ geometry . render ( program , instances = 1 )
401402
402403
403404# These might be "oddly specific" and also needs docstrings. Disabling or 3.0.0
0 commit comments