From f35f666f81221aea0b2eda533573bcbd07d10d65 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 2 Nov 2009 11:20:08 -0800 Subject: xdemos/glsync: Add swap interval support to glsync test --- progs/xdemos/glsync.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'progs/xdemos/glsync.c') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index da87306cf2..e813c8770d 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -59,6 +59,7 @@ void (*video_sync_get)(); void (*video_sync)(); +void (*swap_interval)(); static int GLXExtensionSupported(Display *dpy, const char *extension) { @@ -84,7 +85,7 @@ static int GLXExtensionSupported(Display *dpy, const char *extension) extern char *optarg; extern int optind, opterr, optopt; -static char optstr[] = "w:h:s:v"; +static char optstr[] = "w:h:s:vi:"; enum sync_type { none = 0, @@ -100,6 +101,7 @@ static void usage(char *name) printf("\t\tn: none\n"); printf("\t\ts: SGI video sync extension\n"); printf("\t\tb: buffer swap\n"); + printf("\t-i\n"); printf("\t-v: verbose (print count)\n"); exit(-1); } @@ -117,7 +119,7 @@ int main(int argc, char *argv[]) Atom wmDelete; enum sync_type waitforsync = none; int width = 500, height = 500, verbose = 0, - countonly = 0; + countonly = 0, interval = 1; int c, i = 1; opterr = 0; @@ -148,6 +150,9 @@ int main(int argc, char *argv[]) case 'v': verbose = 1; break; + case 'i': + interval = atoi(optarg); + break; default: usage(argv[0]); break; @@ -227,11 +232,15 @@ int main(int argc, char *argv[]) video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI"); - if (!video_sync_get || !video_sync) { + swap_interval = glXGetProcAddress((unsigned char *)"glXSwapIntervalSGI"); + + if (!video_sync_get || !video_sync || !swap_interval) { fprintf(stderr, "failed to get sync functions\n"); return -1; } + swap_interval(interval); + fprintf(stderr, "set swap interval to %d\n", interval); video_sync_get(&count); count++; while (i++) { @@ -256,6 +265,11 @@ int main(int argc, char *argv[]) continue; } + if (verbose) { + video_sync_get(&count); + fprintf(stderr, "current count: %d\n", count); + } + /* Alternate colors to make tearing obvious */ if (i & 1) glClearColor(1.0f, 1.0f, 1.0f, 1.0f); -- cgit v1.2.3 From f860aac0d8caff6623792c9da272af269e631ed9 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Tue, 3 Nov 2009 10:48:17 -0800 Subject: xdemos/glsync: Make glsync test draw a rectangle Doing simple buffer clears isn't enough to actually allocate render buffers, we need to do real drawing. --- progs/xdemos/glsync.c | 83 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 34 deletions(-) (limited to 'progs/xdemos/glsync.c') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index e813c8770d..0608f75534 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -111,7 +111,6 @@ int main(int argc, char *argv[]) Display *disp; XVisualInfo *pvi; XSetWindowAttributes swa; - int attrib[14]; GLint last_val = -1, count = 0; Window winGL; GLXContext context; @@ -121,6 +120,19 @@ int main(int argc, char *argv[]) int width = 500, height = 500, verbose = 0, countonly = 0, interval = 1; int c, i = 1; + int attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + int db_attribs[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + XSizeHints sizehints; opterr = 0; while ((c = getopt(argc, argv, optstr)) != -1) { @@ -175,34 +187,17 @@ int main(int argc, char *argv[]) return -1; } - attrib[0] = GLX_RGBA; - attrib[1] = 1; - attrib[2] = GLX_RED_SIZE; - attrib[3] = 1; - attrib[4] = GLX_GREEN_SIZE; - attrib[5] = 1; - attrib[6] = GLX_BLUE_SIZE; - attrib[7] = 1; - if (waitforsync != buffer_swap) - attrib[8] = None; - else { - attrib[8] = GLX_DOUBLEBUFFER; - attrib[9] = 1; - attrib[10] = None; + if (waitforsync != buffer_swap) { + pvi = glXChooseVisual(disp, DefaultScreen(disp), attribs); + } else { + pvi = glXChooseVisual(disp, DefaultScreen(disp), db_attribs); } - pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib); if (!pvi) { fprintf(stderr, "failed to choose visual, exiting\n"); return -1; } - context = glXCreateContext(disp, pvi, None, GL_TRUE); - if (!context) { - fprintf(stderr, "failed to create glx context\n"); - return -1; - } - pvi->screen = DefaultScreen(disp); swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen), @@ -222,11 +217,23 @@ int main(int argc, char *argv[]) wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True); XSetWMProtocols(disp, winGL, &wmDelete, 1); + sizehints.x = 0; + sizehints.y = 0; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + + XSetNormalHints(disp, winGL, &sizehints); XSetStandardProperties(disp, winGL, "glsync test", "glsync text", - None, NULL, 0, NULL); + None, NULL, 0, &sizehints); - XMapRaised(disp, winGL); + context = glXCreateContext(disp, pvi, NULL, GL_TRUE); + if (!context) { + fprintf(stderr, "failed to create glx context\n"); + return -1; + } + XMapWindow(disp, winGL); glXMakeCurrent(disp, winGL, context); video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); @@ -239,11 +246,26 @@ int main(int argc, char *argv[]) return -1; } - swap_interval(interval); - fprintf(stderr, "set swap interval to %d\n", interval); + if (waitforsync == buffer_swap) { + swap_interval(interval); + fprintf(stderr, "set swap interval to %d\n", interval); + } video_sync_get(&count); count++; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); while (i++) { + /* Alternate colors to make tearing obvious */ + if (i & 1) { + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 1.0f); + } else { + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); + glColor3f(1.0f, 0.0f, 0.0f); + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glRectf(0, 0, width, height); + /* Wait for vsync */ if (waitforsync == sgi_video_sync) { if (verbose) @@ -254,6 +276,7 @@ int main(int argc, char *argv[]) if (count == last_val) fprintf(stderr, "error: count didn't change: %d\n", count); last_val = count; + glFlush(); } else if (waitforsync == buffer_swap) { glXSwapBuffers(disp, winGL); } @@ -269,14 +292,6 @@ int main(int argc, char *argv[]) video_sync_get(&count); fprintf(stderr, "current count: %d\n", count); } - - /* Alternate colors to make tearing obvious */ - if (i & 1) - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - else - glClearColor(1.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT); - glFlush(); } XDestroyWindow(disp, winGL); -- cgit v1.2.3 From 0269dc19b57b61d46b09fe2636ce430baa9383c3 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 4 Jan 2010 13:13:57 -0500 Subject: xdemos/glsync: check glXMakeCurrent return value Since this program is used for testing, catching this case can be helpful. --- progs/xdemos/glsync.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'progs/xdemos/glsync.c') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index 0608f75534..6108d991d0 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -120,6 +120,7 @@ int main(int argc, char *argv[]) int width = 500, height = 500, verbose = 0, countonly = 0, interval = 1; int c, i = 1; + int ret; int attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, @@ -234,7 +235,10 @@ int main(int argc, char *argv[]) } XMapWindow(disp, winGL); - glXMakeCurrent(disp, winGL, context); + ret = glXMakeCurrent(disp, winGL, context); + if (ret) { + fprintf(stderr, "failed to make context current: %d\n", ret); + } video_sync_get = glXGetProcAddress((unsigned char *)"glXGetVideoSyncSGI"); video_sync = glXGetProcAddress((unsigned char *)"glXWaitVideoSyncSGI"); -- cgit v1.2.3 From c642f3941ba2ab68135037e1fcb1c29dcb820de7 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 4 Jan 2010 16:26:17 -0500 Subject: xdemos/glsync: handle no sync method better Print out count, finish rendering, etc. Makes the -sn option more useful. --- progs/xdemos/glsync.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'progs/xdemos/glsync.c') diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index 6108d991d0..4dc4937703 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -117,8 +117,7 @@ int main(int argc, char *argv[]) int dummy; Atom wmDelete; enum sync_type waitforsync = none; - int width = 500, height = 500, verbose = 0, - countonly = 0, interval = 1; + int width = 500, height = 500, verbose = 0, interval = 1; int c, i = 1; int ret; int attribs[] = { GLX_RGBA, @@ -283,13 +282,10 @@ int main(int argc, char *argv[]) glFlush(); } else if (waitforsync == buffer_swap) { glXSwapBuffers(disp, winGL); - } - - if (countonly) { - video_sync(2, 1, &count); - fprintf(stderr, "current count: %d\n", count); + } else { + video_sync_get(&count); sleep(1); - continue; + glFinish(); } if (verbose) { -- cgit v1.2.3