OpenGL tearing with fullscreen native resolution

2019-07-23 17:29发布

I've got an OpenGL application with win32 api without glut etc...and I run into a problem with screen tearing in fullscreen. Basicly I have set WS_POPUP as a window style and resolution of my monitor as window size. I'm running on AMD radeon HD 7770 and I see terrible tearing! When I put WS_POPUPWINDOW style instead of WS_POPUP, the tearing is gone, however I have unwanted border around my scene. Another thing I noticed is fact, that the tearing disappears when the resolution is NOT native. So when I pass my_screen_resolution + 1 as size parameter, the tearing is gone.

RESx = 1920;
RESy = 1080;
hwnd = CreateWindowEx(NULL, NAME, NAME, WS_POPUP, 0, 0, RESx, RESy, NULL, NULL, hInstance, NULL);
SetWindowPos(hwnd, 0, -1, -1, RESx + 1, RESy + 1, 0); // With this function call, the tearing disappears!

What can I do to get rid of the tearing without having to run on not native resolution?

EDIT: (Hint: It's not V-sync)

2条回答
乱世女痞
2楼-- · 2019-07-23 18:02

What can I do to get rid of the tearing without having to run on not native resolution?

EDIT: (Hint: It's not V-sync)

Yes it is V-Sync.

When you make a fullscreen window, it will bypass the DWM compositor.

If the window is not covering the full screen its contents are going through the DWM compositor. The DWM compositor itself makes itself a copy of the window's contents whenever something indicates, that it is done drawing (return from WM_PAINT handler, EndPaint or SwapBuffers called). The composition itself happens V-synced.

Thanks for your advice, but I want to aviod the tearing without vsync. With vsync I have terrible input lag.

Then you're doing something wrong in your input processing. Most likely your event loop only processes one input event at a time then does a redraw. If that's the case and your scene complexity goes up, then you're getting lag, that's proportional to your scene's drawing complexity. You don't want this to happen.

What you should do is accumulate all the input events that piled up between redraws and coalesce them into a single new drawing state. Ideally input events are collected until only just before the scene is set up for drawing to reflect the most recent state. If you want to get fancy you my add a Kalman filter to predict the input state at the moment the frame gets shown to the user and use that for drawing the scene.

查看更多
别忘想泡老子
3楼-- · 2019-07-23 18:05

To remove OpenGL tearing, you should have "enable" vsync. Follow this link for details: how to enable vertical sync in opengl?

查看更多
登录 后发表回答