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
This commit is contained in:
Spoike 2016-07-28 15:57:22 +00:00
parent 151bd6d0b1
commit 74a7dff814
25 changed files with 407 additions and 388 deletions

View file

@ -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

View file

@ -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++)
{

View file

@ -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

View file

@ -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;

View file

@ -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");

View file

@ -688,6 +688,7 @@ static void Friendly_Crash_Handler(int sig, siginfo_t *info, void *vcontext)
close(fd);
}
#if defined(DEBUG) && defined(GLQUAKE)
if (qrenderer == QR_OPENGL)
DumpGLState();
#endif
exit(1);

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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++)
{

View file

@ -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)
{

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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]);

View file

@ -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)

View file

@ -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;

View file

@ -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)
{

View file

@ -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;

View file

@ -56,7 +56,7 @@ void GLVID_SwapBuffers(void)
}
}
qboolean GLVID_ApplyGammaRamps (unsigned short *ramps)
qboolean GLVID_ApplyGammaRamps (unsigned int gammarampsize, unsigned short *ramps)
{
return false;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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)

View file

@ -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;