blob: be2a111f82a37b396aaeaf1484167c91e75efe4d [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
Jose Fonseca9653f952015-05-19 16:32:43 +010032#pragma once
José Fonseca0396fa02015-01-05 16:20:08 +000033
34
José Fonseca440d8aa2015-01-23 15:32:23 +000035#include <ostream>
36#include <set>
unknownfe5ef8b2015-02-05 11:46:10 +010037#include <string>
José Fonseca440d8aa2015-01-23 15:32:23 +000038
39
José Fonseca0396fa02015-01-05 16:20:08 +000040namespace glprofile {
41
42
43enum Api {
44 API_GL = 0,
45 API_GLES
46};
47
48
49struct Profile {
50 unsigned major:8;
51 unsigned minor:8;
52 unsigned api:1;
53 unsigned core:1;
Jose Fonseca56c419c2015-03-13 16:07:33 +000054 unsigned forwardCompatible:1;
José Fonseca0396fa02015-01-05 16:20:08 +000055
56 inline
Jose Fonseca56c419c2015-03-13 16:07:33 +000057 Profile(
58 Api _api = API_GL,
59 unsigned _major = 1,
60 unsigned _minor = 0,
61 bool _core = false,
62 bool _forwardCompatible = false
63 ) {
José Fonseca0396fa02015-01-05 16:20:08 +000064 api = _api;
65 major = _major;
66 minor = _minor;
67 core = _core;
Jose Fonseca56c419c2015-03-13 16:07:33 +000068 forwardCompatible = _forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +000069 }
70
71 inline bool
José Fonseca34ea6162015-01-08 23:45:43 +000072 desktop(void) {
73 return api == API_GL;
José Fonsecab0c59722015-01-05 20:45:41 +000074 }
75
76 inline bool
77 es(void) const {
78 return api == API_GLES;
79 }
80
81 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +000082 versionGreaterOrEqual(unsigned refMajor, unsigned refMinor) const {
83 return major > refMajor ||
84 (major == refMajor && minor >= refMinor);
85 }
86
Jose Fonseca0e1d41b2015-03-13 17:17:47 +000087 bool
88 matches(const Profile expected) const;
José Fonsecac49a6952015-01-05 20:22:44 +000089
José Fonseca0396fa02015-01-05 16:20:08 +000090 // Comparison operator, mainly for use in std::map
91 inline bool
José Fonsecaa44df7a2015-01-05 19:59:59 +000092 operator == (const Profile & other) const {
93 return major == other.major &&
94 minor == other.minor &&
95 api == other.api &&
Jose Fonseca56c419c2015-03-13 16:07:33 +000096 core == other.core &&
97 forwardCompatible == other.forwardCompatible;
José Fonsecaa44df7a2015-01-05 19:59:59 +000098 }
99
100 // Comparison operator, mainly for use in std::map
101 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +0000102 operator < (const Profile & other) const {
José Fonsecaa44df7a2015-01-05 19:59:59 +0000103 return major < other.major ||
José Fonseca0396fa02015-01-05 16:20:08 +0000104 minor < other.minor ||
José Fonsecaa44df7a2015-01-05 19:59:59 +0000105 api < other.api ||
Jose Fonseca56c419c2015-03-13 16:07:33 +0000106 core < other.core ||
107 forwardCompatible < other.forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +0000108 }
Jose Fonseca4a697ec2015-05-28 15:55:33 +0100109
110 std::string
111 str(void) const;
José Fonseca0396fa02015-01-05 16:20:08 +0000112};
113
114
115std::ostream &
116operator << (std::ostream &os, const Profile & profile);
117
118
José Fonsecaa44df7a2015-01-05 19:59:59 +0000119Profile
120getCurrentContextProfile(void);
121
122
José Fonseca440d8aa2015-01-23 15:32:23 +0000123struct Extensions
124{
125 std::set<std::string> strings;
126
127 void
128 getCurrentContextExtensions(const Profile & profile);
129
130 bool
131 has(const char *string) const;
132};
133
134
135
José Fonseca0396fa02015-01-05 16:20:08 +0000136} /* namespace glprofile */
137
138