Skip to content
Permalink
Browse files

Merged useful fixes from 1.3 branch

  • Loading branch information
slouken committed Feb 1, 2006
1 parent 6b3e41c commit 329d3479db9078edb4644f25399a465f489e1e0b
@@ -56,7 +56,7 @@ SDL_PROC_UNUSED(void,glColorMask,(GLboolean red, GLboolean green, GLboolean blue
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))
@@ -20,6 +20,7 @@
slouken@libsdl.org
*/

#include <stdlib.h>
#include <string.h>

/* WGL implementation of SDL OpenGL support */
@@ -73,17 +74,53 @@ static int WIN_GL_ResetWindow(_THIS)
}

#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;
HDC hdc;
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 @@ static void Init_WGL_ARB_extensions(_THIS)
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 @@ static void Init_WGL_ARB_extensions(_THIS)
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 @@ static void Init_WGL_ARB_extensions(_THIS)
ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);
}
#endif /* !HAVE_OPENGL */

#endif /* HAVE_OPENGL */

int WIN_GL_SetupWindow(_THIS)
{
@@ -198,10 +240,8 @@ int WIN_GL_SetupWindow(_THIS)
*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 @@ int WIN_GL_SetupWindow(_THIS)

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 @@ int WIN_GL_SetupWindow(_THIS)
*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 WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
int retval;

if ( this->gl_data->wgl_arb_pixel_format ) {
if ( this->gl_data->WGL_ARB_pixel_format ) {
int wgl_attrib;

switch(attrib) {
@@ -33,7 +33,7 @@ struct SDL_PrivateGLData {
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);

@@ -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 @@ XVisualInfo *X11_GL_GetVisual(_THIS)
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 @@ void X11_GL_Shutdown(_THIS)
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 @@ void X11_GL_Shutdown(_THIS)

#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 @@ int X11_GL_MakeCurrent(_THIS)
}
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 @@ int X11_GL_LoadLibrary(_THIS, const char* path)
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) ||
@@ -43,13 +43,13 @@ struct SDL_PrivateGLData {
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 @@ struct SDL_PrivateGLData {
int attrib,
int* value );

void (*glXReleaseBuffersMESA)
( Display* dpy,
GLXDrawable drawable );

const char *(*glXQueryExtensionsString)
( Display* dpy,
int screen);
int screen );


#endif /* HAVE_OPENGL_X11 */

0 comments on commit 329d347

Please sign in to comment.