blob: bd23c3a528c96fbbd21ba15513b63d151dd78a0e [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
Jose Fonseca9ed64622016-04-04 13:36:12 +010040namespace glfeatures {
José Fonseca0396fa02015-01-05 16:20:08 +000041
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
Jose Fonseca0a676c52016-04-04 23:24:32 +010072 desktop(void) const {
José Fonseca34ea6162015-01-08 23:45:43 +000073 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 Fonseca53ea8102015-06-25 14:28:09 +010087 inline bool
88 versionGreaterOrEqual(Api refApi, unsigned refMajor, unsigned refMinor) const {
89 return api == refApi && versionGreaterOrEqual(refMajor, refMinor);
90 }
91
Jose Fonseca0e1d41b2015-03-13 17:17:47 +000092 bool
93 matches(const Profile expected) const;
José Fonsecac49a6952015-01-05 20:22:44 +000094
José Fonseca0396fa02015-01-05 16:20:08 +000095 // Comparison operator, mainly for use in std::map
96 inline bool
José Fonsecaa44df7a2015-01-05 19:59:59 +000097 operator == (const Profile & other) const {
98 return major == other.major &&
99 minor == other.minor &&
100 api == other.api &&
Jose Fonseca56c419c2015-03-13 16:07:33 +0000101 core == other.core &&
102 forwardCompatible == other.forwardCompatible;
José Fonsecaa44df7a2015-01-05 19:59:59 +0000103 }
104
105 // Comparison operator, mainly for use in std::map
106 inline bool
José Fonseca0396fa02015-01-05 16:20:08 +0000107 operator < (const Profile & other) const {
José Fonsecaa44df7a2015-01-05 19:59:59 +0000108 return major < other.major ||
José Fonseca0396fa02015-01-05 16:20:08 +0000109 minor < other.minor ||
José Fonsecaa44df7a2015-01-05 19:59:59 +0000110 api < other.api ||
Jose Fonseca56c419c2015-03-13 16:07:33 +0000111 core < other.core ||
112 forwardCompatible < other.forwardCompatible;
José Fonseca0396fa02015-01-05 16:20:08 +0000113 }
Jose Fonseca4a697ec2015-05-28 15:55:33 +0100114
115 std::string
116 str(void) const;
José Fonseca0396fa02015-01-05 16:20:08 +0000117};
118
119
120std::ostream &
121operator << (std::ostream &os, const Profile & profile);
122
123
José Fonsecaa44df7a2015-01-05 19:59:59 +0000124Profile
125getCurrentContextProfile(void);
126
127
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100128class Extensions
José Fonseca440d8aa2015-01-23 15:32:23 +0000129{
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100130private:
José Fonseca440d8aa2015-01-23 15:32:23 +0000131 std::set<std::string> strings;
132
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100133public:
José Fonseca440d8aa2015-01-23 15:32:23 +0000134 void
135 getCurrentContextExtensions(const Profile & profile);
136
137 bool
138 has(const char *string) const;
139};
140
141
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100142struct 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 Fonseca901fe892017-08-04 14:37:47 +0100157 unsigned ARB_color_buffer_float:1;
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100158
Jose Fonseca4cff7bd2016-04-10 23:06:15 +0100159 unsigned texture_3d:1;
Jose Fonseca1f9e61d2016-04-04 16:18:11 +0100160 unsigned pixel_buffer_object:1;
Jose Fonsecacc710e82016-04-10 22:54:37 +0100161 unsigned read_buffer:1;
Jose Fonseca9c6d2c82016-04-10 19:47:51 +0100162 unsigned framebuffer_object:1;
163 unsigned read_framebuffer_object:1;
Jose Fonseca0a676c52016-04-04 23:24:32 +0100164 unsigned query_buffer_object:1;
Jose Fonseca898d6e62016-05-08 22:48:43 +0100165 unsigned primitive_restart:1;
Jose Fonseca487e9c52019-06-17 10:36:16 +0100166 unsigned unpack_subimage:1;
Jose Fonseca1f9e61d2016-04-04 16:18:11 +0100167
Jose Fonseca8d6653a2016-04-04 15:42:25 +0100168 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é Fonseca440d8aa2015-01-23 15:32:23 +0000178
Jose Fonseca9ed64622016-04-04 13:36:12 +0100179} /* namespace glfeatures */