# HG changeset patch # User Sam Lantinga # Date 1138781874 0 # Node ID e94b0d7c33bc68aeff5e0039c3956881d6915282 # Parent 2b3ebc327017aaa13accf33193403d0162b46d5e Merged useful fixes from 1.3 branch diff -r 2b3ebc327017 -r e94b0d7c33bc src/video/SDL_glfuncs.h --- a/src/video/SDL_glfuncs.h Wed Feb 01 08:03:04 2006 +0000 +++ b/src/video/SDL_glfuncs.h Wed Feb 01 08:17:54 2006 +0000 @@ -56,7 +56,7 @@ SDL_PROC_UNUSED(void,glColorMaterial,(GLenum face, GLenum mode)) SDL_PROC_UNUSED(void,glColorPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)) SDL_PROC_UNUSED(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)) -SDL_PROC(void,glCopyTexImage1D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border)) +SDL_PROC_UNUSED(void,glCopyTexImage1D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border)) SDL_PROC_UNUSED(void,glCopyTexImage2D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)) SDL_PROC_UNUSED(void,glCopyTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width)) SDL_PROC_UNUSED(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)) diff -r 2b3ebc327017 -r e94b0d7c33bc src/video/wincommon/SDL_wingl.c --- a/src/video/wincommon/SDL_wingl.c Wed Feb 01 08:03:04 2006 +0000 +++ b/src/video/wincommon/SDL_wingl.c Wed Feb 01 08:17:54 2006 +0000 @@ -20,6 +20,7 @@ slouken@libsdl.org */ +#include #include /* WGL implementation of SDL OpenGL support */ @@ -73,6 +74,41 @@ } #ifdef HAVE_OPENGL + +static int ExtensionSupported(const char *extension, const char *extensions) +{ + const char *start; + const char *where, *terminator; + + /* Extension names should not have spaces. */ + where = strchr(extension, ' '); + if ( where || *extension == '\0' ) + return 0; + + if ( ! extensions ) + return 0; + + /* It takes a bit of care to be fool-proof about parsing the + * OpenGL extensions string. Don't be fooled by sub-strings, + * etc. */ + + start = extensions; + + for (;;) + { + where = strstr(start, extension); + if (!where) break; + + terminator = where + strlen(extension); + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') return 1; + + start = terminator; + } + + return 0; +} + static void Init_WGL_ARB_extensions(_THIS) { HWND hwnd; @@ -80,10 +116,11 @@ HGLRC hglrc; int pformat; const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0; + const char *extensions; hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, 0, 0, 10, 10, - NULL, NULL, SDL_Instance,NULL); + NULL, NULL, SDL_Instance, NULL); hdc = GetDC(hwnd); pformat = ChoosePixelFormat(hdc, &GL_pfd); @@ -97,7 +134,14 @@ wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC)) this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); - if(wglGetExtensionsStringARB && strstr(wglGetExtensionsStringARB(hdc),"WGL_ARB_pixel_format")) { + if( wglGetExtensionsStringARB ) { + extensions = wglGetExtensionsStringARB(hdc); + } else { + extensions = NULL; + } + + this->gl_data->WGL_ARB_pixel_format = 0; + if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) { this->gl_data->wglChoosePixelFormatARB = (BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *)) this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB"); @@ -106,12 +150,9 @@ this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB"); if( (this->gl_data->wglChoosePixelFormatARB != NULL) && - (this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) - this->gl_data->wgl_arb_pixel_format = 1; - else - this->gl_data->wgl_arb_pixel_format = 0; - } else { - this->gl_data->wgl_arb_pixel_format = 0; + (this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) { + this->gl_data->WGL_ARB_pixel_format = 1; + } } if ( hglrc ) { @@ -121,7 +162,8 @@ ReleaseDC(hwnd, hdc); DestroyWindow(hwnd); } -#endif /* !HAVE_OPENGL */ + +#endif /* HAVE_OPENGL */ int WIN_GL_SetupWindow(_THIS) { @@ -198,10 +240,8 @@ *iAttr++ = this->gl_config.alpha_size; } - if ( this->gl_config.double_buffer ) { - *iAttr ++ = WGL_DOUBLE_BUFFER_ARB; - *iAttr ++ = GL_TRUE; - } + *iAttr++ = WGL_DOUBLE_BUFFER_ARB; + *iAttr++ = this->gl_config.double_buffer; *iAttr++ = WGL_DEPTH_BITS_ARB; *iAttr++ = this->gl_config.depth_size; @@ -233,7 +273,7 @@ if ( this->gl_config.stereo ) { *iAttr++ = WGL_STEREO_ARB; - *iAttr++ = this->gl_config.stereo; + *iAttr++ = GL_TRUE; } if ( this->gl_config.multisamplebuffers ) { @@ -249,11 +289,11 @@ *iAttr = 0; /* Choose and set the closest available pixel format */ - if ( !this->gl_data->wgl_arb_pixel_format || + if ( !this->gl_data->WGL_ARB_pixel_format || !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) || !matching ) { pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd); - this->gl_data->wgl_arb_pixel_format = 0; + this->gl_data->WGL_ARB_pixel_format = 0; } if ( !pixel_format ) { SDL_SetError("No matching GL pixel format available"); @@ -331,7 +371,7 @@ { int retval; - if ( this->gl_data->wgl_arb_pixel_format ) { + if ( this->gl_data->WGL_ARB_pixel_format ) { int wgl_attrib; switch(attrib) { diff -r 2b3ebc327017 -r e94b0d7c33bc src/video/wincommon/SDL_wingl_c.h --- a/src/video/wincommon/SDL_wingl_c.h Wed Feb 01 08:03:04 2006 +0000 +++ b/src/video/wincommon/SDL_wingl_c.h Wed Feb 01 08:17:54 2006 +0000 @@ -33,7 +33,7 @@ HDC GL_hdc; HGLRC GL_hrc; int pixel_format; - int wgl_arb_pixel_format; + int WGL_ARB_pixel_format; void * (WINAPI *wglGetProcAddress)(const char *proc); diff -r 2b3ebc327017 -r e94b0d7c33bc src/video/x11/SDL_x11gl.c --- a/src/video/x11/SDL_x11gl.c Wed Feb 01 08:03:04 2006 +0000 +++ b/src/video/x11/SDL_x11gl.c Wed Feb 01 08:17:54 2006 +0000 @@ -44,7 +44,6 @@ #define GLX_SAMPLES_ARB 100001 #endif -/* return the preferred visual to use for openGL graphics */ XVisualInfo *X11_GL_GetVisual(_THIS) { #ifdef HAVE_OPENGL_X11 @@ -162,6 +161,9 @@ SDL_SetError( "Couldn't find matching GLX visual"); return NULL; } +/* + printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid); +*/ return glx_visualinfo; #else SDL_SetError("X11 driver not configured with OpenGL"); @@ -238,9 +240,6 @@ if (glx_context != NULL) this->gl_data->glXDestroyContext(GFX_Display, glx_context); - if( this->gl_data->glXReleaseBuffersMESA ) { - this->gl_data->glXReleaseBuffersMESA(GFX_Display,SDL_Window); - } glx_context = NULL; } gl_active = 0; @@ -249,39 +248,6 @@ #ifdef HAVE_OPENGL_X11 -static int ExtensionSupported(const char *extension) -{ - const GLubyte *extensions = NULL; - const GLubyte *start; - GLubyte *where, *terminator; - - /* Extension names should not have spaces. */ - where = (GLubyte *) strchr(extension, ' '); - if (where || *extension == '\0') - return 0; - - extensions = current_video->glGetString(GL_EXTENSIONS); - /* It takes a bit of care to be fool-proof about parsing the - * OpenGL extensions string. Don't be fooled by sub-strings, - * etc. */ - - start = extensions; - - for (;;) - { - where = (GLubyte *) strstr((const char *) start, extension); - if (!where) break; - - terminator = where + strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') return 1; - - start = terminator; - } - - return 0; -} - /* Make the current context active */ int X11_GL_MakeCurrent(_THIS) { @@ -295,29 +261,6 @@ } pXSync( GFX_Display, False ); - /* - * The context is now current, check for glXReleaseBuffersMESA() - * extension. If extension is _not_ supported, destroy the pointer - * (to make sure it will not be called in X11_GL_Shutdown() ). - * - * DRI/Mesa drivers include glXReleaseBuffersMESA() in the libGL.so, - * but there's no need to call it (is is only needed for some old - * non-DRI drivers). - * - * When using for example glew (http://glew.sf.net), dlsym() for - * glXReleaseBuffersMESA() returns the pointer from the glew library - * (namespace conflict). - * - * The glXReleaseBuffersMESA() pointer in the glew is NULL, if the - * driver doesn't support this extension. So blindly calling it will - * cause segfault with DRI/Mesa drivers! - * - */ - - if ( ! ExtensionSupported("glXReleaseBuffersMESA") ) { - this->gl_data->glXReleaseBuffersMESA = NULL; - } - /* More Voodoo X server workarounds... Grr... */ SDL_Lock_EventThread(); X11_CheckDGAMouse(this); @@ -496,11 +439,7 @@ this->gl_data->glXQueryExtensionsString = (const char *(*)(Display *, int)) do_dlsym(handle, "glXQueryExtensionsString"); - /* We don't compare below for this in case we're not using Mesa. */ - this->gl_data->glXReleaseBuffersMESA = - (void (*)(Display *, GLXDrawable)) do_dlsym( handle, "glXReleaseBuffersMESA" ); - - + if ( (this->gl_data->glXChooseVisual == NULL) || (this->gl_data->glXCreateContext == NULL) || (this->gl_data->glXDestroyContext == NULL) || diff -r 2b3ebc327017 -r e94b0d7c33bc src/video/x11/SDL_x11gl_c.h --- a/src/video/x11/SDL_x11gl_c.h Wed Feb 01 08:03:04 2006 +0000 +++ b/src/video/x11/SDL_x11gl_c.h Wed Feb 01 08:17:54 2006 +0000 @@ -43,13 +43,13 @@ XVisualInfo* (*glXChooseVisual) ( Display* dpy, int screen, - int* attribList ); + int* attribList ); GLXContext (*glXCreateContext) ( Display* dpy, - XVisualInfo* vis, + XVisualInfo* vis, GLXContext shareList, - Bool direct ); + Bool direct ); void (*glXDestroyContext) ( Display* dpy, @@ -70,13 +70,9 @@ int attrib, int* value ); - void (*glXReleaseBuffersMESA) - ( Display* dpy, - GLXDrawable drawable ); - const char *(*glXQueryExtensionsString) ( Display* dpy, - int screen); + int screen ); #endif /* HAVE_OPENGL_X11 */