blob: f6ecf578ade4f4f93070de9dea0e382ed085f617 [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
José Fonsecac49a6952015-01-05 20:22:44 +000088 inline bool
89 matches(const Profile expected) const {
José Fonsecaf28a5be2015-01-06 21:07:17 +000090 /*
91 * GLX_ARB_create_context/WGL_ARB_create_context specs state that
92 *
93 * "If version 3.1 is requested, the context returned may implement
94 * any of the following versions:
95 *
96 * * Version 3.1. The GL_ARB_compatibility extension may or may not
97 * be implemented, as determined by the implementation.
98 *
99 * * The core profile of version 3.2 or greater."
100 */
José Fonsecac49a6952015-01-05 20:22:44 +0000101 return api == expected.api &&
102 versionGreaterOrEqual(expected.major, expected.minor) &&
José Fonsecaf28a5be2015-01-06 21:07:17 +0000103 (core == expected.core ||
Jose Fonseca56c419c2015-03-13 16:07:33 +0000104 (expected.major == 3 && expected.minor == 1)) &&
105 forwardCompatible <= expected.forwardCompatible;
José Fonsecac49a6952015-01-05 20:22:44 +0000106 }
107
José Fonseca0396fa02015-01-05 16:20:08 +0000108 // Comparison operator, mainly for use in std::map
109 inline bool
José Fonsecaa44df7a2015-01-05 19:59:59 +0000110 operator == (const Profile & other) const {
111 return major == other.major &&
112 minor == other.minor &&
113 api == other.api &&
Jose Fonseca56c419c2015-03-13 16:07:33 +0000114 core == other.core &&
115 forwardCompatible == other.forwardCompatible;
José Fonsecaa44df7a2015-01-05 19:59:59 +0000116 }
117
118 // Comparison operator, mainly for use in std::map
119 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +0000120 operator < (const Profile & other) const {
José Fonsecaa44df7a2015-01-05 19:59:59 +0000121 return major < other.major ||
José Fonseca0396fa02015-01-05 16:20:08 +0000122 minor < other.minor ||
José Fonsecaa44df7a2015-01-05 19:59:59 +0000123 api < other.api ||
Jose Fonseca56c419c2015-03-13 16:07:33 +0000124 core < other.core ||
125 forwardCompatible < other.forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +0000126 }
127};
128
129
130std::ostream &
131operator << (std::ostream &os, const Profile & profile);
132
133
José Fonsecaa44df7a2015-01-05 19:59:59 +0000134Profile
135getCurrentContextProfile(void);
136
137
José Fonseca440d8aa2015-01-23 15:32:23 +0000138struct Extensions
139{
140 std::set<std::string> strings;
141
142 void
143 getCurrentContextExtensions(const Profile & profile);
144
145 bool
146 has(const char *string) const;
147};
148
149
150
José Fonseca0396fa02015-01-05 16:20:08 +0000151} /* namespace glprofile */
152
153
154#endif // GLPROFILE_HPP