[Mesa-dev] [PATCH 1/2] glxgears: Refactor visual attributes

Chad Versace chad.versace at linux.intel.com
Fri Jul 20 17:29:22 PDT 2012


Procedurally construct the attribute array according to command-line args.
This is in preparation for the next commit, which add support for
multisampling.

CC: Paul Berry <stereotype441 at gmail.com>
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/xdemos/glxgears.c | 50 ++++++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/xdemos/glxgears.c b/src/xdemos/glxgears.c
index a9b4c0d..74b0bfd 100644
--- a/src/xdemos/glxgears.c
+++ b/src/xdemos/glxgears.c
@@ -478,21 +478,9 @@ make_window( Display *dpy, const char *name,
              int x, int y, int width, int height,
              Window *winRet, GLXContext *ctxRet)
 {
-   int attribs[] = { GLX_RGBA,
-                     GLX_RED_SIZE, 1,
-                     GLX_GREEN_SIZE, 1,
-                     GLX_BLUE_SIZE, 1,
-                     GLX_DOUBLEBUFFER,
-                     GLX_DEPTH_SIZE, 1,
-                     None };
-   int stereoAttribs[] = { GLX_RGBA,
-                           GLX_RED_SIZE, 1,
-                           GLX_GREEN_SIZE, 1,
-                           GLX_BLUE_SIZE, 1,
-                           GLX_DOUBLEBUFFER,
-                           GLX_DEPTH_SIZE, 1,
-                           GLX_STEREO,
-                           None };
+   int attribs[64];
+   int i = 0;
+
    int scrnum;
    XSetWindowAttributes attr;
    unsigned long mask;
@@ -501,6 +489,24 @@ make_window( Display *dpy, const char *name,
    GLXContext ctx;
    XVisualInfo *visinfo;
 
+   /* Singleton attributes. */
+   attribs[i++] = GLX_RGBA;
+   attribs[i++] = GLX_DOUBLEBUFFER;
+   if (stereo)
+      attribs[i++] = GLX_STEREO;
+
+   /* Key/value attributes. */
+   attribs[i++] = GLX_RED_SIZE;
+   attribs[i++] = 1;
+   attribs[i++] = GLX_GREEN_SIZE;
+   attribs[i++] = 1;
+   attribs[i++] = GLX_BLUE_SIZE;
+   attribs[i++] = 1;
+   attribs[i++] = GLX_DEPTH_SIZE;
+   attribs[i++] = 1;
+
+   attribs[i++] = None;
+
    scrnum = DefaultScreen( dpy );
    root = RootWindow( dpy, scrnum );
 
@@ -510,16 +516,12 @@ make_window( Display *dpy, const char *name,
       height = DisplayHeight( dpy, scrnum );
    }
 
-   if (stereo)
-      visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
-   else
-      visinfo = glXChooseVisual( dpy, scrnum, attribs );
+   visinfo = glXChooseVisual(dpy, scrnum, attribs);
    if (!visinfo) {
-      if (stereo) {
-         printf("Error: couldn't get an RGB, "
-                "Double-buffered, Stereo visual\n");
-      } else
-         printf("Error: couldn't get an RGB, Double-buffered visual\n");
+      printf("Error: couldn't get an RGB, Double-buffered");
+      if (stereo)
+         printf(", Stereo");
+      printf(" visual\n");
       exit(1);
    }
 
-- 
1.7.11.2



More information about the mesa-dev mailing list