summaryrefslogtreecommitdiff
path: root/plugins/gtkui/gtkglext-gtk2/gdk/gdkglquery.c
blob: f581cf6b022e4855f6419d827f3849e4d0f726ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* GdkGLExt - OpenGL Extension to GDK
 * Copyright (C) 2002-2004  Naofumi Yasufuku
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 */

#include <stdlib.h>
#include <string.h>

#include "gdkglprivate.h"
#include "gdkglquery.h"

#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include <GL/gl.h>

/*
 * This code is based on glutExtensionSupported().
 */

/**
 * gdk_gl_query_gl_extension:
 * @extension: name of OpenGL extension.
 *
 * Determines whether a given OpenGL extension is supported.
 *
 * There must be a valid current rendering context to call
 * gdk_gl_query_gl_extension().
 *
 * gdk_gl_query_gl_extension() returns information about OpenGL extensions
 * only. This means that window system dependent extensions (for example,
 * GLX extensions) are not reported by gdk_gl_query_gl_extension().
 *
 * Return value: TRUE if the OpenGL extension is supported, FALSE if not 
 *               supported.
 **/
gboolean
gdk_gl_query_gl_extension (const char *extension)
{
  static const GLubyte *extensions = NULL;
  const GLubyte *start;
  GLubyte *where, *terminator;

  /* Extension names should not have spaces. */
  where = (GLubyte *) strchr (extension, ' ');
  if (where || *extension == '\0')
    return FALSE;

  if (extensions == NULL)
    extensions = glGetString (GL_EXTENSIONS);

  /* It takes a bit of care to be fool-proof about parsing the
     OpenGL extensions string.  Don't be fooled by sub-strings,
     etc. */
  start = extensions;
  for (;;)
    {
      /* If your application crashes in the strstr routine below,
         you are probably calling gdk_gl_query_gl_extension without
         having a current window.  Calling glGetString without
         a current OpenGL context has unpredictable results.
         Please fix your program. */
      where = (GLubyte *) strstr ((const char *) start, extension);
      if (where == NULL)
        break;

      terminator = where + strlen (extension);

      if (where == start || *(where - 1) == ' ')
        if (*terminator == ' ' || *terminator == '\0')
          {
            GDK_GL_NOTE (MISC, g_message (" - %s - supported", extension));
            return TRUE;
          }

      start = terminator;
    }

  GDK_GL_NOTE (MISC, g_message (" - %s - not supported", extension));

  return FALSE;
}

/*< private >*/
void
_gdk_gl_print_gl_info (void)
{
  static gboolean done = FALSE;

  if (!done)
    {
      g_message (" -- GL_VENDOR     : %s", glGetString (GL_VENDOR));
      g_message (" -- GL_RENDERER   : %s", glGetString (GL_RENDERER));
      g_message (" -- GL_VERSION    : %s", glGetString (GL_VERSION));
      g_message (" -- GL_EXTENSIONS : %s", glGetString (GL_EXTENSIONS));

      done = TRUE;
    }
}