Search code examples
egl

Can eglSwapInterval(0) cause screen tearing?


When I read eglSwapInterval() api in those documents(https://www.khronos.org/registry/egl/sdk/docs/man/html/eglSwapInterval.xhtml, https://www.opengl.org/wiki/Swap_Interval). When I call eglSwapInterval() with zero value, eglSwapBuffers() call will do swapping back and front buffer without waiting vblank. That means buffer swapping can occur at any time. So, this can cause screen tearing?

Or buffer swapping is also prevented during the vsync pulse in this case?


Solution

  • Yes. A zero swap interval specifies that you want to swap immediately, without waiting for vsync. If this is what your EGL implementation actually does, it'll cause tearing. From the EGL spec:

    If interval is set to a value of 0, buffer swaps are not synchronized to a video frame, and the swap happens as soon as all rendering commands outstanding for the current context are complete. interval is silently clamped to minimum and maximum implementation dependent values before being stored; these values are defined by EGLConfig attributes EGL_MIN_SWAP_INTERVAL and EGL_MAX_SWAP_INTERVAL respectively.

    As the spec suggests, you might not actually get a zero swap interval (if you don't, you won't get tearing). It depends on whether your EGL implementation supports a swap interval of zero (you can query the config to find out), and whether the underlying windowing system is capable of it.