From 916bdda6724efb292e349887c788b76636558214 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 10 Feb 2025 17:28:17 +0800 Subject: [PATCH] fix(texture): detect GL_TEXTURE_LOD_BIAS_QCOM before using it, preventing Xaero from crashing --- src/main/cpp/gl/texture.cpp | 12 ++++++++++++ src/main/cpp/gles/loader.c | 19 +++++++++++++------ src/main/cpp/gles/loader.h | 8 ++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/cpp/gl/texture.cpp b/src/main/cpp/gl/texture.cpp index cd98af7..35732ad 100644 --- a/src/main/cpp/gl/texture.cpp +++ b/src/main/cpp/gl/texture.cpp @@ -244,6 +244,12 @@ void glTexParameterf(GLenum target, GLenum pname, GLfloat param) { LOG(); pname = pname_convert(pname); LOG_D("glTexParameterf, target: %d, pname: %d, param: %f",target, pname, param); + + if (pname == GL_TEXTURE_LOD_BIAS_QCOM && !g_gles_caps.GL_QCOM_texture_lod_bias) { + LOG_D("Does not support GL_QCOM_texture_lod_bias, skipped!") + return; + } + LOAD_GLES(glTexParameterf, void, GLenum target, GLenum pname, GLfloat param); gles_glTexParameterf(target,pname, param); CHECK_GL_ERROR @@ -785,6 +791,12 @@ void glTexParameteri(GLenum target, GLenum pname, GLint param) { LOG() pname = pname_convert(pname); LOG_D("glTexParameterfv, pname: %d", pname) + + if (pname == GL_TEXTURE_LOD_BIAS_QCOM && !g_gles_caps.GL_QCOM_texture_lod_bias) { + LOG_D("Does not support GL_QCOM_texture_lod_bias, skipped!") + return; + } + LOAD_GLES_FUNC(glTexParameteri) gles_glTexParameteri(target,pname,param); CHECK_GL_ERROR diff --git a/src/main/cpp/gles/loader.c b/src/main/cpp/gles/loader.c index 1156091..1e88c5e 100644 --- a/src/main/cpp/gles/loader.c +++ b/src/main/cpp/gles/loader.c @@ -131,11 +131,16 @@ void LogOpenGLExtensions() { } } +struct gles_caps_t g_gles_caps; + void InitGLESCapabilities() { + memset(&g_gles_caps, 0, sizeof(struct gles_caps_t)); + InitGLESBaseExtensions(); - int has_GL_EXT_buffer_storage = 0; - int has_GL_ARB_timer_query = 0; +// int has_GL_EXT_buffer_storage = 0; +// int has_GL_ARB_timer_query = 0; +// int has_GL_QCOM_texture_lod_bias = 0; LOAD_GLES_FUNC(glGetStringi) LOAD_GLES_FUNC(glGetIntegerv) @@ -147,20 +152,22 @@ void InitGLESCapabilities() { if (extension) { LOG_D("%s", (const char*)extension); if (strcmp(extension, "GL_EXT_buffer_storage") == 0) { - has_GL_EXT_buffer_storage = 1; + g_gles_caps.GL_EXT_buffer_storage = 1; } else if (strcmp(extension, "GL_EXT_disjoint_timer_query") == 0) { - has_GL_ARB_timer_query = 1; + g_gles_caps.GL_EXT_disjoint_timer_query = 1; + } else if (strcmp(extension, "GL_QCOM_texture_lod_bias") == 0) { + g_gles_caps.GL_QCOM_texture_lod_bias = 1; } } else { LOG_D("(null)"); } } - if (has_GL_EXT_buffer_storage) { + if (g_gles_caps.GL_EXT_buffer_storage) { AppendExtension("GL_ARB_buffer_storage"); } - if (has_GL_ARB_timer_query) { + if (g_gles_caps.GL_EXT_disjoint_timer_query) { AppendExtension("GL_ARB_timer_query"); AppendExtension("GL_EXT_timer_query"); } diff --git a/src/main/cpp/gles/loader.h b/src/main/cpp/gles/loader.h index b206a7d..b28c136 100644 --- a/src/main/cpp/gles/loader.h +++ b/src/main/cpp/gles/loader.h @@ -178,4 +178,12 @@ GLAPI GLAPIENTRY type name(__VA_ARGS__) { LOG_W("No function: %s @ %s(...)", RENDERERNAME, __FUNCTION__); \ } +struct gles_caps_t { + int GL_EXT_buffer_storage; + int GL_EXT_disjoint_timer_query; + int GL_QCOM_texture_lod_bias; +}; + +extern struct gles_caps_t g_gles_caps; + #endif // MOBILEGLUES_GLES_LOADER_H_