From d8726f265e53ce6a1d5f11a1d261e2f8957f7c62 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 23 Feb 2018 16:46:55 +0000 Subject: [PATCH] Add epoxy_glsl_version() Epoxy should provide a function that returns the version of the GL shading language in use, in the same vein as it allows to get the version of GL. Closes: #145 --- include/epoxy/gl.h | 1 + src/dispatch_common.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/epoxy/gl.h b/include/epoxy/gl.h index ce4763f..1fef4ba 100644 --- a/include/epoxy/gl.h +++ b/include/epoxy/gl.h @@ -91,6 +91,7 @@ EPOXY_BEGIN_DECLS EPOXY_PUBLIC bool epoxy_has_gl_extension(const char *extension); EPOXY_PUBLIC bool epoxy_is_desktop_gl(void); EPOXY_PUBLIC int epoxy_gl_version(void); +EPOXY_PUBLIC int epoxy_glsl_version(void); /* * the type of the stub function that the failure handler must return; diff --git a/src/dispatch_common.c b/src/dispatch_common.c index a2c9154..c9bd27f 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -392,9 +392,9 @@ epoxy_is_desktop_gl(void) } static int -epoxy_internal_gl_version(int error_version) +epoxy_internal_gl_version(const char *version_string, int error_version) { - const char *version = (const char *)glGetString(GL_VERSION); + const char *version = (const char *)glGetString(version_string); GLint major, minor; int scanf_count; @@ -433,7 +433,7 @@ epoxy_internal_gl_version(int error_version) int epoxy_gl_version(void) { - return epoxy_internal_gl_version(0); + return epoxy_internal_gl_version(GL_VERSION, 0); } int @@ -442,7 +442,32 @@ epoxy_conservative_gl_version(void) if (api.begin_count) return 100; - return epoxy_internal_gl_version(100); + return epoxy_internal_gl_version(GL_VERSION, 100); +} + +/** + * @brief Returns the version of the GL Shading Language we are using + * + * The version is encoded as: + * + * ``` + * + * version = major * 10 + minor + * + * ``` + * + * So it can be easily used for version comparisons. + * + * @return The encoded version of the GL Shading Language we are using + */ +int +epoxy_glsl_version(void) +{ + if (epoxy_gl_version() >= 20 || + epoxy_has_gl_extension ("GL_ARB_shading_language_100")) + return epoxy_internal_gl_version(GL_SHADING_LANGUAGE_VERSION, 0); + + return 0; } /**