From 74a7dff814dee38ad246d30d4bd5fc4bde9a17b1 Mon Sep 17 00:00:00 2001 From: Spoike Date: Thu, 28 Jul 2016 15:57:22 +0000 Subject: [PATCH] Make sure vk+x11 can deal with window resizes properly. Fix some warnings. Deal with hardware that uses gamma ramps larger than 256 entries on x11. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5011 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/Makefile | 2 +- engine/client/m_download.c | 5 +- engine/client/merged.h | 2 +- engine/client/pr_csqc.c | 4 +- engine/client/renderer.c | 3 + engine/client/sys_linux.c | 101 +++--- engine/client/vid.h | 3 +- engine/client/vid_headless.c | 2 +- engine/client/view.c | 12 +- engine/common/com_mesh.c | 4 +- engine/common/common.c | 5 +- engine/d3d/vid_d3d.c | 4 +- engine/d3d/vid_d3d11.c | 3 +- engine/gl/gl_viddroid.c | 2 +- engine/gl/gl_vidlinuxglx.c | 32 +- engine/gl/gl_vidnt.c | 4 +- engine/gl/gl_vidrpi.c | 2 +- engine/gl/gl_vidsdl.c | 6 +- engine/gl/gl_vidwayland.c | 2 +- engine/nacl/gl_vidppapi.c | 580 +++++++++++++++++------------------ engine/sw/sw_vidwin.c | 2 +- engine/vk/vk_backend.c | 3 +- engine/vk/vk_init.c | 6 +- engine/vk/vk_win32.c | 4 +- engine/web/gl_vidweb.c | 2 +- 25 files changed, 407 insertions(+), 388 deletions(-) diff --git a/engine/Makefile b/engine/Makefile index 191a8b3dc..320a4607e 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -1130,7 +1130,7 @@ ifeq ($(FTE_TARGET),bsd) M_EXE_NAME=../fteqw MCL_EXE_NAME=../fteqwcl M_LDFLAGS=$(GLLDFLAGS) $(XLDFLAGS) -lpthread - M_CFLAGS=$(GLCFLAGS) -I/usr/X11R6/include + M_CFLAGS=$(VKCFLAGS) $(GLCFLAGS) -I/usr/X11R6/include MB_DIR=m_bsd MCL_DIR=mcl_bsd diff --git a/engine/client/m_download.c b/engine/client/m_download.c index 0e2423486..63aa0d5b7 100644 --- a/engine/client/m_download.c +++ b/engine/client/m_download.c @@ -323,9 +323,9 @@ static package_t *BuildPackageList(vfsfile_t *f, int flags, const char *url, con } if (*prefix) - Q_snprintfz(p->fullname, sizeof(p->fullname), "%s/%s", prefix, Cmd_Argv(0)); + Q_snprintfz(p->fullname, sizeof(p->fullname), "%s/%s", prefix, fullname); else - Q_snprintfz(p->fullname, sizeof(p->fullname), "%s", Cmd_Argv(0)); + Q_snprintfz(p->fullname, sizeof(p->fullname), "%s", fullname); p->name = COM_SkipPath(p->fullname); if (!gamedir) @@ -483,7 +483,6 @@ static package_t *BuildPackageList(vfsfile_t *f, int flags, const char *url, con static void COM_QuotedConcat(const char *cat, char *buf, size_t bufsize) { - qboolean haswhite = false; const unsigned char *gah; for (gah = (const unsigned char*)cat; *gah; gah++) { diff --git a/engine/client/merged.h b/engine/client/merged.h index 1e7c86976..2180c1700 100644 --- a/engine/client/merged.h +++ b/engine/client/merged.h @@ -406,7 +406,7 @@ 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); + qboolean (*VID_ApplyGammaRamps) (unsigned int size, unsigned short *ramps); void *(*VID_CreateCursor) (const char *filename, float hotx, float hoty, float scale); //may be null, stub returns null qboolean (*VID_SetCursor) (void *cursor); //may be null diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index 1bcc9a623..3696e4a09 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -318,7 +318,7 @@ static void CSQC_FindGlobals(qboolean nofuncs) if (!csqcg.trace_surfaceflagsf && !csqcg.trace_surfaceflagsi) { - etype_t etype; + etype_t etype = ev_void; eval_t *v = PR_FindGlobal(csqcprogs, "trace_surfaceflags", 0, &etype); if (etype == ev_float) csqcg.trace_surfaceflagsf = &v->_float; @@ -327,7 +327,7 @@ static void CSQC_FindGlobals(qboolean nofuncs) } if (!csqcg.trace_endcontentsf && !csqcg.trace_endcontentsi) { - etype_t etype; + etype_t etype = ev_void; eval_t *v = PR_FindGlobal(csqcprogs, "trace_endcontents", 0, &etype); if (etype == ev_float) csqcg.trace_endcontentsf = &v->_float; diff --git a/engine/client/renderer.c b/engine/client/renderer.c index 027bfd0ed..9e009b6c8 100644 --- a/engine/client/renderer.c +++ b/engine/client/renderer.c @@ -1263,10 +1263,13 @@ q2colormap: TRACE(("dbg: R_ApplyRenderer: Palette loaded\n")); if (newr) + { + vid.gammarampsize = 256; //make a guess. if (!VID_Init(newr, host_basepal)) { return false; } + } TRACE(("dbg: R_ApplyRenderer: vid applied\n")); W_LoadWadFile("gfx.wad"); diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index 73b1448b7..b32c49100 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -618,79 +618,80 @@ void DumpGLState(void); #endif static void Friendly_Crash_Handler(int sig, siginfo_t *info, void *vcontext) { - int fd; - void *array[64]; - size_t size; - int firstframe = 0; - char signame[32]; + int fd; + void *array[64]; + size_t size; + int firstframe = 0; + char signame[32]; - switch(sig) - { + switch(sig) + { case SIGINT: strcpy(signame, "SIGINT"); break; - case SIGILL: strcpy(signame, "SIGILL"); break; - case SIGFPE: strcpy(signame, "SIGFPE"); break; - case SIGBUS: strcpy(signame, "SIGBUS"); break; - case SIGSEGV: Q_snprintfz(signame, sizeof(signame), "SIGSEGV (%p)", info->si_addr); break; - default: Q_snprintfz(signame, sizeof(signame), "%i", sig); break; - } + case SIGILL: strcpy(signame, "SIGILL"); break; + case SIGFPE: strcpy(signame, "SIGFPE"); break; + case SIGBUS: strcpy(signame, "SIGBUS"); break; + case SIGSEGV: Q_snprintfz(signame, sizeof(signame), "SIGSEGV (%p)", info->si_addr); break; + default: Q_snprintfz(signame, sizeof(signame), "%i", sig); break; + } - // get void*'s for all entries on the stack - size = backtrace(array, sizeof(array)/sizeof(array[0])); + // get void*'s for all entries on the stack + size = backtrace(array, sizeof(array)/sizeof(array[0])); #if defined(__i386__) - //x86 signals don't leave the stack in a clean state, so replace the signal handler with the real crash address, and hide this function - ucontext_t *uc = vcontext; - array[1] = (void*)uc->uc_mcontext.gregs[REG_EIP]; - firstframe = 1; + //x86 signals don't leave the stack in a clean state, so replace the signal handler with the real crash address, and hide this function + ucontext_t *uc = vcontext; + array[1] = (void*)uc->uc_mcontext.gregs[REG_EIP]; + firstframe = 1; #elif defined(__amd64__) - //amd64 is sane enough, but this function and the libc signal handler are on the stack, and should be ignored. - firstframe = 2; + //amd64 is sane enough, but this function and the libc signal handler are on the stack, and should be ignored. + firstframe = 2; #endif - // print out all the frames to stderr - fprintf(stderr, "Error: signal %s:\n", signame); - backtrace_symbols_fd(array+firstframe, size-firstframe, 2); + // print out all the frames to stderr + fprintf(stderr, "Error: signal %s:\n", signame); + backtrace_symbols_fd(array+firstframe, size-firstframe, 2); if (sig == SIGINT) fd = -1; //don't write out crash logs on ctrl+c else fd = open("crash.log", O_WRONLY|O_CREAT|O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP); - if (fd != -1) - { - time_t rawtime; - struct tm * timeinfo; - char buffer [80]; + if (fd != -1) + { + time_t rawtime; + struct tm * timeinfo; + char buffer [80]; - time (&rawtime); - timeinfo = localtime (&rawtime); - strftime (buffer, sizeof(buffer), "Time: %Y-%m-%d %H:%M:%S\n",timeinfo); - write(fd, buffer, strlen(buffer)); + time (&rawtime); + timeinfo = localtime (&rawtime); + strftime (buffer, sizeof(buffer), "Time: %Y-%m-%d %H:%M:%S\n",timeinfo); + write(fd, buffer, strlen(buffer)); - Q_snprintfz(buffer, sizeof(buffer), "Binary: "__DATE__" "__TIME__"\n"); - write(fd, buffer, strlen(buffer)); - Q_snprintfz(buffer, sizeof(buffer), "Ver: %i.%02i%s\n", FTE_VER_MAJOR, FTE_VER_MINOR, + Q_snprintfz(buffer, sizeof(buffer), "Binary: "__DATE__" "__TIME__"\n"); + write(fd, buffer, strlen(buffer)); + Q_snprintfz(buffer, sizeof(buffer), "Ver: %i.%02i%s\n", FTE_VER_MAJOR, FTE_VER_MINOR, #ifdef OFFICIAL_RELEASE - " (official)"); + " (official)"); #else - ""); + ""); #endif - write(fd, buffer, strlen(buffer)); + write(fd, buffer, strlen(buffer)); #ifdef SVNREVISION - if (strcmp(STRINGIFY(SVNREVISION), "-")) - { - Q_snprintfz(buffer, sizeof(buffer), "Revision: %s\n", STRINGIFY(SVNREVISION)); - write(fd, buffer, strlen(buffer)); - } + if (strcmp(STRINGIFY(SVNREVISION), "-")) + { + Q_snprintfz(buffer, sizeof(buffer), "Revision: %s\n", STRINGIFY(SVNREVISION)); + write(fd, buffer, strlen(buffer)); + } #endif - backtrace_symbols_fd(array + firstframe, size - firstframe, fd); - write(fd, "\n", 1); - close(fd); - } + backtrace_symbols_fd(array + firstframe, size - firstframe, fd); + write(fd, "\n", 1); + close(fd); + } #if defined(DEBUG) && defined(GLQUAKE) - DumpGLState(); + if (qrenderer == QR_OPENGL) + DumpGLState(); #endif - exit(1); + exit(1); } #endif // ======================================================================= diff --git a/engine/client/vid.h b/engine/client/vid.h index 43bcc4ff7..f0d19dec9 100644 --- a/engine/client/vid.h +++ b/engine/client/vid.h @@ -75,6 +75,7 @@ typedef struct qboolean activeapp; qboolean isminimized; //can omit rendering as it won't be seen anyway. int fullbright; // index of first fullbright color + int gammarampsize; //typically 256. but can be up to 1024 (yay 10-bit hardware that's crippled to only actually use 8) unsigned fbvwidth; /*virtual 2d width of the current framebuffer image*/ unsigned fbvheight; /*virtual 2d height*/ @@ -103,7 +104,7 @@ extern unsigned int d_8to24bgrtable[256]; #ifdef GLQUAKE //called when gamma ramps need to be reapplied -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps); +qboolean GLVID_ApplyGammaRamps (unsigned int size, unsigned short *ramps); qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette); // Called at startup to set up translation tables, takes 256 8 bit RGB values diff --git a/engine/client/vid_headless.c b/engine/client/vid_headless.c index 2b73d82cf..8bd0ea95e 100644 --- a/engine/client/vid_headless.c +++ b/engine/client/vid_headless.c @@ -150,7 +150,7 @@ static void Headless_VID_DeInit (void) static void Headless_VID_SwapBuffers (void) { } -static qboolean Headless_VID_ApplyGammaRamps (unsigned short *ramps) +static qboolean Headless_VID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { return false; } diff --git a/engine/client/view.c b/engine/client/view.c index ddce5a4d1..8a3f24e17 100644 --- a/engine/client/view.c +++ b/engine/client/view.c @@ -324,7 +324,6 @@ cvar_t v_brightness = CVARFDC("brightness", "0.0", CVAR_ARCHIVE, "Brightness is qbyte gammatable[256]; // palette is sent through this -unsigned short ramps[3][256]; qboolean gammaworks; float hw_blend[4]; // rgba 0.0 - 1.0 /* @@ -849,6 +848,9 @@ void V_UpdatePalette (qboolean force) if (hw_blend[0] != newhw_blend[0] || hw_blend[1] != newhw_blend[1] || hw_blend[2] != newhw_blend[2] || hw_blend[3] != newhw_blend[3] || force) { float r,g,b,a; + static unsigned short allramps[3*2048]; + unsigned int rampsize = min(vid.gammarampsize, countof(allramps)/3); + unsigned short *ramps[3] = {&allramps[0],&allramps[rampsize],&allramps[rampsize*2]}; Vector4Copy(newhw_blend, hw_blend); a = hw_blend[3]; @@ -857,7 +859,8 @@ void V_UpdatePalette (qboolean force) b = 255*hw_blend[2]*a; a = 1-a; - for (i=0 ; i<256 ; i++) + a *= 256.0/rampsize; + for (i=0 ; i < rampsize; i++) { ir = i*a + r; ig = i*a + g; @@ -869,6 +872,7 @@ void V_UpdatePalette (qboolean force) if (ib > 255) ib = 255; + //FIXME: shit precision ramps[0][i] = gammatable[ir]<<8; ramps[1][i] = gammatable[ig]<<8; ramps[2][i] = gammatable[ib]<<8; @@ -876,9 +880,9 @@ void V_UpdatePalette (qboolean force) if (qrenderer) { - applied = rf->VID_ApplyGammaRamps ((unsigned short*)ramps); + applied = rf->VID_ApplyGammaRamps (rampsize, allramps); if (!applied && r2d_canhwgamma) - rf->VID_ApplyGammaRamps (NULL); + rf->VID_ApplyGammaRamps (0, NULL); r2d_canhwgamma = applied; } } diff --git a/engine/common/com_mesh.c b/engine/common/com_mesh.c index a8832e4e3..7cce784f4 100644 --- a/engine/common/com_mesh.c +++ b/engine/common/com_mesh.c @@ -2251,7 +2251,7 @@ qboolean Mod_Trace(model_t *model, int forcehullnum, int frame, vec3_t axis[3], #ifdef SKELETALMODELS if (mod->ofs_skel_weight) { //fixme: would be better to consider the distance to the vertex too. cartesian coord stuff etc. - unsigned int best = 0, v, w, i; + unsigned int v, w, i; float bw = 0; for (i = 0; i < 3; i++) { @@ -7839,4 +7839,4 @@ void Alias_Register(void) Mod_RegisterModelFormatText(NULL, "MD5 Mesh/Anim (md5mesh)", "MD5Version", Mod_LoadMD5MeshModel); Mod_RegisterModelFormatText(NULL, "External Anim", "EXTERNALANIM", Mod_LoadCompositeAnim); #endif -} \ No newline at end of file +} diff --git a/engine/common/common.c b/engine/common/common.c index 5e10befcf..5757ccbb4 100644 --- a/engine/common/common.c +++ b/engine/common/common.c @@ -4548,6 +4548,9 @@ void COM_Version_f (void) Con_Printf("(GLSL)"); #endif #endif +#ifdef VKQUAKE + Con_Printf(" Vulkan"); +#endif #ifdef D3D9QUAKE Con_Printf(" Direct3D9"); #endif @@ -5069,7 +5072,7 @@ static int COM_WorkerThread(void *arg) static void Sys_ErrorThread(void *ctx, void *data, size_t a, size_t b) { //posted to main thread from a worker. - Sys_Error("%s", data); + Sys_Error("%s", (const char*)data); } void COM_WorkerAbort(char *message) { diff --git a/engine/d3d/vid_d3d.c b/engine/d3d/vid_d3d.c index 480ffacb3..70fae879b 100644 --- a/engine/d3d/vid_d3d.c +++ b/engine/d3d/vid_d3d.c @@ -790,11 +790,11 @@ static void (D3D9_VID_DeInit) (void) // Cvar_Unhook(&v_brightness); } -qboolean D3D9_VID_ApplyGammaRamps (unsigned short *ramps) +qboolean D3D9_VID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { if (d3dpp.Windowed) return false; - if (pD3DDev9 && ramps) + if (pD3DDev9 && ramps && gammarampsize == 256) IDirect3DDevice9_SetGammaRamp(pD3DDev9, 0, D3DSGR_NO_CALIBRATION, (D3DGAMMARAMP *)ramps); return true; } diff --git a/engine/d3d/vid_d3d11.c b/engine/d3d/vid_d3d11.c index cbc49f3da..aa4456600 100644 --- a/engine/d3d/vid_d3d11.c +++ b/engine/d3d/vid_d3d11.c @@ -1058,6 +1058,7 @@ extern float hw_blend[4]; // rgba 0.0 - 1.0 static void D3D11_BuildRamps(int points, DXGI_RGB *out) { +//FIXME: repack input rather than recalculating. int i; vec3_t cshift; vec3_t c; @@ -1076,7 +1077,7 @@ static void D3D11_BuildRamps(int points, DXGI_RGB *out) } } -static qboolean D3D11_VID_ApplyGammaRamps(unsigned short *ramps) +static qboolean D3D11_VID_ApplyGammaRamps(unsigned int gammarampsize, unsigned short *ramps) { HRESULT hr; DXGI_GAMMA_CONTROL_CAPABILITIES caps; diff --git a/engine/gl/gl_viddroid.c b/engine/gl/gl_viddroid.c index bd4c8473f..c47325131 100644 --- a/engine/gl/gl_viddroid.c +++ b/engine/gl/gl_viddroid.c @@ -184,7 +184,7 @@ void GLVID_SwapBuffers(void) } #endif -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) +qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { return false; } diff --git a/engine/gl/gl_vidlinuxglx.c b/engine/gl/gl_vidlinuxglx.c index 4ef44a23b..8d1495319 100644 --- a/engine/gl/gl_vidlinuxglx.c +++ b/engine/gl/gl_vidlinuxglx.c @@ -327,8 +327,9 @@ static struct XF86VidModeModeInfo **modes; int num_modes; int usemode; - unsigned short originalramps[3][256]; + unsigned short originalramps[3][2048]; qboolean originalapplied; //states that the origionalramps arrays are valid, and contain stuff that we should revert to on close + int originalrampsize; } vm; static qboolean VMODE_Init(void) { @@ -1017,6 +1018,9 @@ static void GetEvent(void) x11.pXFreeEventData(vid_dpy, &event.xcookie); break; case ResizeRequest: +#ifdef VKQUAKE + vk.neednewswapchain = true; +#endif vid.pixelwidth = event.xresizerequest.width; vid.pixelheight = event.xresizerequest.height; Cvar_ForceCallback(&vid_conautoscale); @@ -1026,6 +1030,9 @@ static void GetEvent(void) case ConfigureNotify: if (event.xconfigurerequest.window == vid_window) { +#ifdef VKQUAKE + vk.neednewswapchain = true; +#endif vid.pixelwidth = event.xconfigurerequest.width; vid.pixelheight = event.xconfigurerequest.height; Cvar_ForceCallback(&vid_conautoscale); @@ -1179,7 +1186,7 @@ static void GetEvent(void) } if (vm.originalapplied) - vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, vm.originalrampsize, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); mw = vid_window; if ((fullscreenflags & FULLSCREEN_LEGACY) && (fullscreenflags & FULLSCREEN_ACTIVE)) @@ -1267,7 +1274,7 @@ void GLVID_Shutdown(void) uninstall_grabs(); if (vm.originalapplied) - vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, vm.originalrampsize, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); X_ShutdownUnicode(); @@ -1344,7 +1351,7 @@ static Cursor CreateNullCursor(Display *display, Window root) return cursor; } -qboolean GLVID_ApplyGammaRamps(unsigned short *ramps) +qboolean GLVID_ApplyGammaRamps(unsigned int rampcount, unsigned short *ramps) { extern qboolean gammaworks; //extern cvar_t vid_hardwaregamma; @@ -1353,7 +1360,7 @@ qboolean GLVID_ApplyGammaRamps(unsigned short *ramps) if (!vm.originalapplied) return false; - if (ramps) + if (ramps || rampcount != vm.originalrampsize) { //hardwaregamma==1 skips hardware gamma when we're not fullscreen, in favour of software glsl based gamma. // if (vid_hardwaregamma.value == 1 && !vid.activeapp && !(fullscreenflags & FULLSCREEN_ACTIVE)) @@ -1365,15 +1372,15 @@ qboolean GLVID_ApplyGammaRamps(unsigned short *ramps) //we have hardware gamma applied - if we're doing a BF, we don't want to reset to the default gamma if it randomly fails (yuck) if (gammaworks) - vm.pXF86VidModeSetGammaRamp (vid_dpy, scrnum, 256, &ramps[0], &ramps[256], &ramps[512]); + vm.pXF86VidModeSetGammaRamp (vid_dpy, scrnum, rampcount, &ramps[0], &ramps[rampcount], &ramps[rampcount*2]); else - gammaworks = !!vm.pXF86VidModeSetGammaRamp (vid_dpy, scrnum, 256, &ramps[0], &ramps[256], &ramps[512]); + gammaworks = !!vm.pXF86VidModeSetGammaRamp (vid_dpy, scrnum, rampcount, &ramps[0], &ramps[rampcount], &ramps[rampcount*2]); return gammaworks; } else { - vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, vm.originalrampsize, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); return true; } } @@ -1845,13 +1852,16 @@ qboolean X11VID_Init (rendererstate_t *info, unsigned char *palette, int psl) { int rampsize = 256; vm.pXF86VidModeGetGammaRampSize(vid_dpy, scrnum, &rampsize); - if (rampsize != 256) + if (rampsize > countof(vm.originalramps[0])) { vm.originalapplied = false; Con_Printf("Gamma ramps are not of 256 components (but %i).\n", rampsize); } else - vm.originalapplied = vm.pXF86VidModeGetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + { + vm.originalrampsize = vid.gammarampsize = rampsize; + vm.originalapplied = vm.pXF86VidModeGetGammaRamp(vid_dpy, scrnum, vm.originalrampsize, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + } } else vm.originalapplied = false; @@ -2033,7 +2043,7 @@ void Sys_SendKeyEvents(void) if (fullscreenflags & FULLSCREEN_VMODE) { if (vm.originalapplied) - vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, 256, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); + vm.pXF86VidModeSetGammaRamp(vid_dpy, scrnum, vm.originalrampsize, vm.originalramps[0], vm.originalramps[1], vm.originalramps[2]); if (fullscreenflags & FULLSCREEN_VMODEACTIVE) { vm.pXF86VidModeSwitchToMode(vid_dpy, scrnum, vm.modes[0]); diff --git a/engine/gl/gl_vidnt.c b/engine/gl/gl_vidnt.c index 1ad34ea6f..022bbcfe7 100644 --- a/engine/gl/gl_vidnt.c +++ b/engine/gl/gl_vidnt.c @@ -1831,11 +1831,11 @@ void OblitterateOldGamma(void) } } -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) +qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { if (ramps) { - if (!gammaworks) + if (!gammaworks || gammarampsize != 256) return false; if (vid_hardwaregamma.value == 1 && modestate == MS_WINDOWED) diff --git a/engine/gl/gl_vidrpi.c b/engine/gl/gl_vidrpi.c index 357a35ed2..9dc345d62 100644 --- a/engine/gl/gl_vidrpi.c +++ b/engine/gl/gl_vidrpi.c @@ -68,7 +68,7 @@ void RPI_DeInit(void) { EGL_Shutdown(); } -qboolean RPI_ApplyGammaRamps(unsigned short *ramps) +qboolean RPI_ApplyGammaRamps(unsigned int gammarampsize, unsigned short *ramps) { //not supported return false; diff --git a/engine/gl/gl_vidsdl.c b/engine/gl/gl_vidsdl.c index 95cb88d43..dcb3feb4b 100644 --- a/engine/gl/gl_vidsdl.c +++ b/engine/gl/gl_vidsdl.c @@ -328,10 +328,10 @@ void GLVID_SwapBuffers (void) } } -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) +qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { #if SDL_MAJOR_VERSION >= 2 - if (ramps) + if (ramps && gammarampsize == 256) { if (vid_hardwaregamma.value) { @@ -353,7 +353,7 @@ qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) return true; } #else - if (ramps) + if (ramps && gammarampsize == 256) { if (vid_hardwaregamma.value) { diff --git a/engine/gl/gl_vidwayland.c b/engine/gl/gl_vidwayland.c index 7a69e4146..23e0a287c 100644 --- a/engine/gl/gl_vidwayland.c +++ b/engine/gl/gl_vidwayland.c @@ -396,7 +396,7 @@ static void WL_DeInit(void) EGL_Shutdown(); wl_egl_window_destroy(w.enwindow); } -static qboolean WL_ApplyGammaRamps(unsigned short *ramps) +static qboolean WL_ApplyGammaRamps(unsigned int gammarampsize, unsigned short *ramps) { //not supported return false; diff --git a/engine/nacl/gl_vidppapi.c b/engine/nacl/gl_vidppapi.c index 2e2631794..cdefa1605 100644 --- a/engine/nacl/gl_vidppapi.c +++ b/engine/nacl/gl_vidppapi.c @@ -1,299 +1,299 @@ -#include "quakedef.h" -#include "glquake.h" - -#include -#include -#include -#include -#include -#include - -extern PPB_Core *ppb_core; -extern PPB_GetInterface sys_gbi; -extern PPB_Graphics3D* graphics3d_interface; -extern PP_Instance pp_instance; -static PP_Resource glcontext; -extern PPB_Instance* instance_interface; -qboolean swappending; - -extern cvar_t vid_vsync; - -void FrameEvent(void* user_data, int32_t result); -qboolean NAGL_SwapPending(void) -{ - return swappending; -} -void swap_callback(void* user_data, int32_t result) -{ - if (swappending) - { - swappending = false; - - FrameEvent(NULL, 0); - } -} - -void GLVID_SwapBuffers(void) -{ - qboolean vsync = vid_vsync.ival || !*vid_vsync.string; - struct PP_CompletionCallback ccb = { swap_callback, NULL, vsync?PP_COMPLETIONCALLBACK_FLAG_NONE:PP_COMPLETIONCALLBACK_FLAG_OPTIONAL}; - glFlush(); - - switch(graphics3d_interface->SwapBuffers(glcontext, ccb)) - { - case PP_OK_COMPLETIONPENDING: - swappending |= vsync; - break; - case PP_OK: - break; - case PP_ERROR_INPROGRESS: - Con_DPrintf("chrome still can't handle vid_wait 0. forcing vsync\n"); - vid_vsync.ival = 1; - break; - default: - Con_DPrintf("unknown error on SwapBuffers call\n"); - break; - } -} - -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) +#include "quakedef.h" +#include "glquake.h" + +#include +#include +#include +#include +#include +#include + +extern PPB_Core *ppb_core; +extern PPB_GetInterface sys_gbi; +extern PPB_Graphics3D* graphics3d_interface; +extern PP_Instance pp_instance; +static PP_Resource glcontext; +extern PPB_Instance* instance_interface; +qboolean swappending; + +extern cvar_t vid_vsync; + +void FrameEvent(void* user_data, int32_t result); +qboolean NAGL_SwapPending(void) +{ + return swappending; +} +void swap_callback(void* user_data, int32_t result) +{ + if (swappending) + { + swappending = false; + + FrameEvent(NULL, 0); + } +} + +void GLVID_SwapBuffers(void) +{ + qboolean vsync = vid_vsync.ival || !*vid_vsync.string; + struct PP_CompletionCallback ccb = { swap_callback, NULL, vsync?PP_COMPLETIONCALLBACK_FLAG_NONE:PP_COMPLETIONCALLBACK_FLAG_OPTIONAL}; + glFlush(); + + switch(graphics3d_interface->SwapBuffers(glcontext, ccb)) + { + case PP_OK_COMPLETIONPENDING: + swappending |= vsync; + break; + case PP_OK: + break; + case PP_ERROR_INPROGRESS: + Con_DPrintf("chrome still can't handle vid_wait 0. forcing vsync\n"); + vid_vsync.ival = 1; + break; + default: + Con_DPrintf("unknown error on SwapBuffers call\n"); + break; + } +} + +qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { return false; -} - -void *PPAPI_GetGLSymbol(char *symname) -{ - int i; - static struct {char *name; void *ptr;} funcs[] = - { -#define f(n) {#n , n}, - f(glActiveTexture) - f(glAttachShader) - f(glBindAttribLocation) - f(glBindBuffer) - f(glBindFramebuffer) - f(glBindRenderbuffer) - f(glBindTexture) - f(glBlendColor) - f(glBlendEquation) - f(glBlendEquationSeparate) - f(glBlendFunc) - f(glBlendFuncSeparate) - f(glBufferData) - f(glBufferSubData) - f(glCheckFramebufferStatus) - f(glClear) - f(glClearColor) - f(glClearDepthf) - f(glClearStencil) - f(glColorMask) - f(glCompileShader) - f(glCompressedTexImage2D) - f(glCompressedTexSubImage2D) - f(glCopyTexImage2D) - f(glCopyTexSubImage2D) - f(glCreateProgram) - f(glCreateShader) - f(glCullFace) - f(glDeleteBuffers) - f(glDeleteFramebuffers) - f(glDeleteProgram) - f(glDeleteRenderbuffers) - f(glDeleteShader) - f(glDeleteTextures) - f(glDepthFunc) - f(glDepthMask) - f(glDepthRangef) - f(glDetachShader) - f(glDisable) - f(glDisableVertexAttribArray) - f(glDrawArrays) - f(glDrawElements) - f(glEnable) - f(glEnableVertexAttribArray) - f(glFinish) - f(glFlush) - f(glFramebufferRenderbuffer) - f(glFramebufferTexture2D) - f(glFrontFace) - f(glGenBuffers) - f(glGenerateMipmap) - f(glGenFramebuffers) - f(glGenRenderbuffers) - f(glGenTextures) - f(glGetActiveAttrib) - f(glGetActiveUniform) - f(glGetAttachedShaders) - f(glGetAttribLocation) - f(glGetBooleanv) - f(glGetBufferParameteriv) - f(glGetError) - f(glGetFloatv) - f(glGetFramebufferAttachmentParameteriv) - f(glGetIntegerv) - f(glGetProgramiv) - f(glGetProgramInfoLog) - f(glGetRenderbufferParameteriv) - f(glGetShaderiv) - f(glGetShaderInfoLog) - f(glGetShaderPrecisionFormat) - f(glGetShaderSource) - f(glGetString) - f(glGetTexParameterfv) - f(glGetTexParameteriv) - f(glGetUniformfv) - f(glGetUniformiv) - f(glGetUniformLocation) - f(glGetVertexAttribfv) - f(glGetVertexAttribiv) - f(glGetVertexAttribPointerv) - f(glHint) - f(glIsBuffer) - f(glIsEnabled) - f(glIsFramebuffer) - f(glIsProgram) - f(glIsRenderbuffer) - f(glIsShader) - f(glIsTexture) - f(glLineWidth) - f(glLinkProgram) - f(glPixelStorei) - f(glPolygonOffset) - f(glReadPixels) - f(glReleaseShaderCompiler) - f(glRenderbufferStorage) - f(glSampleCoverage) - f(glScissor) - f(glShaderBinary) - f(glShaderSource) - f(glStencilFunc) - f(glStencilFuncSeparate) - f(glStencilMask) - f(glStencilMaskSeparate) - f(glStencilOp) - f(glStencilOpSeparate) - f(glTexImage2D) - f(glTexParameterf) - f(glTexParameterfv) - f(glTexParameteri) - f(glTexParameteriv) - f(glTexSubImage2D) - f(glUniform1f) - f(glUniform1fv) - f(glUniform1i) - f(glUniform1iv) - f(glUniform2f) - f(glUniform2fv) - f(glUniform2i) - f(glUniform2iv) - f(glUniform3f) - f(glUniform3fv) - f(glUniform3i) - f(glUniform3iv) - f(glUniform4f) - f(glUniform4fv) - f(glUniform4i) - f(glUniform4iv) - f(glUniformMatrix2fv) - f(glUniformMatrix3fv) - f(glUniformMatrix4fv) - f(glUseProgram) - f(glValidateProgram) - f(glVertexAttrib1f) - f(glVertexAttrib1fv) - f(glVertexAttrib2f) - f(glVertexAttrib2fv) - f(glVertexAttrib3f) - f(glVertexAttrib3fv) - f(glVertexAttrib4f) - f(glVertexAttrib4fv) - f(glVertexAttribPointer) - f(glViewport) - {NULL} - }; - for (i = 0; funcs[i].name; i++) - { - if (!strcmp(funcs[i].name, symname)) - return funcs[i].ptr; - } - return NULL; -} - - -void GL_Resized(int width, int height) -{ - extern cvar_t vid_conautoscale, vid_conwidth; - - vid.pixelwidth = width; - vid.pixelheight = height; - if (glcontext) - { - graphics3d_interface->ResizeBuffers(glcontext, width, height); - Cvar_ForceCallback(&vid_conautoscale); - Cvar_ForceCallback(&vid_conwidth); - } -} - -qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette) +} + +void *PPAPI_GetGLSymbol(char *symname) +{ + int i; + static struct {char *name; void *ptr;} funcs[] = + { +#define f(n) {#n , n}, + f(glActiveTexture) + f(glAttachShader) + f(glBindAttribLocation) + f(glBindBuffer) + f(glBindFramebuffer) + f(glBindRenderbuffer) + f(glBindTexture) + f(glBlendColor) + f(glBlendEquation) + f(glBlendEquationSeparate) + f(glBlendFunc) + f(glBlendFuncSeparate) + f(glBufferData) + f(glBufferSubData) + f(glCheckFramebufferStatus) + f(glClear) + f(glClearColor) + f(glClearDepthf) + f(glClearStencil) + f(glColorMask) + f(glCompileShader) + f(glCompressedTexImage2D) + f(glCompressedTexSubImage2D) + f(glCopyTexImage2D) + f(glCopyTexSubImage2D) + f(glCreateProgram) + f(glCreateShader) + f(glCullFace) + f(glDeleteBuffers) + f(glDeleteFramebuffers) + f(glDeleteProgram) + f(glDeleteRenderbuffers) + f(glDeleteShader) + f(glDeleteTextures) + f(glDepthFunc) + f(glDepthMask) + f(glDepthRangef) + f(glDetachShader) + f(glDisable) + f(glDisableVertexAttribArray) + f(glDrawArrays) + f(glDrawElements) + f(glEnable) + f(glEnableVertexAttribArray) + f(glFinish) + f(glFlush) + f(glFramebufferRenderbuffer) + f(glFramebufferTexture2D) + f(glFrontFace) + f(glGenBuffers) + f(glGenerateMipmap) + f(glGenFramebuffers) + f(glGenRenderbuffers) + f(glGenTextures) + f(glGetActiveAttrib) + f(glGetActiveUniform) + f(glGetAttachedShaders) + f(glGetAttribLocation) + f(glGetBooleanv) + f(glGetBufferParameteriv) + f(glGetError) + f(glGetFloatv) + f(glGetFramebufferAttachmentParameteriv) + f(glGetIntegerv) + f(glGetProgramiv) + f(glGetProgramInfoLog) + f(glGetRenderbufferParameteriv) + f(glGetShaderiv) + f(glGetShaderInfoLog) + f(glGetShaderPrecisionFormat) + f(glGetShaderSource) + f(glGetString) + f(glGetTexParameterfv) + f(glGetTexParameteriv) + f(glGetUniformfv) + f(glGetUniformiv) + f(glGetUniformLocation) + f(glGetVertexAttribfv) + f(glGetVertexAttribiv) + f(glGetVertexAttribPointerv) + f(glHint) + f(glIsBuffer) + f(glIsEnabled) + f(glIsFramebuffer) + f(glIsProgram) + f(glIsRenderbuffer) + f(glIsShader) + f(glIsTexture) + f(glLineWidth) + f(glLinkProgram) + f(glPixelStorei) + f(glPolygonOffset) + f(glReadPixels) + f(glReleaseShaderCompiler) + f(glRenderbufferStorage) + f(glSampleCoverage) + f(glScissor) + f(glShaderBinary) + f(glShaderSource) + f(glStencilFunc) + f(glStencilFuncSeparate) + f(glStencilMask) + f(glStencilMaskSeparate) + f(glStencilOp) + f(glStencilOpSeparate) + f(glTexImage2D) + f(glTexParameterf) + f(glTexParameterfv) + f(glTexParameteri) + f(glTexParameteriv) + f(glTexSubImage2D) + f(glUniform1f) + f(glUniform1fv) + f(glUniform1i) + f(glUniform1iv) + f(glUniform2f) + f(glUniform2fv) + f(glUniform2i) + f(glUniform2iv) + f(glUniform3f) + f(glUniform3fv) + f(glUniform3i) + f(glUniform3iv) + f(glUniform4f) + f(glUniform4fv) + f(glUniform4i) + f(glUniform4iv) + f(glUniformMatrix2fv) + f(glUniformMatrix3fv) + f(glUniformMatrix4fv) + f(glUseProgram) + f(glValidateProgram) + f(glVertexAttrib1f) + f(glVertexAttrib1fv) + f(glVertexAttrib2f) + f(glVertexAttrib2fv) + f(glVertexAttrib3f) + f(glVertexAttrib3fv) + f(glVertexAttrib4f) + f(glVertexAttrib4fv) + f(glVertexAttribPointer) + f(glViewport) + {NULL} + }; + for (i = 0; funcs[i].name; i++) + { + if (!strcmp(funcs[i].name, symname)) + return funcs[i].ptr; + } + return NULL; +} + + +void GL_Resized(int width, int height) +{ + extern cvar_t vid_conautoscale, vid_conwidth; + + vid.pixelwidth = width; + vid.pixelheight = height; + if (glcontext) + { + graphics3d_interface->ResizeBuffers(glcontext, width, height); + Cvar_ForceCallback(&vid_conautoscale); + Cvar_ForceCallback(&vid_conwidth); + } +} + +qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette) { if (!vid.pixelwidth) vid.pixelwidth = info->width; if (!vid.pixelheight) - vid.pixelheight = info->height; - if (vid.pixelwidth < 320) - vid.pixelwidth = 320; - if (vid.pixelheight < 200) - vid.pixelheight = 200; - - int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, vid.pixelwidth, - PP_GRAPHICS3DATTRIB_HEIGHT, vid.pixelheight, - PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, - PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, PP_GRAPHICS3DATTRIB_BUFFER_DESTROYED, - PP_GRAPHICS3DATTRIB_NONE}; - - glcontext = graphics3d_interface->Create(pp_instance, 0, attribs); - - glSetCurrentContextPPAPI(glcontext); - - if (!instance_interface->BindGraphics(pp_instance, glcontext)) - { - Con_Printf("failed to bind context\n"); - return false; - } - - glClearColor(1.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - GLVID_SwapBuffers(); - + vid.pixelheight = info->height; + if (vid.pixelwidth < 320) + vid.pixelwidth = 320; + if (vid.pixelheight < 200) + vid.pixelheight = 200; + + int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, vid.pixelwidth, + PP_GRAPHICS3DATTRIB_HEIGHT, vid.pixelheight, + PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, + PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, + PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, PP_GRAPHICS3DATTRIB_BUFFER_DESTROYED, + PP_GRAPHICS3DATTRIB_NONE}; + + glcontext = graphics3d_interface->Create(pp_instance, 0, attribs); + + glSetCurrentContextPPAPI(glcontext); + + if (!instance_interface->BindGraphics(pp_instance, glcontext)) + { + Con_Printf("failed to bind context\n"); + return false; + } + + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + GLVID_SwapBuffers(); + // vid.pixelwidth = info->width; // vid.pixelheight = info->height; - GL_Init(PPAPI_GetGLSymbol); - - return true; -} - -void GLVID_Shutdown (void) -{ - glClearColor(1.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - GLVID_SwapBuffers(); - - ppb_core->ReleaseResource(glcontext); -// glTerminatePPAPI(); -} -void GLVID_DeInit (void) -{ - GLVID_Shutdown(); -} - -void GLVID_Crashed(void); - -void GLVID_Update (vrect_t *rects); - -int GLVID_SetMode (rendererstate_t *info, unsigned char *palette); - -void GLVID_SetCaption(const char *caption) -{ -} \ No newline at end of file + GL_Init(PPAPI_GetGLSymbol); + + return true; +} + +void GLVID_Shutdown (void) +{ + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + GLVID_SwapBuffers(); + + ppb_core->ReleaseResource(glcontext); +// glTerminatePPAPI(); +} +void GLVID_DeInit (void) +{ + GLVID_Shutdown(); +} + +void GLVID_Crashed(void); + +void GLVID_Update (vrect_t *rects); + +int GLVID_SetMode (rendererstate_t *info, unsigned char *palette); + +void GLVID_SetCaption(const char *caption) +{ +} diff --git a/engine/sw/sw_vidwin.c b/engine/sw/sw_vidwin.c index ffeced9bc..ac9d5f210 100644 --- a/engine/sw/sw_vidwin.c +++ b/engine/sw/sw_vidwin.c @@ -768,7 +768,7 @@ void SW_VID_DeInit(void) ChangeDisplaySettings (NULL, 0); } -qboolean SW_VID_ApplyGammaRamps (unsigned short *ramps) +qboolean SW_VID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { return false; } diff --git a/engine/vk/vk_backend.c b/engine/vk/vk_backend.c index a3707c67f..f1af8b68a 100644 --- a/engine/vk/vk_backend.c +++ b/engine/vk/vk_backend.c @@ -407,7 +407,7 @@ static VkSampler VK_GetSampler(unsigned int flags) #endif //creates the layout stuff for the prog. -static VK_FinishProg(program_t *prog, const char *name) +static void VK_FinishProg(program_t *prog, const char *name) { { VkDescriptorSetLayout desclayout; @@ -4862,7 +4862,6 @@ static qboolean BE_GenerateRefraction(batch_t *batch, shader_t *bs) if (bs->flags & SHADER_HASREFLECT) { - struct vk_rendertarg *targ = vk.rendertarg; vrect_t orect = r_refdef.vrect; pxrect_t oprect = r_refdef.pxrect; diff --git a/engine/vk/vk_init.c b/engine/vk/vk_init.c index db02cda52..d01b3cc4e 100644 --- a/engine/vk/vk_init.c +++ b/engine/vk/vk_init.c @@ -1336,8 +1336,6 @@ static qboolean VK_R_RenderScene_Cubemap(struct vk_rendertarg *fb) shader_t *shader; int facemask; extern cvar_t r_projection; - int oldfbo = -1; - qboolean fboreset = false; int osm = r_refdef.stereomethod; struct vk_rendertarg_cube *rtc = &vk_rt_cubemap; @@ -3178,10 +3176,10 @@ void VK_Shutdown(void) size_t size; if (VK_SUCCESS == vkGetPipelineCacheData(vk.device, vk.pipelinecache, &size, NULL)) { - void *ptr = BZ_Malloc(size); + void *ptr = Z_Malloc(size); //valgrind says nvidia isn't initialising this. if (VK_SUCCESS == vkGetPipelineCacheData(vk.device, vk.pipelinecache, &size, ptr)) FS_WriteFile("vulkan.pcache", ptr, size, FS_ROOT); - BZ_Free(ptr); + Z_Free(ptr); } vkDestroyPipelineCache(vk.device, vk.pipelinecache, vkallocationcb); } diff --git a/engine/vk/vk_win32.c b/engine/vk/vk_win32.c index 84b3cd4f3..c17f2f9b1 100644 --- a/engine/vk/vk_win32.c +++ b/engine/vk/vk_win32.c @@ -953,11 +953,11 @@ static void OblitterateOldGamma(void) } } -static qboolean VKVID_ApplyGammaRamps (unsigned short *ramps) +static qboolean VKVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { if (ramps) { - if (!gammaworks) + if (!gammaworks || gammarampsize != 256) return false; if (vid_hardwaregamma.value == 1 && modestate == MS_WINDOWED) diff --git a/engine/web/gl_vidweb.c b/engine/web/gl_vidweb.c index 399abe4a9..2f7c3cf7b 100644 --- a/engine/web/gl_vidweb.c +++ b/engine/web/gl_vidweb.c @@ -268,7 +268,7 @@ void GLVID_SwapBuffers (void) */ } -qboolean GLVID_ApplyGammaRamps (unsigned short *ramps) +qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps) { gammaworks = false; return gammaworks;