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 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 40 | namespace glfeatures { |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 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 |
Jose Fonseca | 0a676c5 | 2016-04-04 23:24:32 +0100 | [diff] [blame] | 72 | desktop(void) const { |
José Fonseca | 34ea616 | 2015-01-08 23:45:43 +0000 | [diff] [blame] | 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 | 53ea810 | 2015-06-25 14:28:09 +0100 | [diff] [blame] | 87 | inline bool |
| 88 | versionGreaterOrEqual(Api refApi, unsigned refMajor, unsigned refMinor) const { |
| 89 | return api == refApi && versionGreaterOrEqual(refMajor, refMinor); |
| 90 | } |
| 91 | |
Jose Fonseca | 0e1d41b | 2015-03-13 17:17:47 +0000 | [diff] [blame] | 92 | bool |
| 93 | matches(const Profile expected) const; |
José Fonseca | c49a695 | 2015-01-05 20:22:44 +0000 | [diff] [blame] | 94 | |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 95 | // Comparison operator, mainly for use in std::map |
| 96 | inline bool |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 97 | operator == (const Profile & other) const { |
| 98 | return major == other.major && |
| 99 | minor == other.minor && |
| 100 | api == other.api && |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 101 | core == other.core && |
| 102 | forwardCompatible == other.forwardCompatible; |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Comparison operator, mainly for use in std::map |
| 106 | inline bool |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 107 | operator < (const Profile & other) const { |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 108 | return major < other.major || |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 109 | minor < other.minor || |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 110 | api < other.api || |
Jose Fonseca | 56c419c | 2015-03-13 16:07:33 +0000 | [diff] [blame] | 111 | core < other.core || |
| 112 | forwardCompatible < other.forwardCompatible; |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 113 | } |
Jose Fonseca | 4a697ec | 2015-05-28 15:55:33 +0100 | [diff] [blame] | 114 | |
| 115 | std::string |
| 116 | str(void) const; |
José Fonseca | 0396fa0 | 2015-01-05 16:20:08 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | |
| 120 | std::ostream & |
| 121 | operator << (std::ostream &os, const Profile & profile); |
| 122 | |
| 123 | |
José Fonseca | a44df7a | 2015-01-05 19:59:59 +0000 | [diff] [blame] | 124 | Profile |
| 125 | getCurrentContextProfile(void); |
| 126 | |
| 127 | |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 128 | class Extensions |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 129 | { |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 130 | private: |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 131 | std::set<std::string> strings; |
| 132 | |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 133 | public: |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 134 | void |
| 135 | getCurrentContextExtensions(const Profile & profile); |
| 136 | |
| 137 | bool |
| 138 | has(const char *string) const; |
| 139 | }; |
| 140 | |
| 141 | |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 142 | struct Features |
| 143 | { |
| 144 | unsigned ES:1; |
| 145 | unsigned core:1; |
| 146 | |
| 147 | unsigned ARB_draw_buffers:1; |
| 148 | unsigned ARB_sampler_objects:1; |
| 149 | unsigned ARB_get_program_binary:1; |
| 150 | unsigned KHR_debug:1; |
| 151 | unsigned EXT_debug_label:1; |
| 152 | unsigned NV_read_depth_stencil:1; /* ES only */ |
| 153 | unsigned ARB_shader_image_load_store:1; |
| 154 | unsigned ARB_direct_state_access:1; |
| 155 | unsigned ARB_shader_storage_buffer_object:1; |
| 156 | unsigned ARB_program_interface_query:1; |
Jose Fonseca | 901fe89 | 2017-08-04 14:37:47 +0100 | [diff] [blame] | 157 | unsigned ARB_color_buffer_float:1; |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 158 | |
Jose Fonseca | 4cff7bd | 2016-04-10 23:06:15 +0100 | [diff] [blame] | 159 | unsigned texture_3d:1; |
Jose Fonseca | 1f9e61d | 2016-04-04 16:18:11 +0100 | [diff] [blame] | 160 | unsigned pixel_buffer_object:1; |
Jose Fonseca | cc710e8 | 2016-04-10 22:54:37 +0100 | [diff] [blame] | 161 | unsigned read_buffer:1; |
Jose Fonseca | 9c6d2c8 | 2016-04-10 19:47:51 +0100 | [diff] [blame] | 162 | unsigned framebuffer_object:1; |
| 163 | unsigned read_framebuffer_object:1; |
Jose Fonseca | 0a676c5 | 2016-04-04 23:24:32 +0100 | [diff] [blame] | 164 | unsigned query_buffer_object:1; |
Jose Fonseca | 898d6e6 | 2016-05-08 22:48:43 +0100 | [diff] [blame] | 165 | unsigned primitive_restart:1; |
Jose Fonseca | 487e9c5 | 2019-06-17 10:36:16 +0100 | [diff] [blame] | 166 | unsigned unpack_subimage:1; |
Jose Fonseca | 1f9e61d | 2016-04-04 16:18:11 +0100 | [diff] [blame] | 167 | |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 168 | Features(void); |
| 169 | |
| 170 | void |
| 171 | load(const Profile & profile, const Extensions & exts); |
| 172 | |
| 173 | // Load from current context |
| 174 | void |
| 175 | load(void); |
| 176 | }; |
| 177 | |
José Fonseca | 440d8aa | 2015-01-23 15:32:23 +0000 | [diff] [blame] | 178 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 179 | } /* namespace glfeatures */ |