From 2b3fe179a572f465d201e74ac2d9962107c251a3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 15 Dec 2009 20:36:31 +0000 Subject: [PATCH] OpenGL hardware acceleration defaults on --- src/video/SDL_video.c | 4 ++-- src/video/cocoa/SDL_cocoaopengl.m | 6 +++++- src/video/win32/SDL_win32opengl.c | 9 +++------ src/video/x11/SDL_x11opengl.c | 8 +++++--- test/testgl.c | 22 +++++++++------------- test/testgl2.c | 29 +++++++++++++---------------- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index d66c1f64d..8dd9b2d4b 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -239,7 +239,7 @@ SDL_VideoInit(const char *driver_name, Uint32 flags) _this->gl_config.multisamplebuffers = 0; _this->gl_config.multisamplesamples = 0; _this->gl_config.retained_backing = 1; - _this->gl_config.accelerated = -1; /* not known, don't set */ + _this->gl_config.accelerated = 1; _this->gl_config.major_version = 2; _this->gl_config.minor_version = 1; @@ -3274,7 +3274,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) case SDL_GL_ACCELERATED_VISUAL: { /* FIXME: How do we get this information? */ - *value = (_this->gl_config.accelerated != 0); + *value = _this->gl_config.accelerated; return 0; } default: diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 5d1de80bd..3c4ef9647 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -28,6 +28,7 @@ #if SDL_VIDEO_OPENGL_CGL #include #include +#include #include "SDL_loadso.h" #include "SDL_opengl.h" @@ -132,8 +133,11 @@ - (CGLContextObj)CGLContextObj; attr[i++] = NSOpenGLPFANoRecovery; } - if (_this->gl_config.accelerated > 0) { + if (_this->gl_config.accelerated) { attr[i++] = NSOpenGLPFAAccelerated; + } else { + attr[i++] = NSOpenGLPFARendererID; + attr[i++] = kCGLRendererGenericFloatID; } attr[i++] = NSOpenGLPFAScreenMask; diff --git a/src/video/win32/SDL_win32opengl.c b/src/video/win32/SDL_win32opengl.c index d3abd00cb..68e090260 100644 --- a/src/video/win32/SDL_win32opengl.c +++ b/src/video/win32/SDL_win32opengl.c @@ -469,12 +469,9 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) *iAttr++ = _this->gl_config.multisamplesamples; } - if (_this->gl_config.accelerated >= 0) { - *iAttr++ = WGL_ACCELERATION_ARB; - *iAttr++ = - (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : - WGL_NO_ACCELERATION_ARB); - } + *iAttr++ = WGL_ACCELERATION_ARB; + *iAttr++ = (_this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : + WGL_NO_ACCELERATION_ARB); *iAttr = 0; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 64a0d3602..6e2f3d977 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -359,17 +359,19 @@ X11_GL_GetVisual(_THIS, Display * display, int screen) attribs[i++] = _this->gl_config.multisamplesamples; } - if (_this->gl_config.accelerated >= 0 - && _this->gl_data->HAS_GLX_EXT_visual_rating) { + if (_this->gl_data->HAS_GLX_EXT_visual_rating) { attribs[i++] = GLX_VISUAL_CAVEAT_EXT; - attribs[i++] = GLX_NONE_EXT; + attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT : + GLX_SLOW_VISUAL_EXT; } + #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */ if (X11_UseDirectColorVisuals()) { attribs[i++] = GLX_X_VISUAL_TYPE; attribs[i++] = GLX_DIRECT_COLOR; } #endif + attribs[i++] = None; vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); diff --git a/test/testgl.c b/test/testgl.c index dc1558ae7..4abe0c6ca 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -370,7 +370,7 @@ DrawLogoTexture(void) int RunGLTest(int argc, char *argv[], int logo, int logocursor, int slowly, int bpp, float gamma, - int noframe, int fsaa, int sync, int accel) + int noframe, int fsaa, int sync, int noaccel) { int i; int rgb_size[3]; @@ -454,9 +454,7 @@ RunGLTest(int argc, char *argv[], SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); } - if (accel) { - SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); - } + SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, !noaccel); if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) { fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); SDL_Quit(); @@ -493,10 +491,8 @@ RunGLTest(int argc, char *argv[], printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } - if (accel) { - SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); - } + SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); + printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", !noaccel, value); if (sync) { printf("Buffer swap interval: requested 1, got %d\n", SDL_GL_GetSwapInterval()); @@ -707,7 +703,7 @@ main(int argc, char *argv[]) float gamma = 0.0; int noframe = 0; int fsaa = 0; - int accel = 0; + int noaccel = 0; int sync = 0; logo = 0; @@ -738,22 +734,22 @@ main(int argc, char *argv[]) if (strcmp(argv[i], "-fsaa") == 0) { ++fsaa; } - if (strcmp(argv[i], "-accel") == 0) { - ++accel; + if (strcmp(argv[i], "-noaccel") == 0) { + ++noaccel; } 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] [-accel] [-sync] [-fullscreen]\n", + ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-noaccel] [-sync] [-fullscreen]\n", argv[0]); exit(0); } } for (i = 0; i < numtests; ++i) { RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, - noframe, fsaa, sync, accel); + noframe, fsaa, sync, noaccel); } return 0; } diff --git a/test/testgl2.c b/test/testgl2.c index b2c798e05..bffb92600 100644 --- a/test/testgl2.c +++ b/test/testgl2.c @@ -162,7 +162,7 @@ Render() int main(int argc, char *argv[]) { - int fsaa, accel; + int fsaa, noaccel; int value; int i, done; SDL_DisplayMode mode; @@ -172,7 +172,7 @@ main(int argc, char *argv[]) /* Initialize parameters */ fsaa = 0; - accel = 0; + noaccel = 0; /* Initialize test framework */ state = CommonCreateState(argv, SDL_INIT_VIDEO); @@ -187,15 +187,15 @@ main(int argc, char *argv[]) if (SDL_strcasecmp(argv[i], "--fsaa") == 0) { ++fsaa; consumed = 1; - } else if (SDL_strcasecmp(argv[i], "--accel") == 0) { - ++accel; + } else if (SDL_strcasecmp(argv[i], "--noaccel") == 0) { + ++noaccel; consumed = 1; } else { consumed = -1; } } if (consumed < 0) { - fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0], + fprintf(stderr, "Usage: %s %s [--fsaa] [--noaccel]\n", argv[0], CommonUsage(state)); quit(1); } @@ -213,9 +213,7 @@ main(int argc, char *argv[]) state->gl_multisamplebuffers = 1; state->gl_multisamplesamples = fsaa; } - if (accel) { - state->gl_accelerated=1; - } + state->gl_accelerated = !noaccel; if (!CommonInit(state)) { quit(2); @@ -284,14 +282,13 @@ main(int argc, char *argv[]) SDL_GetError()); } } - if (accel) { - status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - if (!status) { - printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); - } else { - printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", - 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()); } /* Set rendering settings */