fix(texture): detect GL_TEXTURE_LOD_BIAS_QCOM before using it, preventing Xaero from crashing

This commit is contained in:
Swung0x48 2025-02-10 17:28:17 +08:00
parent b78759df52
commit 916bdda672
3 changed files with 33 additions and 6 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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_