Gamp v0.0.7-36-g24b1eb6
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
GLLiterals.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11
12#ifndef GAMP_RENDER_GL_GLLITERALS_HPP_
13#define GAMP_RENDER_GL_GLLITERALS_HPP_
14
17
18#include <jau/cpp_lang_util.hpp>
19#include <jau/enum_util.hpp>
20
21namespace gamp::render::gl {
22 using namespace jau::enums;
23
24 /** \addtogroup Gamp_GL
25 *
26 * @{
27 */
28
29 inline static constexpr GLenum GL_NVIDIA_PLATFORM_BINARY_NV = 0x890B;
30
31 /** Version 0.00, i.e. invalid or undefined version. */
33 /** Version 1.00, i.e. GLSL 1.00 for ES 2.0. */
35 /** Version 1.10, i.e. GLSL 1.10 for GL 2.0. */
37 /** Version 1.20, i.e. GLSL 1.20 for GL 2.1. */
39 /** Version 1.30, i.e. GLSL 1.30 for GL 3.0. */
41 /** Version 1.40, i.e. GLSL 1.40 for GL 3.1. */
43 /** Version 1.50, i.e. GLSL 1.50 for GL 3.2. */
45
46 /** Version 1.1, i.e. GL 1.1 */
48
49 /** Version 1.2, i.e. GL 1.2 */
51
52 /** Version 1.4, i.e. GL 1.4 */
54
55 /** Version 1.5, i.e. GL 1.5 */
57
58 /** Version 2.0. As an OpenGL version, it qualifies for desktop {@link #isGL2()} only, or ES 2.0.*/
60
61 /** Version 3.0. As an OpenGL version, it qualifies for desktop {@link #isGL2()} only, or ES 3.0. Or GLSL 3.00 for ES 3.0. */
63
64 /** Version 3.1. As an OpenGL version, it qualifies for {@link #isGL3core()}, {@link #isGL3bc()} and {@link #isGL3()} */
66
67 /** Version 3.2. As an OpenGL version, it qualifies for geometry shader */
69
70 /** Version 4.0. As an OpenGL version. */
72
73 /** Version 4.3. As an OpenGL version, it qualifies for <code>GL_ARB_ES3_compatibility</code> */
75
76 /** OpenGL profile-mask bits. */
77 enum class GLProfileMask : uint32_t {
78 none = 0,
79 /** Desktop compatibility profile. */
80 compat = 1U << 0,
81 /** Desktop core profile. */
82 core = 1U << 1,
83 /** ES profile */
84 es = 1U << 2
85 };
87
88 constexpr std::string_view getGLTypeName(GLenum type) noexcept {
89 switch( type ) {
90 case GL_UNSIGNED_BYTE:
91 return "GL_UNSIGNED_BYTE";
92 case GL_BYTE:
93 return "GL_BYTE";
94 case GL_UNSIGNED_SHORT:
95 return "GL_UNSIGNED_SHORT";
96 case GL_SHORT:
97 return "GL_SHORT";
98 case GL_FLOAT:
99 return "GL_FLOAT";
100 case GL_FIXED:
101 return "GL_FIXED";
102 case GL_INT: // GL2ES2
103 return "GL_INT";
104 case GL_UNSIGNED_INT:
105 return "GL_UNSIGNED_INT";
106 case GL_DOUBLE: // GL2GL3
107 return "GL_DOUBLE";
108 case GL_2_BYTES: // GL2
109 return "GL_2_BYTES";
110 case GL_3_BYTES: // GL2
111 return "GL_3_BYTES";
112 case GL_4_BYTES: // GL2
113 return "GL_4_BYTES";
114 default: return "";
115 }
116 }
117
118 constexpr std::string_view getGLArrayName(GLenum array) noexcept {
119 switch( array ) {
120 case GL_VERTEX_ARRAY:
121 return "GL_VERTEX_ARRAY";
122 case GL_NORMAL_ARRAY:
123 return "GL_NORMAL_ARRAY";
124 case GL_COLOR_ARRAY:
125 return "GL_COLOR_ARRAY";
126 case GL_TEXTURE_COORD_ARRAY:
127 return "GL_TEXTURE_COORD_ARRAY";
128 default: return "";
129 }
130 }
131
132 constexpr bool isValidShaderType(GLenum type) noexcept {
133 switch( type ) {
134 case GL_VERTEX_SHADER: // GL2ES2
135 case GL_FRAGMENT_SHADER: // GL2ES2
136 case GL_GEOMETRY_SHADER: // GL3ES3
137 case GL_TESS_CONTROL_SHADER: // GL3ES3
138 case GL_TESS_EVALUATION_SHADER: // GL3ES3
139 case GL_COMPUTE_SHADER: // GL3ES3
140 return true;
141 default:
142 return false;
143 }
144 }
145
146 constexpr std::string_view shaderTypeString(GLenum type) noexcept {
147 switch( type ) {
148 case GL_VERTEX_SHADER: // GL2ES2
149 return "VERTEX_SHADER";
150 case GL_FRAGMENT_SHADER: // GL2ES2
151 return "FRAGMENT_SHADER";
152 case GL_GEOMETRY_SHADER: // GL3ES3
153 return "GEOMETRY_SHADER";
154 case GL_TESS_CONTROL_SHADER: // GL3ES3
155 return "TESS_CONTROL_SHADER";
156 case GL_TESS_EVALUATION_SHADER: // GL3ES3
157 return "TESS_EVALUATION_SHADER";
158 case GL_COMPUTE_SHADER: // GL3ES3
159 return "COMPUTE_SHADER";
160 default: return "UNKNOWN_SHADER";
161 }
162 }
163
165 if( has_any(mask, GLProfileMask::es) ) {
166 if( 3 == glVersion.major() ) {
167 return Version3_0; // ES 3.0 -> GLSL 3.00
168 } else if( 2 == glVersion.major() ) {
169 return Version1_0; // ES 2.0 -> GLSL 1.00
170 }
171 } else if( 1 == glVersion.major() ) {
172 return Version1_10; // GL 1.x -> GLSL 1.10
173 } else if( 2 == glVersion.major() ) {
174 switch( glVersion.minor() ) {
175 case 0: return Version1_10; // GL 2.0 -> GLSL 1.10
176 default: return Version1_20; // GL 2.1 -> GLSL 1.20
177 }
178 } else if( 3 == glVersion.major() && 2 >= glVersion.minor() ) {
179 switch( glVersion.minor() ) {
180 case 0: return Version1_30; // GL 3.0 -> GLSL 1.30
181 case 1: return Version1_40; // GL 3.1 -> GLSL 1.40
182 default: return Version1_50; // GL 3.2 -> GLSL 1.50
183 }
184 }
185 // The new default: GL >= 3.3, ES >= 3.0
186 return jau::util::VersionNumber(glVersion.major(), glVersion.minor() * 10, 0); // GL M.N -> GLSL M.N
187 }
188
189 inline static constexpr std::string_view mgl_Vertex = "mgl_Vertex";
190 inline static constexpr std::string_view mgl_Normal = "mgl_Normal";
191 inline static constexpr std::string_view mgl_Color = "mgl_Color";
192 inline static constexpr std::string_view mgl_MultiTexCoord = "mgl_MultiTexCoord";
193 inline static constexpr std::string_view mgl_InterleaveArray = "mgl_InterleaveArray"; // magic name for interleaved arrays w/ sub-arrays
194
195 /**
196 * @param glArrayIndex the fixed function array index
197 * @param multiTexCoordIndex index for multiTexCoordIndex
198 * @return default fixed function array name
199 */
200 inline std::string getPredefinedArrayIndexName(GLenum glArrayIndex, GLint multiTexCoordIndex) {
201 switch( glArrayIndex ) {
202 case GL_VERTEX_ARRAY:
203 return std::string(mgl_Vertex);
204 case GL_NORMAL_ARRAY:
205 return std::string(mgl_Normal);
206 case GL_COLOR_ARRAY:
207 return std::string(mgl_Color);
208 case GL_TEXTURE_COORD_ARRAY:
209 if( 0 <= multiTexCoordIndex ) {
210 return std::string(mgl_MultiTexCoord).append(std::to_string(multiTexCoordIndex));
211 } else {
212 return std::string(mgl_MultiTexCoord).append(std::to_string(multiTexCoordIndex));
213 }
214 default: return "";
215 }
216 }
217 /**
218 * @param glArrayIndex the fixed function array index
219 * @return default fixed function array name
220 */
221 inline std::string getPredefinedArrayIndexName(GLenum glArrayIndex) {
222 return getPredefinedArrayIndexName(glArrayIndex, -1);
223 }
224
225 /**@}*/
226
227} // namespace gamp::render::gl
228
229#endif /* GAMP_RENDER_GL_GLLITERALS_HPP_ */
Simple version number class containing a version number either being defined explicit or derived from...
constexpr int major() const noexcept
constexpr int minor() const noexcept
constexpr bool has_any(const E mask, const E bits) noexcept
#define JAU_MAKE_BITFIELD_ENUM_STRING(type,...)
GLProfileMask
OpenGL profile-mask bits.
static constexpr jau::util::VersionNumber Version4_3
Version 4.3.
static constexpr jau::util::VersionNumber Version1_4
Version 1.4, i.e.
static constexpr jau::util::VersionNumber Version4_0
Version 4.0.
std::string getPredefinedArrayIndexName(GLenum glArrayIndex, GLint multiTexCoordIndex)
static constexpr jau::util::VersionNumber Version1_10
Version 1.10, i.e.
static constexpr std::string_view mgl_Color
static constexpr jau::util::VersionNumber Version1_30
Version 1.30, i.e.
static constexpr std::string_view mgl_Vertex
static constexpr jau::util::VersionNumber Version1_1
Version 1.1, i.e.
static constexpr GLenum GL_NVIDIA_PLATFORM_BINARY_NV
static constexpr jau::util::VersionNumber Version2_0
Version 2.0.
static constexpr jau::util::VersionNumber Version1_0
Version 1.00, i.e.
constexpr std::string_view getGLTypeName(GLenum type) noexcept
static constexpr jau::util::VersionNumber Version1_50
Version 1.50, i.e.
static constexpr std::string_view mgl_MultiTexCoord
constexpr jau::util::VersionNumber getGLSLVersionNumber(const jau::util::VersionNumber &glVersion, GLProfileMask mask)
constexpr std::string_view shaderTypeString(GLenum type) noexcept
constexpr bool isValidShaderType(GLenum type) noexcept
static constexpr jau::util::VersionNumber Version3_1
Version 3.1.
static constexpr jau::util::VersionNumber Version1_40
Version 1.40, i.e.
static constexpr std::string_view mgl_Normal
static constexpr jau::util::VersionNumber Version1_5
Version 1.5, i.e.
static constexpr jau::util::VersionNumber Version1_20
Version 1.20, i.e.
constexpr std::string_view getGLArrayName(GLenum array) noexcept
static constexpr std::string_view mgl_InterleaveArray
static constexpr jau::util::VersionNumber Version0_0
Version 0.00, i.e.
static constexpr jau::util::VersionNumber Version3_0
Version 3.0.
static constexpr jau::util::VersionNumber Version3_2
Version 3.2.
static constexpr jau::util::VersionNumber Version1_2
Version 1.2, i.e.
@ compat
Desktop compatibility profile.
@ core
Desktop core profile.