Commit a3245a4e authored by Sam Lantinga's avatar Sam Lantinga

Creating a context makes it current, per the documentation.

Applied a variant of the multi-card OpenGL fix from SDL 1.2

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402497
parent 463ba0e0
...@@ -150,7 +150,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -150,7 +150,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormatAttribute attr[32];
NSOpenGLPixelFormat *fmt; NSOpenGLPixelFormat *fmt;
NSOpenGLContext *nscontext; NSOpenGLContext *context;
int i = 0; int i = 0;
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
...@@ -212,11 +212,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -212,11 +212,11 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
return NULL; return NULL;
} }
nscontext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil]; context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
[fmt release]; [fmt release];
if (nscontext == nil) { if (context == nil) {
SDL_SetError ("Failed creating OpenGL context"); SDL_SetError ("Failed creating OpenGL context");
[pool release]; [pool release];
return NULL; return NULL;
...@@ -240,7 +240,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -240,7 +240,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
{ {
long cache_max = 64; long cache_max = 64;
CGLContextObj ctx = [nscontext CGLContextObj]; CGLContextObj ctx = [context CGLContextObj];
CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max); CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max); CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
} }
...@@ -248,7 +248,13 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -248,7 +248,13 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
/* End Wisdom from Apple Engineer section. --ryan. */ /* End Wisdom from Apple Engineer section. --ryan. */
[pool release]; [pool release];
return nscontext;
if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
Cocoa_GL_DeleteContext(_this, context);
return NULL;
}
return context;
} }
int int
......
...@@ -292,32 +292,11 @@ HasExtension(const char *extension, const char *extensions) ...@@ -292,32 +292,11 @@ HasExtension(const char *extension, const char *extensions)
} }
static void static void
WIN_GL_InitExtensions(_THIS) WIN_GL_InitExtensions(_THIS, HDC hdc)
{ {
HWND hwnd;
HDC hdc;
PIXELFORMATDESCRIPTOR pfd;
int pixel_format;
HGLRC hglrc;
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0; const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
const char *extensions; const char *extensions;
hwnd =
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
10, 10, NULL, NULL, SDL_Instance, NULL);
WIN_PumpEvents(_this);
hdc = GetDC(hwnd);
WIN_GL_SetupPixelFormat(_this, &pfd);
pixel_format = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, pixel_format, &pfd);
hglrc = _this->gl_data->wglCreateContext(hdc);
if (hglrc) {
_this->gl_data->wglMakeCurrent(hdc, hglrc);
}
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC)) wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
_this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
if (wglGetExtensionsStringARB) { if (wglGetExtensionsStringARB) {
...@@ -350,15 +329,48 @@ WIN_GL_InitExtensions(_THIS) ...@@ -350,15 +329,48 @@ WIN_GL_InitExtensions(_THIS)
WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT"); WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
_this->gl_data->wglGetSwapIntervalEXT = _this->gl_data->wglGetSwapIntervalEXT =
WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT"); WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
} else {
_this->gl_data->wglSwapIntervalEXT = NULL;
_this->gl_data->wglGetSwapIntervalEXT = NULL;
} }
}
static int
WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
{
HWND hwnd;
HDC hdc;
HGLRC hglrc;
int pixel_format = 0;
unsigned int matching;
hwnd =
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
10, 10, NULL, NULL, SDL_Instance, NULL);
WIN_PumpEvents(_this);
hdc = GetDC(hwnd);
hglrc = _this->gl_data->wglCreateContext(hdc);
if (hglrc) { if (hglrc) {
_this->gl_data->wglMakeCurrent(hdc, hglrc);
WIN_GL_InitExtensions(_this, hdc);
if (_this->gl_data->WGL_ARB_pixel_format) {
_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
1, &pixel_format,
&matching);
}
_this->gl_data->wglMakeCurrent(NULL, NULL); _this->gl_data->wglMakeCurrent(NULL, NULL);
_this->gl_data->wglDeleteContext(hglrc); _this->gl_data->wglDeleteContext(hglrc);
} }
ReleaseDC(hwnd, hdc); ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd); DestroyWindow(hwnd);
WIN_PumpEvents(_this); WIN_PumpEvents(_this);
return pixel_format;
} }
static int static int
...@@ -383,9 +395,6 @@ WIN_GL_Initialize(_THIS) ...@@ -383,9 +395,6 @@ WIN_GL_Initialize(_THIS)
return -1; return -1;
} }
/* Initialize extensions */
WIN_GL_InitExtensions(_this);
return 0; return 0;
} }
...@@ -408,7 +417,6 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) ...@@ -408,7 +417,6 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window)
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
int pixel_format; int pixel_format;
unsigned int matching;
int iAttribs[64]; int iAttribs[64];
int *iAttr; int *iAttr;
float fAttribs[1] = { 0 }; float fAttribs[1] = { 0 };
...@@ -495,10 +503,8 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window) ...@@ -495,10 +503,8 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window)
*iAttr = 0; *iAttr = 0;
/* Choose and set the closest available pixel format */ /* Choose and set the closest available pixel format */
if (!_this->gl_data->WGL_ARB_pixel_format pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
|| !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, if (!pixel_format) {
1, &pixel_format,
&matching) || !matching) {
pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
} }
if (!pixel_format) { if (!pixel_format) {
...@@ -522,8 +528,22 @@ SDL_GLContext ...@@ -522,8 +528,22 @@ SDL_GLContext
WIN_GL_CreateContext(_THIS, SDL_Window * window) WIN_GL_CreateContext(_THIS, SDL_Window * window)
{ {
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
HGLRC context;
context = _this->gl_data->wglCreateContext(hdc);
if (!context) {
SDL_SetError("Could not create GL context");
return NULL;
}
if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
WIN_GL_DeleteContext(_this, context);
return NULL;
}
WIN_GL_InitExtensions(_this, hdc);
return _this->gl_data->wglCreateContext(hdc); return context;
} }
int int
......
...@@ -426,8 +426,15 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -426,8 +426,15 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
if (!context) { if (!context) {
SDL_SetError("Could not create GL context"); SDL_SetError("Could not create GL context");
return NULL;
} }
return (SDL_GLContext) context;
if (X11_GL_MakeCurrent(_this, window, context) < 0) {
X11_GL_DeleteContext(_this, context);
return NULL;
}
return context;
} }
int int
......
...@@ -225,10 +225,6 @@ main(int argc, char *argv[]) ...@@ -225,10 +225,6 @@ main(int argc, char *argv[])
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2); quit(2);
} }
if (SDL_GL_MakeCurrent(state->windows[0], context) < 0) {
fprintf(stderr, "SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
quit(2);
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) { if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1); SDL_GL_SetSwapInterval(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment