From d14cf3838f182891031c551ce2906cb572ece209 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 16 May 2019 02:19:48 +0100 Subject: [PATCH] gl_common: don't use GL4 feature glGetIntegerv(GL_NUM_EXTENSIONS) is only available since GL4. (However glGetStringi(GL_EXTENSIONS) is available since GL3) Signed-off-by: Yuxuan Shui --- src/backend/gl/gl_common.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/gl/gl_common.h b/src/backend/gl/gl_common.h index 06221bb1..bd483075 100644 --- a/src/backend/gl/gl_common.h +++ b/src/backend/gl/gl_common.h @@ -175,24 +175,26 @@ static inline void gl_check_err_(const char *func, int line) { } } +static inline void gl_clear_err(void) { + while (glGetError() != GL_NO_ERROR); +} + #define gl_check_err() gl_check_err_(__func__, __LINE__) /** * Check if a GLX extension exists. */ static inline bool gl_has_extension(const char *ext) { - GLint nexts = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &nexts); - if (!nexts) { - log_error("Failed to get GL extension list."); - return false; - } - - for (int i = 0; i < nexts; i++) { + for (int i = 0; ; i++) { const char *exti = (const char *)glGetStringi(GL_EXTENSIONS, (GLuint)i); - if (strcmp(ext, exti) == 0) + if (exti == 0) { + break; + } + if (strcmp(ext, exti) == 0) { return true; + } } + gl_clear_err(); log_info("Missing GL extension %s.", ext); return false; }