mirror of
https://github.com/MobileGL-Dev/MobileGlues.git
synced 2025-09-22 10:42:11 -04:00
[Feat] (...): Process more GL functions, add EGL initialization.
Signed-off-by: BZLZHH <admin@bzlzhh.top>
This commit is contained in:
parent
6735d41634
commit
a8bad9ec73
@ -28,6 +28,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
gl/texture.c
|
||||
gl/mg.c
|
||||
gl/glsl/glsl_for_es.cpp
|
||||
glx/lookup.c
|
||||
egl/egl.c
|
||||
egl/loader.c
|
||||
gles/loader.c
|
||||
|
@ -19,7 +19,7 @@ typedef const char * (*EGLQUERYSTRINGPROCP)(EGLDisplay dpy, EGLint name);
|
||||
typedef EGLBoolean (*EGLGETCONFIGSPROCP)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
typedef EGLBoolean (*EGLCHOOSECONFIGPROCP)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
typedef EGLBoolean (*EGLGETCONFIGATTRIBPROCP)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
|
||||
typedef
|
||||
|
||||
typedef EGLSurface (*EGLCREATEWINDOWSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
|
||||
typedef EGLSurface (*EGLCREATEPBUFFERSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
|
||||
typedef EGLSurface (*EGLCREATEPIXMAPSURFACEPROCP)(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
|
||||
@ -27,7 +27,7 @@ typedef EGLBoolean (*EGLDESTROYSURFACEPROCP)(EGLDisplay dpy, EGLSurface surface)
|
||||
typedef EGLBoolean (*EGLQUERYSURFACEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
|
||||
typedef EGLBoolean (*EGLBINDAPIPROCP)(EGLenum api);
|
||||
typedef EGLenum (*EGLQUERYAPIPROCP)(void);
|
||||
typedef
|
||||
|
||||
typedef EGLBoolean (*EGLWAITCLIENTPROCP)(void);
|
||||
typedef EGLBoolean (*EGLRELEASETHREADPROCP)(void);
|
||||
typedef EGLSurface (*EGLCREATEPBUFFERFROMCLIENTBUFFERPROCP)(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
|
||||
|
@ -1,24 +1,122 @@
|
||||
//
|
||||
// Created by Swung0x48 on 2024/10/10.
|
||||
//
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <string.h>
|
||||
#include "loader.h"
|
||||
#include "../includes.h"
|
||||
#include "../gl/log.h"
|
||||
#include "../gl/envvars.h"
|
||||
|
||||
#define EGL_LOAD_FUNC(name) g_egl_func.name = (void*)g_egl_func.eglGetProcAddress(#name);
|
||||
#define LOAD_CORE_FUNC(handle, name) \
|
||||
g_egl_func.name = _mglues_dlsym(handle, #name); \
|
||||
if (!g_egl_func.name) { \
|
||||
LOG_F("Failed to load core function: %s", #name); \
|
||||
}
|
||||
|
||||
void init_target_egl() {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
LOG_V("Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
char* egl_name = GetEnvVar("LIBGL_EGL") ? GetEnvVar("LIBGL_EGL") : "libEGL.so";
|
||||
void* handle = _mglues_dlopen(egl_name);
|
||||
if (!handle) LOG_F("Cannot load system %s!", egl_name);
|
||||
|
||||
// g_egl_func.eglCreateContext = (EGLCREATECONTEXTPROCP)g_egl_func.eglGetProcAddress("eglCreateContext");
|
||||
EGL_LOAD_FUNC(eglCreateContext);
|
||||
EGL_LOAD_FUNC(eglDestroyContext);
|
||||
EGL_LOAD_FUNC(eglMakeCurrent);
|
||||
LOAD_CORE_FUNC(handle, eglGetProcAddress);
|
||||
LOAD_CORE_FUNC(handle, eglBindAPI);
|
||||
LOAD_CORE_FUNC(handle, eglInitialize);
|
||||
LOAD_CORE_FUNC(handle, eglGetDisplay);
|
||||
LOAD_CORE_FUNC(handle, eglCreatePbufferSurface);
|
||||
LOAD_CORE_FUNC(handle, eglDestroySurface);
|
||||
LOAD_CORE_FUNC(handle, eglDestroyContext);
|
||||
LOAD_CORE_FUNC(handle, eglMakeCurrent);
|
||||
LOAD_CORE_FUNC(handle, eglChooseConfig);
|
||||
LOAD_CORE_FUNC(handle, eglCreateContext);
|
||||
LOAD_CORE_FUNC(handle, eglQueryString);
|
||||
LOAD_CORE_FUNC(handle, eglTerminate);
|
||||
LOAD_CORE_FUNC(handle, eglGetError);
|
||||
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got target eglCreateContext @ 0x%lx", g_egl_func.eglCreateContext);
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got target eglDestroyContext @ 0x%lx", g_egl_func.eglDestroyContext);
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got target eglMakeCurrent @ 0x%lx", g_egl_func.eglMakeCurrent);
|
||||
EGLDisplay eglDisplay = EGL_NO_DISPLAY;
|
||||
EGLSurface eglSurface = EGL_NO_SURFACE;
|
||||
EGLContext eglContext = EGL_NO_CONTEXT;
|
||||
|
||||
eglDisplay = g_egl_func.eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (eglDisplay == EGL_NO_DISPLAY) {
|
||||
LOG_E("eglGetDisplay failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (g_egl_func.eglInitialize(eglDisplay, NULL, NULL) != EGL_TRUE) {
|
||||
LOG_E("eglInitialize failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (g_egl_func.eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
|
||||
LOG_E("eglBindAPI failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
EGLint configAttribs[] = {
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_ALPHA_SIZE, 8,
|
||||
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLConfig pbufConfig;
|
||||
EGLint configsFound = 0;
|
||||
if (g_egl_func.eglChooseConfig(eglDisplay, configAttribs, &pbufConfig, 1, &configsFound) != EGL_TRUE) {
|
||||
LOG_E("eglChooseConfig failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (configsFound == 0) {
|
||||
configAttribs[6] = 0;
|
||||
if (g_egl_func.eglChooseConfig(eglDisplay, configAttribs, &pbufConfig, 1, &configsFound) != EGL_TRUE) {
|
||||
LOG_E("Retry eglChooseConfig failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
if (configsFound) {
|
||||
LOG_I("Using config without alpha channel");
|
||||
} else {
|
||||
LOG_E("No valid EGL config found");
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
EGLint ctxAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
||||
eglContext = g_egl_func.eglCreateContext(eglDisplay, pbufConfig, EGL_NO_CONTEXT, ctxAttribs);
|
||||
if (eglContext == EGL_NO_CONTEXT) {
|
||||
LOG_E("eglCreateContext failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
EGLint pbAttribs[] = { EGL_WIDTH, 32, EGL_HEIGHT, 32, EGL_NONE };
|
||||
eglSurface = g_egl_func.eglCreatePbufferSurface(eglDisplay, pbufConfig, pbAttribs);
|
||||
if (eglSurface == EGL_NO_SURFACE) {
|
||||
LOG_E("eglCreatePbufferSurface failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (g_egl_func.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE) {
|
||||
LOG_E("eglMakeCurrent failed (0x%x)", g_egl_func.eglGetError());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
LOG_V("EGL initialized successfully");
|
||||
return;
|
||||
|
||||
cleanup:
|
||||
if (eglSurface != EGL_NO_SURFACE) {
|
||||
g_egl_func.eglDestroySurface(eglDisplay, eglSurface);
|
||||
}
|
||||
if (eglContext != EGL_NO_CONTEXT) {
|
||||
g_egl_func.eglDestroyContext(eglDisplay, eglContext);
|
||||
}
|
||||
if (eglDisplay != EGL_NO_DISPLAY) {
|
||||
g_egl_func.eglTerminate(eglDisplay);
|
||||
}
|
||||
LOG_E("EGL initialization failed");
|
||||
}
|
@ -12,8 +12,18 @@ struct egl_func_t {
|
||||
EGLCREATECONTEXTPROCP eglCreateContext;
|
||||
EGLDESTROYCONTEXTPROCP eglDestroyContext;
|
||||
EGLMAKECURRENTPROCP eglMakeCurrent;
|
||||
EGLQUERYSTRINGPROCP eglQueryString;
|
||||
EGLTERMINATEPROCP eglTerminate;
|
||||
EGLCHOOSECONFIGPROCP eglChooseConfig;
|
||||
EGLBINDAPIPROCP eglBindAPI;
|
||||
EGLINITIALIZEPROCP eglInitialize;
|
||||
EGLGETDISPLAYP eglGetDisplay;
|
||||
EGLCREATEPBUFFERSURFACEPROCP eglCreatePbufferSurface;
|
||||
EGLDESTROYSURFACEPROCP eglDestroySurface;
|
||||
EGLGETERRORPROCP eglGetError;
|
||||
};
|
||||
|
||||
|
||||
void init_target_egl();
|
||||
|
||||
EGLContext mglues_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
|
||||
|
2466
src/main/cpp/gl/gl.c
2466
src/main/cpp/gl/gl.c
File diff suppressed because it is too large
Load Diff
2464
src/main/cpp/gl/gl_modified.c
Normal file
2464
src/main/cpp/gl/gl_modified.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,10 +6,12 @@
|
||||
|
||||
#define LOG() __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, "Use function: %s", __FUNCTION__);
|
||||
|
||||
#define LOG_V(...) __android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME, __VA_ARGS__);
|
||||
#define LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG, RENDERERNAME, __VA_ARGS__);
|
||||
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, RENDERERNAME, __VA_ARGS__);
|
||||
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, RENDERERNAME, __VA_ARGS__);
|
||||
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, RENDERERNAME, __VA_ARGS__);
|
||||
#define LOG_F(...) __android_log_print(ANDROID_LOG_FATAL, RENDERERNAME, __VA_ARGS__);
|
||||
|
||||
#define MOBILEGLUES_LOG_H
|
||||
|
||||
|
@ -10,7 +10,7 @@ gl_state_t gl_state;
|
||||
GLenum pname_convert(GLenum pname){
|
||||
switch (pname) {
|
||||
case GL_TEXTURE_LOD_BIAS:
|
||||
LOG_D("pnameConvert: GL_TEXTURE_LOD_BIAS -> GL_TEXTURE_LOD_BIAS_EXT");
|
||||
LOG_D("pnameConvert: GL_TEXTURE_LOD_BIAS -> GL_TEXTURE_LOD_BIAS_QCOM");
|
||||
return GL_TEXTURE_LOD_BIAS_QCOM;
|
||||
}
|
||||
return pname;
|
||||
|
@ -42,14 +42,6 @@ static const char *gles3_lib[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *egl_lib[] = {
|
||||
#if defined(BCMHOST)
|
||||
"libbrcmEGL",
|
||||
#endif
|
||||
"libEGL",
|
||||
NULL
|
||||
};
|
||||
|
||||
void *open_lib(const char **names, const char *override) {
|
||||
void *lib = NULL;
|
||||
|
||||
@ -83,8 +75,6 @@ void load_libs() {
|
||||
first = 0;
|
||||
const char *gles_override = GetEnvVar("LIBGL_GLES");
|
||||
gles = open_lib(gles3_lib, gles_override);
|
||||
const char *egl_override = GetEnvVar("LIBGL_EGL");
|
||||
egl = open_lib(egl_lib, egl_override);
|
||||
}
|
||||
|
||||
void *(*gles_getProcAddress)(const char *name);
|
||||
|
23
src/main/cpp/glx/lookup.c
Normal file
23
src/main/cpp/glx/lookup.c
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by BZLZHH on 2025/1/27.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <string.h>
|
||||
#include "../includes.h"
|
||||
#include "../gl/log.h"
|
||||
#include "../gl/envvars.h"
|
||||
|
||||
void *glXGetProcAddress(const char *name) {
|
||||
void* proc = dlsym(RTLD_DEFAULT, (const char*)name);
|
||||
|
||||
if (!proc) {
|
||||
fprintf(stderr, "Failed to get OpenGL function %s: %s\n", name, dlerror());
|
||||
LOG_W("Failed to get OpenGL function: %s", (const char*)name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return proc;
|
||||
}
|
10
src/main/cpp/glx/lookup.h
Normal file
10
src/main/cpp/glx/lookup.h
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by Administrator on 2025/1/27.
|
||||
//
|
||||
|
||||
#ifndef MOBILEGLUES_LOOKUP_H
|
||||
#define MOBILEGLUES_LOOKUP_H
|
||||
|
||||
void *glXGetProcAddress(const char *name) __attribute__((visibility("default")));
|
||||
|
||||
#endif //MOBILEGLUES_LOOKUP_H
|
@ -8,6 +8,7 @@
|
||||
#include "egl/egl.h"
|
||||
#include "egl/loader.h"
|
||||
#include "gles/loader.h"
|
||||
#include "gl/envvars.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -19,18 +20,7 @@ __eglMustCastToProperFunctionPointerType prehook(const char *procname);
|
||||
__eglMustCastToProperFunctionPointerType posthook(const char *procname);
|
||||
|
||||
void proc_init() {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
|
||||
void* handle = _mglues_dlopen("libEGL.so");
|
||||
if (handle == NULL)
|
||||
__android_log_print(ANDROID_LOG_FATAL, RENDERERNAME,
|
||||
"Cannot load system libEGL.so!");
|
||||
|
||||
g_egl_func.eglGetProcAddress = _mglues_dlsym(handle, "eglGetProcAddress");
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got target eglGetProcAddress @ 0x%lx", g_egl_func.eglGetProcAddress);
|
||||
|
||||
LOG_V("Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
init_target_egl();
|
||||
init_target_gles();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user