@@ -256,15 +256,20 @@ def __init__(self, ctx: WebGLContext):
256256
257257 @DefaultFrameBuffer .viewport .setter
258258 def viewport (self , value : tuple [int , int , int , int ]):
259- # This is very similar to the OpenGL backend setter
260- # WebGL backend doesn't need to handle pixel scaling for the
261- # default framebuffer like desktop does, the browser does that
262- # for us. However we need a separate implementation for the
263- # function because of ABC
259+ # Pyglet sizes the canvas drawing buffer at physical pixels
260+ # (canvas.width = logical_width * devicePixelRatio), so we apply
261+ # the same pixel-ratio multiply as the OpenGL backend to keep the
262+ # default framebuffer's get/set symmetric in logical pixels.
264263 if not isinstance (value , tuple ) or len (value ) != 4 :
265- raise ValueError ("viewport shouldbe a 4-component tuple" )
264+ raise ValueError ("viewport should be a 4-component tuple" )
266265
267- self ._viewport = value
266+ ratio = self .ctx .window .get_pixel_ratio ()
267+ self ._viewport = (
268+ int (value [0 ] * ratio ),
269+ int (value [1 ] * ratio ),
270+ int (value [2 ] * ratio ),
271+ int (value [3 ] * ratio ),
272+ )
268273
269274 if self ._ctx .active_framebuffer == self :
270275 self ._ctx ._gl .viewport (* self ._viewport )
@@ -280,6 +285,12 @@ def scissor(self, value):
280285 if self ._ctx .active_framebuffer == self :
281286 self ._ctx ._gl .scissor (* self ._viewport )
282287 else :
283- self ._scissor = value
288+ ratio = self .ctx .window .get_pixel_ratio ()
289+ self ._scissor = (
290+ int (value [0 ] * ratio ),
291+ int (value [1 ] * ratio ),
292+ int (value [2 ] * ratio ),
293+ int (value [3 ] * ratio ),
294+ )
284295 if self ._ctx .active_framebuffer == self :
285296 self ._ctx ._gl .scissor (* self ._scissor )
0 commit comments