LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: GLFW/OpenGl Screen tearing when in native resolution.  (Read 343 times)

Fauser

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
GLFW/OpenGl Screen tearing when in native resolution.
« on: August 26, 2017, 12:05:22 »

Hello. I'm experiencing same problem as described here: http://forum.lwjgl.org/index.php?topic=6323.msg33774
I'm using LWJGL 3.1.2 build 29! OpenGL 3.2.13474 Core Profile Forward-Compatible Context 22.19.162.4

I tested it on my PC and laptop.
PC - AMD A87600 with build in graphics.
laptop - i5-3320M with some mix of NVS 5200M and intel hd graphics 4000.

Basically on both machines with and without glSwapInterval(1) if the program is not in native screen resolutions there is no tearing at all. No matter if it is 60fps or 600fps.
When the program is in native resolution without glSwapInterval(1) (basically VSync as i understood) the tearing is now there on both machines. I tried the fullscreen and boarderless screensize window.
That might be understandable, because vsync is not on, but that's where it gets interesting. When i turn glSwapInterval(1) on on both machines with native screen resolution window screen tearing is getting even worse on both machines, even tho i am getting 60fps on both which is both screens refresh rate (so vsync is working).
When i add or subtract 1 pixel from window size (so that it will be no longer in native screen resolution) it magically is not tearing anymore with or without glSwapInterval(1).
And i must note that i have drivers properly installed on both machines and i had never touched any of the graphics card settings until that problem occurs. Also i had never experienced any tearing problems in games or programs with both of machines.

I played with graphics profile setting on my pc (there is only 3 - best performance, balanced and optimize image quality) and there are results.



Best performance option:

Not in native resolution (+1 or -1 pixel):
    Always tearing if in fullscreen in every resolution.
    Always no tearing if boarderless window.

In native resolution fullscreen:
    glfwCreateWindow(vidmode.width(), vidmode.height(), "Title", glfwGetPrimaryMonitor(), NULL);
    without glfwSwapInterval(1) : pretty bad and noticeable tearing.
    with glfwSwapInterval(1) : glfwSwapInterval(1) gets ignored and still tearing.

In native resolution borderless screensize window:
    glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
    glfwCreateWindow(vidmode.width(), vidmode.height(), "Title", NULL, NULL);
    without glfwSwapInterval(1) : pretty bad and noticeable tearing.
    with glfwSwapInterval(1) : glfwSwapInterval(1) is working showing 60 fps, but tearing is even worse then without it.



Balanced option:

Not in native resolution (+1 or -1 pixel):
    In fullscreen tearing if without glfwSwapInterval(1) and no tearing if with glfwSwapInterval(1).
    Always no tearing if boarderless window.

In native resolution fullscreen:
    without glfwSwapInterval(1) : pretty bad and noticeable tearing.
    with glfwSwapInterval(1) : glfwSwapInterval(1) is working showing 60 fps and no tearing.

In native resolution borderless screensize window:
    without glfwSwapInterval(1) : pretty bad and noticeable tearing.
    with glfwSwapInterval(1) : glfwSwapInterval(1) is working showing 60 fps, but tearing is even worse then without it.



Optimize image quality:

Not in native resolution (+1 or -1 pixel):
    In fullscreen always vsynced even without glfwSwapInterval(1) and always no tearing.
    Always no tearing if boarderless window, also it is vsynced at 60fps automatically even without glfwSwapInterval(1).

In native resolution fullscreen:
    without glfwSwapInterval(1) : no tearing and automatically vsynced at 60fps.
    with glfwSwapInterval(1) : no tearing 60fps.

In native resolution borderless screensize window:
    without glfwSwapInterval(1) : no tearing automatically vsynced at 60fps
    with glfwSwapInterval(1) : 60fps and terrible tearing ..WTF !!


So in conclusion there is no way to make it work in borderless window (all modern programs and games are running in borderless screensize window, so u can use win key and still see the program) except some weird situation where it is vsynced when vsync is off and it is automatically vsynced. It was possible to make the fullscreen work by changing some driver settings, but that's not the case. U can not make it work on the new system out of the box without changing settings manually. I had never this issue with any other game. The fact is that with every graphic profile something where not working as it should. On my laptop i could not get it even working without tearing in native resolution whatsoever, because i could not find graphics settings on that machine. So basically lwjgl is not working as it should.

I will attache some working jars and very messy source code (everything that's needed for recreating issue is in Window class lines 93 and 146, Intellij source).


Source code: https://1drv.ms/u/s!AvWTuMXMZ3pUggtbyHKLKVRVz-y3
Jar files: https://1drv.ms/u/s!AvWTuMXMZ3pUggyyNJfOif40m1n9


Logged

Fauser

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
Re: GLFW/OpenGl Screen tearing when in native resolution.
« Reply #1 on: August 27, 2017, 10:11:54 »

Am i wrong? If not will it be fixed? If it will not be fixed should i use LWJGL2 that has only 1 but working window or is there any way to implement your own window in LWJGL3? Should is start learning c++ then?
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Online Online
  • Posts: 1907
Re: GLFW/OpenGl Screen tearing when in native resolution.
« Reply #2 on: August 27, 2017, 15:37:53 »

Some thoughts:

- Have you checked which GPU is actually used on the laptop?
- Have you checked GLFW's issues related to vsync?
- Have you tried the native GLFW tearing demo?

Also, could you please prepare an MVCE that reproduces the issue on your machine(s)? You'll find that not many people are willing to:

a) Build and run a big project without Maven/Gradle (too much hassle), or
b) Run precompiled programs downloaded from a forum (security concerns)
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Online Online
  • Posts: 1907
Re: GLFW/OpenGl Screen tearing when in native resolution.
« Reply #3 on: August 27, 2017, 16:35:05 »

I have tried your project and cannot reproduce any issues in fullscreen mode (with native resolution). There's no tearing with vsync enabled.

glfwSwapInterval is a no-op on Windows, when desktop composition is enabled and there's no fullscreen window. It uses DwmFlush() instead. See this code and this documentation for details. Please note that the GLFW_USE_DWM_SWAP_INTERVAL override does not exist anymore in GLFW.
Logged