mirror of
https://github.com/nzp-team/fteqw.git
synced 2025-02-16 17:01:44 +00:00
------------------------------------------------------------------------
r4214 | acceptthis | 2013-02-18 03:33:35 +0000 (Mon, 18 Feb 2013) | 1 line my attempt at manifest file support. ------------------------------------------------------------------------ git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4211 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
55cb101be1
commit
f7c0eff8c6
4 changed files with 428 additions and 266 deletions
|
@ -862,21 +862,13 @@ static int CL_BootDownload_Extract(const char *fname, int fsize, void *ptr)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
qboolean FS_LoadPackageFromFile(vfsfile_t *vfs, char *pname, char *localname, int *crc, qboolean copyprotect, qboolean istemporary, qboolean isexplicit);
|
||||
|
||||
void FS_GenCachedPakName(char *pname, char *crc, char *local, int llen);
|
||||
static void CL_BootDownload_Complete(struct dl_download *dl)
|
||||
{
|
||||
void *zip;
|
||||
/*
|
||||
int sz;
|
||||
char *buf;
|
||||
FILE *f;
|
||||
sz = VFS_GETLEN(dl->file);
|
||||
buf = malloc(sz);
|
||||
VFS_READ(dl->file, buf, sz);
|
||||
f = fopen("C:/Games/Quake/test/emptybasedir/test.zip", "wb");
|
||||
fwrite(buf, 1, sz, f);
|
||||
fclose(f);
|
||||
free(buf);
|
||||
*/
|
||||
if (dl->status == DL_FINISHED)
|
||||
zip = zipfilefuncs.OpenNew(dl->file, dl->url);
|
||||
else
|
||||
|
@ -885,11 +877,71 @@ static void CL_BootDownload_Complete(struct dl_download *dl)
|
|||
dl->file = NULL;
|
||||
if (zip)
|
||||
{
|
||||
/*scan it to extract its contents*/
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*.pk3", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*.pak", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*/*.pk3", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*/*.pak", CL_BootDownload_Extract, zip);
|
||||
if (dl->user_ctx)
|
||||
{
|
||||
vfsfile_t *in, *out;
|
||||
flocation_t loc;
|
||||
qboolean found = false;
|
||||
int crc;
|
||||
|
||||
found = zipfilefuncs.FindFile(zip, &loc, dl->user_ctx, NULL);
|
||||
if (!found)
|
||||
{
|
||||
char *s = COM_SkipPath(dl->user_ctx);
|
||||
if (s != dl->user_ctx)
|
||||
found = zipfilefuncs.FindFile(zip, &loc, s, NULL);
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
in = zipfilefuncs.OpenVFS(zip, &loc, "rb");
|
||||
if (in)
|
||||
{
|
||||
char local[MAX_OSPATH];
|
||||
FS_GenCachedPakName(dl->user_ctx, va("%i", dl->user_num), local, sizeof(local));
|
||||
FS_CreatePath(local, FS_ROOT);
|
||||
out = FS_OpenVFS(local, "wb", FS_ROOT);
|
||||
if (out)
|
||||
{
|
||||
char buffer[8192];
|
||||
int read;
|
||||
for(;;)
|
||||
{
|
||||
read = VFS_READ(in, buffer, sizeof(buffer));
|
||||
if (read <= 0)
|
||||
break;
|
||||
if (VFS_WRITE(out, buffer, read) != read)
|
||||
{
|
||||
Con_Printf("write failed writing %s. disk full?\n", local);
|
||||
break;
|
||||
}
|
||||
}
|
||||
VFS_CLOSE(out);
|
||||
out = FS_OpenVFS(local, "rb", FS_ROOT);
|
||||
crc = dl->user_num;
|
||||
if (!FS_LoadPackageFromFile(out, dl->user_ctx, local, &crc, true, false, true))
|
||||
{
|
||||
if (crc == dl->user_num)
|
||||
Con_Printf(CON_WARNING "Manifest package \"%s\" is unusable.\n", dl->user_ctx);
|
||||
else
|
||||
Con_Printf(CON_WARNING "Manifest package \"%s\" is unusable or has invalid crc. Stated crc %#x is not calculated crc %#x\n", dl->user_ctx, dl->user_num, crc);
|
||||
FS_Remove(local, FS_ROOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
VFS_CLOSE(in);
|
||||
}
|
||||
|
||||
free(dl->user_ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*scan it to extract its contents*/
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*.pk3", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*.pak", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*/*.pk3", CL_BootDownload_Extract, zip);
|
||||
zipfilefuncs.EnumerateFiles(zip, "*/*/*.pak", CL_BootDownload_Extract, zip);
|
||||
}
|
||||
|
||||
/*close it, delete the temp file from disk, etc*/
|
||||
zipfilefuncs.ClosePath(zip);
|
||||
|
@ -907,6 +959,71 @@ static void CL_BootDownload_Complete(struct dl_download *dl)
|
|||
}
|
||||
}
|
||||
|
||||
static void CL_Manifest_Complete(struct dl_download *dl)
|
||||
{
|
||||
if (dl->file)
|
||||
{
|
||||
vfsfile_t *f;
|
||||
char buffer[1024];
|
||||
char *fname;
|
||||
int crc;
|
||||
char local[MAX_OSPATH];
|
||||
while(VFS_GETS(dl->file, buffer, sizeof(buffer)))
|
||||
{
|
||||
Cmd_TokenizeString(buffer, false, false);
|
||||
if (!Cmd_Argc())
|
||||
continue;
|
||||
fname = Cmd_Argv(0);
|
||||
crc = strtoul(Cmd_Argv(1), NULL, 0);
|
||||
|
||||
f = FS_OpenVFS(fname, "rb", FS_ROOT);
|
||||
if (f)
|
||||
{
|
||||
//should be loaded as needed
|
||||
VFS_CLOSE(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
FS_GenCachedPakName(fname, va("%i", crc), local, sizeof(local));
|
||||
f = FS_OpenVFS(local, "rb", FS_ROOT);
|
||||
if (f)
|
||||
{
|
||||
int truecrc = crc;
|
||||
if (!FS_LoadPackageFromFile(f, fname, local, &truecrc, true, false, true))
|
||||
{
|
||||
if (crc == truecrc)
|
||||
Con_Printf(CON_WARNING "Manifest package \"%s\" is unusable.\n", fname);
|
||||
else
|
||||
Con_Printf(CON_WARNING "Manifest package \"%s\" is unusable or has invalid crc. Stated crc %#x is not calculated crc %#x\n", fname, crc, truecrc);
|
||||
FS_Remove(local, FS_ROOT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_Printf("Downloading %s from %s\n", fname, Cmd_Argv(2));
|
||||
dl = HTTP_CL_Get(Cmd_Argv(2), "", CL_BootDownload_Complete);
|
||||
if (dl)
|
||||
{
|
||||
dl->user_ctx = strdup(fname);
|
||||
dl->user_num = crc;
|
||||
#ifdef MULTITHREAD
|
||||
DL_CreateThread(dl, FS_OpenTemp(), CL_BootDownload_Complete);
|
||||
#endif
|
||||
numbootdownloads++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!--numbootdownloads)
|
||||
{
|
||||
CL_ExecInitialConfigs();
|
||||
Cmd_StuffCmds();
|
||||
Cbuf_Execute ();
|
||||
Cmd_ExecuteString("vid_restart\n", RESTRICT_LOCAL);
|
||||
}
|
||||
}
|
||||
|
||||
qboolean CL_CheckBootDownloads(void)
|
||||
{
|
||||
char *downloads = fs_gamedownload.string;
|
||||
|
@ -916,6 +1033,23 @@ qboolean CL_CheckBootDownloads(void)
|
|||
struct dl_download *dl;
|
||||
int mirrors;
|
||||
|
||||
int man = COM_CheckParm("-manifest");
|
||||
if (man)
|
||||
{
|
||||
const char *fname = com_argv[man+1];
|
||||
|
||||
Con_Printf("Checking manifest from \"%s\"\n", fname);
|
||||
|
||||
dl = HTTP_CL_Get(fname, token, CL_Manifest_Complete);
|
||||
if (dl)
|
||||
{
|
||||
#ifdef MULTITHREAD
|
||||
DL_CreateThread(dl, FS_OpenTemp(), CL_Manifest_Complete);
|
||||
#endif
|
||||
numbootdownloads++;
|
||||
}
|
||||
}
|
||||
|
||||
while ((downloads = COM_ParseOut(downloads, token, sizeof(token))))
|
||||
{
|
||||
//FIXME: do we want to add some sort of file size indicator?
|
||||
|
|
|
@ -1866,6 +1866,47 @@ void FS_GenCachedPakName(char *pname, char *crc, char *local, int llen)
|
|||
}
|
||||
}
|
||||
|
||||
qboolean FS_LoadPackageFromFile(vfsfile_t *vfs, char *pname, char *localname, int *crc, qboolean copyprotect, qboolean istemporary, qboolean isexplicit)
|
||||
{
|
||||
int i;
|
||||
char *ext = COM_FileExtension(pname);
|
||||
void *handle;
|
||||
|
||||
searchpath_t *sp;
|
||||
|
||||
for (i = 0; i < sizeof(searchpathformats)/sizeof(searchpathformats[0]); i++)
|
||||
{
|
||||
if (!searchpathformats[i].extension || !searchpathformats[i].funcs || !searchpathformats[i].funcs->OpenNew)
|
||||
continue;
|
||||
if (!strcmp(ext, searchpathformats[i].extension))
|
||||
{
|
||||
handle = searchpathformats[i].funcs->OpenNew (vfs, localname);
|
||||
if (!handle)
|
||||
break;
|
||||
if (crc)
|
||||
{
|
||||
int truecrc = searchpathformats[i].funcs->GeneratePureCRC(handle, 0, false);
|
||||
if (truecrc != *crc)
|
||||
{
|
||||
*crc = truecrc;
|
||||
VFS_CLOSE(vfs);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sp = FS_AddPathHandle(pname, localname, searchpathformats[i].funcs, handle, copyprotect, istemporary, isexplicit, (unsigned int)-1);
|
||||
|
||||
if (sp)
|
||||
{
|
||||
FS_FlushFSHashReally();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VFS_CLOSE(vfs);
|
||||
return false;
|
||||
}
|
||||
|
||||
//if a server is using private pak files then load the same version of those, but deprioritise them
|
||||
//crcs are not used, but matched only if the server has a different version from a previous file
|
||||
void FS_ImpurePacks(const char *names, const char *crcs)
|
||||
|
@ -1873,6 +1914,7 @@ void FS_ImpurePacks(const char *names, const char *crcs)
|
|||
int crc;
|
||||
searchpath_t *sp;
|
||||
char *pname;
|
||||
qboolean success;
|
||||
|
||||
while(names)
|
||||
{
|
||||
|
@ -1899,31 +1941,14 @@ void FS_ImpurePacks(const char *names, const char *crcs)
|
|||
char local[MAX_OSPATH];
|
||||
vfsfile_t *vfs;
|
||||
char *ext = COM_FileExtension(pname);
|
||||
void *handle;
|
||||
int i;
|
||||
|
||||
FS_GenCachedPakName(pname, va("%i", crc), local, sizeof(local));
|
||||
vfs = FS_OpenVFS(local, "rb", FS_ROOT);
|
||||
success = false;
|
||||
if (vfs)
|
||||
{
|
||||
for (i = 0; i < sizeof(searchpathformats)/sizeof(searchpathformats[0]); i++)
|
||||
{
|
||||
if (!searchpathformats[i].extension || !searchpathformats[i].funcs || !searchpathformats[i].funcs->OpenNew)
|
||||
continue;
|
||||
if (!strcmp(ext, searchpathformats[i].extension))
|
||||
{
|
||||
handle = searchpathformats[i].funcs->OpenNew (vfs, local);
|
||||
if (!handle)
|
||||
break;
|
||||
sp = FS_AddPathHandle(pname, local, searchpathformats[i].funcs, handle, true, true, false, (unsigned int)-1);
|
||||
success = FS_LoadPackageFromFile(vfs, pname, local, NULL, true, true, false);
|
||||
|
||||
FS_FlushFSHashReally();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sp)
|
||||
if (!success)
|
||||
Con_DPrintf("Unable to load matching package file %s\n", pname);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,244 +1,244 @@
|
|||
#include "bothdefs.h"
|
||||
#if defined(GLQUAKE) && defined(USE_EGL)
|
||||
#include "gl_videgl.h"
|
||||
|
||||
EGLContext eglctx = EGL_NO_CONTEXT;
|
||||
EGLDisplay egldpy = EGL_NO_DISPLAY;
|
||||
EGLSurface eglsurf = EGL_NO_SURFACE;
|
||||
|
||||
static dllhandle_t egllibrary;
|
||||
static dllhandle_t eslibrary;
|
||||
|
||||
static EGLint (*qeglGetError)(void);
|
||||
|
||||
static EGLDisplay (*qeglGetDisplay)(EGLNativeDisplayType display_id);
|
||||
static EGLBoolean (*qeglInitialize)(EGLDisplay dpy, EGLint *major, EGLint *minor);
|
||||
static EGLBoolean (*qeglTerminate)(EGLDisplay dpy);
|
||||
|
||||
static EGLBoolean (*qeglGetConfigs)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
static EGLBoolean (*qeglChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
|
||||
static EGLSurface (*qeglCreateWindowSurface)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
|
||||
static EGLBoolean (*qeglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
|
||||
static EGLBoolean (*qeglQuerySurface)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
|
||||
|
||||
static EGLBoolean (*qeglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
|
||||
static EGLBoolean (*qeglMakeCurrent)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
|
||||
static EGLContext (*qeglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
|
||||
static EGLBoolean (*qeglDestroyContext)(EGLDisplay dpy, EGLContext ctx);
|
||||
static void *(*qeglGetProcAddress) (char *name);
|
||||
|
||||
static dllfunction_t qeglfuncs[] =
|
||||
{
|
||||
{(void*)&qeglGetError, "eglGetError"},
|
||||
|
||||
{(void*)&qeglGetDisplay, "eglGetDisplay"},
|
||||
{(void*)&qeglInitialize, "eglInitialize"},
|
||||
{(void*)&qeglTerminate, "eglTerminate"},
|
||||
|
||||
{(void*)&qeglGetConfigs, "eglGetConfigs"},
|
||||
{(void*)&qeglChooseConfig, "eglChooseConfig"},
|
||||
|
||||
{(void*)&qeglCreateWindowSurface, "eglCreateWindowSurface"},
|
||||
{(void*)&qeglDestroySurface, "eglDestroySurface"},
|
||||
{(void*)&qeglQuerySurface, "eglQuerySurface"},
|
||||
|
||||
{(void*)&qeglSwapBuffers, "eglSwapBuffers"},
|
||||
{(void*)&qeglMakeCurrent, "eglMakeCurrent"},
|
||||
{(void*)&qeglCreateContext, "eglCreateContext"},
|
||||
{(void*)&qeglDestroyContext, "eglDestroyContext"},
|
||||
|
||||
{(void*)&qeglGetProcAddress, "eglGetProcAddress"},
|
||||
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
||||
void *EGL_Proc(char *f)
|
||||
{
|
||||
void *proc = NULL;
|
||||
|
||||
/*
|
||||
char fname[512];
|
||||
{
|
||||
sprintf(fname, "wrap_%s", f);
|
||||
f = fname;
|
||||
}
|
||||
*/
|
||||
|
||||
if (qeglGetProcAddress)
|
||||
proc = qeglGetProcAddress(f);
|
||||
if (!proc)
|
||||
proc = Sys_GetAddressForName(eslibrary, f);
|
||||
if (!proc)
|
||||
proc = Sys_GetAddressForName(egllibrary, f);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
void EGL_UnloadLibrary(void)
|
||||
{
|
||||
if (egllibrary)
|
||||
Sys_CloseLibrary(egllibrary);
|
||||
if (egllibrary == eslibrary)
|
||||
eslibrary = NULL;
|
||||
if (eslibrary)
|
||||
Sys_CloseLibrary(eslibrary);
|
||||
eslibrary = egllibrary = NULL;
|
||||
}
|
||||
|
||||
qboolean EGL_LoadLibrary(char *driver)
|
||||
{
|
||||
/* apps seem to load glesv2 first for dependency issues */
|
||||
Sys_Printf("Attempting to dlopen libGLESv2... ");
|
||||
eslibrary = Sys_LoadLibrary("libGLESv2", NULL);
|
||||
if (!eslibrary)
|
||||
{
|
||||
Sys_Printf("failed\n");
|
||||
// return false;
|
||||
}
|
||||
else
|
||||
Sys_Printf("success\n");
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL.so.1.2", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL.so.1.2\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL.so.1", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL.so.1\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
Sys_Printf("unable to load some libGL\n");
|
||||
|
||||
Sys_Printf("Attempting to dlopen libEGL... ");
|
||||
egllibrary = Sys_LoadLibrary("libEGL", qeglfuncs);
|
||||
if (!egllibrary)
|
||||
{
|
||||
Sys_Printf("failed\n");
|
||||
Con_Printf("libEGL library not loadable\n");
|
||||
/* TODO: some implementations combine EGL/GLESv2 into single library... */
|
||||
Sys_CloseLibrary(eslibrary);
|
||||
return false;
|
||||
}
|
||||
Sys_Printf("success\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGL_Shutdown(void)
|
||||
{
|
||||
if (eglctx == EGL_NO_CONTEXT)
|
||||
return;
|
||||
|
||||
qeglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
qeglDestroyContext(egldpy, eglctx);
|
||||
|
||||
if (eglsurf != EGL_NO_SURFACE)
|
||||
qeglDestroySurface(egldpy, eglsurf);
|
||||
|
||||
qeglTerminate(egldpy);
|
||||
|
||||
eglctx = EGL_NO_CONTEXT;
|
||||
egldpy = EGL_NO_DISPLAY;
|
||||
eglsurf = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
void EGL_BeginRendering (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void EGL_EndRendering (void)
|
||||
{
|
||||
qeglSwapBuffers(egldpy, eglsurf);
|
||||
/* TODO: check result? */
|
||||
}
|
||||
|
||||
qboolean EGL_Init (rendererstate_t *info, unsigned char *palette, EGLNativeWindowType window, EGLNativeDisplayType dpy)
|
||||
{
|
||||
EGLint numconfig;
|
||||
EGLConfig cfg;
|
||||
EGLint major, minor;
|
||||
EGLint attrib[] =
|
||||
{
|
||||
EGL_BUFFER_SIZE, info->bpp,
|
||||
EGL_SAMPLES, info->multisample,
|
||||
EGL_STENCIL_SIZE, 8,
|
||||
EGL_ALPHA_MASK_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLint contextattr[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE, EGL_NONE
|
||||
};
|
||||
|
||||
/* if (!EGL_LoadLibrary(""))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: unable to load library!\n");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
egldpy = qeglGetDisplay(dpy);
|
||||
if (egldpy == EGL_NO_DISPLAY)
|
||||
#include "bothdefs.h"
|
||||
#if defined(GLQUAKE) && defined(USE_EGL)
|
||||
#include "gl_videgl.h"
|
||||
|
||||
EGLContext eglctx = EGL_NO_CONTEXT;
|
||||
EGLDisplay egldpy = EGL_NO_DISPLAY;
|
||||
EGLSurface eglsurf = EGL_NO_SURFACE;
|
||||
|
||||
static dllhandle_t egllibrary;
|
||||
static dllhandle_t eslibrary;
|
||||
|
||||
static EGLint (*qeglGetError)(void);
|
||||
|
||||
static EGLDisplay (*qeglGetDisplay)(EGLNativeDisplayType display_id);
|
||||
static EGLBoolean (*qeglInitialize)(EGLDisplay dpy, EGLint *major, EGLint *minor);
|
||||
static EGLBoolean (*qeglTerminate)(EGLDisplay dpy);
|
||||
|
||||
static EGLBoolean (*qeglGetConfigs)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
static EGLBoolean (*qeglChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
|
||||
|
||||
static EGLSurface (*qeglCreateWindowSurface)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
|
||||
static EGLBoolean (*qeglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
|
||||
static EGLBoolean (*qeglQuerySurface)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
|
||||
|
||||
static EGLBoolean (*qeglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
|
||||
static EGLBoolean (*qeglMakeCurrent)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
|
||||
static EGLContext (*qeglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
|
||||
static EGLBoolean (*qeglDestroyContext)(EGLDisplay dpy, EGLContext ctx);
|
||||
static void *(*qeglGetProcAddress) (char *name);
|
||||
|
||||
static dllfunction_t qeglfuncs[] =
|
||||
{
|
||||
{(void*)&qeglGetError, "eglGetError"},
|
||||
|
||||
{(void*)&qeglGetDisplay, "eglGetDisplay"},
|
||||
{(void*)&qeglInitialize, "eglInitialize"},
|
||||
{(void*)&qeglTerminate, "eglTerminate"},
|
||||
|
||||
{(void*)&qeglGetConfigs, "eglGetConfigs"},
|
||||
{(void*)&qeglChooseConfig, "eglChooseConfig"},
|
||||
|
||||
{(void*)&qeglCreateWindowSurface, "eglCreateWindowSurface"},
|
||||
{(void*)&qeglDestroySurface, "eglDestroySurface"},
|
||||
{(void*)&qeglQuerySurface, "eglQuerySurface"},
|
||||
|
||||
{(void*)&qeglSwapBuffers, "eglSwapBuffers"},
|
||||
{(void*)&qeglMakeCurrent, "eglMakeCurrent"},
|
||||
{(void*)&qeglCreateContext, "eglCreateContext"},
|
||||
{(void*)&qeglDestroyContext, "eglDestroyContext"},
|
||||
|
||||
{(void*)&qeglGetProcAddress, "eglGetProcAddress"},
|
||||
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
||||
void *EGL_Proc(char *f)
|
||||
{
|
||||
void *proc = NULL;
|
||||
|
||||
/*
|
||||
char fname[512];
|
||||
{
|
||||
sprintf(fname, "wrap_%s", f);
|
||||
f = fname;
|
||||
}
|
||||
*/
|
||||
|
||||
if (qeglGetProcAddress)
|
||||
proc = qeglGetProcAddress(f);
|
||||
if (!proc)
|
||||
proc = Sys_GetAddressForName(eslibrary, f);
|
||||
if (!proc)
|
||||
proc = Sys_GetAddressForName(egllibrary, f);
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
void EGL_UnloadLibrary(void)
|
||||
{
|
||||
if (egllibrary)
|
||||
Sys_CloseLibrary(egllibrary);
|
||||
if (egllibrary == eslibrary)
|
||||
eslibrary = NULL;
|
||||
if (eslibrary)
|
||||
Sys_CloseLibrary(eslibrary);
|
||||
eslibrary = egllibrary = NULL;
|
||||
}
|
||||
|
||||
qboolean EGL_LoadLibrary(char *driver)
|
||||
{
|
||||
/* apps seem to load glesv2 first for dependency issues */
|
||||
Sys_Printf("Attempting to dlopen libGLESv2... ");
|
||||
eslibrary = Sys_LoadLibrary("libGLESv2", NULL);
|
||||
if (!eslibrary)
|
||||
{
|
||||
Sys_Printf("failed\n");
|
||||
// return false;
|
||||
}
|
||||
else
|
||||
Sys_Printf("success\n");
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL.so.1.2", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL.so.1.2\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
{
|
||||
eslibrary = dlopen("libGL.so.1", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (eslibrary) Sys_Printf("Loaded libGL.so.1\n");
|
||||
}
|
||||
if (!eslibrary)
|
||||
Sys_Printf("unable to load some libGL\n");
|
||||
|
||||
Sys_Printf("Attempting to dlopen libEGL... ");
|
||||
egllibrary = Sys_LoadLibrary("libEGL", qeglfuncs);
|
||||
if (!egllibrary)
|
||||
{
|
||||
Sys_Printf("failed\n");
|
||||
Con_Printf("libEGL library not loadable\n");
|
||||
/* TODO: some implementations combine EGL/GLESv2 into single library... */
|
||||
Sys_CloseLibrary(eslibrary);
|
||||
return false;
|
||||
}
|
||||
Sys_Printf("success\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGL_Shutdown(void)
|
||||
{
|
||||
if (eglctx == EGL_NO_CONTEXT)
|
||||
return;
|
||||
|
||||
qeglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
qeglDestroyContext(egldpy, eglctx);
|
||||
|
||||
if (eglsurf != EGL_NO_SURFACE)
|
||||
qeglDestroySurface(egldpy, eglsurf);
|
||||
|
||||
qeglTerminate(egldpy);
|
||||
|
||||
eglctx = EGL_NO_CONTEXT;
|
||||
egldpy = EGL_NO_DISPLAY;
|
||||
eglsurf = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
void EGL_BeginRendering (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void EGL_EndRendering (void)
|
||||
{
|
||||
qeglSwapBuffers(egldpy, eglsurf);
|
||||
/* TODO: check result? */
|
||||
}
|
||||
|
||||
qboolean EGL_Init (rendererstate_t *info, unsigned char *palette, EGLNativeWindowType window, EGLNativeDisplayType dpy)
|
||||
{
|
||||
EGLint numconfig;
|
||||
EGLConfig cfg;
|
||||
EGLint major, minor;
|
||||
EGLint attrib[] =
|
||||
{
|
||||
EGL_BUFFER_SIZE, info->bpp,
|
||||
EGL_SAMPLES, info->multisample,
|
||||
EGL_STENCIL_SIZE, 8,
|
||||
EGL_ALPHA_MASK_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLint contextattr[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE, EGL_NONE
|
||||
};
|
||||
|
||||
/* if (!EGL_LoadLibrary(""))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: unable to load library!\n");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
egldpy = qeglGetDisplay(dpy);
|
||||
if (egldpy == EGL_NO_DISPLAY)
|
||||
egldpy = qeglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (egldpy == EGL_NO_DISPLAY)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't get display!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//NOTE: mesa's egl really loves to crash on this call, and I define crash as 'anything that fails to return to caller', which fucks everything up.
|
||||
if (!qeglInitialize(egldpy, &major, &minor))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't initialize display!");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!qeglGetConfigs(egldpy, NULL, 0, &numconfigs) || !numconfigs)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't get configs!");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!qeglChooseConfig(egldpy, attrib, &cfg, 1, &numconfig))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't choose config!");
|
||||
return false;
|
||||
}
|
||||
|
||||
eglsurf = qeglCreateWindowSurface(egldpy, cfg, window, NULL);
|
||||
if (eglsurf == EGL_NO_SURFACE)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: no surface!");
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't get display!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//NOTE: mesa's egl really loves to crash on this call, and I define crash as 'anything that fails to return to caller', which fucks everything up.
|
||||
if (!qeglInitialize(egldpy, &major, &minor))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't initialize display!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!qeglGetConfigs(egldpy, NULL, 0, &numconfigs) || !numconfigs)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't get configs!\n");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!qeglChooseConfig(egldpy, attrib, &cfg, 1, &numconfig))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't choose config!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
eglsurf = qeglCreateWindowSurface(egldpy, cfg, window, NULL);
|
||||
if (eglsurf == EGL_NO_SURFACE)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: no surface!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
eglctx = qeglCreateContext(egldpy, cfg, EGL_NO_SURFACE, contextattr);
|
||||
if (eglctx == EGL_NO_CONTEXT)
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: no context!");
|
||||
Con_Printf(CON_ERROR "EGL: no context!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!qeglMakeCurrent(egldpy, eglsurf, eglsurf, eglctx))
|
||||
{
|
||||
Con_Printf(CON_ERROR "EGL: can't make current!");
|
||||
Con_Printf(CON_ERROR "EGL: can't make current!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,5 +14,8 @@
|
|||
</Description>
|
||||
</em:targetApplication>
|
||||
<em:unpack>true</em:unpack>
|
||||
<em:creator>The FTE Contributors</em:creator>
|
||||
<em:description>Run quake in your browser and stuff!</em:creator>
|
||||
<em:homepageURL>http://fteqw.com/</em:creator>
|
||||
</Description>
|
||||
</RDF>
|
||||
|
|
Loading…
Reference in a new issue