186#ifdef HAVE_GPUPERFAPI
187 GPA_Status gpa_status;
189 gpa_status = GPA_Initialize();
190 assert(gpa_status == GPA_STATUS_OK);
196 static int visual_attribs[] =
198 GLX_X_RENDERABLE , True,
199 GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
200 GLX_RENDER_TYPE , GLX_RGBA_BIT,
201 GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
207 GLX_STENCIL_SIZE , 8,
208 GLX_DOUBLEBUFFER , True,
214 int glx_major, glx_minor;
217 int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
223 int (*oldHandler)(Display*, XErrorEvent*);
226 if ( !glXQueryVersion(
display, &glx_major, &glx_minor ) ||
227 ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) )
233 debug_msg(
"Getting matching framebuffer configs\n" );
235 visual_attribs, &fbcount );
238 debug_msg(
"Failed to retrieve a framebuffer config\n" );
241 debug_msg(
"Found %d matching FB configs.\n", fbcount );
246 for (
int i = 0; i < fbcount; i++ )
248 XVisualInfo *vi = glXGetVisualFromFBConfig(
display, fbc[i] );
251 int samp_buf, samples;
252 glXGetFBConfigAttrib(
display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );
253 glXGetFBConfigAttrib(
display, fbc[i], GLX_SAMPLES , &samples );
255 debug_msg(
" Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
257 i, (
unsigned int) vi -> visualid, samp_buf, samples );
259 if ( best_fbc < 0 || (samp_buf && samples > best_num_samp ))
260 best_fbc = i, best_num_samp = samples;
261 if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
262 worst_fbc = i, worst_num_samp = samples;
267 bestFbc = fbc[ best_fbc ];
273 vi = glXGetVisualFromFBConfig(
display, bestFbc );
274 debug_msg(
"Chosen visual ID = 0x%x\n", (
unsigned int) vi->visualid );
277 XSetWindowAttributes swa;
278 swa.colormap = context->
cmap = XCreateColormap(
display,
279 RootWindow(
display, vi->screen ),
280 vi->visual, AllocNone );
281 swa.background_pixmap = None ;
282 swa.border_pixel = 0;
283 swa.event_mask = StructureNotifyMask;
287 0, 0, 1920, 1080, 0, vi->depth, InputOutput,
289 CWBorderPixel|CWColormap|CWEventMask, &swa );
294 debug_msg(
"Failed to create window.\n" );
308 glxExts = glXQueryExtensionsString(
display,
313 glXCreateContextAttribsARB = 0;
315 glXGetProcAddressARB( (
const GLubyte *)
"glXCreateContextAttribsARB" );
331 !glXCreateContextAttribsARB )
333 debug_msg(
"glXCreateContextAttribsARB() not found"
334 " ... using old-style GLX context\n" );
335 context->
ctx = glXCreateNewContext(
display, bestFbc, GLX_RGBA_TYPE, 0, True );
344 int context_attribs[] =
358 context->
ctx = glXCreateContextAttribsARB(
display, bestFbc, 0,
359 True, context_attribs );
364 debug_msg(
"Created GL %d.%d context\n", context_attribs[1], context_attribs[3]);
373 context_attribs[1] = 1;
375 context_attribs[3] = 0;
379 debug_msg(
"Failed to create GL 3.0 context"
380 " ... using old-style GLX context\n" );
381 context->
ctx = glXCreateContextAttribsARB(
display, bestFbc, 0,
382 True, context_attribs );
394 XSetErrorHandler( oldHandler );
398 debug_msg(
"Failed to create an OpenGL context\n" );
403 if ( ! glXIsDirect (
display, context->
ctx ) )
405 debug_msg(
"Indirect GLX rendering context obtained\n" );
409 debug_msg(
"Direct GLX rendering context obtained\n" );
421#ifdef HAVE_GPUPERFAPI
422 gpa_status = GPA_OpenContext( context->
ctx );
423 assert(gpa_status == GPA_STATUS_OK);
426 return (
void *) context;