Implemented bug #5
authorSam Lantinga <slouken@libsdl.org>
Thu, 27 Apr 2006 08:39:51 +0000
changeset 1737eacc5bc01d1c
parent 1736 3b2a92126f4d
child 1738 acfd00fbff5c
Implemented bug #5
Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
WhatsNew
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/maccommon/SDL_macgl.c
src/video/quartz/SDL_QuartzGL.m
src/video/wincommon/SDL_wingl.c
src/video/x11/SDL_x11gl.c
test/testgl.c
     1.1 --- a/WhatsNew	Thu Apr 27 07:59:16 2006 +0000
     1.2 +++ b/WhatsNew	Thu Apr 27 08:39:51 2006 +0000
     1.3 @@ -6,6 +6,8 @@
     1.4  1.2.10:
     1.5  	Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
     1.6  
     1.7 +	Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
     1.8 +
     1.9  	Added current_w and current_h to the SDL_VideoInfo structure,
    1.10  	which is set to the desktop resolution during video intialization,
    1.11  	and then set to the current resolution when a video mode is set.
     2.1 --- a/include/SDL_video.h	Thu Apr 27 07:59:16 2006 +0000
     2.2 +++ b/include/SDL_video.h	Thu Apr 27 08:39:51 2006 +0000
     2.3 @@ -214,6 +214,7 @@
     2.4      SDL_GL_STEREO,
     2.5      SDL_GL_MULTISAMPLEBUFFERS,
     2.6      SDL_GL_MULTISAMPLESAMPLES,
     2.7 +    SDL_GL_ACCELERATED_VISUAL,
     2.8      SDL_GL_SWAP_CONTROL
     2.9  } SDL_GLattr;
    2.10  
     3.1 --- a/src/video/SDL_sysvideo.h	Thu Apr 27 07:59:16 2006 +0000
     3.2 +++ b/src/video/SDL_sysvideo.h	Thu Apr 27 08:39:51 2006 +0000
     3.3 @@ -292,6 +292,7 @@
     3.4  		int stereo;
     3.5  		int multisamplebuffers;
     3.6  		int multisamplesamples;
     3.7 +		int accelerated;
     3.8  		int swap_control;
     3.9  		int driver_loaded;
    3.10  		char driver_path[256];
     4.1 --- a/src/video/SDL_video.c	Thu Apr 27 07:59:16 2006 +0000
     4.2 +++ b/src/video/SDL_video.c	Thu Apr 27 08:39:51 2006 +0000
     4.3 @@ -233,6 +233,7 @@
     4.4  	video->gl_config.stereo = 0;
     4.5  	video->gl_config.multisamplebuffers = 0;
     4.6  	video->gl_config.multisamplesamples = 0;
     4.7 +	video->gl_config.accelerated = -1; /* not known, don't set */
     4.8  	video->gl_config.swap_control = -1; /* not known, don't set */
     4.9  	
    4.10  	/* Initialize the video subsystem */
    4.11 @@ -1475,6 +1476,9 @@
    4.12  		case SDL_GL_MULTISAMPLESAMPLES:
    4.13  			video->gl_config.multisamplesamples = value;
    4.14  			break;
    4.15 +		case SDL_GL_ACCELERATED_VISUAL:
    4.16 +			video->gl_config.accelerated = value;
    4.17 +			break;
    4.18  		case SDL_GL_SWAP_CONTROL:
    4.19  			video->gl_config.swap_control = value;
    4.20  			break;
     5.1 --- a/src/video/maccommon/SDL_macgl.c	Thu Apr 27 07:59:16 2006 +0000
     5.2 +++ b/src/video/maccommon/SDL_macgl.c	Thu Apr 27 08:39:51 2006 +0000
     5.3 @@ -34,7 +34,7 @@
     5.4  #if SDL_VIDEO_OPENGL
     5.5  	AGLPixelFormat format;
     5.6     	int i = 0;
     5.7 -	GLint attributes [ 24 ]; /* 24 is max possible in this setup */
     5.8 +	GLint attributes [ 26 ]; /* 26 is max possible in this setup */
     5.9  	GLboolean noerr;
    5.10     
    5.11  	/* load the gl driver from a default path */
    5.12 @@ -95,6 +95,11 @@
    5.13  		attributes[i++] = this->gl_config.multisamplesamples;
    5.14  	}	
    5.15  #endif
    5.16 +	if ( this->gl_config.accelerated > 0 ) {
    5.17 +		attributes[i++] = AGL_ACCELERATED;
    5.18 +		attributes[i++] = AGL_NO_RECOVERY;
    5.19 +	}
    5.20 +
    5.21  	attributes[i++] = AGL_ALL_RENDERERS;
    5.22  	attributes[i]	= AGL_NONE;
    5.23  
     6.1 --- a/src/video/quartz/SDL_QuartzGL.m	Thu Apr 27 07:59:16 2006 +0000
     6.2 +++ b/src/video/quartz/SDL_QuartzGL.m	Thu Apr 27 08:39:51 2006 +0000
     6.3 @@ -112,6 +112,10 @@
     6.4          attr[i++] = NSOpenGLPFANoRecovery;
     6.5      }
     6.6  
     6.7 +    if ( this->gl_config.accelerated > 0 ) {
     6.8 +        attr[i++] = NSOpenGLPFAAccelerated;
     6.9 +    }
    6.10 +
    6.11      attr[i++] = NSOpenGLPFAScreenMask;
    6.12      attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
    6.13      attr[i] = 0;
    6.14 @@ -242,8 +246,22 @@
    6.15              glGetIntegerv (GL_ALPHA_BITS, &component); bits += component;
    6.16  
    6.17              *value = bits;
    6.18 +            return 0;
    6.19          }
    6.20 -        return 0;
    6.21 +        case SDL_GL_ACCELERATED_VISUAL:
    6.22 +        {
    6.23 +            long val;
    6.24 +            [fmt getValues: &val forAttribute: NSOpenGLPFAAccelerated attr forVirtualScreen: 0];
    6.25 +            *value = val;
    6.26 +            return 0;
    6.27 +        }
    6.28 +        case SDL_GL_SWAP_CONTROL:
    6.29 +        {
    6.30 +            long val;
    6.31 +            [ gl_context getValues: &val forParameter: NSOpenGLCPSwapInterval ];
    6.32 +            *value = val;
    6.33 +            return 0;
    6.34 +        }
    6.35      }
    6.36  
    6.37      glGetIntegerv (attr, (GLint *)value);
     7.1 --- a/src/video/wincommon/SDL_wingl.c	Thu Apr 27 07:59:16 2006 +0000
     7.2 +++ b/src/video/wincommon/SDL_wingl.c	Thu Apr 27 08:39:51 2006 +0000
     7.3 @@ -290,6 +290,11 @@
     7.4  			*iAttr++ = this->gl_config.multisamplesamples;
     7.5  		}
     7.6  
     7.7 +		if ( this->gl_config.accelerated >= 0 ) {
     7.8 +			*iAttr++ = WGL_ACCELERATION_ARB;
     7.9 +			*iAttr++ = (this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB);
    7.10 +		}
    7.11 +
    7.12  		*iAttr = 0;
    7.13  
    7.14  		/* Choose and set the closest available pixel format */
    7.15 @@ -442,6 +447,16 @@
    7.16  		    case SDL_GL_MULTISAMPLESAMPLES:
    7.17  			wgl_attrib = WGL_SAMPLES_ARB;
    7.18  			break;
    7.19 +		    case SDL_GL_ACCELERATED_VISUAL:
    7.20 +			wgl_attrib = WGL_ACCELERATION_ARB;
    7.21 +			this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
    7.22 +			if ( *value == WGL_NO_ACCELERATION_ARB ) {
    7.23 +				*value = SDL_FALSE;
    7.24 +			} else {
    7.25 +				*value = SDL_TRUE;
    7.26 +			}
    7.27 +			return 0;
    7.28 +			break;
    7.29  		    case SDL_GL_SWAP_CONTROL:
    7.30  			if ( this->gl_data->wglGetSwapIntervalEXT ) {
    7.31  				return this->gl_data->wglGetSwapIntervalEXT();
     8.1 --- a/src/video/x11/SDL_x11gl.c	Thu Apr 27 07:59:16 2006 +0000
     8.2 +++ b/src/video/x11/SDL_x11gl.c	Thu Apr 27 08:39:51 2006 +0000
     8.3 @@ -43,6 +43,47 @@
     8.4  #define GLX_SAMPLES_ARB                    100001
     8.5  #endif
     8.6  
     8.7 +#ifndef GLX_EXT_visual_rating
     8.8 +#define GLX_EXT_visual_rating
     8.9 +#define GLX_VISUAL_CAVEAT_EXT              0x20
    8.10 +#define GLX_SLOW_VISUAL_EXT                0x8001
    8.11 +#define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
    8.12 +#endif
    8.13 +
    8.14 +#if SDL_VIDEO_OPENGL_GLX
    8.15 +static int glXExtensionSupported(_THIS, const char *extension)
    8.16 +{
    8.17 +	const char *extensions;
    8.18 +	const char *start;
    8.19 +	const char *where, *terminator;
    8.20 +
    8.21 +	/* Extension names should not have spaces. */
    8.22 +	where = SDL_strchr(extension, ' ');
    8.23 +	if ( where || *extension == '\0' ) {
    8.24 +	      return 0;
    8.25 +	}
    8.26 +
    8.27 +	extensions = this->gl_data->glXQueryExtensionsString(GFX_Display,SDL_Screen);
    8.28 +	/* It takes a bit of care to be fool-proof about parsing the
    8.29 +	 * OpenGL extensions string. Don't be fooled by sub-strings, etc.
    8.30 +	 */
    8.31 +	
    8.32 +	start = extensions;
    8.33 +	
    8.34 +	for (;;) {
    8.35 +		where = SDL_strstr(start, extension);
    8.36 +		if (!where) break;
    8.37 +		
    8.38 +		terminator = where + strlen(extension);
    8.39 +		if (where == start || *(where - 1) == ' ')
    8.40 +	        if (*terminator == ' ' || *terminator == '\0') return 1;
    8.41 +						  
    8.42 +		start = terminator;
    8.43 +	}
    8.44 +	return 0;
    8.45 +}
    8.46 +#endif /* SDL_VIDEO_OPENGL_GLX */
    8.47 +
    8.48  XVisualInfo *X11_GL_GetVisual(_THIS)
    8.49  {
    8.50  #if SDL_VIDEO_OPENGL_GLX
    8.51 @@ -138,6 +179,12 @@
    8.52  		attribs[i++] = this->gl_config.multisamplesamples;
    8.53  	}
    8.54  
    8.55 +	if( this->gl_config.accelerated >= 0 &&
    8.56 +	    glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
    8.57 +		attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
    8.58 +		attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE;
    8.59 +	}
    8.60 +
    8.61  #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
    8.62  	if ( !SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
    8.63  		attribs[i++] = GLX_X_VISUAL_TYPE;
    8.64 @@ -205,7 +252,6 @@
    8.65  {
    8.66  	int retval;
    8.67  #if SDL_VIDEO_OPENGL_GLX
    8.68 -	const char *glXext;
    8.69  
    8.70  	/* We do this to create a clean separation between X and GLX errors. */
    8.71  	XSync( SDL_Display, False );
    8.72 @@ -222,12 +268,10 @@
    8.73  	}
    8.74  	gl_active = 1;
    8.75  
    8.76 -	/* The use of strstr here should be safe */
    8.77 -	glXext = this->gl_data->glXQueryExtensionsString(GFX_Display, DefaultScreen(GFX_Display));
    8.78 -	if ( !SDL_strstr(glXext, "SGI_swap_control") ) {
    8.79 +	if ( !glXExtensionSupported(this, "SGI_swap_control") ) {
    8.80  		this->gl_data->glXSwapIntervalSGI = NULL;
    8.81  	}
    8.82 -	if ( !SDL_strstr(glXext, "GLX_MESA_swap_control") ) {
    8.83 +	if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) {
    8.84  		this->gl_data->glXSwapIntervalMESA = NULL;
    8.85  		this->gl_data->glXGetSwapIntervalMESA = NULL;
    8.86  	}
    8.87 @@ -340,11 +384,25 @@
    8.88   	    case SDL_GL_MULTISAMPLESAMPLES:
    8.89   		glx_attrib = GLX_SAMPLES_ARB;
    8.90   		break;
    8.91 + 	    case SDL_GL_ACCELERATED_VISUAL:
    8.92 +		if ( glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
    8.93 +			glx_attrib = GLX_VISUAL_CAVEAT_EXT;
    8.94 +			retval = this->gl_data->glXGetConfig(GFX_Display, glx_visualinfo, glx_attrib, value);
    8.95 +			if ( *value == GLX_SLOW_VISUAL_EXT ) {
    8.96 +				*value = SDL_FALSE;
    8.97 +			} else {
    8.98 +				*value = SDL_TRUE;
    8.99 +			}
   8.100 +			return retval;
   8.101 +		} else {
   8.102 +			return(-1);
   8.103 +		}
   8.104 +		break;
   8.105  	    case SDL_GL_SWAP_CONTROL:
   8.106  		if ( this->gl_data->glXGetSwapIntervalMESA ) {
   8.107  			return this->gl_data->glXGetSwapIntervalMESA();
   8.108  		} else {
   8.109 -			return -1 /*(this->gl_config.swap_control > 0)*/;
   8.110 +			return(-1)/*(this->gl_config.swap_control > 0)*/;
   8.111  		}
   8.112  		break;
   8.113  	    default:
     9.1 --- a/test/testgl.c	Thu Apr 27 07:59:16 2006 +0000
     9.2 +++ b/test/testgl.c	Thu Apr 27 08:39:51 2006 +0000
     9.3 @@ -445,7 +445,7 @@
     9.4  }
     9.5  
     9.6  int RunGLTest( int argc, char* argv[],
     9.7 -               int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa, int sync )
     9.8 +               int logo, int logocursor, int slowly, int bpp, float gamma, int noframe, int fsaa, int sync, int accel )
     9.9  {
    9.10  	int i;
    9.11  	int rgb_size[3];
    9.12 @@ -531,6 +531,9 @@
    9.13  		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
    9.14  		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa );
    9.15  	}
    9.16 +	if ( accel ) {
    9.17 +		SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
    9.18 +	}
    9.19  	if ( sync ) {
    9.20  		SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );
    9.21  	} else {
    9.22 @@ -566,6 +569,10 @@
    9.23  		SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value );
    9.24  		printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value );
    9.25  	}
    9.26 +	if ( accel ) {
    9.27 +		SDL_GL_GetAttribute( SDL_GL_ACCELERATED_VISUAL, &value );
    9.28 +		printf( "SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value );
    9.29 +	}
    9.30  	if ( sync ) {
    9.31  		SDL_GL_GetAttribute( SDL_GL_SWAP_CONTROL, &value );
    9.32  		printf( "SDL_GL_SWAP_CONTROL: requested 1, got %d\n", value );
    9.33 @@ -779,6 +786,7 @@
    9.34  	float gamma = 0.0;
    9.35  	int noframe = 0;
    9.36  	int fsaa = 0;
    9.37 +	int accel = 0;
    9.38  	int sync = 0;
    9.39  
    9.40  	logo = 0;
    9.41 @@ -814,6 +822,9 @@
    9.42  		if ( strcmp(argv[i], "-fsaa") == 0 ) {
    9.43   		       ++fsaa;
    9.44  		}
    9.45 +		if ( strcmp(argv[i], "-accel") == 0 ) {
    9.46 + 		       ++accel;
    9.47 +		}
    9.48  		if ( strcmp(argv[i], "-sync") == 0 ) {
    9.49   		       ++sync;
    9.50  		}
    9.51 @@ -825,7 +836,7 @@
    9.52  		}
    9.53  	}
    9.54  	for ( i=0; i<numtests; ++i ) {
    9.55 - 		RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync);
    9.56 + 		RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma, noframe, fsaa, sync, accel);
    9.57  	}
    9.58  	return 0;
    9.59  }