blob: 7e81b756695586d0016e541111b90f2fb86876d9 [file] [log] [blame]
José Fonseca0396fa02015-01-05 16:20:08 +00001/**************************************************************************
2 *
3 * Copyright 2014 VMware, Inc.
4 * Copyright 2011 Jose Fonseca
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 **************************************************************************/
26
27/*
28 * Representation and manipulation of OpenGL context profiles.
29 */
30
31
32#include <ostream>
33
34
35#ifndef GLPROFILE_HPP
36#define GLPROFILE_HPP
37
38
39namespace glprofile {
40
41
42enum Api {
43 API_GL = 0,
44 API_GLES
45};
46
47
48struct Profile {
49 unsigned major:8;
50 unsigned minor:8;
51 unsigned api:1;
52 unsigned core:1;
53
54 inline
55 Profile(Api _api = API_GL, unsigned _major = 1, unsigned _minor = 0, bool _core = false) {
56 api = _api;
57 major = _major;
58 minor = _minor;
59 core = _core;
60 }
61
62 inline bool
José Fonsecab0c59722015-01-05 20:45:41 +000063 compat(void) {
64 return api == API_GL && !core;
65 }
66
67 inline bool
68 es(void) const {
69 return api == API_GLES;
70 }
71
72 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +000073 versionGreaterOrEqual(unsigned refMajor, unsigned refMinor) const {
74 return major > refMajor ||
75 (major == refMajor && minor >= refMinor);
76 }
77
José Fonsecac49a6952015-01-05 20:22:44 +000078 inline bool
79 matches(const Profile expected) const {
José Fonsecaf28a5be2015-01-06 21:07:17 +000080 /*
81 * GLX_ARB_create_context/WGL_ARB_create_context specs state that
82 *
83 * "If version 3.1 is requested, the context returned may implement
84 * any of the following versions:
85 *
86 * * Version 3.1. The GL_ARB_compatibility extension may or may not
87 * be implemented, as determined by the implementation.
88 *
89 * * The core profile of version 3.2 or greater."
90 */
José Fonsecac49a6952015-01-05 20:22:44 +000091 return api == expected.api &&
92 versionGreaterOrEqual(expected.major, expected.minor) &&
José Fonsecaf28a5be2015-01-06 21:07:17 +000093 (core == expected.core ||
94 (expected.major == 3 && expected.minor == 1));
José Fonsecac49a6952015-01-05 20:22:44 +000095 }
96
José Fonseca0396fa02015-01-05 16:20:08 +000097 // Comparison operator, mainly for use in std::map
98 inline bool
José Fonsecaa44df7a2015-01-05 19:59:59 +000099 operator == (const Profile & other) const {
100 return major == other.major &&
101 minor == other.minor &&
102 api == other.api &&
103 core == other.core;
104 }
105
106 // Comparison operator, mainly for use in std::map
107 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +0000108 operator < (const Profile & other) const {
José Fonsecaa44df7a2015-01-05 19:59:59 +0000109 return major < other.major ||
José Fonseca0396fa02015-01-05 16:20:08 +0000110 minor < other.minor ||
José Fonsecaa44df7a2015-01-05 19:59:59 +0000111 api < other.api ||
José Fonseca0396fa02015-01-05 16:20:08 +0000112 core < other.core;
113 }
114};
115
116
117std::ostream &
118operator << (std::ostream &os, const Profile & profile);
119
120
José Fonsecaa44df7a2015-01-05 19:59:59 +0000121Profile
122getCurrentContextProfile(void);
123
124
José Fonseca0396fa02015-01-05 16:20:08 +0000125} /* namespace glprofile */
126
127
128#endif // GLPROFILE_HPP