summaryrefslogtreecommitdiff
path: root/gdk/gdkglversionprivate.h
blob: a144b5679c165200fbb019129ea9246cdacee3c6 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* GDK - The GIMP Drawing Kit
 *
 * gdkglcontextprivate.h: GL context abstraction
 *
 * Copyright © 2014  Emmanuele Bassi
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <gdkenums.h>

G_BEGIN_DECLS

/* Version requirements for EGL contexts.
 *
 * If you add support for EGL to your backend, please require this.
 */
#define GDK_EGL_MIN_VERSION_MAJOR (1)
#define GDK_EGL_MIN_VERSION_MINOR (4)

/* Minimum OpenGL versions supported by GTK.
 * Backends should make sure to never create a context of a previous version.
 *
 * The macros refer to OpenGL; OpenGL with OPENGL_COMPATIBILITY_PROFILE_BIT as
 * OPENGL_PROFILE_MASK; and OpenGL ES respectively
 */
#define GDK_GL_MIN_GL_VERSION GDK_GL_VERSION_INIT (3, 2)
#define GDK_GL_MIN_GL_LEGACY_VERSION GDK_GL_VERSION_INIT (3, 0)
#define GDK_GL_MIN_GLES_VERSION GDK_GL_VERSION_INIT (2, 0)

typedef struct _GdkGLVersion GdkGLVersion;

struct _GdkGLVersion
{
  int major;
  int minor;
};

#define GDK_GL_VERSION_INIT(maj,min) { maj, min }

static const GdkGLVersion supported_gl_versions[] = {
  GDK_GL_VERSION_INIT (4, 6),
  GDK_GL_VERSION_INIT (4, 5),
  GDK_GL_VERSION_INIT (4, 4),
  GDK_GL_VERSION_INIT (4, 3),
  GDK_GL_VERSION_INIT (4, 2),
  GDK_GL_VERSION_INIT (4, 1),
  GDK_GL_VERSION_INIT (4, 0),
  GDK_GL_VERSION_INIT (3, 3),
  GDK_GL_VERSION_INIT (3, 2),
  GDK_GL_VERSION_INIT (3, 1),
  GDK_GL_VERSION_INIT (3, 0),

  GDK_GL_VERSION_INIT (0, 0)
};

static const GdkGLVersion supported_gles_versions[] = {
  GDK_GL_VERSION_INIT (3, 2),
  GDK_GL_VERSION_INIT (3, 1),
  GDK_GL_VERSION_INIT (3, 0),
  GDK_GL_VERSION_INIT (2, 0),

  GDK_GL_VERSION_INIT (0, 0)
};

#undef GDK_GL_VERSION_INIT
#define GDK_GL_VERSION_INIT(maj,min) (GdkGLVersion) { maj, min }
#define GDK_GL_VERSION_STRING(str) GDK_GL_VERSION_INIT(str[0] - '0', str[2] - '0')

static inline const GdkGLVersion *
gdk_gl_versions_get_for_api (GdkGLAPI api)
{
  switch (api)
    {
      case GDK_GL_API_GL:
        return supported_gl_versions;
      case GDK_GL_API_GLES:
        return supported_gles_versions;
      default:
        g_assert_not_reached ();
        return NULL;
    }
}

static inline int
gdk_gl_version_get_major (const GdkGLVersion *self)
{
  return self->major;
}

static inline int
gdk_gl_version_get_minor (const GdkGLVersion *self)
{
  return self->minor;
}

static inline int
gdk_gl_version_compare (const GdkGLVersion *a,
                        const GdkGLVersion *b)
{
  if (a->major > b->major)
    return 1;
  if (a->major < b->major)
    return -1;

  if (a->minor > b->minor)
    return 1;
  if (a->minor < b->minor)
    return -1;

  return 0;
}

static inline gboolean
gdk_gl_version_greater_equal (const GdkGLVersion *a,
                              const GdkGLVersion *b)
{
  return gdk_gl_version_compare (a, b) >= 0;
}

/* in gdkglcontext.c */
void            gdk_gl_version_init_epoxy                       (GdkGLVersion           *version);

G_END_DECLS