Propertly use gl4es

This commit is contained in:
nillerusr 2021-08-27 20:41:24 +03:00
parent 20552cc8b9
commit 6fb7fc1f4f
2 changed files with 57 additions and 15 deletions

View File

@ -58,7 +58,7 @@ const int kBogusSwapInterval = INT_MAX;
#ifdef ANDROID
static void *gl4es = NULL;
void *(*_eglGetProcAddress)( const char * );
void *(*_glGetProcAddress)( const char * );
#endif
/*
@ -183,8 +183,8 @@ void *VoidFnPtrLookup_GlMgr(const char *fn, bool &okay, const bool bRequired, vo
#ifdef ANDROID
// SDL does the right thing, so we never need to use tier0 in this case.
if( _eglGetProcAddress )
retval = _eglGetProcAddress(fn);
if( _glGetProcAddress )
retval = _glGetProcAddress(fn);
//printf("CDynamicFunctionOpenGL: SDL_GL_GetProcAddress(\"%s\") returned %p\n", fn, retval);
if ((retval == NULL) && (fallback != NULL))
{
@ -764,7 +764,7 @@ bool CSDLMgr::CreateHiddenGameWindow( const char *pTitle, int width, int height
if( gl4es )
{
_eglGetProcAddress = dlsym(gl4es, "eglGetProcAddress" );
_glGetProcAddress = dlsym(gl4es, "gl4es_GetProcAddress" );
void (*initialize_gl4es)( );
initialize_gl4es = dlsym(gl4es, "initialize_gl4es" );
initialize_gl4es();

View File

@ -8,14 +8,13 @@
#include <stdio.h>
#include <dlfcn.h>
#include "tier0/threadtools.h"
char *LauncherArgv[512];
char java_args[4096];
int iLastArgs = 0;
#define MAX_PATH 2048
#define TAG "SRCENG"
#define PRIO ANDROID_LOG_DEBUG
#define LogPrintf(...) do { __android_log_print(PRIO, TAG, __VA_ARGS__); printf( __VA_ARGS__); } while( 0 );
@ -44,9 +43,6 @@ DLLEXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult()
LogPrintf( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" );
}
typedef void (*t_egl_init)();
t_egl_init egl_init;
void parseArgs( char *args )
{
char *pch;
@ -72,8 +68,8 @@ DLLEXPORT int LauncherMain( int argc, char **argv );
void SetLauncherArgs()
{
static char binPath[MAX_PATH];
snprintf(binPath, MAX_PATH, "%s/hl2_linux", getenv("APP_DATA_PATH") );
static char binPath[2048];
snprintf(binPath, sizeof binPath, "%s/hl2_linux", getenv("APP_DATA_PATH") );
LogPrintf(binPath);
D(binPath);
@ -85,15 +81,61 @@ void SetLauncherArgs()
D("-insecure");
}
static void *lgles;
typedef void (*t_set_getprocaddress)(void *(*new_proc_address)(const char *));
t_set_getprocaddress gl4es_set_getprocaddress;
typedef void *(*t_eglGetProcAddress)( const char * );
t_eglGetProcAddress eglGetProcAddress;
void *GetProcAddress( const char *procname )
{
void *result = dlsym(lgles, procname);
if(result)
return result;
else
return eglGetProcAddress(procname);
}
DLLEXPORT int LauncherMainAndroid( int argc, char **argv )
{
SetLauncherArgs();
void *glHandle = dlopen("libgl4es.so", 0);
egl_init = (t_egl_init)dlsym(glHandle, "egl_init");
if( egl_init )
egl_init();
void *lgl4es = dlopen("libgl4es.so", 0);
if( !lgl4es )
{
LogPrintf("Failed to dlopen library libgl4es.so: %s\n", dlerror());
return 1;
}
void *lEGL = dlopen("libEGL.so", 0);
if( !lEGL )
{
LogPrintf("Failed to dlopen library libEGL.so: %s\n", dlerror());
return 1;
}
lgles = dlopen("libGLESv2.so", 0);
if( !lgles )
{
LogPrintf("Failed to dlopen library libGLESv2.so: %s\n", dlerror());
return 1;
}
gl4es_set_getprocaddress = (t_set_getprocaddress)dlsym(lgl4es, "set_getprocaddress");
eglGetProcAddress = (t_eglGetProcAddress)dlsym(lEGL, "eglGetProcAddress");
if( gl4es_set_getprocaddress && eglGetProcAddress )
{
gl4es_set_getprocaddress( &GetProcAddress );
}
else
{
LogPrintf("Failed to call set_getprocaddress\n");
return 1;
}
DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android