@@ -46,7 +46,8 @@ def update_glfw_canvasses():
4646 canvases = tuple (all_glfw_canvases )
4747 for canvas in canvases :
4848 if canvas ._need_draw :
49- canvas ._perform_draw ()
49+ canvas ._need_draw = False
50+ canvas ._draw_frame_and_present ()
5051 return len (canvases )
5152
5253
@@ -101,8 +102,8 @@ class GlfwWgpuCanvas(WgpuCanvasBase):
101102
102103 # See https://www.glfw.org/docs/latest/group__window.html
103104
104- def __init__ (self , * , size = None , title = None , max_fps = 30 ):
105- super ().__init__ ()
105+ def __init__ (self , * , size = None , title = None , ** kwargs ):
106+ super ().__init__ (** kwargs )
106107
107108 # Handle inputs
108109 if not size :
@@ -121,13 +122,9 @@ def __init__(self, *, size=None, title=None, max_fps=30):
121122 # Create the window (the initial size may not be in logical pixels)
122123 self ._window = glfw .create_window (int (size [0 ]), int (size [1 ]), title , None , None )
123124
124- # Variables to manage the drawing
125+ # Other internal variables
125126 self ._need_draw = False
126127 self ._request_draw_timer_running = False
127- self ._draw_time = 0
128- self ._max_fps = float (max_fps )
129-
130- # Other internal variables
131128 self ._changing_pixel_ratio = False
132129
133130 # Register ourselves
@@ -188,11 +185,6 @@ def _mark_ready_for_draw(self):
188185 self ._need_draw = True # The event loop looks at this flag
189186 glfw .post_empty_event () # Awake the event loop, if it's in wait-mode
190187
191- def _perform_draw (self ):
192- self ._need_draw = False
193- self ._draw_time = time .perf_counter ()
194- self ._draw_frame_and_present ()
195-
196188 def _determine_size (self ):
197189 # Because the value of get_window_size is in physical-pixels
198190 # on some systems and in logical-pixels on other, we use the
@@ -286,11 +278,8 @@ def set_logical_size(self, width, height):
286278
287279 def _request_draw (self ):
288280 if not self ._request_draw_timer_running :
289- now = time .perf_counter ()
290- target_time = self ._draw_time + 1.0 / self ._max_fps
291- wait_time = max (0 , target_time - now )
292281 self ._request_draw_timer_running = True
293- call_later (wait_time , self ._mark_ready_for_draw )
282+ call_later (self . _get_draw_wait_time () , self ._mark_ready_for_draw )
294283
295284 def close (self ):
296285 glfw .set_window_should_close (self ._window , True )
0 commit comments