Check whether swap interval value is supported
[gltest.git] / eglbackend.cpp
index 0e4c9378edc16d4f3004dfa463a68e4a75e7133d..04165c761460cedb93a6d99203a5b367a01381e4 100644 (file)
@@ -112,11 +112,26 @@ EGLBackend::~EGLBackend()
 void EGLBackend::swapBuffers() const
 {
        assert(context != EGL_NO_CONTEXT); // this implies the display is also initialized
-       eglSwapBuffers(display, surface);
+       if (eglSwapBuffers(display, surface) == EGL_FALSE)
+               exitEglError("Failed to swap buffers");
 }
 
 void EGLBackend::setSwapInterval(int i) const
 {
        assert(context != EGL_NO_CONTEXT);
-       eglSwapInterval(display, i);
+       // check if swap interval value is supported
+       EGLint val;
+       eglGetConfigAttrib(display, config, EGL_MIN_SWAP_INTERVAL, &val);
+       if (i < val) {
+               fprintf(stderr, "Cannot set swap interval to %d, minimum supported value is %d\n", i, val);
+               exit(1);
+       }
+       eglGetConfigAttrib(display, config, EGL_MAX_SWAP_INTERVAL, &val);
+       if (i > val) {
+               fprintf(stderr, "Cannot set swap interval to %d, maximum supported value is %d\n", i, val);
+               exit(1);
+       }
+       // use it
+       if (eglSwapInterval(display, i) == EGL_FALSE)
+               exitEglError("Failed to set swap interval");
 }