GLSurface gglCreateSurface(GLDisplay dp,::Window hwin,GLFormat fp) { GGLDisplay* display = (GGLDisplay*)dp; GGLFormat* format = (GGLFormat*)fp; GGLSurface* surface = 0; if (!_hasGLXExtension(display,GLX_VERSION_1_3)) { // Return our own GGL surface rep. surface = new GGLSurface; surface->type = GGLSurface::Window; surface->display = display; surface->drawable = 0; surface->window = hwin; } else { // Get config info from format ID GLXFBConfig config; if (!_getFBConfig(display,format->pformat,config)) return 0; // Create GLX window GLXWindow window = glXCreateWindow(display->display,config,hwin,0); if (!window) { GLenum error = glGetError(); static LogCategory log("/Gfx/Device/GL"); log.print(format("Create window error: %d",error)); return 0; } // Return our own GGL surface rep. surface = new GGLSurface; surface->type = GGLSurface::Window; surface->display = display; surface->drawable = window; surface->window = 0; } return surface; }
GLFormat gglSelectFormat(GLDisplay dp,GLFormatInfo& mode) { GGLDisplay* display = (GGLDisplay*)dp; U32 pformat; if (!_hasGLXExtension(display,GLX_VERSION_1_3)) { // Find GL compatible X visual using 1.2 interface. // 1.2 or earlier does not include pbuffer support. if (mode.target != GLFormatInfo::Window) return 0; int attributes[] = { GLX_RGBA, GLX_RED_SIZE, mode.red, GLX_BLUE_SIZE, mode.blue, GLX_GREEN_SIZE, mode.green, GLX_DEPTH_SIZE, mode.z, GLX_ALPHA_SIZE, mode.alpha, GLX_STENCIL_SIZE, mode.stencil, GLX_DOUBLEBUFFER, true, GLX_DOUBLEBUFFER, None }; XVisualInfo* visual = glXChooseVisual(display->display, display->screen, attributes); if (!visual) { static LogCategory log("/Gfx/Device/GL"); log.print("GGLContext: Could not get an accelerated visual"); return 0; } pformat = visual->visualid; XFree(visual); } else { // Find GL compatible X visual using 1.3 interface. int attributes[] = { GLX_DRAWABLE_TYPE, (mode.target == GLFormatInfo::Buffer)? GLX_PBUFFER_BIT: GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, mode.red, GLX_BLUE_SIZE, mode.blue, GLX_GREEN_SIZE, mode.green, GLX_DEPTH_SIZE, mode.z, GLX_ALPHA_SIZE, mode.alpha, GLX_STENCIL_SIZE, mode.stencil, GLX_DOUBLEBUFFER, true, None }; int count = 0; GLXFBConfig* configList = glXChooseFBConfig(display->display, display->screen,attributes,&count); if (!count) return 0; // Return the config ID int xid; glXGetFBConfigAttrib(display->display,configList[0],GLX_FBCONFIG_ID,&xid); XFree(configList); pformat = xid; } if (pformat) { GGLFormat* format = new GGLFormat; format->pformat = pformat; format->mode = mode; return format; } return 0; }