I have a viewport
that is half of the screen size/framebuffer
.
x, y, w, h = 0, 0, 512, 512
And my scissor
region is the full framebuffer
x, y, w, h = 0, 0, 0 1024, 512
I am drawing a line, that is far outside of the viewport
, from left to right. I am expecting the line to be drawn only inside the viewport. I have tested this on three different graphic cards, and on two of them, I get the result I am I expecting. However on the third one, the line is drawn outside the viewport
, but inside the scissor
region.
Which one of the results is correct here? As far as I understand it, the lines' two vertices should be moved to outer viewport
positions. It should not be drawn outside of it.
If you read pitfall nr 10
on this site:
https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/
They are talking about drawing outside the viewport
, but that is just some special cases, for example where you have a really thick line, my line width is 1
EDIT: After a discussion in the KhronosGroup: From the spec Vulkan 1.0.68:
If either of a line segment’s vertices lie outside of the clip volume, the line segment may be clipped, with new vertex coordinates computed for each vertex that lies outside the clip volume. A clipped line segment endpoint lies on both the original line segment and the boundary of the clip volume.
Nvidia:
We intentionally made this change for maintenance2, to allow for pop-free points and lines. Point clipping behavior is queriable but line clipping behavior is not, though I believe the "preferred" behavior for lines is to be pop-free. We changed the NVIDIA driver last year from tight clipping to pop-free, and even changed CTS tests to allow this new behavior. So this is all working as designed.
Old answer:
The viewport defines a transformation from normalized device coordinates to window coordinates. The viewport transformation does not do any clipping.
However, the clipping does happen before NDC
space, the view frustum clipping does guarantee that no vertex can fall outside the viewport. And if you are using orthogonal projection, clip space and NDC
space are the same. So everything outside [-1,1]
will be clipped. And if you are not doing any of the special cases the opengl link talks about the vertices should be clipped.
If two of your graphics cards draws inside the viewport and one outside, it's probably a driver bug. If you are using Vulkan, which is fairly new, that is most likely the case.