Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11opengl.c @ 3139:7f684f249ec9
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 23 May 2009 22:41:08 +0000 |
parents | cdeee9f9b14b |
children | 08c5964f2a34 |
comparison
equal
deleted
inserted
replaced
3125:d71d8ceda8b3 | 3139:7f684f249ec9 |
---|---|
75 #endif | 75 #endif |
76 | 76 |
77 static void X11_GL_InitExtensions(_THIS); | 77 static void X11_GL_InitExtensions(_THIS); |
78 | 78 |
79 /* Typedef for the GL 3.0 context creation function */ | 79 /* Typedef for the GL 3.0 context creation function */ |
80 typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); | 80 typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy, |
81 GLXFBConfig config, | |
82 GLXContext | |
83 share_context, | |
84 Bool direct, | |
85 const int | |
86 *attrib_list); | |
81 | 87 |
82 int | 88 int |
83 X11_GL_LoadLibrary(_THIS, const char *path) | 89 X11_GL_LoadLibrary(_THIS, const char *path) |
84 { | 90 { |
85 void *handle; | 91 void *handle; |
281 XVisualInfo *vinfo; | 287 XVisualInfo *vinfo; |
282 | 288 |
283 /* 64 seems nice. */ | 289 /* 64 seems nice. */ |
284 int attribs[64]; | 290 int attribs[64]; |
285 int i = 0; | 291 int i = 0; |
286 | 292 |
287 /* Setup our GLX attributes according to the gl_config. */ | 293 /* Setup our GLX attributes according to the gl_config. */ |
288 attribs[i++] = GLX_RGBA; | 294 attribs[i++] = GLX_RGBA; |
289 attribs[i++] = GLX_RED_SIZE; | 295 attribs[i++] = GLX_RED_SIZE; |
290 attribs[i++] = _this->gl_config.red_size; | 296 attribs[i++] = _this->gl_config.red_size; |
291 attribs[i++] = GLX_GREEN_SIZE; | 297 attribs[i++] = GLX_GREEN_SIZE; |
393 XGetWindowAttributes(display, data->window, &xattr); | 399 XGetWindowAttributes(display, data->window, &xattr); |
394 v.screen = screen; | 400 v.screen = screen; |
395 v.visualid = XVisualIDFromVisual(xattr.visual); | 401 v.visualid = XVisualIDFromVisual(xattr.visual); |
396 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); | 402 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); |
397 if (vinfo) { | 403 if (vinfo) { |
398 if (_this->gl_config.major_version < 3) { | 404 if (_this->gl_config.major_version < 3) { |
399 context = | 405 context = |
400 _this->gl_data->glXCreateContext(display, vinfo, NULL, True); | 406 _this->gl_data->glXCreateContext(display, vinfo, NULL, True); |
401 } else { | 407 } else { |
402 /* If we want a GL 3.0 context or later we need to get a temporary | 408 /* If we want a GL 3.0 context or later we need to get a temporary |
403 context to grab the new context creation function */ | 409 context to grab the new context creation function */ |
404 GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); | 410 GLXContext temp_context = |
411 _this->gl_data->glXCreateContext(display, vinfo, NULL, True); | |
405 if (!temp_context) { | 412 if (!temp_context) { |
406 SDL_SetError("Could not create GL context"); | 413 SDL_SetError("Could not create GL context"); |
407 return NULL; | 414 return NULL; |
408 } else { | 415 } else { |
409 int attribs[] = { | 416 int attribs[] = { |
410 GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, | 417 GLX_CONTEXT_MAJOR_VERSION_ARB, |
411 GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, | 418 _this->gl_config.major_version, |
412 0 | 419 GLX_CONTEXT_MINOR_VERSION_ARB, |
420 _this->gl_config.minor_version, | |
421 0 | |
413 }; | 422 }; |
414 | 423 |
415 /* Get a pointer to the context creation function for GL 3.0 */ | 424 /* Get a pointer to the context creation function for GL 3.0 */ |
416 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)_this->gl_data->glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB"); | 425 PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = |
426 (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data-> | |
427 glXGetProcAddress((GLubyte *) | |
428 "glXCreateContextAttribsARB"); | |
417 if (!glXCreateContextAttribs) { | 429 if (!glXCreateContextAttribs) { |
418 SDL_SetError("GL 3.x is not supported"); | 430 SDL_SetError("GL 3.x is not supported"); |
419 context = temp_context; | 431 context = temp_context; |
420 } else { | 432 } else { |
421 /* Create a GL 3.x context */ | 433 /* Create a GL 3.x context */ |
422 GLXFBConfig *framebuffer_config = NULL; | 434 GLXFBConfig *framebuffer_config = NULL; |
423 int fbcount = 0; | 435 int fbcount = 0; |
424 GLXFBConfig* (*glXChooseFBConfig)(Display* disp, int screen, const int* attrib_list, int* nelements); | 436 GLXFBConfig *(*glXChooseFBConfig) (Display * disp, |
425 | 437 int screen, |
426 glXChooseFBConfig = (GLXFBConfig* (*)(Display*, int, const int*, int*))_this->gl_data->glXGetProcAddress((GLubyte*)"glXChooseFBConfig"); | 438 const int *attrib_list, |
427 | 439 int *nelements); |
428 if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), NULL, &fbcount))) { | 440 |
429 SDL_SetError("No good framebuffers found. GL 3.x disabled"); | 441 glXChooseFBConfig = |
442 (GLXFBConfig * | |
443 (*)(Display *, int, const int *, | |
444 int *)) _this->gl_data-> | |
445 glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); | |
446 | |
447 if (!glXChooseFBConfig | |
448 || !(framebuffer_config = | |
449 glXChooseFBConfig(display, | |
450 DefaultScreen(display), NULL, | |
451 &fbcount))) { | |
452 SDL_SetError | |
453 ("No good framebuffers found. GL 3.x disabled"); | |
430 context = temp_context; | 454 context = temp_context; |
431 } else { | 455 } else { |
432 context = glXCreateContextAttribs(display, framebuffer_config[0], NULL, True, attribs); | 456 context = |
433 _this->gl_data->glXDestroyContext(display, temp_context); | 457 glXCreateContextAttribs(display, |
458 framebuffer_config[0], | |
459 NULL, True, attribs); | |
460 _this->gl_data->glXDestroyContext(display, | |
461 temp_context); | |
434 } | 462 } |
435 } | 463 } |
436 } | 464 } |
437 } | 465 } |
438 XFree(vinfo); | 466 XFree(vinfo); |