feat(egl): broken egl hook

This commit is contained in:
Swung0x48 2025-02-08 15:51:31 +08:00
parent d8597f6082
commit 17d08ce143
9 changed files with 363 additions and 82 deletions

View File

@ -40,6 +40,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
glx/lookup.c
egl/egl.c
egl/loader.c
egl/egl_native.c
gles/loader.c
config/cJSON.c
config/config.c

View File

@ -5,6 +5,79 @@
#include "egl.h"
#include "../includes.h"
#define DEBUG 0
extern GLuint watermark_vao;
extern GLuint watermark_vbo;
extern GLuint watermark_program;
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
LOG()
LOAD_EGL_FUNC(eglSwapBuffers)
LOG_D("Drawing watermark!")
LOAD_GLES_FUNC(glGetIntegerv)
LOAD_GLES_FUNC(glBindVertexArray)
LOAD_GLES_FUNC(glBindBuffer)
LOAD_GLES_FUNC(glUseProgram)
LOAD_GLES_FUNC(glDrawArrays)
LOAD_GLES_FUNC(glEnableVertexAttribArray)
INIT_CHECK_GL_ERROR
// Save states
GLint prev_vao;
GLint prev_vbo;
GLint prev_prog;
gles_glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &prev_vao);
CHECK_GL_ERROR_NO_INIT
gles_glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &prev_vbo);
CHECK_GL_ERROR_NO_INIT
gles_glGetIntegerv(GL_CURRENT_PROGRAM, &prev_prog);
CHECK_GL_ERROR_NO_INIT
LOG_D("prev vao: %d", prev_vao);
LOG_D("prev vbo: %d", prev_vbo);
LOG_D("prev program: %d", prev_prog);
LOG_D("Save ok")
// Set states
gles_glBindVertexArray(watermark_vao);
CHECK_GL_ERROR_NO_INIT
// gles_glEnableVertexAttribArray(0);
gles_glBindBuffer(GL_ARRAY_BUFFER, watermark_vbo);
// CHECK_GL_ERROR_NO_INIT
gles_glUseProgram(watermark_program);
CHECK_GL_ERROR_NO_INIT
LOG_D("set ok")
LOG_D("Watermark vao: %d", watermark_vao);
LOG_D("Watermark vbo: %d", watermark_vbo);
LOG_D("Watermark program: %d", watermark_program);
LOG_D("gles_glDrawArrays: 0x%x", *gles_glDrawArrays);
// Draw!
gles_glDrawArrays(GL_TRIANGLES, 0, 3);
CHECK_GL_ERROR_NO_INIT
LOG_D("draw ok")
// Restore states
gles_glBindVertexArray(prev_vao);
CHECK_GL_ERROR_NO_INIT
gles_glBindBuffer(GL_ARRAY_BUFFER, prev_vbo);
CHECK_GL_ERROR_NO_INIT
gles_glUseProgram(prev_prog);
CHECK_GL_ERROR_NO_INIT
LOG_D("restore ok")
EGLBoolean ret = egl_eglSwapBuffers(dpy, surface);
return ret;
}
//EGLContext mglues_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) {
// __android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
// "%s @ %s(...)", RENDERERNAME, __FUNCTION__);

View File

@ -7,53 +7,22 @@
#include <EGL/egl.h>
typedef intptr_t EGLAttrib;
extern struct egl_func_t g_egl_func;
typedef __eglMustCastToProperFunctionPointerType (*EGLGETPROCADDRESSPROCP) (const char *procname);
#define EGL_NATIVE_FUNCTION_END(type,name,...) \
LOG_D("Use native function: %s @ %s(...)", RENDERERNAME, __FUNCTION__); \
LOAD_EGL_FUNC(name); \
type ret = egl_##name(__VA_ARGS__); \
return ret; \
}
typedef EGLint (*EGLGETERRORPROCP)(void);
typedef EGLDisplay (*EGLGETDISPLAYP)(EGLNativeDisplayType display_id);
typedef EGLBoolean (*EGLINITIALIZEPROCP)(EGLDisplay dpy, EGLint *major, EGLint *minor);
typedef EGLBoolean (*EGLTERMINATEPROCP)(EGLDisplay dpy);
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);
#define EGL_NATIVE_FUNCTION_END_NO_RETURN(type,name,...) \
LOG_D("Use native function: %s @ %s(...)", RENDERERNAME, __FUNCTION__); \
LOAD_EGL_FUNC(name); \
egl_##name(__VA_ARGS__); \
}
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);
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 EGLBoolean (*EGLWAITCLIENTPROCP)(void);
typedef EGLBoolean (*EGLRELEASETHREADPROCP)(void);
typedef EGLSurface (*EGLCREATEPBUFFERFROMCLIENTBUFFERPROCP)(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
typedef EGLBoolean (*EGLSURFACEATTRIBPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
typedef EGLBoolean (*EGLBINDTEXIMAGEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
typedef EGLBoolean (*EGLRELEASETEXIMAGEPROCP)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
typedef EGLBoolean (*EGLSWAPINTERVALPROCP)(EGLDisplay dpy, EGLint interval);
typedef EGLContext (*EGLCREATECONTEXTPROCP)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
typedef EGLBoolean (*EGLDESTROYCONTEXTPROCP)(EGLDisplay dpy, EGLContext ctx);
typedef EGLBoolean (*EGLMAKECURRENTPROCP)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
typedef EGLContext (*EGLGETCURRENTCONTEXTPROCP)(void);
typedef EGLSurface (*EGLGETCURRENTSURFACEPROCP)(EGLint readdraw);
typedef EGLDisplay (*EGLGETCURRENTDISPLAYPROCP)(void);
typedef EGLDisplay (*EGLGETPLATFORMDISPLAYPROCP)(EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
typedef EGLBoolean (*EGLQUERYCONTEXTPROCP)(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
typedef EGLBoolean (*EGLWAITGLPROCP)(void);
typedef EGLBoolean (*EGLWAITNATIVEPROCP)(EGLint engine);
typedef EGLBoolean (*EGLSWAPBUFFERSPROCP)(EGLDisplay dpy, EGLSurface surface);
typedef EGLBoolean (*EGLCOPYBUFFERSPROCP)(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
// Undocumented libmali internals, needed for ODROID Go Ultra
//NativePixmapType (*EGL_CREATE_PIXMAP_ID_MAPPINGPROCP)(void *pixmap);
//NativePixmapType (*EGL_DESTROY_PIXMAP_ID_MAPPINGPROCP)(int id);
// Undocumented libmali internals, needed for ODROID Go Ultra
//NativePixmapType (*EGL_CREATE_PIXMAP_ID_MAPPINGPROCP)(void *pixmap);
//NativePixmapType (*EGL_DESTROY_PIXMAP_ID_MAPPINGPROCP)(int id);
#define EGL_NATIVE_FUNCTION_HEAD(type,name,...) \
__attribute__((visibility("default"))) type EGLAPIENTRY name(__VA_ARGS__) { \
#endif //FOLD_CRAFT_LAUNCHER_EGL_H

View File

@ -0,0 +1,128 @@
#include "egl.h"
#include "../includes.h"
#include "loader.h"
#define DEBUG 0
//EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglBindAPI, EGLenum api) EGL_NATIVE_FUNCTION_END(EGLBoolean, eglBindAPI, api)
EGL_NATIVE_FUNCTION_HEAD(EGLint, eglGetError) EGL_NATIVE_FUNCTION_END(EGLint, eglGetError)
EGL_NATIVE_FUNCTION_HEAD(EGLDisplay, eglGetDisplay, EGLNativeDisplayType display_id) EGL_NATIVE_FUNCTION_END(EGLDisplay, eglGetDisplay, display_id)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglInitialize, EGLDisplay dpy, EGLint *major, EGLint *minor) EGL_NATIVE_FUNCTION_END(EGLBoolean, eglInitialize, dpy, major, minor)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglTerminate, EGLDisplay dpy) EGL_NATIVE_FUNCTION_END(EGLBoolean, eglTerminate, dpy)
EGL_NATIVE_FUNCTION_HEAD(const char *, eglQueryString, EGLDisplay dpy, EGLint name) EGL_NATIVE_FUNCTION_END(const char *, eglQueryString, dpy, name)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglGetConfigs, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) EGL_NATIVE_FUNCTION_END(EGLBoolean, eglGetConfigs, dpy, configs, config_size, num_config)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglChooseConfig, EGLDisplay dpy, const EGLint *attrib_list,
EGLConfig *configs, EGLint config_size,
EGLint *num_config)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglChooseConfig, dpy, attrib_list,
configs, config_size,
num_config)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglGetConfigAttrib, EGLDisplay dpy, EGLConfig config,
EGLint attribute, EGLint *value)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglGetConfigAttrib, dpy, config, attribute, value)
EGL_NATIVE_FUNCTION_HEAD(EGLSurface, eglCreateWindowSurface, EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win,
const EGLint *attrib_list)
EGL_NATIVE_FUNCTION_END(EGLSurface, eglCreateWindowSurface, dpy, config,
win,
attrib_list)
EGL_NATIVE_FUNCTION_HEAD(EGLSurface, eglCreatePbufferSurface, EGLDisplay dpy, EGLConfig config,
const EGLint *attrib_list)
EGL_NATIVE_FUNCTION_END(EGLSurface, eglCreatePbufferSurface, dpy, config, attrib_list)
EGL_NATIVE_FUNCTION_HEAD(EGLSurface, eglCreatePixmapSurface, EGLDisplay dpy, EGLConfig config,
EGLNativePixmapType pixmap,
const EGLint *attrib_list)
EGL_NATIVE_FUNCTION_END(EGLSurface, eglCreatePixmapSurface, dpy, config,
pixmap,
attrib_list)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglDestroySurface, EGLDisplay dpy, EGLSurface surface)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglDestroySurface, dpy, surface)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglQuerySurface, EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglQuerySurface, dpy, surface, attribute, value)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglBindAPI, EGLenum api)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglBindAPI, api)
EGL_NATIVE_FUNCTION_HEAD(EGLenum, eglQueryAPI)
EGL_NATIVE_FUNCTION_END(EGLenum, eglQueryAPI)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglWaitClient)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglWaitClient)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglReleaseThread)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglReleaseThread)
EGL_NATIVE_FUNCTION_HEAD(EGLSurface, eglCreatePbufferFromClientBuffer,
EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
EGLConfig config, const EGLint *attrib_list)
EGL_NATIVE_FUNCTION_END(EGLSurface, eglCreatePbufferFromClientBuffer,
dpy, buftype, buffer,
config, attrib_list)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglSurfaceAttrib, EGLDisplay dpy, EGLSurface surface,
EGLint attribute, EGLint value)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglSurfaceAttrib, dpy, surface,
attribute, value)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglBindTexImage, EGLDisplay dpy, EGLSurface surface, EGLint buffer)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglBindTexImage, dpy, surface, buffer)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglReleaseTexImage, EGLDisplay dpy, EGLSurface surface, EGLint buffer)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglReleaseTexImage, dpy, surface, buffer)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglSwapInterval, EGLDisplay dpy, EGLint interval)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglSwapInterval, dpy, interval)
EGL_NATIVE_FUNCTION_HEAD(EGLContext, eglCreateContext, EGLDisplay dpy, EGLConfig config,
EGLContext share_context,
const EGLint *attrib_list)
EGL_NATIVE_FUNCTION_END(EGLContext, eglCreateContext, dpy, config,
share_context,
attrib_list)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglDestroyContext, EGLDisplay dpy, EGLContext ctx)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglDestroyContext, dpy, ctx)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglMakeCurrent, EGLDisplay dpy, EGLSurface draw,
EGLSurface read, EGLContext ctx)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglMakeCurrent, dpy, draw, read, ctx)
EGL_NATIVE_FUNCTION_HEAD(EGLContext, eglGetCurrentContext)
EGL_NATIVE_FUNCTION_END(EGLContext, eglGetCurrentContext)
EGL_NATIVE_FUNCTION_HEAD(EGLSurface, eglGetCurrentSurface, EGLint readdraw)
EGL_NATIVE_FUNCTION_END(EGLSurface, eglGetCurrentSurface, readdraw)
EGL_NATIVE_FUNCTION_HEAD(EGLDisplay, eglGetCurrentDisplay)
EGL_NATIVE_FUNCTION_END(EGLDisplay, eglGetCurrentDisplay)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglQueryContext, EGLDisplay dpy, EGLContext ctx,
EGLint attribute, EGLint *value)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglQueryContext, dpy, ctx,
attribute, value)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglWaitGL)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglWaitGL)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglWaitNative, EGLint engine)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglWaitNative, engine)
//EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglSwapBuffers, EGLDisplay dpy, EGLSurface surface)
//EGL_NATIVE_FUNCTION_END(EGLBoolean, eglSwapBuffers, dpy, surface)
EGL_NATIVE_FUNCTION_HEAD(EGLBoolean, eglCopyBuffers, EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
EGL_NATIVE_FUNCTION_END(EGLBoolean, eglCopyBuffers, dpy, surface, target)
EGL_NATIVE_FUNCTION_HEAD(__eglMustCastToProperFunctionPointerType , eglGetProcAddress, const char *procname)
EGL_NATIVE_FUNCTION_END(__eglMustCastToProperFunctionPointerType , eglGetProcAddress, procname)

View File

@ -12,25 +12,41 @@
#define DEBUG 0
struct egl_func_t g_egl_func;
void init_target_egl() {
LOG_D("Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
EGLDisplay eglDisplay = EGL_NO_DISPLAY;
EGLSurface eglSurface = EGL_NO_SURFACE;
EGLContext eglContext = EGL_NO_CONTEXT;
LOAD_EGL(eglGetProcAddress);
LOAD_EGL(eglBindAPI);
LOAD_EGL(eglInitialize);
LOAD_EGL(eglGetDisplay);
LOAD_EGL(eglCreatePbufferSurface);
LOAD_EGL(eglDestroySurface);
LOAD_EGL(eglDestroyContext);
LOAD_EGL(eglMakeCurrent);
LOAD_EGL(eglChooseConfig);
LOAD_EGL(eglCreateContext);
LOAD_EGL(eglQueryString);
LOAD_EGL(eglTerminate);
LOAD_EGL(eglGetError);
INIT_EGL_FUNC(eglGetProcAddress);
INIT_EGL_FUNC(eglBindAPI);
INIT_EGL_FUNC(eglInitialize);
INIT_EGL_FUNC(eglGetDisplay);
INIT_EGL_FUNC(eglCreatePbufferSurface);
INIT_EGL_FUNC(eglDestroySurface);
INIT_EGL_FUNC(eglDestroyContext);
INIT_EGL_FUNC(eglMakeCurrent);
INIT_EGL_FUNC(eglChooseConfig);
INIT_EGL_FUNC(eglCreateContext);
INIT_EGL_FUNC(eglQueryString);
INIT_EGL_FUNC(eglTerminate);
INIT_EGL_FUNC(eglGetError);
LOAD_EGL_FUNC(eglGetProcAddress);
LOAD_EGL_FUNC(eglBindAPI);
LOAD_EGL_FUNC(eglInitialize);
LOAD_EGL_FUNC(eglGetDisplay);
LOAD_EGL_FUNC(eglCreatePbufferSurface);
LOAD_EGL_FUNC(eglDestroySurface);
LOAD_EGL_FUNC(eglDestroyContext);
LOAD_EGL_FUNC(eglMakeCurrent);
LOAD_EGL_FUNC(eglChooseConfig);
LOAD_EGL_FUNC(eglCreateContext);
LOAD_EGL_FUNC(eglQueryString);
LOAD_EGL_FUNC(eglTerminate);
LOAD_EGL_FUNC(eglGetError);
eglDisplay = egl_eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL_NO_DISPLAY) {

View File

@ -6,6 +6,7 @@
#define FOLD_CRAFT_LAUNCHER_EGL_LOADER_H
#include "egl.h"
#include "../gl/log.h"
typedef EGLBoolean (*eglBindAPI_PTR)(EGLenum api);
typedef EGLBoolean (*eglBindTexImage_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
@ -87,27 +88,27 @@ struct egl_func_t {
eglWaitNative_PTR eglWaitNative;
};
/*
struct egl_func_t {
EGLGETPROCADDRESSPROCP eglGetProcAddress;
EGLCREATECONTEXTPROCP eglCreateContext;
EGLDESTROYCONTEXTPROCP eglDestroyContext;
EGLMAKECURRENTPROCP eglMakeCurrent;
EGLQUERYSTRINGPROCP eglQueryString;
EGLTERMINATEPROCP eglTerminate;
EGLCHOOSECONFIGPROCP eglChooseConfig;
EGLBINDAPIPROCP eglBindAPI;
EGLINITIALIZEPROCP eglInitialize;
EGLGETDISPLAYP eglGetDisplay;
EGLCREATEPBUFFERSURFACEPROCP eglCreatePbufferSurface;
EGLDESTROYSURFACEPROCP eglDestroySurface;
EGLGETERRORPROCP eglGetError;
EGLCREATEWINDOWSURFACEPROCP eglCreateWindowSurface;
};
EGLContext mglues_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
EGLBoolean mglues_eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
EGLBoolean mglues_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
*/
#define WARN_EGL_NULL(name) \
if (g_egl_func.name == NULL) { \
LOG_W("%s line %d function %s: " #name " is NULL\n", __FILE__, __LINE__, __func__); \
}
#if GLOBAL_DEBUG
#define INIT_EGL_FUNC(name) \
{ \
LOG_D("INIT_EGL_FUNC(%s)", #name); \
g_egl_func.name = (name##_PTR)proc_address(egl, #name); \
WARN_EGL_NULL(name) \
}
#else
#define INIT_EGL_FUNC(name) \
{ \
g_egl_func.name = (name##_PTR)proc_address(egl, #name); \
}
#endif
#define LOAD_EGL_FUNC(name) \
name##_PTR egl_##name = g_egl_func.name;
void init_target_egl();

View File

@ -9,6 +9,10 @@
struct framebuffer_t* bound_framebuffer;
GLuint draw_fbo = 0;
GLuint read_fbo = 0;
GLint MAX_DRAW_BUFFERS = 0;
GLint getMaxDrawBuffers() {
@ -58,16 +62,20 @@ void glBindFramebuffer(GLenum target, GLuint framebuffer) {
case GL_DRAW_FRAMEBUFFER:
free(bound_framebuffer->draw_attachment);
bound_framebuffer->draw_attachment = malloc(getMaxDrawBuffers() * sizeof(struct attachment_t));
draw_fbo = framebuffer;
break;
case GL_READ_FRAMEBUFFER:
free(bound_framebuffer->read_attachment);
bound_framebuffer->read_attachment = malloc(getMaxDrawBuffers() * sizeof(struct attachment_t));
read_fbo = framebuffer;
break;
case GL_FRAMEBUFFER:
free(bound_framebuffer->draw_attachment);
bound_framebuffer->draw_attachment = malloc(getMaxDrawBuffers() * sizeof(struct attachment_t));
free(bound_framebuffer->read_attachment);
bound_framebuffer->read_attachment = malloc(getMaxDrawBuffers() * sizeof(struct attachment_t));
draw_fbo = framebuffer;
read_fbo = framebuffer;
break;
default:
break;

View File

@ -12,13 +12,98 @@
#define DEBUG 0
extern GLuint draw_fbo;
extern GLuint read_fbo;
GLAPI GLAPIENTRY void glClearDepth(GLclampd depth) {
LOG();
glClearDepthf(depth);
glClear(GL_DEPTH_BUFFER_BIT);
LOAD_GLES_FUNC(glClear)
gles_glClear(GL_DEPTH_BUFFER_BIT);
}
void glHint(GLenum target, GLenum mode) {
LOG();
}
extern GLuint watermark_vao;
extern GLuint watermark_vbo;
extern GLuint watermark_program;
extern int init_watermark_res();
extern int watermark_inited;
void glClear(GLbitfield mask) {
LOG();
LOAD_GLES_FUNC(glClear)
gles_glClear(mask);
if (!watermark_inited && init_watermark_res() != 0) {
LOG_E("init_watermark_res failed!")
abort();
}
if (draw_fbo == 0) {
LOG_D("Drawing watermark!")
LOAD_GLES_FUNC(glGetIntegerv)
LOAD_GLES_FUNC(glBindVertexArray)
LOAD_GLES_FUNC(glBindBuffer)
LOAD_GLES_FUNC(glUseProgram)
LOAD_GLES_FUNC(glDrawArrays)
LOAD_GLES_FUNC(glEnableVertexAttribArray)
INIT_CHECK_GL_ERROR
// Save states
GLint prev_vao;
GLint prev_vbo;
GLint prev_prog;
gles_glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &prev_vao);
CHECK_GL_ERROR_NO_INIT
gles_glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &prev_vbo);
CHECK_GL_ERROR_NO_INIT
gles_glGetIntegerv(GL_CURRENT_PROGRAM, &prev_prog);
CHECK_GL_ERROR_NO_INIT
LOG_D("prev vao: %d", prev_vao);
LOG_D("prev vbo: %d", prev_vbo);
LOG_D("prev program: %d", prev_prog);
LOG_D("Save ok")
// Set states
gles_glBindVertexArray(watermark_vao);
CHECK_GL_ERROR_NO_INIT
// gles_glEnableVertexAttribArray(0);
gles_glBindBuffer(GL_ARRAY_BUFFER, watermark_vbo);
// CHECK_GL_ERROR_NO_INIT
gles_glUseProgram(watermark_program);
CHECK_GL_ERROR_NO_INIT
LOG_D("set ok")
LOG_D("Watermark vao: %d", watermark_vao);
LOG_D("Watermark vbo: %d", watermark_vbo);
LOG_D("Watermark program: %d", watermark_program);
LOG_D("gles_glDrawArrays: 0x%x", *gles_glDrawArrays);
// Draw!
gles_glDrawArrays(GL_TRIANGLES, 0, 3);
CHECK_GL_ERROR_NO_INIT
LOG_D("draw ok")
// Restore states
gles_glBindVertexArray(prev_vao);
CHECK_GL_ERROR_NO_INIT
gles_glBindBuffer(GL_ARRAY_BUFFER, prev_vbo);
CHECK_GL_ERROR_NO_INIT
gles_glUseProgram(prev_prog);
CHECK_GL_ERROR_NO_INIT
LOG_D("restore ok")
}
CHECK_GL_ERROR
}

View File

@ -28,7 +28,7 @@ NATIVE_FUNCTION_HEAD(void, glBlendFuncSeparate, GLenum sfactorRGB, GLenum dfacto
NATIVE_FUNCTION_HEAD(void, glBufferData, GLenum target, GLsizeiptr size, const void *data, GLenum usage) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferData, target,size,data,usage)
NATIVE_FUNCTION_HEAD(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const void *data) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferSubData, target,offset,size,data)
//NATIVE_FUNCTION_HEAD(GLenum, glCheckFramebufferStatus, GLenum target) NATIVE_FUNCTION_END(GLenum, glCheckFramebufferStatus, target)
NATIVE_FUNCTION_HEAD(void, glClear, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glClear, mask)
//NATIVE_FUNCTION_HEAD(void, glClear, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glClear, mask)
NATIVE_FUNCTION_HEAD(void, glClearColor, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) NATIVE_FUNCTION_END_NO_RETURN(void, glClearColor, red,green,blue,alpha)
NATIVE_FUNCTION_HEAD(void, glClearDepthf, GLfloat d) NATIVE_FUNCTION_END_NO_RETURN(void, glClearDepthf, d)
NATIVE_FUNCTION_HEAD(void, glClearStencil, GLint s) NATIVE_FUNCTION_END_NO_RETURN(void, glClearStencil, s)
@ -120,7 +120,7 @@ NATIVE_FUNCTION_HEAD(void, glStencilOpSeparate, GLenum face, GLenum sfail, GLenu
//NATIVE_FUNCTION_HEAD(void, glTexImage2D, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexImage2D, target,level,internalformat,width,height,border,format,type,pixels)
//NATIVE_FUNCTION_HEAD(void, glTexParameterf, GLenum target, GLenum pname, GLfloat param) NATIVE_FUNCTION_END_NO_RETURN(void, glTexParameterf, target,pname,param)
NATIVE_FUNCTION_HEAD(void, glTexParameterfv, GLenum target, GLenum pname, const GLfloat *params) NATIVE_FUNCTION_END_NO_RETURN(void, glTexParameterfv, target,pname,params)
NATIVE_FUNCTION_HEAD(void, glTexParameteri, GLenum target, GLenum pname, GLint param) NATIVE_FUNCTION_END_NO_RETURN(void, glTexParameteri, target,pname,param)
//NATIVE_FUNCTION_HEAD(void, glTexParameteri, GLenum target, GLenum pname, GLint param) NATIVE_FUNCTION_END_NO_RETURN(void, glTexParameteri, target,pname,param)
//NATIVE_FUNCTION_HEAD(void, glTexParameteriv, GLenum target, GLenum pname, const GLint *params) NATIVE_FUNCTION_END_NO_RETURN(void, glTexParameteriv, target,pname,params)
//NATIVE_FUNCTION_HEAD(void, glTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexSubImage2D, target,level,xoffset,yoffset,width,height,format,type,pixels)
NATIVE_FUNCTION_HEAD(void, glUniform1f, GLint location, GLfloat v0) NATIVE_FUNCTION_END_NO_RETURN(void, glUniform1f, location,v0)