X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_shared.c;h=7ee5b34f6d3d50fbef0dd0f6defe285d7a662787;hb=a7dec84b2f42d22b1261bf88ac9244ac5cc9d4c4;hp=7c321c2aa94819089e4898e017747fe06b42c85c;hpb=33cefdeb9044350e531ca015aafcb44dc644c178;p=xonotic%2Fdarkplaces.git diff --git a/vid_shared.c b/vid_shared.c index 7c321c2a..7ee5b34f 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -140,9 +140,6 @@ cvar_t vid_soft = {CVAR_SAVE, "vid_soft", "0", "enables use of the DarkPlaces So cvar_t vid_soft_threads = {CVAR_SAVE, "vid_soft_threads", "8", "the number of threads the DarkPlaces Software Rasterizer should use"}; cvar_t vid_soft_interlace = {CVAR_SAVE, "vid_soft_interlace", "1", "whether the DarkPlaces Software Rasterizer should interlace the screen bands occupied by each thread"}; -// we don't know until we try it! -cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1", "indicates whether hardware gamma is supported (updated by attempts to set hardware gamma ramps)"}; - // VorteX: more info cvars, mostly set in VID_CheckExtensions cvar_t gl_info_vendor = {CVAR_READONLY, "gl_info_vendor", "", "indicates brand of graphics chip"}; cvar_t gl_info_renderer = {CVAR_READONLY, "gl_info_renderer", "", "indicates graphics chip model and other information"}; @@ -151,13 +148,6 @@ cvar_t gl_info_extensions = {CVAR_READONLY, "gl_info_extensions", "", "indicates cvar_t gl_info_platform = {CVAR_READONLY, "gl_info_platform", "", "indicates GL platform: WGL, GLX, or AGL."}; cvar_t gl_info_driver = {CVAR_READONLY, "gl_info_driver", "", "name of driver library (opengl32.dll, libGL.so.1, or whatever)."}; -// whether hardware gamma ramps are currently in effect -qboolean vid_usinghwgamma = false; - -int vid_gammarampsize = 0; -unsigned short *vid_gammaramps = NULL; -unsigned short *vid_systemgammaramps = NULL; - cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1", "use fullscreen (1) or windowed (0)"}; cvar_t vid_width = {CVAR_SAVE, "vid_width", "640", "resolution"}; cvar_t vid_height = {CVAR_SAVE, "vid_height", "480", "resolution"}; @@ -205,10 +195,9 @@ cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5", "desired color of g cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1", "desired color of white"}; cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1", "desired color of white"}; cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1", "desired color of white"}; -cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "0", "enables use of hardware gamma correction ramps if available (note: does not work very well on Windows2000 and above), values are 0 = off, 1 = attempt to use hardware gamma, 2 = use hardware gamma whether it works or not"}; -cvar_t v_glslgamma = {CVAR_SAVE, "v_glslgamma", "1", "enables use of GLSL to apply gamma correction ramps if available (note: overrides v_hwgamma)"}; +cvar_t v_glslgamma = {CVAR_SAVE, "v_glslgamma", "1", "enables use of GLSL to apply gamma correction ramps"}; cvar_t v_glslgamma_2d = {CVAR_SAVE, "v_glslgamma_2d", "0", "applies GLSL gamma to 2d pictures (HUD, fonts)"}; -cvar_t v_psycho = {0, "v_psycho", "0", "easter egg"}; +cvar_t v_psycho = {0, "v_psycho", "0", "easter egg - R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667"}; // brand of graphics chip const char *gl_vendor; @@ -1095,6 +1084,9 @@ void VID_CheckExtensions(void) vid.support.ext_texture_edge_clamp = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false); vid.support.ext_texture_filter_anisotropic = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false); vid.support.ext_texture_srgb = GL_CheckExtension("GL_EXT_texture_sRGB", NULL, "-nosrgb", false); + vid.support.arb_texture_float = GL_CheckExtension("GL_ARB_texture_float", NULL, "-notexturefloat", false); + vid.support.arb_half_float_pixel = GL_CheckExtension("GL_ARB_half_float_pixel", NULL, "-nohalffloatpixel", false); + vid.support.arb_half_float_vertex = GL_CheckExtension("GL_ARB_half_float_vertex", NULL, "-nohalffloatvertex", false); vid.support.arb_multisample = GL_CheckExtension("GL_ARB_multisample", multisamplefuncs, "-nomultisample", false); vid.allowalphatocoverage = false; @@ -1227,14 +1219,14 @@ void VID_CheckExtensions(void) } #endif -float VID_JoyState_GetAxis(const vid_joystate_t *joystate, int axis, float sensitivity, float deadzone) +float VID_JoyState_GetAxis(const vid_joystate_t *joystate, int axis, float fsensitivity, float deadzone) { float value; value = (axis >= 0 && axis < MAXJOYAXIS) ? joystate->axis[axis] : 0.0f; value = value > deadzone ? (value - deadzone) : (value < -deadzone ? (value + deadzone) : 0.0f); value *= deadzone > 0 ? (1.0f / (1.0f - deadzone)) : 1.0f; value = bound(-1, value, 1); - return value * sensitivity; + return value * fsensitivity; } qboolean VID_JoyBlockEmulatedKeys(int keycode) @@ -1471,7 +1463,22 @@ static void Force_CenterView_f (void) static int gamma_forcenextframe = false; static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost; -static int cachecolorenable, cachehwgamma; +static int cachecolorenable; + +void VID_ApplyGammaToColor(const float *rgb, float *out) +{ + int i; + if (cachecolorenable) + { + for (i = 0; i < 3; i++) + out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / invpow(0.5, 1 - cachegrey[i])) * cachewhite[i] + cacheblack[i]; + } + else + { + for (i = 0; i < 3; i++) + out[i] = pow(cachecontrastboost * rgb[i] / ((cachecontrastboost - 1) * rgb[i] + 1), 1.0 / cachegamma) * cachecontrast + cachebrightness; + } +} unsigned int vid_gammatables_serial = 0; // so other subsystems can poll if gamma parameters have changed qboolean vid_gammatables_trivial = true; @@ -1500,6 +1507,8 @@ void VID_BuildGammaTables(unsigned short *ramps, int rampsize) // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have // immensely butchered it to work with variable framerates and fit in with // the rest of darkplaces. + // + // R.I.P. zinx http://obits.al.com/obituaries/birmingham/obituary.aspx?n=christopher-robert-lais&pid=186080667 if (v_psycho.integer) { int x, y; @@ -1537,36 +1546,12 @@ void VID_BuildGammaTables(unsigned short *ramps, int rampsize) } } -void VID_UpdateGamma(qboolean force, int rampsize) +void VID_UpdateGamma(void) { cvar_t *c; float f; - int wantgamma; qboolean gamma_changed = false; - // LordHavoc: don't mess with gamma tables if running dedicated - if (cls.state == ca_dedicated) - return; - - wantgamma = v_hwgamma.integer; - switch(vid.renderpath) - { - case RENDERPATH_GL20: - case RENDERPATH_D3D9: - case RENDERPATH_D3D10: - case RENDERPATH_D3D11: - case RENDERPATH_SOFT: - case RENDERPATH_GLES2: - if (v_glslgamma.integer) - wantgamma = 0; - break; - case RENDERPATH_GL11: - case RENDERPATH_GL13: - case RENDERPATH_GLES1: - break; - } - if(!vid_activewindow) - wantgamma = 0; #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f); BOUNDCVAR(v_gamma, 0.1, 5); BOUNDCVAR(v_contrast, 0.2, 5); @@ -1612,6 +1597,7 @@ void VID_UpdateGamma(qboolean force, int rampsize) } } + // if any gamma settings were changed, bump vid_gammatables_serial so we regenerate the gamma ramp texture #define GAMMACHECK(cache, value) if (cache != (value)) gamma_changed = true;cache = (value) if(v_psycho.integer) gamma_changed = true; @@ -1632,64 +1618,7 @@ void VID_UpdateGamma(qboolean force, int rampsize) if(gamma_changed) ++vid_gammatables_serial; - - GAMMACHECK(cachehwgamma , wantgamma); #undef GAMMACHECK - - if (!force && !gamma_forcenextframe && !gamma_changed) - return; - - gamma_forcenextframe = false; - - if (cachehwgamma) - { - if (!vid_usinghwgamma) - { - vid_usinghwgamma = true; - if (vid_gammarampsize != rampsize || !vid_gammaramps) - { - vid_gammarampsize = rampsize; - if (vid_gammaramps) - Z_Free(vid_gammaramps); - vid_gammaramps = (unsigned short *)Z_Malloc(6 * vid_gammarampsize * sizeof(unsigned short)); - vid_systemgammaramps = vid_gammaramps + 3 * vid_gammarampsize; - } - VID_GetGamma(vid_systemgammaramps, vid_gammarampsize); - } - - VID_BuildGammaTables(vid_gammaramps, vid_gammarampsize); - - // set vid_hardwaregammasupported to true if VID_SetGamma succeeds, OR if vid_hwgamma is >= 2 (forced gamma - ignores driver return value) - Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps, vid_gammarampsize) || cachehwgamma >= 2); - // if custom gamma ramps failed (Windows stupidity), restore to system gamma - if(!vid_hardwaregammasupported.integer) - { - if (vid_usinghwgamma) - { - vid_usinghwgamma = false; - VID_SetGamma(vid_systemgammaramps, vid_gammarampsize); - } - } - } - else - { - if (vid_usinghwgamma) - { - vid_usinghwgamma = false; - VID_SetGamma(vid_systemgammaramps, vid_gammarampsize); - } - } -} - -void VID_RestoreSystemGamma(void) -{ - if (vid_usinghwgamma) - { - vid_usinghwgamma = false; - Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps, vid_gammarampsize)); - // force gamma situation to be reexamined next frame - gamma_forcenextframe = true; - } } #ifdef WIN32 @@ -1725,7 +1654,6 @@ void VID_Shared_Init(void) Con_Printf("DPSOFTRAST not available (SSE2 not compiled in)\n"); #endif - Cvar_RegisterVariable(&vid_hardwaregammasupported); Cvar_RegisterVariable(&gl_info_vendor); Cvar_RegisterVariable(&gl_info_renderer); Cvar_RegisterVariable(&gl_info_version); @@ -1748,7 +1676,6 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&v_color_white_g); Cvar_RegisterVariable(&v_color_white_b); - Cvar_RegisterVariable(&v_hwgamma); Cvar_RegisterVariable(&v_glslgamma); Cvar_RegisterVariable(&v_glslgamma_2d); @@ -1923,6 +1850,7 @@ static int VID_Mode(int fullscreen, int width, int height, int bpp, float refres static void VID_OpenSystems(void) { + Key_ReleaseAll(); R_Modules_Start(); S_Startup(); } @@ -1931,6 +1859,7 @@ static void VID_CloseSystems(void) { S_Shutdown(); R_Modules_Shutdown(); + Key_ReleaseAll(); } qboolean vid_commandlinecheck = true;