Merged useful fixes from 1.3 branch
authorSam Lantinga
Wed, 01 Feb 2006 08:17:54 +0000
changeset 1315e94b0d7c33bc
parent 1314 2b3ebc327017
child 1316 0781906086fa
Merged useful fixes from 1.3 branch
src/video/SDL_glfuncs.h
src/video/wincommon/SDL_wingl.c
src/video/wincommon/SDL_wingl_c.h
src/video/x11/SDL_x11gl.c
src/video/x11/SDL_x11gl_c.h
     1.1 --- a/src/video/SDL_glfuncs.h	Wed Feb 01 08:03:04 2006 +0000
     1.2 +++ b/src/video/SDL_glfuncs.h	Wed Feb 01 08:17:54 2006 +0000
     1.3 @@ -56,7 +56,7 @@
     1.4  SDL_PROC_UNUSED(void,glColorMaterial,(GLenum face, GLenum mode))
     1.5  SDL_PROC_UNUSED(void,glColorPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer))
     1.6  SDL_PROC_UNUSED(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type))
     1.7 -SDL_PROC(void,glCopyTexImage1D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border))
     1.8 +SDL_PROC_UNUSED(void,glCopyTexImage1D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border))
     1.9  SDL_PROC_UNUSED(void,glCopyTexImage2D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border))
    1.10  SDL_PROC_UNUSED(void,glCopyTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width))
    1.11  SDL_PROC_UNUSED(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height))
     2.1 --- a/src/video/wincommon/SDL_wingl.c	Wed Feb 01 08:03:04 2006 +0000
     2.2 +++ b/src/video/wincommon/SDL_wingl.c	Wed Feb 01 08:17:54 2006 +0000
     2.3 @@ -20,6 +20,7 @@
     2.4      slouken@libsdl.org
     2.5  */
     2.6  
     2.7 +#include <stdlib.h>
     2.8  #include <string.h>
     2.9  
    2.10  /* WGL implementation of SDL OpenGL support */
    2.11 @@ -73,6 +74,41 @@
    2.12  }
    2.13  
    2.14  #ifdef HAVE_OPENGL
    2.15 +
    2.16 +static int ExtensionSupported(const char *extension, const char *extensions)
    2.17 +{
    2.18 +	const char *start;
    2.19 +	const char *where, *terminator;
    2.20 +
    2.21 +	/* Extension names should not have spaces. */
    2.22 +	where = strchr(extension, ' ');
    2.23 +	if ( where || *extension == '\0' )
    2.24 +	      return 0;
    2.25 +	
    2.26 +	if ( ! extensions )
    2.27 +		return 0;
    2.28 +
    2.29 +	/* It takes a bit of care to be fool-proof about parsing the
    2.30 +	 *      OpenGL extensions string. Don't be fooled by sub-strings,
    2.31 +	 *           etc. */
    2.32 +	
    2.33 +	start = extensions;
    2.34 +	
    2.35 +	for (;;)
    2.36 +	{
    2.37 +		where = strstr(start, extension);
    2.38 +		if (!where) break;
    2.39 +		
    2.40 +		terminator = where + strlen(extension);
    2.41 +		if (where == start || *(where - 1) == ' ')
    2.42 +	        if (*terminator == ' ' || *terminator == '\0') return 1;
    2.43 +
    2.44 +		start = terminator;
    2.45 +	}
    2.46 +	
    2.47 +	return 0;
    2.48 +}
    2.49 +
    2.50  static void Init_WGL_ARB_extensions(_THIS)
    2.51  {
    2.52  	HWND hwnd;
    2.53 @@ -80,10 +116,11 @@
    2.54  	HGLRC hglrc;
    2.55  	int pformat;
    2.56  	const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0;
    2.57 +	const char *extensions;
    2.58  	
    2.59  	hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
    2.60  	                    0, 0, 10, 10,
    2.61 -	                    NULL, NULL, SDL_Instance,NULL);
    2.62 +	                    NULL, NULL, SDL_Instance, NULL);
    2.63  	hdc = GetDC(hwnd);
    2.64  
    2.65  	pformat = ChoosePixelFormat(hdc, &GL_pfd);
    2.66 @@ -97,7 +134,14 @@
    2.67  	wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC))
    2.68  		this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
    2.69  
    2.70 -	if(wglGetExtensionsStringARB && strstr(wglGetExtensionsStringARB(hdc),"WGL_ARB_pixel_format")) {
    2.71 +	if( wglGetExtensionsStringARB ) {
    2.72 +		extensions = wglGetExtensionsStringARB(hdc);
    2.73 +	} else {
    2.74 +		extensions = NULL;
    2.75 +	}
    2.76 +
    2.77 +	this->gl_data->WGL_ARB_pixel_format = 0;
    2.78 +	if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) {
    2.79  		this->gl_data->wglChoosePixelFormatARB =
    2.80  			(BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))
    2.81  			this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
    2.82 @@ -106,12 +150,9 @@
    2.83  			this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
    2.84  
    2.85  		if( (this->gl_data->wglChoosePixelFormatARB != NULL) &&
    2.86 -		    (this->gl_data->wglGetPixelFormatAttribivARB != NULL) )
    2.87 -			this->gl_data->wgl_arb_pixel_format = 1;
    2.88 -		else 
    2.89 -			this->gl_data->wgl_arb_pixel_format = 0;
    2.90 -	} else {
    2.91 -		this->gl_data->wgl_arb_pixel_format = 0;
    2.92 +		    (this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) {
    2.93 +			this->gl_data->WGL_ARB_pixel_format = 1;
    2.94 +		}
    2.95  	}
    2.96  	
    2.97  	if ( hglrc ) {
    2.98 @@ -121,7 +162,8 @@
    2.99  	ReleaseDC(hwnd, hdc);
   2.100  	DestroyWindow(hwnd);
   2.101  }
   2.102 -#endif /* !HAVE_OPENGL */
   2.103 +
   2.104 +#endif /* HAVE_OPENGL */
   2.105  
   2.106  int WIN_GL_SetupWindow(_THIS)
   2.107  {
   2.108 @@ -198,10 +240,8 @@
   2.109  			*iAttr++ = this->gl_config.alpha_size;
   2.110  		}
   2.111  
   2.112 -		if ( this->gl_config.double_buffer ) {
   2.113 -			*iAttr ++ = WGL_DOUBLE_BUFFER_ARB;
   2.114 -			*iAttr ++ = GL_TRUE;
   2.115 -		}
   2.116 +		*iAttr++ = WGL_DOUBLE_BUFFER_ARB;
   2.117 +		*iAttr++ = this->gl_config.double_buffer;
   2.118  
   2.119  		*iAttr++ = WGL_DEPTH_BITS_ARB;
   2.120  		*iAttr++ = this->gl_config.depth_size;
   2.121 @@ -233,7 +273,7 @@
   2.122  
   2.123  		if ( this->gl_config.stereo ) {
   2.124  			*iAttr++ = WGL_STEREO_ARB;
   2.125 -			*iAttr++ = this->gl_config.stereo;
   2.126 +			*iAttr++ = GL_TRUE;
   2.127  		}
   2.128  
   2.129  		if ( this->gl_config.multisamplebuffers ) {
   2.130 @@ -249,11 +289,11 @@
   2.131  		*iAttr = 0;
   2.132  
   2.133  		/* Choose and set the closest available pixel format */
   2.134 -		if ( !this->gl_data->wgl_arb_pixel_format ||
   2.135 +		if ( !this->gl_data->WGL_ARB_pixel_format ||
   2.136  		     !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) ||
   2.137  		     !matching ) {
   2.138  			pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
   2.139 -			this->gl_data->wgl_arb_pixel_format = 0;
   2.140 +			this->gl_data->WGL_ARB_pixel_format = 0;
   2.141  		}
   2.142  		if ( !pixel_format ) {
   2.143  			SDL_SetError("No matching GL pixel format available");
   2.144 @@ -331,7 +371,7 @@
   2.145  {
   2.146  	int retval;
   2.147  	
   2.148 -	if ( this->gl_data->wgl_arb_pixel_format ) {
   2.149 +	if ( this->gl_data->WGL_ARB_pixel_format ) {
   2.150  		int wgl_attrib;
   2.151  
   2.152  		switch(attrib) {
     3.1 --- a/src/video/wincommon/SDL_wingl_c.h	Wed Feb 01 08:03:04 2006 +0000
     3.2 +++ b/src/video/wincommon/SDL_wingl_c.h	Wed Feb 01 08:17:54 2006 +0000
     3.3 @@ -33,7 +33,7 @@
     3.4      HDC GL_hdc;
     3.5      HGLRC GL_hrc;
     3.6      int pixel_format;
     3.7 -    int wgl_arb_pixel_format;
     3.8 +    int WGL_ARB_pixel_format;
     3.9  
    3.10      void * (WINAPI *wglGetProcAddress)(const char *proc);
    3.11  
     4.1 --- a/src/video/x11/SDL_x11gl.c	Wed Feb 01 08:03:04 2006 +0000
     4.2 +++ b/src/video/x11/SDL_x11gl.c	Wed Feb 01 08:17:54 2006 +0000
     4.3 @@ -44,7 +44,6 @@
     4.4  #define GLX_SAMPLES_ARB                    100001
     4.5  #endif
     4.6  
     4.7 -/* return the preferred visual to use for openGL graphics */
     4.8  XVisualInfo *X11_GL_GetVisual(_THIS)
     4.9  {
    4.10  #ifdef HAVE_OPENGL_X11
    4.11 @@ -162,6 +161,9 @@
    4.12  		SDL_SetError( "Couldn't find matching GLX visual");
    4.13  		return NULL;
    4.14  	}
    4.15 +/*
    4.16 +	printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid);
    4.17 +*/
    4.18  	return glx_visualinfo;
    4.19  #else
    4.20  	SDL_SetError("X11 driver not configured with OpenGL");
    4.21 @@ -238,9 +240,6 @@
    4.22  		if (glx_context != NULL)
    4.23  			this->gl_data->glXDestroyContext(GFX_Display, glx_context);
    4.24  
    4.25 -		if( this->gl_data->glXReleaseBuffersMESA ) {
    4.26 -		    this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window);
    4.27 -		}
    4.28  		glx_context = NULL;
    4.29  	}
    4.30  	gl_active = 0;
    4.31 @@ -249,39 +248,6 @@
    4.32  
    4.33  #ifdef HAVE_OPENGL_X11
    4.34  
    4.35 -static int ExtensionSupported(const char *extension)
    4.36 -{
    4.37 -	const GLubyte *extensions = NULL;
    4.38 -	const GLubyte *start;
    4.39 -	GLubyte *where, *terminator;
    4.40 -
    4.41 -	/* Extension names should not have spaces. */
    4.42 -	where = (GLubyte *) strchr(extension, ' ');
    4.43 -	if (where || *extension == '\0')
    4.44 -	      return 0;
    4.45 -	
    4.46 -	extensions = current_video->glGetString(GL_EXTENSIONS);
    4.47 -	/* It takes a bit of care to be fool-proof about parsing the
    4.48 -	 *      OpenGL extensions string. Don't be fooled by sub-strings,
    4.49 -	 *           etc. */
    4.50 -	
    4.51 -	start = extensions;
    4.52 -	
    4.53 -	for (;;)
    4.54 -	{
    4.55 -		where = (GLubyte *) strstr((const char *) start, extension);
    4.56 -		if (!where) break;
    4.57 -		
    4.58 -		terminator = where + strlen(extension);
    4.59 -		if (where == start || *(where - 1) == ' ')
    4.60 -	        if (*terminator == ' ' || *terminator == '\0') return 1;
    4.61 -						  
    4.62 -		start = terminator;
    4.63 -	}
    4.64 -	
    4.65 -	return 0;
    4.66 -}
    4.67 -
    4.68  /* Make the current context active */
    4.69  int X11_GL_MakeCurrent(_THIS)
    4.70  {
    4.71 @@ -295,29 +261,6 @@
    4.72  	}
    4.73  	pXSync( GFX_Display, False );
    4.74  
    4.75 -	/* 
    4.76 -	 * The context is now current, check for glXReleaseBuffersMESA() 
    4.77 -	 * extension. If extension is _not_ supported, destroy the pointer 
    4.78 -	 * (to make sure it will not be called in X11_GL_Shutdown() ).
    4.79 -	 * 
    4.80 -	 * DRI/Mesa drivers include glXReleaseBuffersMESA() in the libGL.so, 
    4.81 -	 * but there's no need to call it (is is only needed for some old 
    4.82 -	 * non-DRI drivers).
    4.83 -	 * 
    4.84 -	 * When using for example glew (http://glew.sf.net), dlsym() for
    4.85 -	 * glXReleaseBuffersMESA() returns the pointer from the glew library
    4.86 -	 * (namespace conflict).
    4.87 -	 *
    4.88 -	 * The glXReleaseBuffersMESA() pointer in the glew is NULL, if the 
    4.89 -	 * driver doesn't support this extension. So blindly calling it will
    4.90 -	 * cause segfault with DRI/Mesa drivers!
    4.91 -	 * 
    4.92 -	 */
    4.93 -	
    4.94 -	if ( ! ExtensionSupported("glXReleaseBuffersMESA") ) {
    4.95 -		this->gl_data->glXReleaseBuffersMESA = NULL;
    4.96 -	}
    4.97 -
    4.98  	/* More Voodoo X server workarounds... Grr... */
    4.99  	SDL_Lock_EventThread();
   4.100  	X11_CheckDGAMouse(this);
   4.101 @@ -496,11 +439,7 @@
   4.102  	this->gl_data->glXQueryExtensionsString =
   4.103  		(const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString");
   4.104  	
   4.105 -	/* We don't compare below for this in case we're not using Mesa. */
   4.106 -	this->gl_data->glXReleaseBuffersMESA =
   4.107 -		(void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" );
   4.108 -	
   4.109 -	
   4.110 +
   4.111  	if ( (this->gl_data->glXChooseVisual == NULL) || 
   4.112  	     (this->gl_data->glXCreateContext == NULL) ||
   4.113  	     (this->gl_data->glXDestroyContext == NULL) ||
     5.1 --- a/src/video/x11/SDL_x11gl_c.h	Wed Feb 01 08:03:04 2006 +0000
     5.2 +++ b/src/video/x11/SDL_x11gl_c.h	Wed Feb 01 08:17:54 2006 +0000
     5.3 @@ -43,13 +43,13 @@
     5.4      XVisualInfo* (*glXChooseVisual)
     5.5  		( Display*		dpy,
     5.6  		  int			screen,
     5.7 -		  int*		attribList );
     5.8 +		  int*			attribList );
     5.9  
    5.10      GLXContext (*glXCreateContext)
    5.11  		( Display*		dpy,
    5.12 -		  XVisualInfo*	vis,
    5.13 +		  XVisualInfo*		vis,
    5.14  		  GLXContext		shareList,
    5.15 -		  Bool		direct );
    5.16 +		  Bool			direct );
    5.17  
    5.18      void (*glXDestroyContext)
    5.19  		( Display* 		dpy,
    5.20 @@ -70,13 +70,9 @@
    5.21  	   int attrib,
    5.22  	   int* value );
    5.23  
    5.24 -    void (*glXReleaseBuffersMESA)
    5.25 -	 ( Display* dpy,
    5.26 -	   GLXDrawable drawable );
    5.27 -
    5.28      const char *(*glXQueryExtensionsString)
    5.29  	    ( Display* dpy,
    5.30 -	      int screen);
    5.31 +	      int screen );
    5.32  
    5.33      
    5.34  #endif /* HAVE_OPENGL_X11 */