[Feat|Fix] (...): Process GL_NUM_EXTENSIONS in glGetIntegerv. Add simulated glGetStringi. Fix LOG_V and LOG_I.

Signed-off-by: BZLZHH <admin@bzlzhh.top>
This commit is contained in:
BZLZHH 2025-01-30 14:28:49 +08:00
parent e1a9318b25
commit 00c33feeef
4 changed files with 108 additions and 5 deletions

View File

@ -12,6 +12,26 @@ void glGetIntegerv(GLenum pname, GLint *params) {
if (pname == GL_CONTEXT_PROFILE_MASK) {
(*params) = GL_CONTEXT_CORE_PROFILE_BIT;
return;
}
if (pname == GL_NUM_EXTENSIONS) {
static GLint num_extensions = -1;
if (num_extensions == -1) {
const GLubyte* ext_str = glGetString(GL_EXTENSIONS);
if (ext_str) {
char* copy = strdup((const char*)ext_str);
char* token = strtok(copy, " ");
num_extensions = 0;
while (token) {
num_extensions++;
token = strtok(NULL, " ");
}
free(copy);
} else {
num_extensions = 0;
}
}
(*params) = num_extensions;
return;
}
LOAD_GLES(glGetIntegerv, void, GLenum pname, GLint *params);
gles_glGetIntegerv(pname, params);
@ -26,7 +46,7 @@ GLenum glGetError() {
}
char* GetExtensionsList() {
char *extensions = (char*)malloc(10000);
char *extensions = (char*)malloc(20000);
strcpy(extensions,
"GL_EXT_abgr "
"GL_EXT_packed_pixels "
@ -145,7 +165,8 @@ char* GetExtensionsList() {
"GL_ARB_vertex_program "
"GL_ARB_fragment_program "
"GL_EXT_program_parameters "
"GL_ARB_get_program_binary ");
"GL_ARB_get_program_binary "
"GL_ARB_draw_buffers_blend ");
return extensions;
}
@ -165,4 +186,68 @@ const GLubyte * glGetString( GLenum name ) {
return (const GLubyte *) GetExtensionsList();
}
return gles_glGetString(name);
}
const GLubyte * glGetStringi(GLenum name, GLuint index) {
LOG();
LOAD_GLES(glGetStringi, const GLubyte *, GLenum, GLuint);
typedef struct {
GLenum name;
const char** parts;
GLuint count;
} StringCache;
static StringCache caches[] = {
{GL_EXTENSIONS, NULL, 0},
{GL_VENDOR, NULL, 0},
{GL_VERSION, NULL, 0},
{GL_SHADING_LANGUAGE_VERSION, NULL, 0}
};
static int initialized = 0;
if (!initialized) {
for (int i = 0; i < sizeof(caches)/sizeof(StringCache); i++) {
GLenum target = caches[i].name;
const GLubyte* str = NULL;
const char* delimiter = " ";
switch (target) {
case GL_VENDOR:
str = (const GLubyte*)"Swung0x48, BZLZHH, Tungsten";
delimiter = ", ";
break;
case GL_VERSION:
str = (const GLubyte*)"3.3.0 MobileGlues";
delimiter = " .";
break;
case GL_SHADING_LANGUAGE_VERSION:
str = (const GLubyte*)"4.50 MobileGlues with glslang and SPIRV-Cross";
break;
case GL_EXTENSIONS:
str = glGetString(GL_EXTENSIONS);
break;
}
if (!str) continue;
char* copy = strdup((const char*)str);
char* token = strtok(copy, delimiter);
while (token) {
caches[i].parts = (const char**)realloc(caches[i].parts, (caches[i].count + 1) * sizeof(char*));
caches[i].parts[caches[i].count++] = strdup(token);
token = strtok(NULL, delimiter);
}
free(copy);
}
initialized = 1;
}
for (int i = 0; i < sizeof(caches)/sizeof(StringCache); i++) {
if (caches[i].name == name) {
if (index >= caches[i].count) {
return NULL;
}
return (const GLubyte*)caches[i].parts[index];
}
}
return NULL;
}

View File

@ -9,6 +9,7 @@
#include "loader.h"
#include "../gles/loader.h"
#include "mg.h"
#include <GLES/gl32.h>
#define DEBUG false
@ -368,4 +369,3 @@ NATIVE_FUNCTION_HEAD(void, glTexBuffer, GLenum target, GLenum internalformat, GL
NATIVE_FUNCTION_HEAD(void, glTexBufferRange, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size) NATIVE_FUNCTION_END_NO_RETURN(void, glTexBufferRange, target,internalformat,buffer,offset,size)
NATIVE_FUNCTION_HEAD(void, glTexStorage3DMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations) NATIVE_FUNCTION_END_NO_RETURN(void, glTexStorage3DMultisample, target,samples,internalformat,width,height,depth,fixedsamplelocations)
NATIVE_FUNCTION_HEAD(void*, glMapBufferRange, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) NATIVE_FUNCTION_END(void*, glMapBufferRange, target,offset,length,access)
NATIVE_FUNCTION_HEAD(const GLubyte *, glGetStringi, GLenum name, GLuint index) NATIVE_FUNCTION_END(const GLubyte *, glGetStringi, name,index)

View File

@ -12,8 +12,8 @@
#define LOG_E(...) if(DEBUG||GLOBAL_DEBUG) {__android_log_print(ANDROID_LOG_ERROR, RENDERERNAME, __VA_ARGS__);printf(__VA_ARGS__);printf("\n\n");}
#define LOG_F(...) if(DEBUG||GLOBAL_DEBUG) {__android_log_print(ANDROID_LOG_FATAL, RENDERERNAME, __VA_ARGS__);printf(__VA_ARGS__);printf("\n\n");}
#define LOG_V(...) __android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME, __VA_ARGS__);
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, RENDERERNAME, __VA_ARGS__);
#define LOG_V(...) {__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME, __VA_ARGS__);printf(__VA_ARGS__);printf("\n\n");}
#define LOG_I(...) {__android_log_print(ANDROID_LOG_INFO, RENDERERNAME, __VA_ARGS__);printf(__VA_ARGS__);printf("\n\n");}
#define MOBILEGLUES_LOG_H

View File

@ -108,6 +108,23 @@ void init_gl_state() {
set_gl_state_proxy_intformat(0);
}
void LogOpenGLExtensions() {
const GLubyte* raw_extensions = glGetString(GL_EXTENSIONS);
LOG_D("Extensions list using glGetString:\n%s", raw_extensions ? (const char*)raw_extensions : "(null)");
GLint num_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
LOG_D("Extensions list using glGetStringi:\n");
for (GLint i = 0; i < num_extensions; ++i) {
const GLubyte* extension = glGetStringi(GL_EXTENSIONS, i);
if (extension) {
LOG_D("%s", (const char*)extension);
} else {
LOG_D("(null)");
}
}
}
void init_target_gles() {
LOG_I("Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
LOG_I("Initializing %s @ OpenGL ES", RENDERERNAME);
@ -116,4 +133,5 @@ void init_target_gles() {
set_hard_ext();
LOG_I("Initializing %s @ gl_state", RENDERERNAME);
init_gl_state();
LogOpenGLExtensions();
}