dispatch_glx.c revision e52adb7b
1/*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include <assert.h>
25#include <string.h>
26#include <stdio.h>
27
28#include "dispatch_common.h"
29
30/**
31 * If we can determine the GLX version from the current context, then
32 * return that, otherwise return a version that will just send us on
33 * to dlsym() or get_proc_address().
34 */
35int
36epoxy_conservative_glx_version(void)
37{
38    Display *dpy = glXGetCurrentDisplay();
39    GLXContext ctx = glXGetCurrentContext();
40    int screen;
41
42    if (!dpy || !ctx)
43        return 14;
44
45    glXQueryContext(dpy, ctx, GLX_SCREEN, &screen);
46
47    return epoxy_glx_version(dpy, screen);
48}
49
50PUBLIC int
51epoxy_glx_version(Display *dpy, int screen)
52{
53    int server_major, server_minor;
54    int client_major, client_minor;
55    int server, client;
56    const char *version_string;
57    int ret;
58
59    version_string = glXQueryServerString(dpy, screen, GLX_VERSION);
60    ret = sscanf(version_string, "%d.%d", &server_major, &server_minor);
61    assert(ret == 2);
62    server = server_major * 10 + server_minor;
63
64    version_string = glXGetClientString(dpy, GLX_VERSION);
65    ret = sscanf(version_string, "%d.%d", &client_major, &client_minor);
66    assert(ret == 2);
67    client = client_major * 10 + client_minor;
68
69    if (client < server)
70        return client;
71    else
72        return server;
73}
74
75/**
76 * If we can determine the GLX extension support from the current
77 * context, then return that, otherwise give the answer that will just
78 * send us on to get_proc_address().
79 */
80bool
81epoxy_conservative_has_glx_extension(const char *ext)
82{
83    Display *dpy = glXGetCurrentDisplay();
84    GLXContext ctx = glXGetCurrentContext();
85    int screen;
86
87    if (!dpy || !ctx)
88        return true;
89
90    glXQueryContext(dpy, ctx, GLX_SCREEN, &screen);
91
92    return epoxy_has_glx_extension(dpy, screen, ext);
93}
94
95PUBLIC bool
96epoxy_has_glx_extension(Display *dpy, int screen, const char *ext)
97 {
98    /* No, you can't just use glXGetClientString or
99     * glXGetServerString() here.  Those each tell you about one half
100     * of what's needed for an extension to be supported, and
101     * glXQueryExtensionsString() is what gives you the intersection
102     * of the two.
103     */
104    return epoxy_extension_in_string(glXQueryExtensionsString(dpy, screen), ext);
105}
106