1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (gl_capabilities.c).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include <glsym/glsym.h>
32 #include <gfx/gl_capabilities.h>
34 static bool gl_core_context = false;
36 bool gl_query_core_context_in_use(void)
38 return gl_core_context;
41 void gl_query_core_context_set(bool set)
43 gl_core_context = set;
46 void gl_query_core_context_unset(void)
48 gl_core_context = false;
51 bool gl_query_extension(const char *ext)
55 if (gl_query_core_context_in_use())
57 #ifdef GL_NUM_EXTENSIONS
60 glGetIntegerv(GL_NUM_EXTENSIONS, &exts);
61 for (i = 0; i < exts; i++)
63 const char *str = (const char*)glGetStringi(GL_EXTENSIONS, i);
64 if (str && strstr(str, ext))
74 const char *str = (const char*)glGetString(GL_EXTENSIONS);
75 ret = str && strstr(str, ext);
81 bool gl_check_error(char **error_string)
83 int error = glGetError();
87 *error_string = strdup("GL: Invalid enum.");
89 case GL_INVALID_VALUE:
90 *error_string = strdup("GL: Invalid value.");
92 case GL_INVALID_OPERATION:
93 *error_string = strdup("GL: Invalid operation.");
95 case GL_OUT_OF_MEMORY:
96 *error_string = strdup("GL: Out of memory.");
101 *error_string = strdup("Non specified GL error.");
108 bool gl_check_capability(enum gl_capability_enum enum_idx)
112 const char *vendor = (const char*)glGetString(GL_VENDOR);
113 const char *renderer = (const char*)glGetString(GL_RENDERER);
114 const char *version = (const char*)glGetString(GL_VERSION);
116 if (version && sscanf(version, "OpenGL ES %u.%u", &major, &minor) != 2)
118 if (version && sscanf(version, "%u.%u", &major, &minor) != 2)
127 case GL_CAPS_GLES3_SUPPORTED:
128 #if defined(HAVE_OPENGLES)
133 case GL_CAPS_EGLIMAGE:
134 #if defined(HAVE_EGL) && defined(HAVE_OPENGLES)
135 if (glEGLImageTargetTexture2DOES != NULL)
144 if (gl_query_extension("ARB_sync") &&
145 glFenceSync && glDeleteSync && glClientWaitSync)
151 static bool extension_queried = false;
152 static bool extension = false;
154 if (!extension_queried)
156 extension = gl_query_extension("ARB_framebuffer_object");
157 extension_queried = true;
165 #ifndef HAVE_OPENGLES
166 if (!gl_query_core_context_in_use() && !gl_query_extension("ARB_vertex_array_object"))
169 if (glGenVertexArrays && glBindVertexArray && glDeleteVertexArrays)
174 #if defined(HAVE_PSGL) || defined(HAVE_OPENGLES2) || defined(HAVE_OPENGLES3) || defined(HAVE_OPENGLES_3_1) || defined(HAVE_OPENGLES_3_2)
177 if ( !gl_query_core_context_in_use()
178 && !gl_query_extension("ARB_framebuffer_object")
179 && !gl_query_extension("EXT_framebuffer_object"))
182 if (gl_query_extension("ARB_framebuffer_object"))
185 if (gl_query_extension("EXT_framebuffer_object"))
194 if (gl_query_extension("OES_rgb8_rgba8")
195 || gl_query_extension("ARM_rgba8")
199 /* TODO/FIXME - implement this for non-GLES? */
203 if (gl_query_extension("KHR_debug"))
205 #ifndef HAVE_OPENGLES
206 if (gl_query_extension("ARB_debug_output"))
210 case GL_CAPS_PACKED_DEPTH_STENCIL:
213 if (gl_query_extension("OES_packed_depth_stencil"))
215 if (gl_query_extension("EXT_packed_depth_stencil"))
218 case GL_CAPS_ES2_COMPAT:
219 #ifndef HAVE_OPENGLES
220 /* ATI card detected, skipping check for GL_RGB565 support... */
221 if (vendor && renderer && (strstr(vendor, "ATI") || strstr(renderer, "ATI")))
224 if (gl_query_extension("ARB_ES2_compatibility"))
228 case GL_CAPS_UNPACK_ROW_LENGTH:
233 /* Extension GL_EXT_unpack_subimage, can copy textures faster
234 * than using UNPACK_ROW_LENGTH */
235 if (gl_query_extension("GL_EXT_unpack_subimage"))
239 case GL_CAPS_FULL_NPOT_SUPPORT:
243 if (gl_query_extension("ARB_texture_non_power_of_two") ||
244 gl_query_extension("OES_texture_npot"))
248 GLint max_texture_size = 0;
249 GLint max_native_instr = 0;
250 /* try to detect actual npot support. might fail for older cards. */
251 bool arb_npot = gl_query_extension("ARB_texture_non_power_of_two");
252 bool arb_frag_program = gl_query_extension("ARB_fragment_program");
254 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
256 #ifdef GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
257 if (arb_frag_program && glGetProgramivARB)
258 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB,
259 GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &max_native_instr);
262 if (arb_npot && arb_frag_program &&
263 (max_texture_size >= 8192) && (max_native_instr >= 4096))
268 case GL_CAPS_SRGB_FBO_ES3:
275 case GL_CAPS_SRGB_FBO:
276 #if defined(HAVE_OPENGLES)
277 if (major >= 3 || gl_query_extension("EXT_sRGB"))
280 if (gl_check_capability(GL_CAPS_FBO))
282 if ( gl_query_core_context_in_use() ||
283 (gl_query_extension("EXT_texture_sRGB")
284 && gl_query_extension("ARB_framebuffer_sRGB"))
290 /* GLES - No extensions for float FBO currently. */
291 #ifndef HAVE_OPENGLES
292 if (gl_check_capability(GL_CAPS_FBO))
294 /* Float FBO is core in 3.2. */
295 if (gl_query_core_context_in_use() || gl_query_extension("ARB_texture_float"))
300 case GL_CAPS_BGRA8888:
302 /* There are both APPLE and EXT variants. */
303 if (gl_query_extension("BGRA8888"))
309 case GL_CAPS_TEX_STORAGE:
314 if (vendor && strstr(vendor, "ATI Technologies"))
316 if (gl_query_extension("ARB_texture_storage"))
320 case GL_CAPS_TEX_STORAGE_EXT:
321 #ifdef TARGET_OS_IPHONE
322 /* Not working on iOS */
325 if (gl_query_extension("EXT_texture_storage"))