diff --git a/engine/Makefile b/engine/Makefile index 686aa0348..afdea79da 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -685,7 +685,7 @@ GLCL_DIR=glcl_$(FTE_FULLTARGET) SV_OBJS=$(COMMON_OBJS) $(SERVER_OBJS) $(PROGS_OBJS) $(SERVERONLY_OBJS) SV_EXE_NAME=../fteqw_sv$(FTE_FULLTARGET) SV_CFLAGS=$(SERVER_ONLY_CFLAGS) -SV_LDFLAGS=-lz +SV_LDFLAGS= MINGL_DIR=mingl_$(FTE_FULLTARGET) MINGL_EXE_NAME=../fteqw_mingl$(FTE_FULLTARGET) @@ -693,7 +693,7 @@ MINGL_EXE_NAME=../fteqw_mingl$(FTE_FULLTARGET) MB_DIR=m_$(FTE_FULLTARGET) M_EXE_NAME=../fteqw_$(FTE_FULLTARGET) MCL_OBJS=$(D3DGL_OBJS) $(GLQUAKE_OBJS) $(SOFTWARE_OBJS) gl_vidsdl.o snd_sdl.o cd_sdl.o sys_sdl.o in_sdl.o -M_CFLAGS=$(GLCFLAGS) `$(SDLCONFIG) --cflags` -D_MERGED_SDL +M_CFLAGS=$(GLCFLAGS) `$(SDLCONFIG) --cflags` M_LDFLAGS=$(GLLDFLAGS) $(IMAGELDFLAGS) $(OGGVORBISLDFLAGS) ifdef windir @@ -703,6 +703,13 @@ else M_LDFLAGS=$(MLDFLAGS) `$(SDLCONFIG) --libs` $(IMAGELDFLAGS) $(OGGVORBISLDFLAGS) endif +ifeq (,$(findstring NO_ZLIB,$(CFLAGS))) + SV_LDFLAGS+=-lz + GL_LDFLAGS+=-lz + M_LDFLAGS+=-lz +endif + + #specific targets override those defaults as needed. #google native client @@ -1007,11 +1014,10 @@ ifeq ($(FTE_TARGET),bsd) MINGL_EXE_NAME=../fteqw.mingl MINGL_DIR=mingl_bsd endif -ifneq ($(shell echo $(FTE_TARGET)|grep linux),) - +ifneq (,$(findstring linux,$(FTE_TARGET))) SV_DIR=sv_linux$(BITS) - SV_LDFLAGS=-lz SV_EXE_NAME=../fteqw.sv$(BITS) + SV_LDFLAGS= NPFTE_OBJS=httpclient.o image.o sys_linux_threads.o sys_npfte.o sys_axfte.o sys_plugfte.o NPFTE_DLL_NAME=../npfte$(BITS).so @@ -1022,25 +1028,49 @@ ifneq ($(shell echo $(FTE_TARGET)|grep linux),) GLCL_OBJS=$(GL_OBJS) $(D3DGL_OBJS) $(GLQUAKE_OBJS) $(BOTLIB_OBJS) $(SPEEX_OBJS) gl_vidlinuxglx.o gl_videgl.o snd_alsa.o snd_linux.o cd_linux.o sys_linux.o sys_linux_threads.o GL_EXE_NAME=../fteqw.gl$(BITS) GLCL_EXE_NAME=../fteqwcl.gl$(BITS) - GL_LDFLAGS=$(GLLDFLAGS) $(XLDFLAGS) $(OGGVORBISLDFLAGS) -lz + GL_LDFLAGS=$(GLLDFLAGS) $(XLDFLAGS) $(OGGVORBISLDFLAGS) GL_CFLAGS=$(GLCFLAGS) -I/usr/X11R6/include $(SPEEXCFLAGS) -DMULTITHREAD -DLIBVORBISFILE_STATIC -DDYNAMIC_LIBPNG -DDYNAMIC_LIBJPEG GLB_DIR=gl_linux$(BITS) GLCL_DIR=glcl_linux$(BITS) - MCL_OBJS=$(D3DGL_OBJS) $(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(BOTLIB_OBJS) $(SPEEX_OBJS) gl_vidlinuxglx.o snd_linux.o snd_alsa.o cd_linux.o sys_linux.o sys_linux_threads.o + MCL_OBJS=$(D3DGL_OBJS) $(GLQUAKE_OBJS) $(SOFTWARE_OBJS) $(BOTLIB_OBJS) $(SPEEX_OBJS) gl_vidlinuxglx.o gl_videgl.o snd_linux.o snd_alsa.o cd_linux.o sys_linux.o sys_linux_threads.o M_EXE_NAME=../fteqw$(BITS) MCL_EXE_NAME=../fteqwcl$(BITS) - M_LDFLAGS=$(GLLDFLAGS) $(XLDFLAGS) $(OGGVORBISLDFLAGS) -lz - M_CFLAGS=$(GLCFLAGS) -I/usr/X11R6/include $(SPEEXCFLAGS) -DLIBVORBISFILE_STATIC -DDYNAMIC_LIBPNG -DDYNAMIC_LIBJPEG + M_LDFLAGS=$(GL_LDFLAGS) + M_CFLAGS=$(GL_CFLAGS) MB_DIR=m_linux$(BITS) MCL_DIR=mcl_linux$(BITS) IMAGELDFLAGS= + ifeq (,$(findstring NO_ZLIB,$(CFLAGS))) + SV_LDFLAGS+= -lz + GL_LDFLAGS+= -lz + M_LDFLAGS+= -lz + endif MINGL_EXE_NAME=../fteqw.mingl$(BITS) MINGL_DIR=mingl_linux$(BITS) + +endif +ifneq (,$(findstring rpi,$(FTE_TARGET))) + #These next two lines enable cross compiling. If you're compiling natively you can just kill the two. + RPI_SYSROOT:=$(realpath $(shell echo ~)/rpi/rpi-sysroot/) + CC=~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc --sysroot=$(RPI_SYSROOT) + SDLCONFIG=$(RPI_SYSROOT)/usr/bin/sdl-config --prefix=$(RPI_SYSROOT)/usr + GL_CFLAGS+= -I$(RPI_SYSROOT)/opt/vc/include -I$(RPI_SYSROOT)/opt/vc/include/interface/vmcs_host/linux -I$(RPI_SYSROOT)/opt/vc/include/interface/vcos/pthreads -DFTE_RPI -DUSE_EGL + GL_LDFLAGS+= -L$(RPI_SYSROOT)/opt/vc/lib -Wl,--sysroot=$(RPI_SYSROOT),-rpath=/opt/vc/lib,-rpath-link=$(RPI_SYSROOT)/opt/vc/lib -lbcm_host + GLCL_OBJS+=gl_vidrpi.o +endif +ifneq (,$(findstring wayland,$(FTE_TARGET))) + GL_CFLAGS+=-DUSE_EGL + GLCL_OBJS+=gl_vidwayland.o + GL_LDFLAGS+=-lwayland-client -lwayland-egl +endif +ifneq (,$(findstring fbdev,$(FTE_TARGET))) + GL_CFLAGS+=-DUSE_EGL + GLCL_OBJS+=gl_vidfbdev.o endif ifneq ($(shell echo $(FTE_TARGET)|grep macosx),) SV_DIR=sv_macosx$(EXTENSION)$(BITS) @@ -1162,8 +1192,8 @@ ifeq ($(FTE_TARGET),web) JSLIBS=--js-library web/ftejslib.js -s DISABLE_GL_EMULATION=1 EMCC_ARGS=$(JSLIBS) $(WEB_PREJS) --shell-file web/fteshell.html -s ERROR_ON_UNDEFINED_SYMBOLS=1 RELEASE_CFLAGS=-DOMIT_QCC -DGL_STATIC -DFTE_TARGET_WEB - DEBUG_CFLAGS=-g --jcache -DOMIT_QCC -DGL_STATIC -DFTE_TARGET_WEB - RELEASE_LDFLAGS=-s ASM_JS=1 -O1 -s TOTAL_MEMORY=$(ASMJS_MEMORY) $(EMCC_ARGS) + DEBUG_CFLAGS=-g -DOMIT_QCC -DGL_STATIC -DFTE_TARGET_WEB + RELEASE_LDFLAGS=-s ASM_JS=1 -O2 -s TOTAL_MEMORY=$(ASMJS_MEMORY) $(EMCC_ARGS) # RELEASE_LDFLAGS=-s ASM_JS=0 -O1 -s TOTAL_MEMORY=$(WEB_MEMORY) $(EMCC_ARGS) DEBUG_LDLAGS=-O0 -s TOTAL_MEMORY=$(WEB_MEMORY) $(EMCC_ARGS) CC=emcc @@ -1311,7 +1341,7 @@ PRECOMPHEADERS ?= $(OUT_DIR)/quakedef.h.gch #god knows how gcc loads the list properly. #or at least I hope he does. It makes no sence to mortals. -DO_LD ?= $(CC) -o $@ $(LTO_LD) $(WCFLAGS) $(CFLAGS) +DO_LD ?= $(DO_ECHO) $(CC) -o $@ $(LTO_LD) $(WCFLAGS) $(CFLAGS) $(OUT_DIR)/$(EXE_NAME): $(PRECOMPHEADERS) $(foreach fn, $(CUSTOMOBJS) $(foreach ol, $(OBJS), $($(ol))),$(if $(findstring ltox,$(fn)),,$(OUT_DIR)/$(fn))) $(DO_LD) $(foreach fn, $(CUSTOMOBJS) $(foreach ol, $(OBJS) $(LTO_END), $($(ol))),$(if $(findstring ltox,$(fn)),$(subst ltox,-x ,$(fn)),$(NATIVE_OUT_DIR)/$(fn)) ) $(LDFLAGS) diff --git a/engine/client/cl_screen.c b/engine/client/cl_screen.c index 5661292d9..dc34bbda6 100644 --- a/engine/client/cl_screen.c +++ b/engine/client/cl_screen.c @@ -1383,7 +1383,7 @@ void SCR_SetLoadingFile(char *str) } } -void SCR_DrawLoading (void) +void SCR_DrawLoading (qboolean opaque) { int sizex, x, y; mpic_t *pic; @@ -1399,6 +1399,8 @@ void SCR_DrawLoading (void) R2D_ImageColours(1, 1, 1, 1); R2D_ScalePic (0, 0, vid.width, vid.height, pic); } + else if (opaque) + R2D_ConsoleBackground (0, vid.height, true); qdepth = COM_FDepthFile("gfx/loading.lmp", true); h2depth = COM_FDepthFile("gfx/menu/loading.lmp", true); @@ -1606,7 +1608,7 @@ void SCR_ImageName (char *mapname) scr_disabled_for_loading = false; scr_drawloading = true; GL_BeginRendering (); - SCR_DrawLoading(); + SCR_DrawLoading(false); SCR_SetUpToDrawConsole(); if (Key_Dest_Has(kdm_console) || !*levelshotname) SCR_DrawConsole(!!*levelshotname); @@ -2163,7 +2165,7 @@ void SCR_DrawTwoDimensional(int uimenu, qboolean nohud) if (scr_drawloading || loading_stage) { - SCR_DrawLoading(); + SCR_DrawLoading(false); SCR_ShowPics_Draw(); } diff --git a/engine/client/console.c b/engine/client/console.c index d1d7cc6a9..1250283df 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -910,7 +910,6 @@ void VARGS Con_DPrintf (const char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; - extern cvar_t log_developer; #ifdef CRAZYDEBUGGING va_start (argptr,fmt); @@ -919,6 +918,7 @@ void VARGS Con_DPrintf (const char *fmt, ...) Sys_Printf("%s", msg); return; #else + extern cvar_t log_developer; if (!developer.value && !log_developer.value) return; // early exit #endif diff --git a/engine/client/merged.h b/engine/client/merged.h index 8fcf85adb..149da3027 100644 --- a/engine/client/merged.h +++ b/engine/client/merged.h @@ -309,9 +309,10 @@ typedef struct rendererinfo_s { qboolean (*VID_Init) (rendererstate_t *info, unsigned char *palette); void (*VID_DeInit) (void); + void (*VID_SwapBuffers) (void); //force a buffer swap, regardless of what's displayed. qboolean (*VID_ApplyGammaRamps) (unsigned short *ramps); - char *(*VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight); void (*VID_SetWindowCaption) (char *msg); + char *(*VID_GetRGBInfo) (int prepad, int *truevidwidth, int *truevidheight); void (*SCR_UpdateScreen) (void); @@ -349,6 +350,8 @@ typedef struct rendererinfo_s { #define rf currentrendererstate.renderer +#define VID_SwapBuffers rf->VID_SwapBuffers + #define R_LoadTexture rf->IMG_LoadTexture #define R_LoadTexture8Pal24 rf->IMG_LoadTexture8Pal24 #define R_LoadTexture8Pal32 rf->IMG_LoadTexture8Pal32 diff --git a/engine/client/r_2d.c b/engine/client/r_2d.c index 3e86b0cc3..caf543efa 100644 --- a/engine/client/r_2d.c +++ b/engine/client/r_2d.c @@ -229,7 +229,7 @@ void R2D_Init(void) "blendfunc blend\n" "}\n" "}\n"); - shader_contrastup = R_RegisterShader("constrastupshader", SUF_NONE, + shader_contrastup = R_RegisterShader("contrastupshader", SUF_NONE, "{\n" "program defaultfill\n" "{\n" @@ -241,7 +241,7 @@ void R2D_Init(void) "}\n" "}\n" ); - shader_contrastdown = R_RegisterShader("constrastdownshader", SUF_NONE, + shader_contrastdown = R_RegisterShader("contrastdownshader", SUF_NONE, "{\n" "program defaultfill\n" "{\n" @@ -938,6 +938,7 @@ void R2D_BrightenScreen (void) if (r2d_canhwgamma) return; + TRACE(("R2D_BrightenScreen: brightening\n")); if (v_gamma.value != 1 && shader_gammacb->prog) { //this should really be done properly, with render-to-texture diff --git a/engine/client/renderer.c b/engine/client/renderer.c index fa3c43b6c..09c95ff6f 100644 --- a/engine/client/renderer.c +++ b/engine/client/renderer.c @@ -795,11 +795,10 @@ rendererinfo_t dedicatedrendererinfo = { NULL, //VID_Init, NULL, //VID_DeInit, + NULL, //VID_SwapBuffers NULL, //VID_ApplyGammaRamps, - NULL, //VID_GetRGBInfo, - - NULL, //set caption + NULL, //VID_GetRGBInfo, NULL, //SCR_UpdateScreen; @@ -832,6 +831,9 @@ rendererinfo_t *pdedicatedrendererinfo = &dedicatedrendererinfo; #ifdef GLQUAKE extern rendererinfo_t openglrendererinfo; rendererinfo_t eglrendererinfo; +extern rendererinfo_t rpirendererinfo; +rendererinfo_t waylandrendererinfo; +rendererinfo_t fbdevrendererinfo; #endif #ifdef D3DQUAKE rendererinfo_t d3d9rendererinfo; @@ -847,8 +849,13 @@ rendererinfo_t *rendererinfo[] = &dedicatedrendererinfo, #endif #ifdef GLQUAKE +#ifdef FTE_RPI + &rpirendererinfo, +#endif &openglrendererinfo, &eglrendererinfo, + &waylandrendererinfo, + &fbdevrendererinfo, #endif #ifdef D3DQUAKE &d3d9rendererinfo, diff --git a/engine/client/screen.h b/engine/client/screen.h index c2e00b8e3..ea13ab349 100644 --- a/engine/client/screen.h +++ b/engine/client/screen.h @@ -55,7 +55,7 @@ void SCR_ImageName (char *mapname); void RSpeedShow(void); void SCR_CrosshairPosition(playerview_t *pview, float *x, float *y); -void SCR_DrawLoading (void); +void SCR_DrawLoading (qboolean opaque); void SCR_TileClear (void); void SCR_DrawNotifyString (void); void SCR_CheckDrawCenterString (void); diff --git a/engine/client/sys_droid.c b/engine/client/sys_droid.c index 6052b6794..b332adade 100644 --- a/engine/client/sys_droid.c +++ b/engine/client/sys_droid.c @@ -1,621 +1,621 @@ -#include -#include - -#include - -#include "quakedef.h" -#include -#include -#include -#include -#include - -#ifndef isDedicated -#ifdef SERVERONLY -qboolean isDedicated = true; -#else -qboolean isDedicated = false; -#endif -#endif -void *sys_window; /*public so the renderer can attach to the correct place*/ -static int sys_running = false; -int sys_glesversion; -int sys_soundflags; /*1 means active. 2 means reset (so claim that its not active for one frame to force a reset)*/ -static void *sys_memheap; -static unsigned int sys_lastframe; -static unsigned int vibrateduration; -static char errormessage[256]; -static char sys_basedir[MAX_OSPATH]; -static char sys_basepak[MAX_OSPATH]; -extern jmp_buf host_abort; - -cvar_t sys_vibrate = CVARD("sys_vibrate", "1", "Enables the system vibrator for damage events and such things. The value provided is a duration scaler."); -cvar_t sys_osk = CVAR("sys_osk", "0"); //to be toggled -cvar_t sys_keepscreenon = CVARD("sys_keepscreenon", "1", "If set, the screen will never darken. This might cost some extra battery power, but then so will running a 3d engine."); //to be toggled -cvar_t sys_orientation = CVARD("sys_orientation", "landscape", "Specifies what angle to render quake at.\nValid values are: sensor (autodetect), landscape, portrait, reverselandscape, reverseportrait"); -cvar_t sys_glesversion_cvar = CVARD("sys_glesversion", "1", "Specifies which version of gles to use. 1 or 2 are valid values."); -extern cvar_t vid_conautoscale; - - -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, DISTRIBUTION"Droid", __VA_ARGS__)) -#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, DISTRIBUTION"Droid", __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, DISTRIBUTION"Droid", __VA_ARGS__)) - -void Sys_Vibrate(float count) -{ - if (count < 0) - count = 0; - vibrateduration += count*10*sys_vibrate.value; -} -JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getvibrateduration(JNIEnv *env, jobject obj) -{ - unsigned int dur = vibrateduration; - vibrateduration = 0; - return dur; -} - -JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_geterrormessage(JNIEnv *env, jobject obj) -{ - return (*env)->NewStringUTF(env, errormessage); -} -JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedorientation(JNIEnv *env, jobject obj) -{ - sys_orientation.modified = false; - sys_glesversion_cvar.modified = false; - return (*env)->NewStringUTF(env, sys_orientation.string); -} - -JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedglesversion(JNIEnv *env, jobject obj) -{ - return sys_glesversion_cvar.ival; -} - -/*the java passes in all input directly via a 'UI' thread. we don't need to poll it at all*/ +#include +#include + +#include + +#include "quakedef.h" +#include +#include +#include +#include +#include + +#ifndef isDedicated +#ifdef SERVERONLY +qboolean isDedicated = true; +#else +qboolean isDedicated = false; +#endif +#endif +void *sys_window; /*public so the renderer can attach to the correct place*/ +static int sys_running = false; +int sys_glesversion; +int sys_soundflags; /*1 means active. 2 means reset (so claim that its not active for one frame to force a reset)*/ +static void *sys_memheap; +static unsigned int sys_lastframe; +static unsigned int vibrateduration; +static char errormessage[256]; +static char sys_basedir[MAX_OSPATH]; +static char sys_basepak[MAX_OSPATH]; +extern jmp_buf host_abort; + +cvar_t sys_vibrate = CVARD("sys_vibrate", "1", "Enables the system vibrator for damage events and such things. The value provided is a duration scaler."); +cvar_t sys_osk = CVAR("sys_osk", "0"); //to be toggled +cvar_t sys_keepscreenon = CVARD("sys_keepscreenon", "1", "If set, the screen will never darken. This might cost some extra battery power, but then so will running a 3d engine."); //to be toggled +cvar_t sys_orientation = CVARD("sys_orientation", "landscape", "Specifies what angle to render quake at.\nValid values are: sensor (autodetect), landscape, portrait, reverselandscape, reverseportrait"); +cvar_t sys_glesversion_cvar = CVARD("sys_glesversion", "1", "Specifies which version of gles to use. 1 or 2 are valid values."); +extern cvar_t vid_conautoscale; + + +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, DISTRIBUTION"Droid", __VA_ARGS__)) +#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, DISTRIBUTION"Droid", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, DISTRIBUTION"Droid", __VA_ARGS__)) + +void Sys_Vibrate(float count) +{ + if (count < 0) + count = 0; + vibrateduration += count*10*sys_vibrate.value; +} +JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getvibrateduration(JNIEnv *env, jobject obj) +{ + unsigned int dur = vibrateduration; + vibrateduration = 0; + return dur; +} + +JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_geterrormessage(JNIEnv *env, jobject obj) +{ + return (*env)->NewStringUTF(env, errormessage); +} +JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedorientation(JNIEnv *env, jobject obj) +{ + sys_orientation.modified = false; + sys_glesversion_cvar.modified = false; + return (*env)->NewStringUTF(env, sys_orientation.string); +} + +JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedglesversion(JNIEnv *env, jobject obj) +{ + return sys_glesversion_cvar.ival; +} + +/*the java passes in all input directly via a 'UI' thread. we don't need to poll it at all*/ void INS_Move(float *movements, int pnum) { -} +} void INS_Commands(void) { -} +} void INS_Init(void) { -} +} void INS_ReInit(void) { -} +} void INS_Shutdown(void) { -} -JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_keypress(JNIEnv *env, jobject obj, - jint down, jint keycode, jint unicode) -{ - IN_KeyEvent(0, down, keycode, unicode); -} -JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion(JNIEnv *env, jobject obj, - jint act, jint ptrid, jfloat x, jfloat y, jfloat size) -{ - if (act) - IN_KeyEvent(ptrid, act==1, K_MOUSE1, 0); - else - IN_MouseMove(ptrid, true, x, y, 0, size); -} - -JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_frame(JNIEnv *env, jobject obj, - jfloat ax, jfloat ay, jfloat az) -{ - int ret; - static vec3_t oac; - - //if we had an error, don't even run a frame any more. - if (*errormessage || !sys_running) - { - Sys_Printf("Crashed or quit\n"); - return 8; - } - - #ifdef SERVERONLY - SV_Frame(); - #else - unsigned int now = Sys_Milliseconds(); - double tdelta = (now - sys_lastframe) * 0.001; - if (oac[0] != ax || oac[1] != ay || oac[2] != az) - { - //down: x= +9.8 - //left: y= -9.8 - //up: z= +9.8 - CSQC_Accelerometer(ax, ay, az); - oac[0] = ax; - oac[1] = ay; - oac[2] = az; - } - Host_Frame(tdelta); - sys_lastframe = now; - #endif - - ret = 0; - if (Key_Dest_Has(kdm_console|kdm_message) || (!Key_Dest_Has(~kdm_game) && cls.state == ca_disconnected) || sys_osk.ival) - ret |= 1; - if (vibrateduration) - ret |= 2; - if (sys_keepscreenon.ival) - ret |= 4; - if (*errormessage) - ret |= 8; - if (sys_orientation.modified || sys_glesversion_cvar.modified) - ret |= 16; - if (sys_soundflags) - { - if (sys_soundflags & 2) - sys_soundflags &= ~2; - else - ret |= 32; - } - return ret; -} - -//tells us that our old gl context got completely obliterated -JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_newglcontext(JNIEnv *env, jobject obj) -{ - if (sys_running) - sys_running = 2; - - //fixme: wipe image handles -} - -//called when the user tries to use us to open one of our file types -JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_openfile(JNIEnv *env, jobject obj, - jstring openfile) -{ - const char *fname = (*env)->GetStringUTFChars(env, openfile, NULL); - Host_RunFile(fname, strlen(fname), NULL); - (*env)->ReleaseStringUTFChars(env, openfile, fname); -} - -//called for init or resizes -JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_init(JNIEnv *env, jobject obj, - jint width, jint height, jint glesversion, jstring japkpath, jstring jusrpath) -{ - const char *tmp; - - if (*errormessage) - return; - - vid.pixelwidth = width; - vid.pixelheight = height; - sys_glesversion = glesversion; - if (sys_running) - { - Sys_Printf("vid size changed\n"); - if (1)//FFS sys_running == 2) - { - //if our textures got destroyed, we need to reload them all - Cmd_ExecuteString("vid_restart\n", RESTRICT_LOCAL); - } - else - { - //otherwise we just need to set the size properly again. - Cvar_ForceCallback(&vid_conautoscale); - } - } - else - { - const char *args [] = - { - "ftedroid", - "-basepack", - sys_basepak, /*filled in later*/ - "", - "" - }; - char *basepack; - int align; - quakeparms_t parms; - Sys_Printf("reinit\n"); - if (sys_memheap) - free(sys_memheap); - memset(&parms, 0, sizeof(parms)); - parms.basedir = sys_basedir; /*filled in later*/ - parms.argc = 3; - parms.argv = args; - - tmp = (*env)->GetStringUTFChars(env, japkpath, NULL); - Q_strncpyz(sys_basepak, tmp, sizeof(sys_basedir)); - (*env)->ReleaseStringUTFChars(env, japkpath, tmp); - - tmp = (*env)->GetStringUTFChars(env, jusrpath, NULL); - Q_strncpyz(sys_basedir, tmp, sizeof(sys_basedir)); - (*env)->ReleaseStringUTFChars(env, jusrpath, tmp); - - - Sys_Printf("Starting up (apk=%s, usr=%s)\n", args[2], parms.basedir); - - COM_InitArgv(parms.argc, parms.argv); - TL_InitLanguages(); - #ifdef SERVERONLY - SV_Init(&parms); - #else - Host_Init(&parms); - #endif - sys_running = true; - sys_lastframe = Sys_Milliseconds(); - sys_orientation.modified = true; - } -} - -static int secbase; - -#ifdef _POSIX_TIMERS -double Sys_DoubleTime(void) -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - - if (!secbase) - { - secbase = ts.tv_sec; - return ts.tv_nsec/1000000000.0; - } - return (ts.tv_sec - secbase) + ts.tv_nsec/1000000000.0; -} -unsigned int Sys_Milliseconds(void) -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - - if (!secbase) - { - secbase = ts.tv_sec; - return ts.tv_nsec/1000000; - } - return (ts.tv_sec - secbase)*1000 + ts.tv_nsec/1000000; -} -#else -double Sys_DoubleTime(void) -{ - struct timeval tp; - struct timezone tzp; - - gettimeofday(&tp, &tzp); - - if (!secbase) - { - secbase = tp.tv_sec; - return tp.tv_usec/1000000.0; - } - - return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; -} -unsigned int Sys_Milliseconds(void) -{ - struct timeval tp; - struct timezone tzp; - - gettimeofday(&tp, &tzp); - - if (!secbase) - { - secbase = tp.tv_sec; - return tp.tv_usec/1000; - } - - return (tp.tv_sec - secbase)*1000 + tp.tv_usec/1000; -} -#endif - -void Sys_Shutdown(void) -{ - free(sys_memheap); -} -void Sys_Quit(void) -{ -#ifndef SERVERONLY - Host_Shutdown (); -#else - SV_Shutdown(); -#endif - - LOGI("%s", "quitting"); - - longjmp(host_abort, 1); - exit(0); -} -void Sys_Error (const char *error, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, error); - vsnprintf (string,sizeof(string)-1, error,argptr); - va_end (argptr); - if (!*string) - strcpy(string, "no error"); - - Q_strncpyz(errormessage, string, sizeof(errormessage)); - - LOGE("%s", string); - - longjmp(host_abort, 1); - exit(1); -} -void Sys_Printf (char *fmt, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, fmt); - vsnprintf (string,sizeof(string)-1, fmt,argptr); - va_end (argptr); - - LOGI("%s", string); -} -void Sys_Warn (char *fmt, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, fmt); - vsnprintf (string,sizeof(string)-1, fmt,argptr); - va_end (argptr); - - LOGW("%s", string); -} - -void Sys_CloseLibrary(dllhandle_t *lib) -{ - dlclose(lib); -} -dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) -{ - dllhandle_t *h; - h = dlopen(name, RTLD_LAZY); - return h; -} -void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) -{ - return dlsym(module, exportname); -} -char *Sys_ConsoleInput (void) -{ - return NULL; -} -void Sys_mkdir (char *path) //not all pre-unix systems have directories (including dos 1) -{ - mkdir(path, 0777); -} -qboolean Sys_remove (char *path) -{ - return !unlink(path); -} -qboolean Sys_Rename (char *oldfname, char *newfname) -{ - return !rename(oldfname, newfname); -} -void Sys_SendKeyEvents(void) -{ -} -void Sys_Init(void) -{ - Cvar_Register(&sys_vibrate, "android stuff"); - Cvar_Register(&sys_osk, "android stuff"); - Cvar_Register(&sys_keepscreenon, "android stuff"); - Cvar_Register(&sys_orientation, "android stuff"); - Cvar_Register(&sys_glesversion_cvar, "android stuff"); -} - -qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refreshrate) -{ - *width = 320; - *height = 240; - *bpp = 16; - *refreshrate = 60; - return false; -} -qboolean Sys_RandomBytes(qbyte *string, int len) -{ - qboolean res = false; - int fd = open("/dev/urandom", 0); - if (fd >= 0) - { - res = (read(fd, string, len) == len); - close(fd); - } - - return res; -} - -void Sys_ServerActivity(void) -{ - /*FIXME: flash window*/ -} -void Sys_Sleep (double seconds) -{ - struct timespec ts; - - ts.tv_sec = (time_t)seconds; - seconds -= ts.tv_sec; - ts.tv_nsec = seconds * 1000000000.0; - - nanosleep(&ts, NULL); -} -qboolean Sys_InitTerminal(void) -{ - /*switching to dedicated mode, show text window*/ - return false; -} -void Sys_CloseTerminal(void) -{ -} - -#define SYS_CLIPBOARD_SIZE 256 -static char clipboard_buffer[SYS_CLIPBOARD_SIZE] = {0}; -char *Sys_GetClipboard(void) -{ - return clipboard_buffer; -} -void Sys_CloseClipboard(char *bf) -{ -} -void Sys_SaveClipboard(char *text) -{ - Q_strncpyz(clipboard_buffer, text, SYS_CLIPBOARD_SIZE); -} - - -int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, qofs_t, void *, searchpathfuncs_t *), void *parm, searchpathfuncs_t *spath) -{ - DIR *dir; - char apath[MAX_OSPATH]; - char file[MAX_OSPATH]; - char truepath[MAX_OSPATH]; - char *s; - struct dirent *ent; - struct stat st; - - //printf("path = %s\n", gpath); - //printf("match = %s\n", match); - - if (!gpath) - gpath = ""; - *apath = '\0'; - - Q_strncpyz(apath, match, sizeof(apath)); - for (s = apath+strlen(apath)-1; s >= apath; s--) - { - if (*s == '/') - { - s[1] = '\0'; - match += s - apath+1; - break; - } - } - if (s < apath) //didn't find a '/' - *apath = '\0'; - - Q_snprintfz(truepath, sizeof(truepath), "%s/%s", gpath, apath); - - - //printf("truepath = %s\n", truepath); - //printf("gamepath = %s\n", gpath); - //printf("apppath = %s\n", apath); - //printf("match = %s\n", match); - dir = opendir(truepath); - if (!dir) - { - Con_DPrintf("Failed to open dir %s\n", truepath); - return true; - } - do - { - ent = readdir(dir); - if (!ent) - break; - if (*ent->d_name != '.') - { - if (wildcmp(match, ent->d_name)) - { - Q_snprintfz(file, sizeof(file), "%s/%s", truepath, ent->d_name); - - if (stat(file, &st) == 0) - { - Q_snprintfz(file, sizeof(file), "%s%s%s", apath, ent->d_name, S_ISDIR(st.st_mode)?"/":""); - - if (!func(file, st.st_size, parm, spath)) - { - closedir(dir); - return false; - } - } - else - printf("Stat failed for \"%s\"\n", file); - } - } - } while(1); - closedir(dir); - - return true; -} - -#if 0 -#include -int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, qofs_t, void *), void *parm) -{ - qboolean go = true; - const char *f; - - struct AAssetDir *ad; - ad = AAssetManager_openDir(assetmgr, gpath); - - while(go && (f = AAssetDir_getNextFileName(ad))) - { - if (wildcmp(match, f)) - { -Sys_Printf("Found %s\n", f); - go = func(f, 0, parm); - } - } - - AAssetDir_close(ad); - return 0; -} - -typedef struct -{ - vfsfile_t funcs; - AAsset *handle; -} assetfile_t; -static int AF_ReadBytes(vfsfile_t *h, void *buf, int len) -{ - assetfile_t *f = (assetfile_t*)h; - return AAsset_read(f->handle, buf, len); -} -static qboolean AF_Seek(vfsfile_t *h, unsigned long offs) -{ - assetfile_t *f = (assetfile_t*)h; - AAsset_seek(f->handle, offs, SEEK_SET); - return true; -} -static unsigned long AF_Tell(vfsfile_t *h) -{ - assetfile_t *f = (assetfile_t*)h; - return AAsset_seek(f->handle, 0, SEEK_CUR); -} -static unsigned long AF_GetSize(vfsfile_t *h) -{ - assetfile_t *f = (assetfile_t*)h; - return AAsset_getLength(f->handle); -} - -static void AF_Close(vfsfile_t *h) -{ - assetfile_t *f = (assetfile_t*)h; - AAsset_close(f->handle); - Z_Free(f); -} -static void AF_Flush(vfsfile_t *h) -{ -} -vfsfile_t *Sys_OpenAsset(char *fname) -{ - assetfile_t *file; - AAsset *a; - a = AAssetManager_open(assetmgr, fname, AASSET_MODE_UNKNOWN); - if (!a) - { - Sys_Printf("Unable to open asset %s\n", fname); - return NULL; - } - Sys_Printf("opened asset %s\n", fname); - - file = Z_Malloc(sizeof(assetfile_t)); - file->funcs.ReadBytes = AF_ReadBytes; - file->funcs.WriteBytes = NULL; - file->funcs.Seek = AF_Seek; - file->funcs.Tell = AF_Tell; - file->funcs.GetLen = AF_GetSize; - file->funcs.Close = AF_Close; - file->funcs.Flush = AF_Flush; - file->handle = a; - - return (vfsfile_t*)file; -} -#endif +} +JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_keypress(JNIEnv *env, jobject obj, + jint down, jint keycode, jint unicode) +{ + IN_KeyEvent(0, down, keycode, unicode); +} +JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion(JNIEnv *env, jobject obj, + jint act, jint ptrid, jfloat x, jfloat y, jfloat size) +{ + if (act) + IN_KeyEvent(ptrid, act==1, K_MOUSE1, 0); + else + IN_MouseMove(ptrid, true, x, y, 0, size); +} + +JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_frame(JNIEnv *env, jobject obj, + jfloat ax, jfloat ay, jfloat az) +{ + int ret; + static vec3_t oac; + + //if we had an error, don't even run a frame any more. + if (*errormessage || !sys_running) + { + Sys_Printf("Crashed or quit\n"); + return 8; + } + + #ifdef SERVERONLY + SV_Frame(); + #else + unsigned int now = Sys_Milliseconds(); + double tdelta = (now - sys_lastframe) * 0.001; + if (oac[0] != ax || oac[1] != ay || oac[2] != az) + { + //down: x= +9.8 + //left: y= -9.8 + //up: z= +9.8 + CSQC_Accelerometer(ax, ay, az); + oac[0] = ax; + oac[1] = ay; + oac[2] = az; + } + Host_Frame(tdelta); + sys_lastframe = now; + #endif + + ret = 0; + if (Key_Dest_Has(kdm_console|kdm_message) || (!Key_Dest_Has(~kdm_game) && cls.state == ca_disconnected) || sys_osk.ival) + ret |= 1; + if (vibrateduration) + ret |= 2; + if (sys_keepscreenon.ival) + ret |= 4; + if (*errormessage) + ret |= 8; + if (sys_orientation.modified || sys_glesversion_cvar.modified) + ret |= 16; + if (sys_soundflags) + { + if (sys_soundflags & 2) + sys_soundflags &= ~2; + else + ret |= 32; + } + return ret; +} + +//tells us that our old gl context got completely obliterated +JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_newglcontext(JNIEnv *env, jobject obj) +{ + if (sys_running) + sys_running = 2; + + //fixme: wipe image handles +} + +//called when the user tries to use us to open one of our file types +JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_openfile(JNIEnv *env, jobject obj, + jstring openfile) +{ + const char *fname = (*env)->GetStringUTFChars(env, openfile, NULL); + Host_RunFile(fname, strlen(fname), NULL); + (*env)->ReleaseStringUTFChars(env, openfile, fname); +} + +//called for init or resizes +JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_init(JNIEnv *env, jobject obj, + jint width, jint height, jint glesversion, jstring japkpath, jstring jusrpath) +{ + const char *tmp; + + if (*errormessage) + return; + + vid.pixelwidth = width; + vid.pixelheight = height; + sys_glesversion = glesversion; + if (sys_running) + { + Sys_Printf("vid size changed\n"); + if (1)//FFS sys_running == 2) + { + //if our textures got destroyed, we need to reload them all + Cmd_ExecuteString("vid_restart\n", RESTRICT_LOCAL); + } + else + { + //otherwise we just need to set the size properly again. + Cvar_ForceCallback(&vid_conautoscale); + } + } + else + { + const char *args [] = + { + "ftedroid", + "-basepack", + sys_basepak, /*filled in later*/ + "", + "" + }; + char *basepack; + int align; + quakeparms_t parms; + Sys_Printf("reinit\n"); + if (sys_memheap) + free(sys_memheap); + memset(&parms, 0, sizeof(parms)); + parms.basedir = sys_basedir; /*filled in later*/ + parms.argc = 3; + parms.argv = args; + + tmp = (*env)->GetStringUTFChars(env, japkpath, NULL); + Q_strncpyz(sys_basepak, tmp, sizeof(sys_basedir)); + (*env)->ReleaseStringUTFChars(env, japkpath, tmp); + + tmp = (*env)->GetStringUTFChars(env, jusrpath, NULL); + Q_strncpyz(sys_basedir, tmp, sizeof(sys_basedir)); + (*env)->ReleaseStringUTFChars(env, jusrpath, tmp); + + + Sys_Printf("Starting up (apk=%s, usr=%s)\n", args[2], parms.basedir); + + COM_InitArgv(parms.argc, parms.argv); + TL_InitLanguages(); + #ifdef SERVERONLY + SV_Init(&parms); + #else + Host_Init(&parms); + #endif + sys_running = true; + sys_lastframe = Sys_Milliseconds(); + sys_orientation.modified = true; + } +} + +static int secbase; + +#ifdef _POSIX_TIMERS +double Sys_DoubleTime(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + if (!secbase) + { + secbase = ts.tv_sec; + return ts.tv_nsec/1000000000.0; + } + return (ts.tv_sec - secbase) + ts.tv_nsec/1000000000.0; +} +unsigned int Sys_Milliseconds(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + if (!secbase) + { + secbase = ts.tv_sec; + return ts.tv_nsec/1000000; + } + return (ts.tv_sec - secbase)*1000 + ts.tv_nsec/1000000; +} +#else +double Sys_DoubleTime(void) +{ + struct timeval tp; + struct timezone tzp; + + gettimeofday(&tp, &tzp); + + if (!secbase) + { + secbase = tp.tv_sec; + return tp.tv_usec/1000000.0; + } + + return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; +} +unsigned int Sys_Milliseconds(void) +{ + struct timeval tp; + struct timezone tzp; + + gettimeofday(&tp, &tzp); + + if (!secbase) + { + secbase = tp.tv_sec; + return tp.tv_usec/1000; + } + + return (tp.tv_sec - secbase)*1000 + tp.tv_usec/1000; +} +#endif + +void Sys_Shutdown(void) +{ + free(sys_memheap); +} +void Sys_Quit(void) +{ +#ifndef SERVERONLY + Host_Shutdown (); +#else + SV_Shutdown(); +#endif + + LOGI("%s", "quitting"); + + longjmp(host_abort, 1); + exit(0); +} +void Sys_Error (const char *error, ...) +{ + va_list argptr; + char string[1024]; + + va_start (argptr, error); + vsnprintf (string,sizeof(string)-1, error,argptr); + va_end (argptr); + if (!*string) + strcpy(string, "no error"); + + Q_strncpyz(errormessage, string, sizeof(errormessage)); + + LOGE("%s", string); + + longjmp(host_abort, 1); + exit(1); +} +void Sys_Printf (char *fmt, ...) +{ + va_list argptr; + char string[1024]; + + va_start (argptr, fmt); + vsnprintf (string,sizeof(string)-1, fmt,argptr); + va_end (argptr); + + LOGI("%s", string); +} +void Sys_Warn (char *fmt, ...) +{ + va_list argptr; + char string[1024]; + + va_start (argptr, fmt); + vsnprintf (string,sizeof(string)-1, fmt,argptr); + va_end (argptr); + + LOGW("%s", string); +} + +void Sys_CloseLibrary(dllhandle_t *lib) +{ + dlclose(lib); +} +dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) +{ + dllhandle_t *h; + h = dlopen(name, RTLD_LAZY); + return h; +} +void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) +{ + return dlsym(module, exportname); +} +char *Sys_ConsoleInput (void) +{ + return NULL; +} +void Sys_mkdir (char *path) //not all pre-unix systems have directories (including dos 1) +{ + mkdir(path, 0777); +} +qboolean Sys_remove (char *path) +{ + return !unlink(path); +} +qboolean Sys_Rename (char *oldfname, char *newfname) +{ + return !rename(oldfname, newfname); +} +void Sys_SendKeyEvents(void) +{ +} +void Sys_Init(void) +{ + Cvar_Register(&sys_vibrate, "android stuff"); + Cvar_Register(&sys_osk, "android stuff"); + Cvar_Register(&sys_keepscreenon, "android stuff"); + Cvar_Register(&sys_orientation, "android stuff"); + Cvar_Register(&sys_glesversion_cvar, "android stuff"); +} + +qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refreshrate) +{ + *width = 320; + *height = 240; + *bpp = 16; + *refreshrate = 60; + return false; +} +qboolean Sys_RandomBytes(qbyte *string, int len) +{ + qboolean res = false; + int fd = open("/dev/urandom", 0); + if (fd >= 0) + { + res = (read(fd, string, len) == len); + close(fd); + } + + return res; +} + +void Sys_ServerActivity(void) +{ + /*FIXME: flash window*/ +} +void Sys_Sleep (double seconds) +{ + struct timespec ts; + + ts.tv_sec = (time_t)seconds; + seconds -= ts.tv_sec; + ts.tv_nsec = seconds * 1000000000.0; + + nanosleep(&ts, NULL); +} +qboolean Sys_InitTerminal(void) +{ + /*switching to dedicated mode, show text window*/ + return false; +} +void Sys_CloseTerminal(void) +{ +} + +#define SYS_CLIPBOARD_SIZE 256 +static char clipboard_buffer[SYS_CLIPBOARD_SIZE] = {0}; +char *Sys_GetClipboard(void) +{ + return clipboard_buffer; +} +void Sys_CloseClipboard(char *bf) +{ +} +void Sys_SaveClipboard(char *text) +{ + Q_strncpyz(clipboard_buffer, text, SYS_CLIPBOARD_SIZE); +} + + +int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, qofs_t, void *, searchpathfuncs_t *), void *parm, searchpathfuncs_t *spath) +{ + DIR *dir; + char apath[MAX_OSPATH]; + char file[MAX_OSPATH]; + char truepath[MAX_OSPATH]; + char *s; + struct dirent *ent; + struct stat st; + + //printf("path = %s\n", gpath); + //printf("match = %s\n", match); + + if (!gpath) + gpath = ""; + *apath = '\0'; + + Q_strncpyz(apath, match, sizeof(apath)); + for (s = apath+strlen(apath)-1; s >= apath; s--) + { + if (*s == '/') + { + s[1] = '\0'; + match += s - apath+1; + break; + } + } + if (s < apath) //didn't find a '/' + *apath = '\0'; + + Q_snprintfz(truepath, sizeof(truepath), "%s/%s", gpath, apath); + + + //printf("truepath = %s\n", truepath); + //printf("gamepath = %s\n", gpath); + //printf("apppath = %s\n", apath); + //printf("match = %s\n", match); + dir = opendir(truepath); + if (!dir) + { + Con_DPrintf("Failed to open dir %s\n", truepath); + return true; + } + do + { + ent = readdir(dir); + if (!ent) + break; + if (*ent->d_name != '.') + { + if (wildcmp(match, ent->d_name)) + { + Q_snprintfz(file, sizeof(file), "%s/%s", truepath, ent->d_name); + + if (stat(file, &st) == 0) + { + Q_snprintfz(file, sizeof(file), "%s%s%s", apath, ent->d_name, S_ISDIR(st.st_mode)?"/":""); + + if (!func(file, st.st_size, parm, spath)) + { + closedir(dir); + return false; + } + } + else + printf("Stat failed for \"%s\"\n", file); + } + } + } while(1); + closedir(dir); + + return true; +} + +#if 0 +#include +int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, qofs_t, void *), void *parm) +{ + qboolean go = true; + const char *f; + + struct AAssetDir *ad; + ad = AAssetManager_openDir(assetmgr, gpath); + + while(go && (f = AAssetDir_getNextFileName(ad))) + { + if (wildcmp(match, f)) + { +Sys_Printf("Found %s\n", f); + go = func(f, 0, parm); + } + } + + AAssetDir_close(ad); + return 0; +} + +typedef struct +{ + vfsfile_t funcs; + AAsset *handle; +} assetfile_t; +static int AF_ReadBytes(vfsfile_t *h, void *buf, int len) +{ + assetfile_t *f = (assetfile_t*)h; + return AAsset_read(f->handle, buf, len); +} +static qboolean AF_Seek(vfsfile_t *h, unsigned long offs) +{ + assetfile_t *f = (assetfile_t*)h; + AAsset_seek(f->handle, offs, SEEK_SET); + return true; +} +static unsigned long AF_Tell(vfsfile_t *h) +{ + assetfile_t *f = (assetfile_t*)h; + return AAsset_seek(f->handle, 0, SEEK_CUR); +} +static unsigned long AF_GetSize(vfsfile_t *h) +{ + assetfile_t *f = (assetfile_t*)h; + return AAsset_getLength(f->handle); +} + +static void AF_Close(vfsfile_t *h) +{ + assetfile_t *f = (assetfile_t*)h; + AAsset_close(f->handle); + Z_Free(f); +} +static void AF_Flush(vfsfile_t *h) +{ +} +vfsfile_t *Sys_OpenAsset(char *fname) +{ + assetfile_t *file; + AAsset *a; + a = AAssetManager_open(assetmgr, fname, AASSET_MODE_UNKNOWN); + if (!a) + { + Sys_Printf("Unable to open asset %s\n", fname); + return NULL; + } + Sys_Printf("opened asset %s\n", fname); + + file = Z_Malloc(sizeof(assetfile_t)); + file->funcs.ReadBytes = AF_ReadBytes; + file->funcs.WriteBytes = NULL; + file->funcs.Seek = AF_Seek; + file->funcs.Tell = AF_Tell; + file->funcs.GetLen = AF_GetSize; + file->funcs.Close = AF_Close; + file->funcs.Flush = AF_Flush; + file->handle = a; + + return (vfsfile_t*)file; +} +#endif diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index 24889d669..45c6693c2 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -201,6 +201,8 @@ void Sys_Printf (char *fmt, ...) putc(tab[w&31], stdout); } } + else if (w < ' ' && w != '\t' && w != '\r' && w != '\n') + putc('?', stdout); //don't let anyone print escape codes or other things that could crash an xterm. else { /*putwc doesn't like me. force it in utf8*/ @@ -731,7 +733,6 @@ int main (int c, const char **v) { double time, oldtime, newtime; quakeparms_t parms; - int j; // char cwd[1024]; char bindir[1024]; diff --git a/engine/client/valid.c b/engine/client/valid.c index 2c89030ae..a4382b9c0 100644 --- a/engine/client/valid.c +++ b/engine/client/valid.c @@ -547,7 +547,7 @@ void Validation_Apply_Ruleset(void) } if (!rs->rulesetname) { - Con_Printf("Cannot apply ruleset %s - not recognised\n", rs->rulesetname); + Con_Printf("Cannot apply ruleset %s - not recognised\n", ruleset.string); return; } diff --git a/engine/client/vid.h b/engine/client/vid.h index b85c4a1d5..bd9ec0f88 100644 --- a/engine/client/vid.h +++ b/engine/client/vid.h @@ -102,8 +102,9 @@ int GLVID_SetMode (rendererstate_t *info, unsigned char *palette); // sets the mode; only used by the Quake engine for resetting to mode 0 (the // base mode) on memory allocation failures -qboolean GLVID_Is8bit(); +qboolean GLVID_Is8bit(void); +void GLVID_SwapBuffers(void); char *GLVID_GetRGBInfo(int prepadbytes, int *truewidth, int *trueheight); void GLVID_SetCaption(char *caption); #endif diff --git a/engine/common/fs.c b/engine/common/fs.c index 48664e1e3..a8a439ab2 100644 --- a/engine/common/fs.c +++ b/engine/common/fs.c @@ -590,11 +590,11 @@ void COM_Locate_f (void) { if (!*loc.rawname) { - Con_Printf("File is %i bytes compressed inside %s\n", loc.len, loc.search->logicalpath); + Con_Printf("File is %u bytes compressed inside %s\n", (unsigned)loc.len, loc.search->logicalpath); } else { - Con_Printf("Inside %s (%i bytes)\n %s\n", loc.rawname, loc.len, loc.search->logicalpath); + Con_Printf("Inside %s (%u bytes)\n %s\n", loc.rawname, (unsigned)loc.len, loc.search->logicalpath); } } else diff --git a/engine/common/fs_stdio.c b/engine/common/fs_stdio.c index d9c4cb4e0..51aa19ea8 100644 --- a/engine/common/fs_stdio.c +++ b/engine/common/fs_stdio.c @@ -300,7 +300,7 @@ static void QDECL FSSTDIO_ReadFile(searchpathfuncs_t *handle, flocation_t *loc, result = fread(buffer, 1, loc->len, f); // do soemthing with result if (result != loc->len) - Con_Printf("FSSTDIO_ReadFile() fread: Filename: %s, expected %i, result was %u (%s)\n",loc->rawname,loc->len,(unsigned int)result,strerror(errno)); + Con_Printf("FSSTDIO_ReadFile() fread: Filename: %s, expected %u, result was %u (%s)\n",loc->rawname,(unsigned int)loc->len,(unsigned int)result,strerror(errno)); fclose(f); } diff --git a/engine/common/net_ssl_gnutls.c b/engine/common/net_ssl_gnutls.c index 254cae139..e9396f8d0 100644 --- a/engine/common/net_ssl_gnutls.c +++ b/engine/common/net_ssl_gnutls.c @@ -27,43 +27,43 @@ typedef struct DSTRUCT* gnutls_anon_client_credentials; struct gnutls_session_int; typedef struct gnutls_session_int* gnutls_session_t; typedef void * gnutls_transport_ptr_t; -struct gnutls_x509_crt_int; +struct gnutls_x509_crt_int; typedef struct gnutls_x509_crt_int *gnutls_x509_crt_t; -typedef struct -{ - unsigned char *data; - unsigned int size; +typedef struct +{ + unsigned char *data; + unsigned int size; } gnutls_datum_t; typedef enum gnutls_kx_algorithm { GNUTLS_KX_RSA=1, GNUTLS_KX_DHE_DSS, GNUTLS_KX_DHE_RSA, GNUTLS_KX_ANON_DH, GNUTLS_KX_SRP, GNUTLS_KX_RSA_EXPORT, GNUTLS_KX_SRP_RSA, GNUTLS_KX_SRP_DSS } gnutls_kx_algorithm; -typedef enum { - GNUTLS_CRT_UNKNOWN = 0, - GNUTLS_CRT_X509 = 1, - GNUTLS_CRT_OPENPGP = 2, - GNUTLS_CRT_RAW = 3 +typedef enum { + GNUTLS_CRT_UNKNOWN = 0, + GNUTLS_CRT_X509 = 1, + GNUTLS_CRT_OPENPGP = 2, + GNUTLS_CRT_RAW = 3 } gnutls_certificate_type_t; -typedef enum { - GNUTLS_X509_FMT_DER = 0, - GNUTLS_X509_FMT_PEM = 1 +typedef enum { + GNUTLS_X509_FMT_DER = 0, + GNUTLS_X509_FMT_PEM = 1 } gnutls_x509_crt_fmt_t; -typedef enum -{ - GNUTLS_CERT_INVALID = 1<<1, - GNUTLS_CERT_REVOKED = 1<<5, - GNUTLS_CERT_SIGNER_NOT_FOUND = 1<<6, - GNUTLS_CERT_SIGNER_NOT_CA = 1<<7, - GNUTLS_CERT_INSECURE_ALGORITHM = 1<<8, - GNUTLS_CERT_NOT_ACTIVATED = 1<<9, - GNUTLS_CERT_EXPIRED = 1<<10, - GNUTLS_CERT_SIGNATURE_FAILURE = 1<<11, - GNUTLS_CERT_REVOCATION_DATA_SUPERSEDED = 1<<12, - GNUTLS_CERT_UNEXPECTED_OWNER = 1<<14, - GNUTLS_CERT_REVOCATION_DATA_ISSUED_IN_FUTURE = 1<<15, - GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE = 1<<16, - GNUTLS_CERT_MISMATCH = 1<<17, +typedef enum +{ + GNUTLS_CERT_INVALID = 1<<1, + GNUTLS_CERT_REVOKED = 1<<5, + GNUTLS_CERT_SIGNER_NOT_FOUND = 1<<6, + GNUTLS_CERT_SIGNER_NOT_CA = 1<<7, + GNUTLS_CERT_INSECURE_ALGORITHM = 1<<8, + GNUTLS_CERT_NOT_ACTIVATED = 1<<9, + GNUTLS_CERT_EXPIRED = 1<<10, + GNUTLS_CERT_SIGNATURE_FAILURE = 1<<11, + GNUTLS_CERT_REVOCATION_DATA_SUPERSEDED = 1<<12, + GNUTLS_CERT_UNEXPECTED_OWNER = 1<<14, + GNUTLS_CERT_REVOCATION_DATA_ISSUED_IN_FUTURE = 1<<15, + GNUTLS_CERT_SIGNER_CONSTRAINTS_FAILURE = 1<<16, + GNUTLS_CERT_MISMATCH = 1<<17, } gnutls_certificate_status_t; typedef enum gnutls_connection_end { GNUTLS_SERVER=1, GNUTLS_CLIENT } gnutls_connection_end; typedef enum gnutls_credentials_type { GNUTLS_CRD_CERTIFICATE=1, GNUTLS_CRD_ANON, GNUTLS_CRD_SRP } gnutls_credentials_type; @@ -229,10 +229,10 @@ static int QDECL SSL_CheckCert(gnutls_session_t session) if (certstatus == 0) return 0; - type = gnutls_certificate_type_get (session); + type = gnutls_certificate_type_get (session); if (gnutls_certificate_verification_status_print(certstatus, type, &out, 0) >= 0) { - Con_Printf("%s: %s\n", file->certname, out.data); + Con_Printf("%s: %s\n", file->certname, out.data); gnutls_free(out.data); #else @@ -358,15 +358,15 @@ static int QDECL SSL_Write(struct vfsfile_s *f, const void *buffer, int bytestow return -1; //closed by remote connection. return written; } -static qboolean QDECL SSL_Seek (struct vfsfile_s *file, unsigned long pos) +static qboolean QDECL SSL_Seek (struct vfsfile_s *file, qofs_t pos) { return false; } -static unsigned long QDECL SSL_Tell (struct vfsfile_s *file) +static qofs_t QDECL SSL_Tell (struct vfsfile_s *file) { return 0; } -static unsigned long QDECL SSL_GetLen (struct vfsfile_s *file) +static qofs_t QDECL SSL_GetLen (struct vfsfile_s *file) { return 0; } @@ -463,8 +463,8 @@ vfsfile_t *FS_OpenSSL(const char *hostname, vfsfile_t *source, qboolean server) #ifdef GNUTLS_VERSION_3_0_0_PLUS gnutls_certificate_set_x509_system_trust (xcred); #else - gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM); -#endif + gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM); +#endif gnutls_certificate_set_verify_function (xcred, SSL_CheckCert); needinit = false; diff --git a/engine/gl/gl_backend.c b/engine/gl/gl_backend.c index cfc2ce762..7c17fafd9 100644 --- a/engine/gl/gl_backend.c +++ b/engine/gl/gl_backend.c @@ -2657,7 +2657,6 @@ static void BE_SubmitMeshChain(void) break; } } - qglDrawRangeElements(batchtype, startv, endv, endi-starti, GL_INDEX_TYPE, (index_t*)shaderstate.sourcevbo->indicies.gl.addr + starti); RQuantAdd(RQUANT_DRAWS, 1); } @@ -4864,7 +4863,6 @@ void GLBE_DrawWorld (qboolean drawworld, qbyte *vis) if (!r_refdef.recurse) { - GL_DoSwap(); if (shaderstate.wbatch + 50 > shaderstate.maxwbatches) { int newm = shaderstate.wbatch + 100; diff --git a/engine/gl/gl_draw.c b/engine/gl/gl_draw.c index a3316ebe4..847aba80a 100644 --- a/engine/gl/gl_draw.c +++ b/engine/gl/gl_draw.c @@ -513,7 +513,7 @@ TRACE(("dbg: GLDraw_ReInit: Allocating upload buffers\n")); TRACE(("dbg: GLDraw_ReInit: GL_EndRendering\n")); GL_EndRendering (); - GL_DoSwap(); + VID_SwapBuffers(); GL_SetupSceneProcessingTextures(); diff --git a/engine/gl/gl_rmain.c b/engine/gl/gl_rmain.c index 622cba9e2..7890a338e 100644 --- a/engine/gl/gl_rmain.c +++ b/engine/gl/gl_rmain.c @@ -997,7 +997,6 @@ void GLR_DrawPortal(batch_t *batch, batch_t **blist, batch_t *depthmasklist[2], //transform the old surface plane into the new view matrix if (Matrix4_Invert(r_refdef.m_view, ivmat)) { - extern cvar_t temp1; Matrix4_Multiply(ivmat, vmat, trmat); plane.normal[0] = -(oplane.normal[0] * trmat[0] + oplane.normal[1] * trmat[1] + oplane.normal[2] * trmat[2]); plane.normal[1] = -(oplane.normal[0] * trmat[4] + oplane.normal[1] * trmat[5] + oplane.normal[2] * trmat[6]); @@ -1465,8 +1464,6 @@ void GLR_RenderView (void) checkglerror(); - GL_DoSwap(); - if (r_norefresh.value || !vid.pixelwidth || !vid.pixelheight) return; diff --git a/engine/gl/gl_rmisc.c b/engine/gl/gl_rmisc.c index dbf33b808..aec2ce1d7 100644 --- a/engine/gl/gl_rmisc.c +++ b/engine/gl/gl_rmisc.c @@ -584,21 +584,18 @@ void GLR_TimeRefresh_f (void) if (frames < 1) frames = 128; -#if defined(_WIN32) && !defined(FTE_SDL) if (finish == 2) { - extern HDC maindc; qglFinish (); start = Sys_DoubleTime (); for (i=0 ; i= 2) || gl_config.glversion >= 3) //theoretically that should be a 2 not 3. + if ((gl_config.gles && gl_config.glversion >= 2) || (!gl_config.gles && gl_config.glversion >= 3)) //theoretically that should be a 2 not 3. qglStencilOpSeparateATI = (void *) getglext("glStencilOpSeparate"); else if (GL_CheckExtension("GL_ATI_separate_stencil")) qglStencilOpSeparateATI = (void *) getglext("glStencilOpSeparateATI"); @@ -890,14 +900,16 @@ void GL_CheckExtensions (void *(*getglfunction) (char *name)) qglGenVertexArrays = NULL; qglBindVertexArray = NULL; } - else if (gl_config.glversion >= 3) + else if (gl_config.glversion >= 3 && !gl_config.gles) { /*yay core!*/ + Con_Printf("Using vao (core)\n"); qglGenVertexArrays = (void *)getglext("glGenVertexArrays"); qglBindVertexArray = (void *)getglext("glBindVertexArray"); } else if (GL_CheckExtension("GL_ARB_vertex_array_object")) { + Con_Printf("Using vao (extension)\n"); qglGenVertexArrays = (void *)getglext("glGenVertexArraysARB"); qglBindVertexArray = (void *)getglext("glBindVertexArrayARB"); } @@ -1868,7 +1880,7 @@ void DumpGLState(void) GLint glint; GLint glint4[4]; - if (qglGetVertexAttribiv) +// if (qglGetVertexAttribiv) { qglGetIntegerv(GL_VERTEX_ARRAY_BINDING, &rval); Sys_Printf("VERTEX_ARRAY_BINDING: %i\n", rval); @@ -1920,6 +1932,7 @@ void DumpGLState(void) Sys_Printf("GL_VERTEX_ARRAY: %s %i:%p\n", qglIsEnabled(GL_VERTEX_ARRAY)?"en":"dis", rval, ptr); } + if (qglGetVertexAttribiv) for (i = 0; i < 16; i++) { int en, bo, as, st, ty, no; @@ -2019,10 +2032,10 @@ rendererinfo_t openglrendererinfo = { GLVID_Init, GLVID_DeInit, + GLVID_SwapBuffers, GLVID_ApplyGammaRamps, - GLVID_GetRGBInfo, - GLVID_SetCaption, //setcaption + GLVID_GetRGBInfo, GLSCR_UpdateScreen, diff --git a/engine/gl/gl_viddroid.c b/engine/gl/gl_viddroid.c index 8d0dae7b6..6103b33c1 100644 --- a/engine/gl/gl_viddroid.c +++ b/engine/gl/gl_viddroid.c @@ -36,10 +36,7 @@ void *GLES_GetSymbol(char *symname) } #if 1 -void GL_BeginRendering(void) -{ -} -void GL_EndRendering (void) +void GLVID_SwapBuffers(void) { } void GLVID_DeInit(void) @@ -174,20 +171,12 @@ qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette) return true; } -void GL_BeginRendering(void) -{ -} - -void GL_EndRendering (void) +void GLVID_SwapBuffers(void) { eglSwapBuffers(sys_display, sys_surface); } #endif -void GL_DoSwap(void) -{ -} - qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) { return false; diff --git a/engine/gl/gl_videgl.c b/engine/gl/gl_videgl.c index bf5ad69d9..cbd622d71 100644 --- a/engine/gl/gl_videgl.c +++ b/engine/gl/gl_videgl.c @@ -1,227 +1,235 @@ -#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_SwapBuffers (void) +{ + TRACE(("EGL_SwapBuffers\n")); + TRACE(("swapping buffers\n")); + qeglSwapBuffers(egldpy, eglsurf); + /* TODO: check result? */ + TRACE(("EGL_SwapBuffers done\n")); +} + +qboolean EGL_Init (rendererstate_t *info, unsigned char *palette, EGLNativeWindowType window, EGLNativeDisplayType dpy) +{ + EGLint numconfig; + EGLConfig cfg; + EGLint major, minor; + EGLint attrib[] = + { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, +// EGL_BUFFER_SIZE, info->bpp, +// EGL_SAMPLES, info->multisample, +// EGL_STENCIL_SIZE, 8, + EGL_ALPHA_MASK_SIZE, 0, + EGL_DEPTH_SIZE, 16, + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + 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!\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"); + { + 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; + } + + if (!numconfig) + { + Con_Printf(CON_ERROR "EGL: no configs!\n"); + return false; + } + + eglsurf = qeglCreateWindowSurface(egldpy, cfg, window, NULL); + if (eglsurf == EGL_NO_SURFACE) + { + Con_Printf(CON_ERROR "EGL: eglCreateWindowSurface failed: %x\n", qeglGetError()); return false; } @@ -237,8 +245,8 @@ qboolean EGL_Init (rendererstate_t *info, unsigned char *palette, EGLNativeWindo Con_Printf(CON_ERROR "EGL: can't make current!\n"); return false; } - - return true; -} -#endif - + + return true; +} +#endif + diff --git a/engine/gl/gl_videgl.h b/engine/gl/gl_videgl.h index 34e1257e7..c57afc09d 100644 --- a/engine/gl/gl_videgl.h +++ b/engine/gl/gl_videgl.h @@ -10,8 +10,7 @@ void *EGL_Proc(char *f); void EGL_UnloadLibrary(void); qboolean EGL_LoadLibrary(char *driver); void EGL_Shutdown(void); -void EGL_BeginRendering (void); -void EGL_EndRendering (void); +void EGL_SwapBuffers (void); qboolean EGL_Init (rendererstate_t *info, unsigned char *palette, EGLNativeWindowType window, EGLNativeDisplayType dpy); #endif diff --git a/engine/gl/gl_vidlinuxglx.c b/engine/gl/gl_vidlinuxglx.c index cadc6972d..236809873 100644 --- a/engine/gl/gl_vidlinuxglx.c +++ b/engine/gl/gl_vidlinuxglx.c @@ -18,6 +18,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* +Small note: anything concerning EGL in here is specific to egl-with-x11. +if you want egl-with-framebuffer, look elsewhere. +*/ + /* X11 is a huge pile of shit. I don't mean just the old x11 protocol, but all the _current_ standards that don't even try to fix the issues too. @@ -52,12 +57,12 @@ none of these issues will be fixed by a compositing window manager, because ther #include "quakedef.h" #include #include -#include "glquake.h" #include #ifdef USE_EGL #include "gl_videgl.h" #endif +#include "glquake.h" #include #include @@ -69,6 +74,7 @@ static Window vid_decoywindow; //for legacy mode, this is a boring window that w static Window vid_root; static GLXContext ctx = NULL; static int scrnum; +static long vid_x_eventmask; static enum { PSL_NONE, @@ -92,6 +98,8 @@ extern long sys_parentwindow; #define X_MASK (KEY_MASK | MOUSE_MASK | ResizeRequest | StructureNotifyMask | FocusChangeMask | VisibilityChangeMask) +struct _XrmHashBucketRec; + static struct { void *lib; @@ -145,6 +153,22 @@ static struct int (*pXUngrabKeyboard)(Display *display, Time time); int (*pXUngrabPointer)(Display *display, Time time); int (*pXWarpPointer)(Display *display, Window src_w, Window dest_w, int src_x, int src_y, unsigned int src_width, unsigned int src_height, int dest_x, int dest_y); + Status (*pXMatchVisualInfo)(Display *display, int screen, int depth, int class, XVisualInfo *vinfo_return); + + char *(*pXSetLocaleModifiers)(char *modifier_list); + Bool (*pXSupportsLocale)(void); + XIM (*pXOpenIM)(Display *display, struct _XrmHashBucketRec *db, char *res_name, char *res_class); + XIC (*pXCreateIC)(XIM im, ...); + void (*pXSetICFocus)(XIC ic); + char * (*pXGetICValues)(XIC ic, ...); + Bool (*pXFilterEvent)(XEvent *event, Window w); + int (*pXutf8LookupString)(XIC ic, XKeyPressedEvent *event, char *buffer_return, int bytes_buffer, KeySym *keysym_return, Status *status_return); + int (*pXwcLookupString)(XIC ic, XKeyPressedEvent *event, wchar_t *buffer_return, int bytes_buffer, KeySym *keysym_return, Status *status_return); + void (*pXDestroyIC)(XIC ic); + Status (*pXCloseIM)(XIM im); + qboolean dounicode; + XIC unicodecontext; + XIM inputmethod; } x11; static qboolean x11_initlib(void) { @@ -198,6 +222,7 @@ static qboolean x11_initlib(void) {(void**)&x11.pXUngrabKeyboard, "XUngrabKeyboard"}, {(void**)&x11.pXUngrabPointer, "XUngrabPointer"}, {(void**)&x11.pXWarpPointer, "XWarpPointer"}, + {(void**)&x11.pXMatchVisualInfo, "XMatchVisualInfo"}, {NULL, NULL} }; @@ -214,8 +239,22 @@ static qboolean x11_initlib(void) //these ones are extensions, and the reason we're doing this. if (x11.lib) { - x11.pXGetEventData = Sys_GetAddressForName(x11.lib, "XGetEventData"); - x11.pXFreeEventData = Sys_GetAddressForName(x11.lib, "XFreeEventData"); + //raw input (yay mouse deltas) + x11.pXGetEventData = Sys_GetAddressForName(x11.lib, "XGetEventData"); + x11.pXFreeEventData = Sys_GetAddressForName(x11.lib, "XFreeEventData"); + + //internationalisation + x11.pXSetLocaleModifiers = Sys_GetAddressForName(x11.lib, "XSetLocaleModifiers"); + x11.pXSupportsLocale = Sys_GetAddressForName(x11.lib, "XSupportsLocale"); + x11.pXOpenIM = Sys_GetAddressForName(x11.lib, "XOpenIM"); + x11.pXCreateIC = Sys_GetAddressForName(x11.lib, "XCreateIC"); + x11.pXSetICFocus = Sys_GetAddressForName(x11.lib, "XSetICFocus"); + x11.pXGetICValues = Sys_GetAddressForName(x11.lib, "XGetICValues"); + x11.pXFilterEvent = Sys_GetAddressForName(x11.lib, "XFilterEvent"); + x11.pXutf8LookupString = Sys_GetAddressForName(x11.lib, "Xutf8LookupString"); + x11.pXwcLookupString = Sys_GetAddressForName(x11.lib, "XwcLookupString"); + x11.pXDestroyIC = Sys_GetAddressForName(x11.lib, "XDestroyIC"); + x11.pXCloseIM = Sys_GetAddressForName(x11.lib, "XCloseIM"); } else { @@ -299,7 +338,7 @@ static qboolean VMODE_Init(void) if (!x11.pXQueryExtension(vid_dpy, "XFree86-VidModeExtension", &vm.opcode, &vm.event, &vm.error)) { - Con_Printf("DGA extension not available.\n"); + Con_Printf("VidModeExtension extension not available.\n"); return false; } @@ -308,14 +347,14 @@ static qboolean VMODE_Init(void) if (vm.lib) { - if (vm.pXF86VidModeQueryVersion(vid_dpy, &vm.vmajor, &vm.vminor)) - Con_Printf("Using XF86-VidModeExtension Ver. %d.%d\n", vm.vmajor, vm.vminor); + if (vm.pXF86VidModeQueryVersion(vid_dpy, &vm.vmajor, &vm.vminor)) + Con_Printf("Using XF86-VidModeExtension Ver. %d.%d\n", vm.vmajor, vm.vminor); else - { - Con_Printf("No XF86-VidModeExtension support\n"); + { + Con_Printf("No XF86-VidModeExtension support\n"); vm.vmajor = 0; - vm.vminor = 0; - } + vm.vminor = 0; + } } return vm.vmajor; @@ -429,7 +468,12 @@ static qboolean XI2_Init(void) if (!xi2.libxi) { - xi2.libxi = Sys_LoadLibrary("libXi.so.6", xi2_functable); +#ifdef __CYGWIN__ + if (!xi2.libxi) + xi2.libxi = Sys_LoadLibrary("cygXi-6.dll", xi2_functable); +#endif + if (!xi2.libxi) + xi2.libxi = Sys_LoadLibrary("libXi.so.6", xi2_functable); if (!xi2.libxi) xi2.libxi = Sys_LoadLibrary("libXi", xi2_functable); if (!xi2.libxi) @@ -507,6 +551,10 @@ qboolean GLX_InitLibrary(char *driver) gllibrary = Sys_LoadLibrary(driver, funcs); else gllibrary = NULL; +#ifdef __CYGWIN__ + if (!gllibrary) + gllibrary = Sys_LoadLibrary("cygGL-1.dll", funcs); +#endif if (!gllibrary) //I hate this. gllibrary = Sys_LoadLibrary("libGL.so.1", funcs); if (!gllibrary) @@ -535,24 +583,116 @@ void *GLX_GetSymbol(char *name) return symb; } -static int XLateKey(XKeyEvent *ev, unsigned int *unicode) +static void X_ShutdownUnicode(void) { + if (x11.unicodecontext) + x11.pXDestroyIC(x11.unicodecontext); + if (x11.inputmethod) + x11.pXCloseIM(x11.inputmethod); + x11.dounicode = false; +} +#include +static long X_InitUnicode(void) +{ + long requiredevents = 0; +//return 0; + X_ShutdownUnicode(); + if (x11.pXSetLocaleModifiers && x11.pXSupportsLocale && x11.pXOpenIM && x11.pXCreateIC && x11.pXSetICFocus && x11.pXGetICValues && x11.pXFilterEvent && (x11.pXutf8LookupString || x11.pXwcLookupString) && x11.pXDestroyIC && x11.pXCloseIM) + { + setlocale(LC_CTYPE, ""); + x11.pXSetLocaleModifiers(""); + if (x11.pXSupportsLocale()) + { + x11.inputmethod = x11.pXOpenIM(vid_dpy, NULL, NULL, NULL); + if (x11.inputmethod) + { + x11.unicodecontext = x11.pXCreateIC(x11.inputmethod, + XNInputStyle, XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, vid_window, + XNFocusWindow, vid_window, + NULL); + if (x11.unicodecontext) + { + x11.pXSetICFocus(x11.unicodecontext); + x11.dounicode = true; + + x11.pXGetICValues(x11.unicodecontext, XNFilterEvents, &requiredevents, NULL); + } + } + } +// setlocale(LC_ALL, "C"); + } + + Con_Printf("Unicode support: %s\n", x11.dounicode?"available":"unavailable"); + + return requiredevents; +} + +static void X_KeyEvent(XKeyEvent *ev, qboolean pressed) +{ + int i; int key; - char buf[64]; KeySym keysym, shifted; - + unsigned int unichar[64]; + int unichars = 0; key = 0; keysym = x11.pXLookupKeysym(ev, 0); - if (unicode) + if (pressed) { - if ((keysym & 0xff000000) == 0x01000000) - *unicode = keysym & 0x00ffffff; + if (x11.dounicode) + { + Status status = XLookupNone; + if (x11.pXutf8LookupString) + { + char buf1[1] = {0}; + char *buf = buf1, *c; + int count = x11.pXutf8LookupString(x11.unicodecontext, (XKeyPressedEvent*)ev, buf1, sizeof(buf1), NULL, &status); + if (status == XBufferOverflow) + { + buf = alloca(count+1); + count = x11.pXutf8LookupString(x11.unicodecontext, (XKeyPressedEvent*)ev, buf, count, NULL, &status); + } + for (c = buf; c < &buf[count]; ) + { + int error; + unsigned int uc = utf8_decode(&error, c, &c); + if (uc) + unichar[unichars++] = uc; + } + } + else + { + //is allowed some weird encodings... + wchar_t buf1[4] = {0}; + wchar_t *buf = buf1; + int count = x11.pXwcLookupString(x11.unicodecontext, (XKeyPressedEvent*)ev, buf, sizeof(buf1), &shifted, &status); + if (status == XBufferOverflow) + { + buf = alloca(sizeof(wchar_t)*(count+1)); + printf("XBufferOverflow\n"); + count = x11.pXwcLookupString(x11.unicodecontext, (XKeyPressedEvent*)ev, buf, count, NULL, &status); + } + printf("Translated to \"%ls\" (%i %i)\n", buf, count, status); + //if wchar_t is 16bit, then expect problems when we completely ignore surrogates. this is why we favour the utf8 route as it doesn't care whether wchar_t is defined as 16bit or 32bit. + for (i = 0; i < count; i++) + if (buf[i]) + unichar[unichars++] = buf[i]; + } + } else { - x11.pXLookupString(ev, buf, sizeof buf, &shifted, 0); - *unicode = (unsigned char)buf[0]; + char buf[64]; + if ((keysym & 0xff000000) == 0x01000000) + unichar[unichars++] = keysym & 0x00ffffff; + else + { + int count = x11.pXLookupString(ev, buf, sizeof(buf), &shifted, 0); + for (i = 0; i < count; i++) + if (buf[i]) + unichar[unichars++] = (unsigned char)buf[i]; + } } } @@ -676,7 +816,21 @@ static int XLateKey(XKeyEvent *ev, unsigned int *unicode) break; } - return key; + if (unichars) + { + //we got some text, this is fun isn't it? + //the key value itself is sent with the last text char. this avoids multiple presses, and dead keys were already sent. + for (i = 0; i < unichars-1; i++) + { + IN_KeyEvent(0, pressed, 0, unichar[i]); + } + IN_KeyEvent(0, pressed, key, unichar[i]); + } + else + { + //no text available, just do the keypress + IN_KeyEvent(0, pressed, key, 0); + } } static void install_grabs(void) @@ -737,12 +891,18 @@ static void GetEvent(void) { XEvent event, rep; int b; - unsigned int uc; qboolean x11violations = true; Window mw; x11.pXNextEvent(vid_dpy, &event); + if (x11.dounicode) + if (x11.pXFilterEvent(&event, vid_window)) + { + Con_Printf("Event filtered\n"); + return; + } + switch (event.type) { case GenericEvent: @@ -833,12 +993,10 @@ static void GetEvent(void) // x11.pXMoveWindow(vid_dpy, vid_window, 0, 0); break; case KeyPress: - b = XLateKey(&event.xkey, &uc); - Key_Event(0, b, uc, true); + X_KeyEvent(&event.xkey, true); break; case KeyRelease: - b = XLateKey(&event.xkey, NULL); - Key_Event(0, b, 0, false); + X_KeyEvent(&event.xkey, false); break; case MotionNotify: @@ -857,10 +1015,10 @@ static void GetEvent(void) IN_MouseMove(0, false, event.xmotion.x - cx, event.xmotion.y - cy, 0, 0); /* move the mouse to the window center again (disabling warp first so we don't see it*/ - x11.pXSelectInput(vid_dpy, vid_window, X_MASK & ~PointerMotionMask); + x11.pXSelectInput(vid_dpy, vid_window, vid_x_eventmask & ~PointerMotionMask); x11.pXWarpPointer(vid_dpy, None, vid_window, 0, 0, 0, 0, cx, cy); - x11.pXSelectInput(vid_dpy, vid_window, X_MASK); + x11.pXSelectInput(vid_dpy, vid_window, vid_x_eventmask); } } else @@ -1066,6 +1224,8 @@ void GLVID_Shutdown(void) if (vm.originalapplied) vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + X_ShutdownUnicode(); + switch(currentpsl) { #ifdef USE_EGL @@ -1178,35 +1338,14 @@ qboolean GLVID_ApplyGammaRamps(unsigned short *ramps) } } -/* -================= -GL_BeginRendering - -================= -*/ -void GL_BeginRendering (void) +void GLVID_SwapBuffers (void) { switch(currentpsl) { #ifdef USE_EGL + default: case PSL_EGL: - EGL_BeginRendering(); - break; -#endif - case PSL_GLX: - case PSL_NONE: - break; - } -} - - -void GL_EndRendering (void) -{ - switch(currentpsl) - { -#ifdef USE_EGL - case PSL_EGL: - EGL_EndRendering(); + EGL_SwapBuffers(); break; #endif case PSL_GLX: @@ -1214,8 +1353,6 @@ void GL_EndRendering (void) //chances are, it's version is more suitable anyway. At least there's the chance that it might be. qglXSwapBuffers(vid_dpy, vid_window); break; - case PSL_NONE: - break; } } @@ -1225,11 +1362,16 @@ void X_StoreIcon(Window wnd) int i; unsigned long data[64*64+2]; unsigned int *indata = (unsigned int*)icon.pixel_data; + unsigned int inwidth = icon.width; + unsigned int inheight = icon.height; + + //FIXME: support loading an icon from the filesystem. + Atom propname = x11.pXInternAtom(vid_dpy, "_NET_WM_ICON", false); Atom proptype = x11.pXInternAtom(vid_dpy, "CARDINAL", false); - data[0] = icon.width; - data[1] = icon.height; + data[0] = inwidth; + data[1] = inheight; for (i = 0; i < data[0]*data[1]; i++) data[i+2] = indata[i]; @@ -1352,7 +1494,7 @@ Window X_CreateWindow(qboolean override, XVisualInfo *visinfo, unsigned int widt attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = x11.pXCreateColormap(vid_dpy, vid_root, visinfo->visual, AllocNone); - attr.event_mask = X_MASK; + attr.event_mask = vid_x_eventmask = X_MASK; attr.backing_store = NotUseful; attr.save_under = False; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWBackingStore |CWSaveUnder; @@ -1576,6 +1718,9 @@ qboolean X11VID_Init (rendererstate_t *info, unsigned char *palette, int psl) else vid_window = X_CreateWindow(false, visinfo, width, height, fullscreen); + vid_x_eventmask |= X_InitUnicode(); + x11.pXSelectInput(vid_dpy, vid_window, vid_x_eventmask); + CL_UpdateWindowTitle(); /*make it visible*/ @@ -1629,7 +1774,7 @@ qboolean X11VID_Init (rendererstate_t *info, unsigned char *palette, int psl) break; #ifdef USE_EGL case PSL_EGL: - if (!EGL_Init(info, palette, vid_window, vid_dpy)) + if (!EGL_Init(info, palette, (EGLNativeWindowType)vid_window, (EGLNativeDisplayType)vid_dpy)) { Con_Printf("Failed to create EGL context.\n"); GLVID_Shutdown(); @@ -1662,17 +1807,17 @@ qboolean X11VID_Init (rendererstate_t *info, unsigned char *palette, int psl) if (!COM_CheckParm("-noxi2") && XI2_Init()) { x11_input_method = XIM_XI2; - Con_Printf("Using XInput2\n"); + Con_DPrintf("Using XInput2\n"); } else if (!COM_CheckParm("-nodga") && !COM_CheckParm("-nomdga") && DGAM_Init()) { x11_input_method = XIM_DGA; - Con_Printf("Using DGA mouse\n"); + Con_DPrintf("Using DGA mouse\n"); } else { x11_input_method = XIM_ORIG; - Con_Printf("Using X11 mouse\n"); + Con_DPrintf("Using X11 mouse\n"); } if (Cvar_Get("vidx_grabkeyboard", "0", 0, "Additional video options")->value) @@ -1843,8 +1988,6 @@ void INS_Shutdown(void) { } -void GL_DoSwap(void) {} - void GLVID_SetCaption(char *text) { x11.pXStoreName(vid_dpy, vid_window, text); @@ -1855,7 +1998,7 @@ void GLVID_SetCaption(char *text) #include "gl_draw.h" rendererinfo_t eglrendererinfo = { - "EGL", + "EGL(X11)", { "egl" }, @@ -1880,16 +2023,13 @@ rendererinfo_t eglrendererinfo = GLR_NewMap, GLR_PreNewMap, - Surf_AddStain, - Surf_LessenStains, - EGLVID_Init, GLVID_DeInit, - GLVID_SetPalette, - GLVID_ShiftPalette, - GLVID_GetRGBInfo, + GLVID_SwapBuffers, + GLVID_ApplyGammaRamps, GLVID_SetCaption, //setcaption + GLVID_GetRGBInfo, GLSCR_UpdateScreen, @@ -1906,8 +2046,16 @@ rendererinfo_t eglrendererinfo = GLBE_UploadAllLightmaps, GLBE_SelectEntity, GLBE_SelectDLight, + GLBE_Scissor, GLBE_LightCullModel, + GLBE_VBO_Begin, + GLBE_VBO_Data, + GLBE_VBO_Finish, + GLBE_VBO_Destroy, + + GLBE_RenderToTextureUpdate2d, + "" }; #endif diff --git a/engine/gl/gl_vidmacos.c b/engine/gl/gl_vidmacos.c index 1ede0ebd2..323299308 100644 --- a/engine/gl/gl_vidmacos.c +++ b/engine/gl/gl_vidmacos.c @@ -113,10 +113,6 @@ void GLVID_DeInit(void) killCocoa(); } -void GL_DoSwap(void) -{ -} - void GLVID_SetPalette (unsigned char *palette) { qbyte *pal; @@ -179,11 +175,7 @@ void GLVID_SetCaption(char *text) { } -void GL_BeginRendering (void) -{ -} - -void GL_EndRendering(void) +void GLVID_SwapBuffers(void) { flushCocoa(); } diff --git a/engine/gl/gl_vidmorphos.c b/engine/gl/gl_vidmorphos.c index 535e2a017..0b1519d54 100644 --- a/engine/gl/gl_vidmorphos.c +++ b/engine/gl/gl_vidmorphos.c @@ -581,19 +581,11 @@ void GLVID_DeInit(void) } } -void GL_BeginRendering(void) -{ -} - -void GL_EndRendering (void) +void GLVID_SwapBuffers (void) { glASwapBuffers(); } -void GL_DoSwap(void) -{ -} - void GLVID_SetPalette (unsigned char *palette) { qbyte *pal; diff --git a/engine/gl/gl_vidnt.c b/engine/gl/gl_vidnt.c index 6cdeb492f..a6c27dc53 100644 --- a/engine/gl/gl_vidnt.c +++ b/engine/gl/gl_vidnt.c @@ -1274,25 +1274,6 @@ qboolean VID_AttachGL (rendererstate_t *info) return true; } -/* -================= -GL_BeginRendering - -================= -*/ -void GL_BeginRendering (void) -{ - vid.pixelwidth = WindowRect.right - WindowRect.left; - vid.pixelheight = WindowRect.bottom - WindowRect.top; - - qglDisable(GL_SCISSOR_TEST); - -// if (!wglMakeCurrent( maindc, baseRC )) -// Sys_Error ("wglMakeCurrent failed"); - -// glViewport (*x, *y, *width, *height); -} - void VID_Wait_Override_Callback(struct cvar_s *var, char *oldvalue) { if (qwglSwapIntervalEXT && *vid_vsync.string) @@ -1371,13 +1352,8 @@ void VID_WndAlpha_Override_Callback(struct cvar_s *var, char *oldvalue) #endif } -qboolean screenflush; -void GL_DoSwap (void) +void GLVID_SwapBuffers (void) { - if (!screenflush) - return; - screenflush = 0; - qSwapBuffers(maindc); // handle the mouse state when windowed if that's changed @@ -1385,13 +1361,6 @@ void GL_DoSwap (void) INS_UpdateGrabs(modestate != MS_WINDOWED, ActiveApp); } -void GL_EndRendering (void) -{ - screenflush = true; - if (!gl_lateswap.value) - GL_DoSwap(); -} - void OblitterateOldGamma(void) { int i; diff --git a/engine/gl/gl_vidnull.c b/engine/gl/gl_vidnull.c index 5398ad25b..f30a840b3 100644 --- a/engine/gl/gl_vidnull.c +++ b/engine/gl/gl_vidnull.c @@ -29,15 +29,7 @@ void GLD_EndDirectRect(int x, int y, int width, int height) { } -void GL_BeginRendering (void) -{ -} - -void GL_EndRendering (void) -{ -} - -void GL_DoSwap(void) +void GLVID_SwapBuffers(void) { } diff --git a/engine/gl/gl_vidrpi.c b/engine/gl/gl_vidrpi.c new file mode 100644 index 000000000..b1ee92653 --- /dev/null +++ b/engine/gl/gl_vidrpi.c @@ -0,0 +1,146 @@ +#include "bothdefs.h" +#if defined(GLQUAKE) && defined(USE_EGL) +#include "gl_videgl.h" + +#include +#include "glquake.h" +#include "shader.h" +qboolean RPI_Init (rendererstate_t *info, unsigned char *palette) +{ + static EGL_DISPMANX_WINDOW_T nativewindow; + + DISPMANX_ELEMENT_HANDLE_T dispman_element; + DISPMANX_DISPLAY_HANDLE_T dispman_display; + DISPMANX_UPDATE_HANDLE_T dispman_update; + VC_RECT_T dst_rect; + VC_RECT_T src_rect; + int rw, rh; + + if (!EGL_LoadLibrary(info->subrenderer)) + { + Con_Printf("couldn't load EGL library\n"); + return false; + } + bcm_host_init(); + + graphics_get_display_size(0 /* LCD */, &rw, &rh); + Con_Printf("Screen size is actually %i*%i\n", rw, rh); + + if (info->width < 64 || info->height < 64) + { + info->width = rw; + info->height = rh; + } + dispman_display = vc_dispmanx_display_open(0 /* LCD */); + dispman_update = vc_dispmanx_update_start(0); + + + dst_rect.x = 0; + dst_rect.y = 0; + dst_rect.width = info->width; + dst_rect.height = info->height; + + src_rect.x = 0; + src_rect.y = 0; + src_rect.width = info->width << 16; + src_rect.height = info->height << 16; + + vid.pixelwidth = info->width; + vid.pixelheight = info->height; + + dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/); + + nativewindow.element = dispman_element; + nativewindow.width = info->width; + nativewindow.height = info->height; + vc_dispmanx_update_submit_sync(dispman_update); + + + if (!EGL_Init(info, palette, &nativewindow, EGL_DEFAULT_DISPLAY)) + { + Con_Printf("couldn't initialise EGL context\n"); + return false; + } + GL_Init(&EGL_Proc); + return true; +} +void RPI_DeInit(void) +{ + EGL_Shutdown(); +} +qboolean RPI_ApplyGammaRamps(unsigned short *ramps) +{ + //not supported + return false; +} +void RPI_SetCaption(char *text) +{ +} + +#include "gl_draw.h" +rendererinfo_t rpirendererinfo = +{ + "EGL(VideoCore)", + { + "rpi", + "videocore", + "rpiegl" + }, + QR_OPENGL, + + GLDraw_Init, + GLDraw_DeInit, + + GL_LoadTextureFmt, + GL_LoadTexture8Pal24, + GL_LoadTexture8Pal32, + GL_LoadCompressed, + GL_FindTexture, + GL_AllocNewTexture, + GL_UploadFmt, + GL_DestroyTexture, + + GLR_Init, + GLR_DeInit, + GLR_RenderView, + + GLR_NewMap, + GLR_PreNewMap, + + RPI_Init, + RPI_DeInit, + RPI_ApplyGammaRamps, + GLVID_GetRGBInfo, + + RPI_SetCaption, //setcaption + + + GLSCR_UpdateScreen, + + GLBE_SelectMode, + GLBE_DrawMesh_List, + GLBE_DrawMesh_Single, + GLBE_SubmitBatch, + GLBE_GetTempBatch, + GLBE_DrawWorld, + GLBE_Init, + GLBE_GenBrushModelVBO, + GLBE_ClearVBO, + GLBE_UploadAllLightmaps, + GLBE_SelectEntity, + GLBE_SelectDLight, + GLBE_Scissor, + GLBE_LightCullModel, + + GLBE_VBO_Begin, + GLBE_VBO_Data, + GLBE_VBO_Finish, + GLBE_VBO_Destroy, + + GLBE_RenderToTextureUpdate2d, + + "" +}; + +#endif + diff --git a/engine/gl/gl_vidsdl.c b/engine/gl/gl_vidsdl.c index 07b777f5a..009c24f8f 100644 --- a/engine/gl/gl_vidsdl.c +++ b/engine/gl/gl_vidsdl.c @@ -230,21 +230,8 @@ void GLVID_DeInit (void) } -void GL_BeginRendering (void) +void GLVID_SwapBuffers (void) { -// if (!wglMakeCurrent( maindc, baseRC )) -// Sys_Error ("wglMakeCurrent failed"); - -// qglViewport (*x, *y, *width, *height); -} - -qboolean screenflush; -void GL_DoSwap (void) -{ - if (!screenflush) - return; - screenflush = 0; - #if SDL_MAJOR_VERSION >= 2 if (vid_vsync.modified) { @@ -279,13 +266,6 @@ void GL_DoSwap (void) } } -void GL_EndRendering (void) -{ - screenflush = true; - if (!gl_lateswap.value) - GL_DoSwap(); -} - qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) { #if SDL_MAJOR_VERSION >= 2 diff --git a/engine/gl/gl_vidwayland.c b/engine/gl/gl_vidwayland.c new file mode 100644 index 000000000..bb8b928f0 --- /dev/null +++ b/engine/gl/gl_vidwayland.c @@ -0,0 +1,473 @@ +#include "bothdefs.h" +#if defined(GLQUAKE) && defined(USE_EGL) +#include +#include +#include //this is shite. +#include "gl_videgl.h" + +#if WAYLAND_VERSION_MAJOR < 1 +#error "wayland headers are too old" +#endif + +#include "glquake.h" +#include "shader.h" + +static struct wdisplay_s +{ + //display stuff + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_shell *shell; + + //seat stuff + void *pointer; + void *keyboard; + void *seat; + + //window stuff + struct wl_egl_window *enwindow; + struct wl_surface *surface; + struct wl_shell_surface *ssurface; +} w; +static void WL_shell_handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) +{ + wl_shell_surface_pong(shell_surface, serial); +} +static void WL_shell_handle_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) +{ + if (w.enwindow) + wl_egl_window_resize(w.enwindow, width, height, 0, 0); + + vid.pixelwidth = width; + vid.pixelheight = height; +} +static void WL_shell_handle_popup_done(void *data, struct wl_shell_surface *shell_surface) +{ +} + +static const struct wl_shell_surface_listener shell_surface_listener = +{ + WL_shell_handle_ping, + WL_shell_handle_configure, + WL_shell_handle_popup_done +}; + +//qkeys are ascii-compatible for the most part. +qbyte waylandinputsucksbighairydonkeyballs[] = +{ + 0, K_ESCAPE,'1','2','3','4','5','6', //0x + '7','8','9','0','-','=',K_BACKSPACE,K_TAB, + 'q','w','e','r','t','y','u','i', //1x + 'o','p','[',']',K_ENTER,K_LCTRL,'a', 's', + 'd','f','g','h','j','k','l',';', //2x + '\'','`',K_LSHIFT,'#','z','x','c','v', + 'b','n','m',',','.','/',K_RSHIFT,K_KP_STAR, //3x + K_LALT,' ',K_CAPSLOCK,K_F1,K_F2,K_F3,K_F4,K_F5, + K_F6,K_F7,K_F8,K_F9,K_F10,K_KP_NUMLOCK,K_SCRLCK,K_KP_HOME,//4x + K_KP_UPARROW,K_KP_PGUP,K_KP_MINUS,K_KP_LEFTARROW,K_KP_5,K_KP_RIGHTARROW,K_KP_PLUS,K_KP_END, + K_KP_DOWNARROW,K_KP_PGDN,K_KP_INS,K_KP_DEL,0,0,'\\',K_F11, //5x + K_F12,0,0,0,0,0,0,0, + K_KP_ENTER,0,K_KP_SLASH,0,K_RALT,0,K_HOME,K_UPARROW, //6x + K_PGUP,K_LEFTARROW,K_RIGHTARROW,K_END,K_DOWNARROW,K_PGDN,K_INS,K_DEL, + 0,0,0,0,0,0,0,K_PAUSE, //7x + 0,0,0,0,0,K_LWIN,K_RWIN,K_APP +}; +qbyte waylandinputsucksbighairydonkeyballsshift[] = +{ + 0, K_ESCAPE,'!','\"','3','$','%','^', //0x + '&','*','(',')','_','+',K_BACKSPACE,K_TAB, + 'Q','W','E','R','T','Y','U','I', //1x + 'O','P','{','}',K_ENTER,K_LCTRL,'A', 'S', + 'D','F','G','H','J','K','L',':', //2x + '@','`',K_LSHIFT,'~','Z','X','C','V', + 'B','N','M','<','>','?',K_RSHIFT,K_KP_STAR, //3x + K_LALT,' ',K_CAPSLOCK,K_F1,K_F2,K_F3,K_F4,K_F5, + K_F6,K_F7,K_F8,K_F9,K_F10,K_KP_NUMLOCK,K_SCRLCK,K_KP_HOME,//4x + K_KP_UPARROW,K_KP_PGUP,K_KP_MINUS,K_KP_LEFTARROW,K_KP_5,K_KP_RIGHTARROW,K_KP_PLUS,K_KP_END, + K_KP_DOWNARROW,K_KP_PGDN,K_KP_INS,K_KP_DEL,0,0,'|',K_F11, //5x + K_F12,0,0,0,0,0,0,0, + K_KP_ENTER,0,K_KP_SLASH,0,K_RALT,0,K_HOME,K_UPARROW, //6x + K_PGUP,K_LEFTARROW,K_RIGHTARROW,K_END,K_DOWNARROW,K_PGDN,K_INS,K_DEL, + 0,0,0,0,0,0,0,K_PAUSE, //7x + 0,0,0,0,0,K_LWIN,K_RWIN,K_APP +}; +static void WL_pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) +{ +/* + struct display *display = data; + struct wl_buffer *buffer; + struct wl_cursor *cursor = display->default_cursor; + struct wl_cursor_image *image; + + if (display->window->fullscreen) + wl_pointer_set_cursor(pointer, serial, NULL, 0, 0); + else if (cursor) { + image = display->default_cursor->images[0]; + buffer = wl_cursor_image_get_buffer(image); + wl_pointer_set_cursor(pointer, serial, + display->cursor_surface, + image->hotspot_x, + image->hotspot_y); + wl_surface_attach(display->cursor_surface, buffer, 0, 0); + wl_surface_damage(display->cursor_surface, 0, 0, + image->width, image->height); + wl_surface_commit(display->cursor_surface); + } +*/ +} +static void WL_pointer_handle_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) +{ +} + +static void WL_pointer_handle_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t sx, wl_fixed_t sy) +{ + //wayland is shite shite shite. + //1.4 still has no relative mouse motion. + IN_MouseMove(0, true, wl_fixed_to_double(sx), wl_fixed_to_double(sy), 0, 0); +} + +static void WL_pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) +{ + struct wdisplay *display = data; + int qkey; + + switch(button) + { + default: + return; //blurgh. + case BTN_LEFT: + qkey = K_MOUSE1; + break; + case BTN_RIGHT: + qkey = K_MOUSE2; + break; + case BTN_MIDDLE: + qkey = K_MOUSE3; + break; + case BTN_SIDE: + qkey = K_MOUSE4; + break; + case BTN_EXTRA: + qkey = K_MOUSE5; + break; + case BTN_FORWARD: + qkey = K_MOUSE6; + break; + case BTN_BACK: + qkey = K_MOUSE7; + break; + case BTN_TASK: + qkey = K_MOUSE8; + break; + } + IN_KeyEvent(0, !!state, qkey, 0); +// wl_shell_surface_move(display->window->shell_surface, display->seat, serial); +} + +static void WL_pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) +{ + if (value < 0) + { + IN_KeyEvent(0, 1, K_MWHEELUP, 0); + IN_KeyEvent(0, 0, K_MWHEELUP, 0); + } + else + { + IN_KeyEvent(0, 1, K_MWHEELDOWN, 0); + IN_KeyEvent(0, 0, K_MWHEELDOWN, 0); + } +} + +static const struct wl_pointer_listener pointer_listener = +{ + WL_pointer_handle_enter, + WL_pointer_handle_leave, + WL_pointer_handle_motion, + WL_pointer_handle_button, + WL_pointer_handle_axis, +}; + +static void WL_keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) +{ +} + +static void WL_keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) +{ +} + +static void WL_keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) +{ +} + +static void WL_keyboard_handle_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) +{ + extern int shift_down; + struct display *d = data; + uint32_t qkey; + uint32_t ukey; + + if (key < sizeof(waylandinputsucksbighairydonkeyballs)/sizeof(waylandinputsucksbighairydonkeyballs[0])) + { + qkey = waylandinputsucksbighairydonkeyballs[key]; + if (shift_down) + ukey = waylandinputsucksbighairydonkeyballsshift[key]; + else + ukey = waylandinputsucksbighairydonkeyballs[key]; + } + else + ukey = qkey = 0; + if (ukey < ' ' || ukey > 127) + ukey = 0; + + if (state) + IN_KeyEvent(0, 1, qkey, ukey); + else + IN_KeyEvent(0, 0, qkey, 0); +} + +static void WL_keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) +{ +} + +static const struct wl_keyboard_listener keyboard_listener = +{ + WL_keyboard_handle_keymap, + WL_keyboard_handle_enter, + WL_keyboard_handle_leave, + WL_keyboard_handle_key, + WL_keyboard_handle_modifiers +}; +static void WL_seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps) +{ + struct wdisplay_s *s = data; + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !s->pointer) + { + s->pointer = wl_seat_get_pointer(seat); + wl_pointer_add_listener(s->pointer, &pointer_listener, s); + } + else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && s->pointer) + { + wl_pointer_destroy(s->pointer); + s->pointer = NULL; + } + + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !s->keyboard) + { + s->keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_add_listener(s->keyboard, &keyboard_listener, s); + } + else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && s->keyboard) + { + wl_keyboard_destroy(s->keyboard); + s->keyboard = NULL; + } +} +static const struct wl_seat_listener seat_listener = +{ + WL_seat_handle_capabilities +}; + +static void WL_handle_global(void *data, struct wl_registry *registry, +uint32_t id, const char *interface, uint32_t version) +{ + struct wdisplay_s *d = data; +//Sys_Printf("Interface %s id %u\n", interface, id); + if (strcmp(interface, "wl_compositor") == 0) + d->compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1); + else if (strcmp(interface, "wl_shell") == 0) + d->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1); + else if (strcmp(interface, "wl_seat") == 0 && !d->seat) + { + d->seat = wl_registry_bind(registry, id, &wl_seat_interface, 1); + wl_seat_add_listener(d->seat, &seat_listener, d); + } +/* else if (!strcmp(interface, "input_device")) + display_add_input(id); +*/ +} + +static const struct wl_registry_listener WL_registry_listener = { + WL_handle_global +}; + +static void WL_waitabit(void) +{ + wl_display_roundtrip(w.display); +} + +static void WL_SwapBuffers(void) +{ + float r; + TRACE(("WL_SwapBuffers\n")); + + wl_surface_set_opaque_region(w.surface, NULL); + + EGL_SwapBuffers(); + //wl_surface_damage(w.surface, 0, 0, vid.pixelwidth, vid.pixelheight); + wl_display_dispatch_pending(w.display); +} + +static qboolean WL_Init (rendererstate_t *info, unsigned char *palette) +{ + cvar_t *v; + w.display = wl_display_connect(NULL); + if (!w.display) + { + Con_Printf("couldn't connect to wayland server\n"); + return false; + } + w.registry = wl_display_get_registry(w.display); + wl_registry_add_listener(w.registry, &WL_registry_listener, &w); //w.compositor = + + v = Cvar_FindVar("gl_menutint_shader"); + if (v && v->ival) + { + Con_Printf("Disabling gl_menutint_shader to avoid wayland/mesa EGL bugs.\n"); + Cvar_SetValue(v, 0); + } + v = Cvar_FindVar("r_waterstyle"); + if (v && v->ival>1) + { + Con_Printf("Disabling r_waterstyle to avoid wayland/mesa EGL bugs.\n"); + Cvar_SetValue(v, 1); + } + v = Cvar_FindVar("r_slimestyle"); + if (v && v->ival>1) + { + Con_Printf("Disabling r_slimestyle to avoid wayland/mesa EGL bugs.\n"); + Cvar_SetValue(v, 1); + } + v = Cvar_FindVar("r_lavastyle"); + if (v && v->ival>1) + { + Con_Printf("Disabling r_lavastyle to avoid wayland/mesa EGL bugs.\n"); + Cvar_SetValue(v, 1); + } + + WL_waitabit(); + + if (!w.compositor) + { + Con_Printf("no compositor running, apparently\n"); + return false; + } + + w.surface = wl_compositor_create_surface(w.compositor); + w.ssurface = wl_shell_get_shell_surface(w.shell, w.surface); + wl_shell_surface_add_listener(w.ssurface, &shell_surface_listener, &w); + w.enwindow = wl_egl_window_create(w.surface, info->width, info->height); + + vid.pixelwidth = info->width; + vid.pixelheight = info->height; + + setenv("EGL_PLATFORM", "wayland", 1); + if (!EGL_LoadLibrary(info->subrenderer)) + { + Con_Printf("couldn't load EGL library\n"); + return false; + } + + if (!EGL_Init(info, palette, (EGLNativeWindowType)w.enwindow, (EGLNativeDisplayType) w.display)) + { + Con_Printf("couldn't initialise EGL context\n"); + return false; + } + + if (info->fullscreen) + wl_shell_surface_set_fullscreen(w.ssurface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 60, NULL); + else + wl_shell_surface_set_toplevel(w.ssurface); + + + //window_set_keyboard_focus_handler(window, WL_handler_keyfocus); + //window_set_resize_handler(w.surface, WL_handler_resize); + + wl_display_dispatch_pending(w.display); + + GL_Init(&EGL_Proc); + +// while(1) +// WL_SwapBuffers(); + return true; +} +static void WL_DeInit(void) +{ + EGL_Shutdown(); + wl_egl_window_destroy(w.enwindow); +} +static qboolean WL_ApplyGammaRamps(unsigned short *ramps) +{ + //not supported + return false; +} +static void WL_SetCaption(char *text) +{ + wl_shell_surface_set_title(w.ssurface, text); +} + +#include "gl_draw.h" +rendererinfo_t waylandrendererinfo = +{ + "Wayland", + { + "wayland" + }, + QR_OPENGL, + + GLDraw_Init, + GLDraw_DeInit, + + GL_LoadTextureFmt, + GL_LoadTexture8Pal24, + GL_LoadTexture8Pal32, + GL_LoadCompressed, + GL_FindTexture, + GL_AllocNewTexture, + GL_UploadFmt, + GL_DestroyTexture, + + GLR_Init, + GLR_DeInit, + GLR_RenderView, + + GLR_NewMap, + GLR_PreNewMap, + + WL_Init, + WL_DeInit, + WL_SwapBuffers, + WL_ApplyGammaRamps, + WL_SetCaption, //setcaption + GLVID_GetRGBInfo, + + + GLSCR_UpdateScreen, + + GLBE_SelectMode, + GLBE_DrawMesh_List, + GLBE_DrawMesh_Single, + GLBE_SubmitBatch, + GLBE_GetTempBatch, + GLBE_DrawWorld, + GLBE_Init, + GLBE_GenBrushModelVBO, + GLBE_ClearVBO, + GLBE_UploadAllLightmaps, + GLBE_SelectEntity, + GLBE_SelectDLight, + GLBE_Scissor, + GLBE_LightCullModel, + + GLBE_VBO_Begin, + GLBE_VBO_Data, + GLBE_VBO_Finish, + GLBE_VBO_Destroy, + + GLBE_RenderToTextureUpdate2d, + + "" +}; + +#endif + diff --git a/engine/gl/glquake.h b/engine/gl/glquake.h index 707af4486..6653ba972 100644 --- a/engine/gl/glquake.h +++ b/engine/gl/glquake.h @@ -59,29 +59,13 @@ extern r_config_t r_config; #endif #else #include - /*gles has no fixed function*/ - #define GL_PROJECTION 0 - #define GL_MODELVIEW 0 - #define GL_CLIP_PLANE0 0 - #define GL_ALPHA_TEST 0 - #define GL_MODULATE 0 - #define GL_FLAT 0 - #define GL_SMOOTH 0 - #define GL_DECAL 0 - #define GL_ADD 0 - #define GL_TEXTURE_ENV 0 - #define GL_TEXTURE_ENV_MODE 0 - #define GL_COLOR_ARRAY 0 - #define GL_VERTEX_ARRAY 0 #define GL_TEXTURE_COORD_ARRAY 0 #endif /*gles has no doubles*/ #define GLclampd GLclampf #define GLdouble GLfloat - #define GL_CLAMP GL_CLAMP_TO_EDGE #define GL_NONE 0 - #define GL_FILL (Sys_Error("GL_FILL was used"),0) #define GL_QUADS (Sys_Error("GL_QUADS was used"),0) #elif defined(__MACOSX__) //apple, you suck. @@ -90,28 +74,6 @@ extern r_config_t r_config; #include #define GLclampd GLclampf #define GLdouble GLfloat - #define GL_CLAMP GL_CLAMP_TO_EDGE - #define GL_POLYGON (Con_Printf("GL_POLYGON was used"),0) - #define GL_QUAD_STRIP (Con_Printf("GL_QUAD_STRIP was used"),0) - #define GL_QUADS (Con_Printf("GL_QUADS was used"),0) - - - #define GL_PROJECTION (Con_Printf("GL_PROJECTION was used"),0) - #define GL_MODELVIEW (Con_Printf("GL_MODELVIEW was used"),0) - #define GL_CLIP_PLANE0 (Con_Printf("GL_CLIP_PLANE0 was used"),0) - #define GL_MODULATE (Con_Printf("GL_MODULATE was used"),0) - #define GL_FLAT (Con_Printf("GL_FLAT was used"),0) - #define GL_SMOOTH (Con_Printf("GL_SMOOTH was used"),0) - #define GL_DECAL (Con_Printf("GL_DECAL was used"),0) - #define GL_ADD (Con_Printf("GL_ADD was used"),0) - #define GL_FILL (Con_Printf("GL_FILL was used"),0) - #define GL_TEXTURE_ENV (Con_Printf("GL_TEXTURE_ENV was used"),0) - #define GL_TEXTURE_ENV_MODE (Con_Printf("GL_TEXTURE_ENV_MODE was used"),0) - #define GL_COLOR_ARRAY (Con_Printf("GL_COLOR_ARRAY was used"),0) - #define GL_VERTEX_ARRAY (Con_Printf("GL_VERTEX_ARRAY was used"),0) - #define GL_TEXTURE_COORD_ARRAY (Con_Printf("GL_TEXTURE_COORD_ARRAY was used"),0) - - #else #include #ifdef GL_STATIC @@ -121,11 +83,53 @@ extern r_config_t r_config; #endif //#include #include "glsupp.h" + + + + /*gles2 has no fixed function*/ +#ifndef GL_ALPHA_TEST + #define GL_ALPHA_TEST 0 +#endif +#ifndef GL_FILL + #define GL_FILL (Sys_Error("GL_FILL was used"),0) +#endif +#ifndef GL_CLAMP + #define GL_CLAMP GL_CLAMP_TO_EDGE +#endif +#ifndef GL_TEXTURE_ENV + #define GL_TEXTURE_ENV (Con_Printf("GL_TEXTURE_ENV was used"),0) + #define GL_TEXTURE_ENV_MODE (Con_Printf("GL_TEXTURE_ENV_MODE was used"),0) + #define GL_VERTEX_ARRAY (Con_Printf("GL_VERTEX_ARRAY was used"),0) + #define GL_COLOR_ARRAY (Con_Printf("GL_COLOR_ARRAY was used"),0) + #define GL_TEXTURE_COORD_ARRAY (Con_Printf("GL_TEXTURE_COORD_ARRAY was used"),0) + #define GL_DECAL (Con_Printf("GL_DECAL was used"),0) + #define GL_ADD (Con_Printf("GL_ADD was used"),0) + #define GL_FLAT (Con_Printf("GL_FLAT was used"),0) + #define GL_SMOOTH (Con_Printf("GL_SMOOTH was used"),0) + #define GL_MODULATE 0x2100 + #define GL_PROJECTION (Con_Printf("GL_PROJECTION was used"),0) + #define GL_MODELVIEW (Con_Printf("GL_MODELVIEW was used"),0) + #define GL_CLIP_PLANE0 (Con_Printf("GL_CLIP_PLANE0 was used"),0) +#endif +#ifndef GL_COLOR_ARRAY_POINTER + #define GL_COLOR_ARRAY_POINTER 0 + #define GL_NORMAL_ARRAY 0 + #define GL_NORMAL_ARRAY_POINTER 0 + #define GL_TEXTURE_COORD_ARRAY_POINTER 0 + #define GL_VERTEX_ARRAY_POINTER 0 + #define GL_BLEND_SRC 0 + #define GL_BLEND_DST 0 +#endif +#ifndef GL_POLYGON + #define GL_POLYGON (Con_Printf("GL_POLYGON was used"),0) + #define GL_QUAD_STRIP (Con_Printf("GL_QUAD_STRIP was used"),0) + #define GL_QUADS (Con_Printf("GL_QUADS was used"),0) +#endif void GL_InitFogTexture(void); -void GL_BeginRendering (void); -void GL_EndRendering (void); +#define GL_BeginRendering() +#define GL_EndRendering() void GL_FlushSkinCache(void); void GL_GAliasFlushSkinCache(void); @@ -342,13 +346,6 @@ void GL_ForceDepthWritable(void); #endif -// -// vid_gl*.c -// -#ifdef GLQUAKE -void GL_DoSwap (void); -#endif - // // gl_backend.c // diff --git a/engine/http/ftpserver.c b/engine/http/ftpserver.c index 2513aeadc..215c6b6ac 100644 --- a/engine/http/ftpserver.c +++ b/engine/http/ftpserver.c @@ -159,9 +159,9 @@ static int QDECL SendFileNameTo(const char *rawname, qofs_t size, void *param, s fname = slash+1; if (isdir) - sprintf(buffer, "drw-r--r--\t1\troot\troot\t%8u Jan 1 12:00 %s\r\n", size, fname); + sprintf(buffer, "drw-r--r--\t1\troot\troot\t%8u Jan 1 12:00 %s\r\n", (unsigned int)size, fname); else - sprintf(buffer, "-rw-r--r--\t1\troot\troot\t%8u Jan 1 12:00 %s\r\n", size, fname); + sprintf(buffer, "-rw-r--r--\t1\troot\troot\t%8u Jan 1 12:00 %s\r\n", (unsigned int)size, fname); // strcpy(buffer, fname); // for (i = strlen(buffer); i < 40; i+=8) diff --git a/engine/http/httpclient.c b/engine/http/httpclient.c index 5a504e587..d81b5a6b0 100644 --- a/engine/http/httpclient.c +++ b/engine/http/httpclient.c @@ -730,14 +730,14 @@ void HTTPDL_Establish(struct dl_download *dl) Q_snprintfz(con->buffer, con->bufferlen, "POST %s HTTP/1.1\r\n" "Host: %s\r\n" - "Content-Length: %i\r\n" + "Content-Length: %u\r\n" "Content-Type: %s\r\n" "Connection: close\r\n" #if !defined(NPFTE) && defined(AVAIL_ZLIB) "Accept-Encoding: gzip\r\n" #endif "User-Agent: "FULLENGINENAME"\r\n" - "\r\n", uri, server, dl->postlen, dl->postmimetype); + "\r\n", uri, server, (unsigned int)dl->postlen, dl->postmimetype); con->bufferused = strlen(con->buffer); memcpy(con->buffer + con->bufferused, dl->postdata, dl->postlen); con->bufferused += dl->postlen; diff --git a/engine/qclib/qcc_pr_lex.c b/engine/qclib/qcc_pr_lex.c index 80a9be49c..9f541b4f3 100644 --- a/engine/qclib/qcc_pr_lex.c +++ b/engine/qclib/qcc_pr_lex.c @@ -2949,7 +2949,7 @@ char *QCC_PR_CheckCompConstTooltip(char *word, char *outstart, char *outend) QC_snprintfz(out, outend-out, "%s", c->params[i]); out += strlen(out); } - QC_snprintfz(out, outend-out, ")", c->name); + QC_snprintfz(out, outend-out, ")"); } else QC_snprintfz(out, outend-out, "#define %s", c->name); diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index ea6a577f7..7be7fc823 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -2784,7 +2784,7 @@ void SV_DownloadSize_f(void) break; case -5: /*package*/ case 0: /*exists*/ - name = va("dlsize \"%s\" %u\n", name, loc.len); + name = va("dlsize \"%s\" %u\n", name, (unsigned int)loc.len); ClientReliableWrite_Begin (host_client, svc_stufftext, 2+strlen(name)); ClientReliableWrite_String (host_client, name); break; diff --git a/engine/web/gl_vidweb.c b/engine/web/gl_vidweb.c index de1c77ede..c7ff4283b 100644 --- a/engine/web/gl_vidweb.c +++ b/engine/web/gl_vidweb.c @@ -142,17 +142,8 @@ void GLVID_DeInit (void) } -void GL_BeginRendering (void) +void VIDGL_SwapBuffers (void) { -} - -qboolean screenflush; -void GL_DoSwap (void) -{ - if (!screenflush) - return; - screenflush = 0; - //webgl doesn't support swapbuffers. //you can't use it for loading screens. //such things must result in waiting until the following frame. @@ -179,13 +170,6 @@ void GL_DoSwap (void) */ } -void GL_EndRendering (void) -{ - screenflush = true; - if (!gl_lateswap.value) - GL_DoSwap(); -} - qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) { gammaworks = false;