From 24f1cc2e69795fb9759a73f7529b9c24ea727701 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Thu, 11 Mar 2021 20:46:38 -0300 Subject: [PATCH 1/9] Added GOA_CLONE definitions. Sets compilation definitions for GO Advance clones, such as the RG351p/v, Gameforce Chi, RGB10 and other such devices. --- CMakeLists.txt | 7 +++++++ src/gl/init.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fd1f4914..3cc3bfea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(PANDORA "Set to ON if targeting an OpenPandora device" ${PANDORA}) option(PYRA "Set to ON if targeting an Dragonbox Pyra device" ${PYRA}) option(BCMHOST "Set to ON if targeting an RPi(2) device" ${BCMHOST}) option(ODROID "Set to ON if targeting an ODroid device" ${ODROID}) +option(GOA_CLONE "Set to ON if targeting GO Advance clones, like RG351p/v, Gameforce Chi, RGB10..." ${GOA_CLONE}) option(ANDROID "Set to ON if targeting an Android device" ${ANDROID}) option(CHIP "Set to ON if targeting an C.H.I.P. device" ${CHIP}) option(AMIGAOS4 "Set to ON if targeting an AmigaOS4/Warp3D platform (activate NOEGL and NOX11)" ${AMIGAOS4}) @@ -88,6 +89,12 @@ if(ODROID) add_definitions(-DODROID) endif() +# GOA_CLONE +if(GOA_CLONE) + add_definitions(-DGOA_CLONE) + add_definitions(-mcpu=cortex-a35 -mfpu=neon-vfpv3 -march=armv8-a+crc+simd+crypto -mfloat-abi=hard -ftree-vectorize -fsingle-precision-constant -ffast-math) +endif() + # Android if(ANDROID) add_definitions(-DANDROID) diff --git a/src/gl/init.c b/src/gl/init.c index b182ba9b9..e7dc31aea 100644 --- a/src/gl/init.c +++ b/src/gl/init.c @@ -33,7 +33,7 @@ void fpe_shader_reset_internals(); globals4es_t globals4es = {0}; -#if defined(PANDORA) || defined(CHIP) +#if defined(PANDORA) || defined(CHIP) || defined(GOA_CLONE) static void fast_math() { // enable Cortex A8 RunFast int v = 0; @@ -385,7 +385,7 @@ void initialize_gl4es() { } if(IsEnvVarTrue("LIBGL_FASTMATH")) { -#if defined(PANDORA) || defined(CHIP) +#if defined(PANDORA) || defined(CHIP) || defined(GOA_CLONE) SHUT_LOGD("Enable FastMath for cortex-a8\n"); fast_math(); #else From 59c2ba4279f01a99cbcaf1b71aad805a0c8693bd Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 5 Sep 2021 17:50:02 -0300 Subject: [PATCH 2/9] Add glX function stubs to be used with NOX11 targets. Can be enabled with GLX_STUBS, Works around Shovel Knight assert failures during startup. --- CMakeLists.txt | 7 +++++ src/CMakeLists.txt | 1 + src/glx/glx.h | 23 +++++++++----- src/glx/glx_stubs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/glx/lookup.c | 10 +++--- 5 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 src/glx/glx_stubs.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cc3bfea1..23ed054a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ option(NO_LOADER "disable library loader (useful for static library with NOEGL, option(NO_INIT_CONSTRUCTOR "disable automatic initialization (useful for static library, use include/gl4esinit.h)" ${NO_INIT_CONSTRUCTOR}) option(USE_ANDROID_LOG "Set to ON to use Android log instead of stdio" ${USE_ANDROID_LOG}) option(EGL_WRAPPER "Set to ON to build EGL wrapper" ${EGL_WRAPPER}) +option(GLX_STUBS "Set to ON to build GLX function stubs" ${GLX_STUBS}) include(CheckSymbolExists) check_symbol_exists(backtrace "execinfo.h" HAS_BACKTRACE) @@ -93,6 +94,8 @@ endif() if(GOA_CLONE) add_definitions(-DGOA_CLONE) add_definitions(-mcpu=cortex-a35 -mfpu=neon-vfpv3 -march=armv8-a+crc+simd+crypto -mfloat-abi=hard -ftree-vectorize -fsingle-precision-constant -ffast-math) + set(EGL_WRAPPER ON) + set(GLX_STUBS ON) endif() # Android @@ -163,6 +166,10 @@ if(NO_INIT_CONSTRUCTOR) add_definitions(-DNO_INIT_CONSTRUCTOR) endif() +if(GLX_STUBS) + add_definitions(-DGLX_STUBS) +endif() + #DEFAULT_ES=2 if(DEFAULT_ES EQUAL 2) add_definitions(-DDEFAULT_ES=2) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7af91140f..388a90f93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,6 +145,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT NO_LOADER) ${CMAKE_CURRENT_SOURCE_DIR}/glx/hardext.c ${CMAKE_CURRENT_SOURCE_DIR}/glx/gbm.c ${CMAKE_CURRENT_SOURCE_DIR}/glx/glx.c + ${CMAKE_CURRENT_SOURCE_DIR}/glx/glx_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/glx/lookup.c ${CMAKE_CURRENT_SOURCE_DIR}/glx/rpi.c ${CMAKE_CURRENT_SOURCE_DIR}/glx/streaming.c diff --git a/src/glx/glx.h b/src/glx/glx.h index b45c66ebd..95e8dedd2 100644 --- a/src/glx/glx.h +++ b/src/glx/glx.h @@ -238,8 +238,15 @@ struct __GLXFBConfigRec { double minBlue, maxBlue; double minAlpha, maxAlpha; }; + +#ifdef NOX11 +// Declare stub types +typedef void *XVisualInfo, *GLXContext, *Font, *Window, *Pixmap; +typedef unsigned int GLXPixmap, GLXPbuffer; +#endif + typedef struct __GLXFBConfigRec *GLXFBConfig; -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) GLXContext gl4es_glXCreateContext(Display *dpy, XVisualInfo *visual, GLXContext shareList, @@ -250,11 +257,11 @@ GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config const int *attrib_list); void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval); -#endif //NOX11 +#endif // !defined(NOX11) || defined(GLX_STUBS) void gl4es_glXSwapInterval(int interval); // GLX 1.1? -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) Bool gl4es_glXIsDirect(Display * display, GLXContext ctx); Bool gl4es_glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context); Bool gl4es_glXQueryExtension(Display *display, int *errorBase, int *eventBase); @@ -262,18 +269,18 @@ Bool gl4es_glXQueryVersion(Display *display, int *major, int *minor); const char *gl4es_glXGetClientString(Display *display, int name); const char *gl4es_glXQueryExtensionsString(Display *display, int screen); const char *gl4es_glXQueryServerString(Display *display, int screen, int name); -#endif //NOX11 +#endif GLXDrawable gl4es_glXGetCurrentDrawable(); -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) int gl4es_glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value); void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask); void gl4es_glXDestroyContext(Display *display, GLXContext ctx); void gl4es_glXSwapBuffers(Display *display, GLXDrawable drawable); void gl4es_glXUseXFont(Font font, int first, int count, int listBase); -#endif //NOX11 +#endif // !defined(NOX11) || defined(GLX_STUBS) void gl4es_glXWaitGL(); void gl4es_glXWaitX(); -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) XVisualInfo *gl4es_glXChooseVisual(Display *display, int screen, int *attributes); int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); @@ -304,6 +311,6 @@ GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixma void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap); GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); -#endif // NOX11 +#endif // !defined(NOX11) || defined(GLX_STUBS) #endif // _GLX_GLX_H diff --git a/src/glx/glx_stubs.c b/src/glx/glx_stubs.c new file mode 100644 index 000000000..4ba4de5cf --- /dev/null +++ b/src/glx/glx_stubs.c @@ -0,0 +1,77 @@ +#include "glx.h" +#include "../gl/init.h" +#include "../gl/logs.h" + + +#if defined(NOX11) && defined(GLX_STUBS) +//#define WARN_GLX_STUB() LOGD("Warning, stubbed %s\n", __FUNCTION__); return NULL; +#define WARN_GLX_STUB() return NULL; + +GLXContext gl4es_glXCreateContext(Display *display, XVisualInfo *visual, GLXContext shareList, Bool isDirect){ WARN_GLX_STUB(); } +GLXContext gl4es_glXCreateContextAttribsARB(Display *display, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list){ WARN_GLX_STUB(); } +void gl4es_glXDestroyContext(Display *display, GLXContext ctx){ WARN_GLX_STUB(); } +Display *gl4es_glXGetCurrentDisplay(){ WARN_GLX_STUB(); } +XVisualInfo *gl4es_glXChooseVisual(Display *display, int screen, int *attributes){ WARN_GLX_STUB(); } +Bool gl4es_glXMakeCurrent(Display *display, GLXDrawable drawable, GLXContext context){ WARN_GLX_STUB(); } +Bool gl4es_glXMakeContextCurrent(Display *display, int drawable, int readable, GLXContext context){ WARN_GLX_STUB(); } +void gl4es_glXSwapBuffers(Display *display, GLXDrawable drawable){ WARN_GLX_STUB(); } +int gl4es_glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value){ WARN_GLX_STUB(); } +int gl4es_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value){ WARN_GLX_STUB(); } +GLXContext gl4es_glXGetCurrentContext(){ WARN_GLX_STUB(); } +GLXFBConfig *gl4es_glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count){ WARN_GLX_STUB(); } +GLXFBConfig *gl4es_glXChooseFBConfigSGIX(Display *display, int screen, const int *attrib_list, int *count){ WARN_GLX_STUB(); } +GLXFBConfig *gl4es_glXGetFBConfigs(Display *display, int screen, int *count){ WARN_GLX_STUB(); } +int gl4es_glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value){ WARN_GLX_STUB(); } +XVisualInfo *gl4es_glXGetVisualFromFBConfig(Display *display, GLXFBConfig config){ WARN_GLX_STUB(); } +GLXContext gl4es_glXCreateNewContext(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct){ WARN_GLX_STUB(); } +void gl4es_glXSwapIntervalEXT(Display *display, int drawable, int interval){ WARN_GLX_STUB(); } +void gl4es_glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask){ WARN_GLX_STUB(); } +Window gl4es_glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list){ WARN_GLX_STUB(); } +void gl4es_glXDestroyWindow(Display *display, void *win){ WARN_GLX_STUB(); } +GLXDrawable gl4es_glXGetCurrentDrawable(){ WARN_GLX_STUB(); } +Bool gl4es_glXIsDirect(Display * display, GLXContext ctx){ WARN_GLX_STUB(); } +void gl4es_glXUseXFont(Font font, int first, int count, int listBase){ WARN_GLX_STUB(); } +int gl4es_glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value){ WARN_GLX_STUB(); } +void gl4es_glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf){ WARN_GLX_STUB(); } +GLXPbuffer gl4es_glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int * attrib_list){ WARN_GLX_STUB(); } +GLXPixmap gl4es_glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap){ WARN_GLX_STUB(); } +GLXPixmap gl4es_glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list){ WARN_GLX_STUB(); } +void gl4es_glXDestroyGLXPixmap(Display *display, void *pixmap){ WARN_GLX_STUB(); } +void gl4es_glXDestroyPixmap(Display *display, void *pixmap){ WARN_GLX_STUB(); } +GLXContext gl4es_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list){ WARN_GLX_STUB(); } +void gl4es_glXSwapIntervalMESA(int interval){ WARN_GLX_STUB(); } +void gl4es_glXSwapIntervalSGI(int interval){ WARN_GLX_STUB(); } + +AliasExport(GLXContext,glXCreateContext,,(Display *display, XVisualInfo *visual, GLXContext shareList, Bool isDirect)); +AliasExport(GLXContext,glXCreateContextAttribs,ARB,(Display *display, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list)); +AliasExport(void,glXDestroyContext,,(Display *display, GLXContext ctx)); +AliasExport(Display*,glXGetCurrentDisplay,,()); +AliasExport(XVisualInfo*,glXChooseVisual,,(Display *display, int screen, int *attributes)); +AliasExport(Bool,glXMakeCurrent,,(Display *display, GLXDrawable drawable, GLXContext context)); +AliasExport(Bool,glXMakeContextCurrent,,(Display *display, int drawable, int readable, GLXContext context)); +AliasExport(void,glXSwapBuffers,,(Display *display, GLXDrawable drawable)); +AliasExport(int,glXGetConfig,,(Display *display, XVisualInfo *visual, int attribute, int *value)); +AliasExport(int,glXQueryContext,,( Display *dpy, GLXContext ctx, int attribute, int *value)); +AliasExport(GLXContext,glXGetCurrentContext,,()); +AliasExport(GLXFBConfig*,glXChooseFBConfig,,(Display *display, int screen, const int *attrib_list, int *count)); +AliasExport(GLXFBConfig*,glXChooseFBConfig,SGIX,(Display *display, int screen, const int *attrib_list, int *count)); +AliasExport(GLXFBConfig*,glXGetFBConfigs,,(Display *display, int screen, int *count)); +AliasExport(int,glXGetFBConfigAttrib,,(Display *display, GLXFBConfig config, int attribute, int *value)); +AliasExport(XVisualInfo*,glXGetVisualFromFBConfig,,(Display *display, GLXFBConfig config)); +AliasExport(GLXContext,glXCreateNewContext,,(Display *display, GLXFBConfig config, int render_type, GLXContext share_list, Bool is_direct)); +AliasExport(void,glXSwapIntervalEXT,,(Display *display, int drawable, int interval)); +AliasExport(void,glXCopyContext,,(Display *display, GLXContext src, GLXContext dst, GLuint mask)); +AliasExport(Window,glXCreateWindow,,(Display *display, GLXFBConfig config, Window win, int *attrib_list)); +AliasExport(void,glXDestroyWindow,,(Display *display, void *win)); +AliasExport(GLXDrawable,glXGetCurrentDrawable,,()); +AliasExport(Bool,glXIsDirect,,(Display * display, GLXContext ctx)); +AliasExport(void,glXUseXFont,,(Font font, int first, int count, int listBase)); +AliasExport(int,glXQueryDrawable,,(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)); +AliasExport(void,glXDestroyPbuffer,,(Display * dpy, GLXPbuffer pbuf)); +AliasExport(GLXPbuffer,glXCreatePbuffer,,(Display * dpy, GLXFBConfig config, const int * attrib_list)); +AliasExport(GLXPixmap,glXCreateGLXPixmap,,(Display *display, XVisualInfo * visual, Pixmap pixmap)); +AliasExport(GLXPixmap,glXCreatePixmap,,(Display * dpy, GLXFBConfig config, Pixmap pixmap, const int * attrib_list)); +AliasExport(void,glXDestroyGLXPixmap,,(Display *display, void *pixmap)); +AliasExport(void,glXDestroyPixmap,,(Display *display, void *pixmap)); +AliasExport(GLXContext,glXCreateContextAttribs,,(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list)); +#endif \ No newline at end of file diff --git a/src/glx/lookup.c b/src/glx/lookup.c index f21cbed73..e558439e3 100644 --- a/src/glx/lookup.c +++ b/src/glx/lookup.c @@ -15,7 +15,7 @@ void glXStub(void *x, ...) { void *gl4es_glXGetProcAddress(const char *name) __attribute__((visibility("default"))); void *gl4es_glXGetProcAddress(const char *name) { -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) // glX calls _EX(glXChooseVisual); _EX(glXCopyContext); @@ -33,10 +33,10 @@ void *gl4es_glXGetProcAddress(const char *name) { _EX(glXQueryServerString); _EX(glXSwapBuffers); _EX(glXSwapIntervalEXT); -#endif //NOX11 +#endif MAP("glXSwapIntervalMESA", gl4es_glXSwapInterval); MAP("glXSwapIntervalSGI", gl4es_glXSwapInterval); -#ifndef NOX11 +#if !defined(NOX11) || defined(GLX_STUBS) _EX(glXUseXFont); _EX(glXWaitGL); _EX(glXWaitX); @@ -63,10 +63,10 @@ void *gl4es_glXGetProcAddress(const char *name) { STUB(glXGetCurrentReadDrawable); STUB(glXGetSelectedEvent); STUB(glXSelectEvent); - + _EX(glXCreateContextAttribs); _ARB(glXCreateContextAttribs); -#endif //NOX11 +#endif _EX(glXGetProcAddress); _ARB(glXGetProcAddress); From 589175d0daee5d5e25fdae89f7c9f66b3026ac24 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 00:11:19 -0300 Subject: [PATCH 3/9] Fix bit rot on EGL wrappers. --- src/egl/egl.c | 66 ++++++++++++++++++++++++------------------------ src/egl/lookup.c | 2 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/egl/egl.c b/src/egl/egl.c index 7301db178..737b5d912 100644 --- a/src/egl/egl.c +++ b/src/egl/egl.c @@ -189,37 +189,37 @@ EGLBoolean gl4es_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePix return egl_eglCopyBuffers(dpy, surface, target); } -EGLint eglGetError(void) AliasExport("gl4es_eglGetError"); -EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) AliasExport("gl4es_eglGetDisplay"); -EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) AliasExport("gl4es_eglInitialize"); -EGLBoolean eglTerminate(EGLDisplay dpy) AliasExport("gl4es_eglTerminate"); -const char * eglQueryString(EGLDisplay dpy, EGLint name) AliasExport("gl4es_eglQueryString"); -EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) AliasExport("gl4es_eglGetConfigs"); -EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) AliasExport("gl4es_eglChooseConfig"); -EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) AliasExport("gl4es_eglGetConfigAttrib"); -EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) AliasExport("gl4es_eglCreateWindowSurface"); -EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) AliasExport("gl4es_eglCreatePbufferSurface"); -EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) AliasExport("gl4es_eglCreatePixmapSurface"); -EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) AliasExport("gl4es_eglDestroySurface"); -EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) AliasExport("gl4es_eglQuerySurface"); -EGLBoolean eglBindAPI(EGLenum api) AliasExport("gl4es_eglBindAPI"); -EGLenum eglQueryAPI(void) AliasExport("gl4es_eglQueryAPI"); -EGLBoolean eglWaitClient(void) AliasExport("gl4es_eglWaitClient"); -EGLBoolean eglReleaseThread(void) AliasExport("gl4es_eglReleaseThread"); -EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) AliasExport("gl4es_eglCreatePbufferFromClientBuffer"); -EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) AliasExport("gl4es_eglSurfaceAttrib"); -EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) AliasExport("gl4es_eglBindTexImage"); -EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) AliasExport("gl4es_eglReleaseTexImage"); -EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) AliasExport("gl4es_eglSwapInterval"); -EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) AliasExport("gl4es_eglCreateContext"); -EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) AliasExport("gl4es_eglDestroyContext"); -EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) AliasExport("gl4es_eglMakeCurrent"); -EGLContext eglGetCurrentContext(void) AliasExport("gl4es_eglGetCurrentContext"); -EGLSurface eglGetCurrentSurface(EGLint readdraw) AliasExport("gl4es_eglGetCurrentSurface"); -EGLDisplay eglGetCurrentDisplay(void) AliasExport("gl4es_eglGetCurrentDisplay"); -EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) AliasExport("gl4es_eglQueryContext"); -EGLBoolean eglWaitGL(void) AliasExport("gl4es_eglWaitGL"); -EGLBoolean eglWaitNative(EGLint engine) AliasExport("gl4es_eglWaitNative"); -EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) AliasExport("gl4es_eglSwapBuffers"); -EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) AliasExport("gl4es_eglCopyBuffers"); +AliasExport(EGLint, eglGetError,,(void)); +AliasExport(EGLDisplay, eglGetDisplay,,(EGLNativeDisplayType display_id)); +AliasExport(EGLBoolean, eglInitialize,,(EGLDisplay dpy, EGLint *major, EGLint *minor)); +AliasExport(EGLBoolean, eglTerminate,,(EGLDisplay dpy)); +AliasExport(const char *, eglQueryString,,(EGLDisplay dpy, EGLint name)); +AliasExport(EGLBoolean, eglGetConfigs,,(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)); +AliasExport(EGLBoolean, eglChooseConfig,,(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)); +AliasExport(EGLBoolean, eglGetConfigAttrib,,(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)); +AliasExport(EGLSurface, eglCreateWindowSurface,,(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)); +AliasExport(EGLSurface, eglCreatePbufferSurface,,(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)); +AliasExport(EGLSurface, eglCreatePixmapSurface,,(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)); +AliasExport(EGLBoolean, eglDestroySurface,,(EGLDisplay dpy, EGLSurface surface)); +AliasExport(EGLBoolean, eglQuerySurface,,(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)); +AliasExport(EGLBoolean, eglBindAPI,,(EGLenum api)); +AliasExport(EGLenum, eglQueryAPI,,(void)); +AliasExport(EGLBoolean, eglWaitClient,,(void)); +AliasExport(EGLBoolean, eglReleaseThread,,(void)); +AliasExport(EGLSurface, eglCreatePbufferFromClientBuffer,,(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)); +AliasExport(EGLBoolean, eglSurfaceAttrib,,(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)); +AliasExport(EGLBoolean, eglBindTexImage,,(EGLDisplay dpy, EGLSurface surface, EGLint buffer)); +AliasExport(EGLBoolean, eglReleaseTexImage,,(EGLDisplay dpy, EGLSurface surface, EGLint buffer)); +AliasExport(EGLBoolean, eglSwapInterval,,(EGLDisplay dpy, EGLint interval)); +AliasExport(EGLContext, eglCreateContext,,(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)); +AliasExport(EGLBoolean, eglDestroyContext,,(EGLDisplay dpy, EGLContext ctx)); +AliasExport(EGLBoolean, eglMakeCurrent,,(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)); +AliasExport(EGLContext, eglGetCurrentContext,,(void)); +AliasExport(EGLSurface, eglGetCurrentSurface,,(EGLint readdraw)); +AliasExport(EGLDisplay, eglGetCurrentDisplay,,(void)); +AliasExport(EGLBoolean, eglQueryContext,,(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)); +AliasExport(EGLBoolean, eglWaitGL,,(void)); +AliasExport(EGLBoolean, eglWaitNative,,(EGLint engine)); +AliasExport(EGLBoolean, eglSwapBuffers,,(EGLDisplay dpy, EGLSurface surface)); +AliasExport(EGLBoolean, eglCopyBuffers,,(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)); diff --git a/src/egl/lookup.c b/src/egl/lookup.c index b063e53d5..7c9fbe014 100644 --- a/src/egl/lookup.c +++ b/src/egl/lookup.c @@ -58,5 +58,5 @@ void* gl4es_eglGetProcAddress(const char *name) { return gl4es_GetProcAddress(name); } -__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *name) AliasExport("gl4es_eglGetProcAddress"); +AliasExport(__eglMustCastToProperFunctionPointerType, eglGetProcAddress,, (const char *name)); From d70f86693060fca70f181399d378344f6e0ac074 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 01:58:33 -0300 Subject: [PATCH 4/9] Added eglGetPlatformDisplay wrappers. --- src/egl/egl.c | 12 ++++++++++++ src/egl/egl.h | 1 + src/egl/lookup.c | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/egl/egl.c b/src/egl/egl.c index 737b5d912..4207064c0 100644 --- a/src/egl/egl.c +++ b/src/egl/egl.c @@ -164,6 +164,16 @@ EGLDisplay gl4es_eglGetCurrentDisplay(void) { return egl_eglGetCurrentDisplay(); } +EGLDisplay gl4es_eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list) { + LOAD_EGL_EXT(eglGetPlatformDisplay); + if (egl_eglGetPlatformDisplay) + return egl_eglGetPlatformDisplay(platform, native_display, attrib_list); + else { + LOAD_EGL(eglGetDisplay); + return egl_eglGetDisplay((EGLNativeDisplayType)native_display); + } +} + EGLBoolean gl4es_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) { LOAD_EGL(eglQueryContext); return egl_eglQueryContext(dpy, ctx, attribute, value); @@ -217,6 +227,8 @@ AliasExport(EGLBoolean, eglMakeCurrent,,(EGLDisplay dpy, EGLSurface draw, EGLSur AliasExport(EGLContext, eglGetCurrentContext,,(void)); AliasExport(EGLSurface, eglGetCurrentSurface,,(EGLint readdraw)); AliasExport(EGLDisplay, eglGetCurrentDisplay,,(void)); +AliasExport(EGLDisplay, eglGetPlatformDisplay,, (EGLenum platform, void *native_display, const EGLAttrib *attrib_list)); +AliasExport(EGLDisplay, eglGetPlatformDisplay, EXT, (EGLenum platform, void *native_display, const EGLAttrib *attrib_list)); AliasExport(EGLBoolean, eglQueryContext,,(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)); AliasExport(EGLBoolean, eglWaitGL,,(void)); AliasExport(EGLBoolean, eglWaitNative,,(EGLint engine)); diff --git a/src/egl/egl.h b/src/egl/egl.h index 12a3558c0..c40347aa3 100644 --- a/src/egl/egl.h +++ b/src/egl/egl.h @@ -39,6 +39,7 @@ EGLBoolean gl4es_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read EGLContext gl4es_eglGetCurrentContext(void); EGLSurface gl4es_eglGetCurrentSurface(EGLint readdraw); EGLDisplay gl4es_eglGetCurrentDisplay(void); +EGLDisplay gl4es_eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list); EGLBoolean gl4es_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); EGLBoolean gl4es_eglWaitGL(void); EGLBoolean gl4es_eglWaitNative(EGLint engine); diff --git a/src/egl/lookup.c b/src/egl/lookup.c index 7c9fbe014..bd8e83f93 100644 --- a/src/egl/lookup.c +++ b/src/egl/lookup.c @@ -45,6 +45,8 @@ void* gl4es_eglGetProcAddress(const char *name) { _EX(eglGetCurrentContext); _EX(eglGetCurrentSurface); _EX(eglGetCurrentDisplay); + _EX(eglGetPlatformDisplay); + _EXT(eglGetPlatformDisplay); _EX(eglQueryContext); _EX(eglWaitGL); _EX(eglWaitNative); From d69d0e03938f47cef8b1ae6fcc68ffb5540d99d8 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 02:00:32 -0300 Subject: [PATCH 5/9] Include string.h on egl/lookup.c (for strcmp). --- src/egl/lookup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/egl/lookup.c b/src/egl/lookup.c index bd8e83f93..4e9b49670 100644 --- a/src/egl/lookup.c +++ b/src/egl/lookup.c @@ -1,3 +1,5 @@ +#include + #include "../gl/attributes.h" #include "../gl/init.h" #include "../gl/logs.h" From 2b939f0f846ae9661199179994214a28db98a385 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 04:10:13 -0300 Subject: [PATCH 6/9] Fix backslash newline shader failures. --- src/gl/shaderconv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/gl/shaderconv.c b/src/gl/shaderconv.c index e25ea8c36..185ff7a4a 100644 --- a/src/gl/shaderconv.c +++ b/src/gl/shaderconv.c @@ -632,6 +632,20 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need) Tmp = InplaceInsert(GetLine(Tmp, headline), textureCubeGradAlt, Tmp, &tmpsize); } } + + // Some drivers have troubles with "\\\r\n" or "\\\n" sequences on preprocessor macros + newptr = Tmp; + while (*newptr!=0x00) { + if (*newptr == '\\') { + if (*(newptr+1) == '\r' && *(newptr+2) == '\n') + memmove(newptr, newptr+3, strlen(newptr+3)+1); + else if (*(newptr+1) == '\n') + memmove(newptr, newptr+2, strlen(newptr+2)+1); + } + + newptr++; + } + // now check to remove trailling "f" after float, as it's not supported too newptr = Tmp; // simple state machine... From ab082d7b3611bb49a82dd6959478bfdfb7c85d47 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 05:10:33 -0300 Subject: [PATCH 7/9] Added fbo resolution hack. The envvar LIBGL_FB_TEX_SCALE controls the scale of the framebuffer textures. --- src/gl/framebuffers.c | 13 +++++++++++-- src/gl/init.c | 4 ++++ src/gl/init.h | 1 + src/gl/raster.c | 20 ++++++++++++++++++++ src/gl/texture.h | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/gl/framebuffers.c b/src/gl/framebuffers.c index 4aa512da6..b189ff88c 100644 --- a/src/gl/framebuffers.c +++ b/src/gl/framebuffers.c @@ -449,8 +449,10 @@ void APIENTRY_GL4ES gl4es_glFramebufferTexture2D(GLenum target, GLenum attachmen LOGE("texture for FBO not found, name=%u\n", texture); } else { texture = tex->glname; - // check if texture is shrinked... - if (tex->shrink || tex->useratio || (tex->adjust && (hardext.npot==1 || hardext.npot==2) && !globals4es.potframebuffer)) { + tex->fbtex_ratio = (globals4es.fbtexscale > 0.0f) ? globals4es.fbtexscale : 0.0f; + + // check if texture is shrinked or if fb texture is being scaled... + if (globals4es.fbtexscale > 0.0f || tex->shrink || tex->useratio || (tex->adjust && (hardext.npot==1 || hardext.npot==2) && !globals4es.potframebuffer)) { LOGD("%s texture for FBO\n",(tex->useratio)?"going back to npot size pot'ed":"unshrinking shrinked"); if(tex->shrink || tex->useratio) { if(tex->useratio) { @@ -461,6 +463,13 @@ void APIENTRY_GL4ES gl4es_glFramebufferTexture2D(GLenum target, GLenum attachmen tex->height *= 1<shrink; } } + + // Use FBO Ratio + if (tex->fbtex_ratio > 0.0f) { + tex->width *= tex->fbtex_ratio; + tex->height *= tex->fbtex_ratio; + } + tex->nwidth = (hardext.npot>0 || hardext.esversion>1)?tex->width:npot(tex->width); tex->nheight = (hardext.npot>0 || hardext.esversion>1)?tex->height:npot(tex->height); tex->adjustxy[0] = (float)tex->width / tex->nwidth; diff --git a/src/gl/init.c b/src/gl/init.c index e7dc31aea..bc81924e8 100644 --- a/src/gl/init.c +++ b/src/gl/init.c @@ -685,6 +685,10 @@ void initialize_gl4es() { } } } + + if(GetEnvVarFloat("LIBGL_FB_TEX_SCALE",&globals4es.fbtexscale,0.0f)) { + SHUT_LOGD("Framebuffer Textures will be scaled by %.2f\n", globals4es.fbtexscale); + } } diff --git a/src/gl/init.h b/src/gl/init.h index 87d731391..bdfbbae90 100644 --- a/src/gl/init.h +++ b/src/gl/init.h @@ -74,6 +74,7 @@ typedef struct _globals4es { int glxnative; int normalize; // force normal normalization (workaround a bug) int blitfb0; + float fbtexscale; #ifndef NO_GBM char drmcard[50]; #endif diff --git a/src/gl/raster.c b/src/gl/raster.c index 802607573..197dc8364 100644 --- a/src/gl/raster.c +++ b/src/gl/raster.c @@ -59,6 +59,16 @@ void APIENTRY_GL4ES gl4es_glWindowPos3f(GLfloat x, GLfloat y, GLfloat z) { } void APIENTRY_GL4ES gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { + if (glstate->fbo.current_fb->id != 0) { + gltexture_t *tex = gl4es_getTexture(glstate->fbo.current_fb->t_color[0], glstate->fbo.current_fb->color[0]); + if (tex->fbtex_ratio > 0.0f) { + width *= tex->fbtex_ratio; + height *= tex->fbtex_ratio; + x *= tex->fbtex_ratio; + y *= tex->fbtex_ratio; + } + } + if(!glstate->list.pending) PUSH_IF_COMPILING(glViewport); if( glstate->raster.viewport.x!=x || @@ -84,6 +94,16 @@ void APIENTRY_GL4ES gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei he } void APIENTRY_GL4ES gl4es_glScissor(GLint x, GLint y, GLsizei width, GLsizei height) { + if (glstate->fbo.current_fb->id != 0) { + gltexture_t *tex = gl4es_getTexture(glstate->fbo.current_fb->t_color[0], glstate->fbo.current_fb->color[0]); + if (tex->fbtex_ratio > 0.0f) { + width *= tex->fbtex_ratio; + height *= tex->fbtex_ratio; + x *= tex->fbtex_ratio; + y *= tex->fbtex_ratio; + } + } + if(!glstate->list.pending) PUSH_IF_COMPILING(glScissor); #ifdef AMIGAOS4 diff --git a/src/gl/texture.h b/src/gl/texture.h index 4d4f27b4c..4614a234a 100644 --- a/src/gl/texture.h +++ b/src/gl/texture.h @@ -155,6 +155,7 @@ typedef struct { GLvoid *data; // in case we want to keep a copy of it (it that case, always RGBA/GL_UNSIGNED_BYTE glsampler_t sampler; // internal sampler if not superceeded by glBindSampler glsampler_t actual; // actual sampler + float fbtex_ratio; // Lower rendering resolution } gltexture_t; KHASH_MAP_DECLARE_INT(tex, gltexture_t *); From 6d577515a0a2410eeced1d8a9203ec3345c3e6c1 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 05:13:43 -0300 Subject: [PATCH 8/9] Added texture copy skip hack. The envvar LIBGL_SKIPTEXCOPIES controls whether or not to skip texture copies are skipped. --- src/gl/init.c | 1 + src/gl/init.h | 1 + src/gl/texture_read.c | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/src/gl/init.c b/src/gl/init.c index bc81924e8..a1ffa0941 100644 --- a/src/gl/init.c +++ b/src/gl/init.c @@ -686,6 +686,7 @@ void initialize_gl4es() { } } + env(LIBGL_SKIPTEXCOPIES, globals4es.skiptexcopies, "Texture Copies will be skipped"); if(GetEnvVarFloat("LIBGL_FB_TEX_SCALE",&globals4es.fbtexscale,0.0f)) { SHUT_LOGD("Framebuffer Textures will be scaled by %.2f\n", globals4es.fbtexscale); } diff --git a/src/gl/init.h b/src/gl/init.h index bdfbbae90..22b95ac52 100644 --- a/src/gl/init.h +++ b/src/gl/init.h @@ -74,6 +74,7 @@ typedef struct _globals4es { int glxnative; int normalize; // force normal normalization (workaround a bug) int blitfb0; + int skiptexcopies; float fbtexscale; #ifndef NO_GBM char drmcard[50]; diff --git a/src/gl/texture_read.c b/src/gl/texture_read.c index 74f99fe79..e994b78cc 100644 --- a/src/gl/texture_read.c +++ b/src/gl/texture_read.c @@ -41,6 +41,11 @@ void APIENTRY_GL4ES gl4es_glCopyTexImage2D(GLenum target, GLint level, GLenum // actualy bound if targetting shared TEX2D realize_bound(glstate->texture.active, target); + if (globals4es.skiptexcopies) { + DBG(printf("glCopyTexImage2D skipped.\n")); + return; + } + errorGL(); // "Unmap" if buffer mapped... @@ -101,6 +106,11 @@ void APIENTRY_GL4ES gl4es_glCopyTexSubImage2D(GLenum target, GLint level, GLint DBG(printf("glCopyTexSubImage2D(%s, %i, %i, %i, %i, %i, %i, %i), bounded texture=%u format/type=%s, %s\n", PrintEnum(target), level, xoffset, yoffset, x, y, width, height, (glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->texture:0, PrintEnum((glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->format:0), PrintEnum((glstate->texture.bound[glstate->texture.active][itarget])?glstate->texture.bound[glstate->texture.active][itarget]->type:0));) // PUSH_IF_COMPILING(glCopyTexSubImage2D); FLUSH_BEGINEND; + + if (globals4es.skiptexcopies) { + DBG(printf("glCopyTexSubImage2D skipped.\n")); + return; + } LOAD_GLES(glCopyTexSubImage2D); errorGL(); From 93c1388ae37cb9859b627d88fd3c86df87a39482 Mon Sep 17 00:00:00 2001 From: JohnnyonFlame Date: Sun, 7 Nov 2021 05:15:58 -0300 Subject: [PATCH 9/9] Skip Iconoclasts hotspot shaders for performance reasons. --- src/gl/shader_hacks.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/gl/shader_hacks.c b/src/gl/shader_hacks.c index 2d068904a..35b39497b 100644 --- a/src/gl/shader_hacks.c +++ b/src/gl/shader_hacks.c @@ -383,6 +383,60 @@ static const hack_t gl4es_hacks[] = { "\tFogOffsetU = 0.5 / FogTexSize;\r\n" "\tFogScaleU = ( FogTexSize - 1.0 ) / FogTexSize;\r\n" }}, +// for Iconoclasts +// Disable hotspot shaders 1 +#ifdef GOA_CLONE +{ + "void main()\n" + "{\n" + " vec4 p = texture2D(texture, texture_coordinate0);\n" + " float factor = (0.5 - p.r) * magnification;\n" + " vec2 t = texture_coordinate1;\n" + " t.x += (t.x - hotspotX) * factor;\n" + " t.y += (t.y - hotspotY) * factor;\n" + " gl_FragColor = sample_backtex(background_texture, t) * gl_Color;\n" + "}", + 1, + { + "void main() { discard; }" + } +}, +// Disable hotspot shaders 2 +{ + "void main()\n" + "{\n" + " vec4 p = texture2D(texture, texture_coordinate0) * gl_Color;\n" + " if (p.a != 0.0) {\n" + " float zoomFactor = (0.0 - (p.r + p.g + p.b) / 3.0) * magnification;\n" + " vec2 t = texture_coordinate1;\n" + " t.x += (t.x - hotspotX + offx / texture_size.x) * zoomFactor;\n" + " t.y += (t.y - hotspotY + offy / texture_size.y) * zoomFactor;\n" + " gl_FragColor = sample_backtex(background_texture, t);\n" + " return;\n" + " }\n" + " gl_FragColor = p;\n" + "}", + 1, + { + "void main() { discard; }" + } +}, +// Disable hotspot shaders 3 +{ + "void main()\n" + "{\n" + " vec4 p = texture2D(texture, texture_coordinate0) * gl_Color;\n" + " float factor = (0.0 - (p.r + p.g + p.b) / 3.0) * magnification;\n" + " vec2 t = background_offset.xy - texture_coordinate1 * \n" + " (background_offset.xy * 2.0 - vec2(1.0));\n" + " t.x += (t.x - hotspotX) * factor;\n" + " t.y += (t.y - hotspotY) * factor;\n" + " gl_FragColor = sample_backtex(background_texture, t);\n" + "}", + 1, + {"void main() { discard; }"} +} +#endif }; // For Stellaris