Description
I've set up a simple sandbox here - when you click it will toggle the active viewport between two states:
- Initial: the full canvas,
viewport = [0, 0, canvas width, canvas height]
- Toggled: the bottom left quarter of the screen,
viewport = [0, 0, half canvas width, half canvas height]
After toggling, the current viewport size reported by three.js and R3F are logged to the console:
- Initial (for a canvas with width = 2228, height = 721)
R3f Viewport: {width: 23.71, height: 7.67, factor: 93.96, distance: 5.0, aspect: 3.09}
Three.js Viewport: (4) [0, 0, 2228, 721]
- Toggled (same canvas)
R3f Viewport: {width: 23.71, height: 7.67, factor: 93.96, distance: 5.0, aspect: 3.09}
Three.js Viewport: (4) [0, 0, 1114, 360.5]
As you can see, three.js updates to show the new size. R3F continues to report the viewport as the entire canvas.
I think the issue here is actually semantics - in R3F, the word "viewport" is being used to report various stats about the state of the canvas
element combined with the dpr. However, three.js is reporting the value of glViewport
.
Since viewport usually has a specific meaning in 3d computer graphics - it's the size of the viewing rectangle into which you will output the scene, in pixels - I'm inclined to say the three.js usage of the term is more correct here.