changeset 3571:19691cebb866

Default to allow either accelerated or not
author Sam Lantinga <slouken@libsdl.org>
date Tue, 15 Dec 2009 20:53:09 +0000
parents 7812d3e9564e
children 6bb9952d5029
files src/video/SDL_video.c src/video/cocoa/SDL_cocoaopengl.m src/video/win32/SDL_win32opengl.c src/video/x11/SDL_x11opengl.c test/common.c test/testgl.c test/testgl2.c
diffstat 7 files changed, 54 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_video.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/src/video/SDL_video.c	Tue Dec 15 20:53:09 2009 +0000
@@ -239,7 +239,7 @@
     _this->gl_config.multisamplebuffers = 0;
     _this->gl_config.multisamplesamples = 0;
     _this->gl_config.retained_backing = 1;
-    _this->gl_config.accelerated = 1;
+    _this->gl_config.accelerated = -1;  /* accelerated or not, both are fine */
     _this->gl_config.major_version = 2;
     _this->gl_config.minor_version = 1;
 
@@ -3274,7 +3274,7 @@
     case SDL_GL_ACCELERATED_VISUAL:
         {
             /* FIXME: How do we get this information? */
-            *value = _this->gl_config.accelerated;
+            *value = (_this->gl_config.accelerated != 0);
             return 0;
         }
     default:
--- a/src/video/cocoa/SDL_cocoaopengl.m	Tue Dec 15 20:36:31 2009 +0000
+++ b/src/video/cocoa/SDL_cocoaopengl.m	Tue Dec 15 20:53:09 2009 +0000
@@ -133,11 +133,13 @@
         attr[i++] = NSOpenGLPFANoRecovery;
     }
 
-    if (_this->gl_config.accelerated) {
-        attr[i++] = NSOpenGLPFAAccelerated;
-    } else {
-        attr[i++] = NSOpenGLPFARendererID;
-        attr[i++] = kCGLRendererGenericFloatID;
+    if (_this->gl_config.accelerated >= 0) {
+        if (_this->gl_config.accelerated) {
+            attr[i++] = NSOpenGLPFAAccelerated;
+        } else {
+            attr[i++] = NSOpenGLPFARendererID;
+            attr[i++] = kCGLRendererGenericFloatID;
+        }
     }
 
     attr[i++] = NSOpenGLPFAScreenMask;
--- a/src/video/win32/SDL_win32opengl.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/src/video/win32/SDL_win32opengl.c	Tue Dec 15 20:53:09 2009 +0000
@@ -469,9 +469,12 @@
         *iAttr++ = _this->gl_config.multisamplesamples;
     }
 
-    *iAttr++ = WGL_ACCELERATION_ARB;
-    *iAttr++ = (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB :
-                                               WGL_NO_ACCELERATION_ARB);
+    if (_this->gl_config.accelerated >= 0) {
+        *iAttr++ = WGL_ACCELERATION_ARB;
+        *iAttr++ =
+            (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB :
+             WGL_NO_ACCELERATION_ARB);
+    }
 
     *iAttr = 0;
 
--- a/src/video/x11/SDL_x11opengl.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/src/video/x11/SDL_x11opengl.c	Tue Dec 15 20:53:09 2009 +0000
@@ -359,7 +359,8 @@
         attribs[i++] = _this->gl_config.multisamplesamples;
     }
 
-    if (_this->gl_data->HAS_GLX_EXT_visual_rating) {
+    if (_this->gl_config.accelerated >= 0 &&
+        _this->gl_data->HAS_GLX_EXT_visual_rating) {
         attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
         attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
                                                       GLX_SLOW_VISUAL_EXT;
--- a/test/common.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/test/common.c	Tue Dec 15 20:53:09 2009 +0000
@@ -104,7 +104,7 @@
     state->gl_multisamplebuffers = 0;
     state->gl_multisamplesamples = 0;
     state->gl_retained_backing = 1;
-    state->gl_accelerated = 1;
+    state->gl_accelerated = -1;
     state->gl_major_version = 2;
     state->gl_minor_version = 1;
 
@@ -659,7 +659,10 @@
         SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
-        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, state->gl_accelerated);
+        if (state->gl_accelerated >= 0) {
+            SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
+                                state->gl_accelerated);
+        }
         SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
--- a/test/testgl.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/test/testgl.c	Tue Dec 15 20:53:09 2009 +0000
@@ -370,7 +370,7 @@
 int
 RunGLTest(int argc, char *argv[],
           int logo, int logocursor, int slowly, int bpp, float gamma,
-          int noframe, int fsaa, int sync, int noaccel)
+          int noframe, int fsaa, int sync, int accel)
 {
     int i;
     int rgb_size[3];
@@ -454,7 +454,9 @@
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
     }
-    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, !noaccel);
+    if (accel >= 0) {
+        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, accel);
+    }
     if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) {
         fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
         SDL_Quit();
@@ -491,8 +493,11 @@
         printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
                value);
     }
-    SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
-    printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", !noaccel, value);
+    if (accel >= 0) {
+        SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
+        printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
+               value);
+    }
     if (sync) {
         printf("Buffer swap interval: requested 1, got %d\n",
                SDL_GL_GetSwapInterval());
@@ -703,7 +708,7 @@
     float gamma = 0.0;
     int noframe = 0;
     int fsaa = 0;
-    int noaccel = 0;
+    int accel = -1;
     int sync = 0;
 
     logo = 0;
@@ -734,22 +739,22 @@
         if (strcmp(argv[i], "-fsaa") == 0) {
             ++fsaa;
         }
-        if (strcmp(argv[i], "-noaccel") == 0) {
-            ++noaccel;
+        if (strcmp(argv[i], "-accel") == 0) {
+            accel = atoi(argv[++i]);
         }
         if (strcmp(argv[i], "-sync") == 0) {
             ++sync;
         }
         if (strncmp(argv[i], "-h", 2) == 0) {
             printf
-                ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-noaccel] [-sync] [-fullscreen]\n",
+                ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel n] [-sync] [-fullscreen]\n",
                  argv[0]);
             exit(0);
         }
     }
     for (i = 0; i < numtests; ++i) {
         RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma,
-                  noframe, fsaa, sync, noaccel);
+                  noframe, fsaa, sync, accel);
     }
     return 0;
 }
--- a/test/testgl2.c	Tue Dec 15 20:36:31 2009 +0000
+++ b/test/testgl2.c	Tue Dec 15 20:53:09 2009 +0000
@@ -162,7 +162,7 @@
 int
 main(int argc, char *argv[])
 {
-    int fsaa, noaccel;
+    int fsaa, accel;
     int value;
     int i, done;
     SDL_DisplayMode mode;
@@ -172,7 +172,7 @@
 
     /* Initialize parameters */
     fsaa = 0;
-    noaccel = 0;
+    accel = -1;
 
     /* Initialize test framework */
     state = CommonCreateState(argv, SDL_INIT_VIDEO);
@@ -187,15 +187,15 @@
             if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
                 ++fsaa;
                 consumed = 1;
-            } else if (SDL_strcasecmp(argv[i], "--noaccel") == 0) {
-                ++noaccel;
-                consumed = 1;
+            } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
+                accel = atoi(argv[i+1]);
+                consumed = 2;
             } else {
                 consumed = -1;
             }
         }
         if (consumed < 0) {
-            fprintf(stderr, "Usage: %s %s [--fsaa] [--noaccel]\n", argv[0],
+            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel n]\n", argv[0],
                     CommonUsage(state));
             quit(1);
         }
@@ -213,7 +213,9 @@
         state->gl_multisamplebuffers = 1;
         state->gl_multisamplesamples = fsaa;
     }
-    state->gl_accelerated = !noaccel;
+    if (accel >= 0) {
+        state->gl_accelerated = accel;
+    }
 
     if (!CommonInit(state)) {
         quit(2);
@@ -282,13 +284,15 @@
                    SDL_GetError());
         }
     }
-    status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
-    if (!status) {
-        printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", !noaccel,
-               value);
-    } else {
-        printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
-               SDL_GetError());
+    if (accel >= 0) {
+        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
+        if (!status) {
+            printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
+                   value);
+        } else {
+            printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
+                   SDL_GetError());
+        }
     }
 
     /* Set rendering settings */