José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 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 Fonseca | 9653f95 | 2015-05-19 16:32:43 +0100 | [diff] [blame^] | 32 | #pragma once |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 33 | |
| 34 | |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 35 | #include <ostream> |
| 36 | #include <set> |
unknown | fe5ef8b | 2015-02-05 11:46:10 +0100 | [diff] [blame] | 37 | #include <string> |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 38 | |
| 39 | |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 40 | namespace glprofile { |
| 41 | |
| 42 | |
| 43 | enum Api { |
| 44 | API_GL = 0, |
| 45 | API_GLES |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | struct Profile { |
| 50 | unsigned major:8; |
| 51 | unsigned minor:8; |
| 52 | unsigned api:1; |
| 53 | unsigned core:1; |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 54 | unsigned forwardCompatible:1; |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 55 | |
| 56 | inline |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 57 | Profile( |
| 58 | Api _api = API_GL, |
| 59 | unsigned _major = 1, |
| 60 | unsigned _minor = 0, |
| 61 | bool _core = false, |
| 62 | bool _forwardCompatible = false |
| 63 | ) { |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 64 | api = _api; |
| 65 | major = _major; |
| 66 | minor = _minor; |
| 67 | core = _core; |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 68 | forwardCompatible = _forwardCompatible; |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | inline bool |
José Fonseca | 34ea616 | 2015-01-08 23:45:43 +0000 | [diff] [blame] | 72 | desktop(void) { |
| 73 | return api == API_GL; |
José Fonseca | b0c5972 | 2015-01-05 20:45:41 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | inline bool |
| 77 | es(void) const { |
| 78 | return api == API_GLES; |
| 79 | } |
| 80 | |
| 81 | inline bool |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 82 | versionGreaterOrEqual(unsigned refMajor, unsigned refMinor) const { |
| 83 | return major > refMajor || |
| 84 | (major == refMajor && minor >= refMinor); |
| 85 | } |
| 86 | |
Jose Fonseca | 0e1d41b | 2015-03-13 17:17:47 +0000 | [diff] [blame] | 87 | bool |
| 88 | matches(const Profile expected) const; |
José Fonseca | c49a695 | 2015-01-05 20:22:44 +0000 | [diff] [blame] | 89 | |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 90 | // Comparison operator, mainly for use in std::map |
| 91 | inline bool |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 92 | operator == (const Profile & other) const { |
| 93 | return major == other.major && |
| 94 | minor == other.minor && |
| 95 | api == other.api && |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 96 | core == other.core && |
| 97 | forwardCompatible == other.forwardCompatible; |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Comparison operator, mainly for use in std::map |
| 101 | inline bool |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 102 | operator < (const Profile & other) const { |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 103 | return major < other.major || |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 104 | minor < other.minor || |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 105 | api < other.api || |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 106 | core < other.core || |
| 107 | forwardCompatible < other.forwardCompatible; |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 108 | } |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | std::ostream & |
| 113 | operator << (std::ostream &os, const Profile & profile); |
| 114 | |
| 115 | |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 116 | Profile |
| 117 | getCurrentContextProfile(void); |
| 118 | |
| 119 | |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 120 | struct Extensions |
| 121 | { |
| 122 | std::set<std::string> strings; |
| 123 | |
| 124 | void |
| 125 | getCurrentContextExtensions(const Profile & profile); |
| 126 | |
| 127 | bool |
| 128 | has(const char *string) const; |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 133 | } /* namespace glprofile */ |
| 134 | |
| 135 | |