fix renderToArray() broken for hidpi

define opts['viewport'] to be in device pixels.

note from the removed comments that there was one place assuming
opts['viewport'] was in device pixels and the other assuming that it was
in device independent pixels.
This commit is contained in:
KIU Shueng Chuan 2021-07-17 14:41:15 +08:00
parent bc52a2afe0
commit 9bf6c01f58

View File

@ -45,6 +45,7 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
'azimuth': 45, ## camera's azimuthal angle in degrees 'azimuth': 45, ## camera's azimuthal angle in degrees
## (rotation around z-axis 0 points along x-axis) ## (rotation around z-axis 0 points along x-axis)
'viewport': None, ## glViewport params; None == whole widget 'viewport': None, ## glViewport params; None == whole widget
## note that 'viewport' is in device pixels
'rotationMethod': rotationMethod 'rotationMethod': rotationMethod
} }
self.reset() self.reset()
@ -146,10 +147,7 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
if vp is None: if vp is None:
return (0, 0, self.deviceWidth(), self.deviceHeight()) return (0, 0, self.deviceWidth(), self.deviceHeight())
else: else:
# note: the following code means that we have defined opts['viewport'] return vp
# to be in device independent pixels.
dpr = self.devicePixelRatio()
return tuple([int(x * dpr) for x in vp])
def devicePixelRatio(self): def devicePixelRatio(self):
return self.devicePixelRatioF() return self.devicePixelRatioF()
@ -232,8 +230,6 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
if viewport is None: if viewport is None:
glViewport(*self.getViewport()) glViewport(*self.getViewport())
else: else:
# note: the following code means that we have defined "viewport"
# to be in device pixels.
glViewport(*viewport) glViewport(*viewport)
self.setProjection(region=region) self.setProjection(region=region)
self.setModelview() self.setModelview()