blob: b662f3afd20f104340490115889909628b411d6c [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
José Fonseca0396fa02015-01-05 16:20:08 +000032#ifndef GLPROFILE_HPP
33#define GLPROFILE_HPP
34
35
José Fonseca440d8aa2015-01-23 15:32:23 +000036#include <ostream>
37#include <set>
unknownfe5ef8b2015-02-05 11:46:10 +010038#include <string>
José Fonseca440d8aa2015-01-23 15:32:23 +000039
40
José Fonseca0396fa02015-01-05 16:20:08 +000041namespace glprofile {
42
43
44enum Api {
45 API_GL = 0,
46 API_GLES
47};
48
49
50struct Profile {
51 unsigned major:8;
52 unsigned minor:8;
53 unsigned api:1;
54 unsigned core:1;
Jose Fonseca56c419c2015-03-13 16:07:33 +000055 unsigned forwardCompatible:1;
José Fonseca0396fa02015-01-05 16:20:08 +000056
57 inline
Jose Fonseca56c419c2015-03-13 16:07:33 +000058 Profile(
59 Api _api = API_GL,
60 unsigned _major = 1,
61 unsigned _minor = 0,
62 bool _core = false,
63 bool _forwardCompatible = false
64 ) {
José Fonseca0396fa02015-01-05 16:20:08 +000065 api = _api;
66 major = _major;
67 minor = _minor;
68 core = _core;
Jose Fonseca56c419c2015-03-13 16:07:33 +000069 forwardCompatible = _forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +000070 }
71
72 inline bool
José Fonseca34ea6162015-01-08 23:45:43 +000073 desktop(void) {
74 return api == API_GL;
José Fonsecab0c59722015-01-05 20:45:41 +000075 }
76
77 inline bool
78 es(void) const {
79 return api == API_GLES;
80 }
81
82 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +000083 versionGreaterOrEqual(unsigned refMajor, unsigned refMinor) const {
84 return major > refMajor ||
85 (major == refMajor && minor >= refMinor);
86 }
87
Jose Fonseca0e1d41b2015-03-13 17:17:47 +000088 bool
89 matches(const Profile expected) const;
José Fonsecac49a6952015-01-05 20:22:44 +000090
José Fonseca0396fa02015-01-05 16:20:08 +000091 // Comparison operator, mainly for use in std::map
92 inline bool
José Fonsecaa44df7a2015-01-05 19:59:59 +000093 operator == (const Profile & other) const {
94 return major == other.major &&
95 minor == other.minor &&
96 api == other.api &&
Jose Fonseca56c419c2015-03-13 16:07:33 +000097 core == other.core &&
98 forwardCompatible == other.forwardCompatible;
José Fonsecaa44df7a2015-01-05 19:59:59 +000099 }
100
101 // Comparison operator, mainly for use in std::map
102 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +0000103 operator < (const Profile & other) const {
José Fonsecaa44df7a2015-01-05 19:59:59 +0000104 return major < other.major ||
José Fonseca0396fa02015-01-05 16:20:08 +0000105 minor < other.minor ||
José Fonsecaa44df7a2015-01-05 19:59:59 +0000106 api < other.api ||
Jose Fonseca56c419c2015-03-13 16:07:33 +0000107 core < other.core ||
108 forwardCompatible < other.forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +0000109 }
110};
111
112
113std::ostream &
114operator << (std::ostream &os, const Profile & profile);
115
116
José Fonsecaa44df7a2015-01-05 19:59:59 +0000117Profile
118getCurrentContextProfile(void);
119
120
José Fonseca440d8aa2015-01-23 15:32:23 +0000121struct Extensions
122{
123 std::set<std::string> strings;
124
125 void
126 getCurrentContextExtensions(const Profile & profile);
127
128 bool
129 has(const char *string) const;
130};
131
132
133
José Fonseca0396fa02015-01-05 16:20:08 +0000134} /* namespace glprofile */
135
136
137#endif // GLPROFILE_HPP