X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_shared.c;h=26b69ad095cf0dbbf8fde3f40095739d8bd2c271;hb=refs%2Fheads%2FColdSpirit%2Fcvar_onchange_stable;hp=2d6497e508e80efe14cc1517f5ec7a1286e2af2f;hpb=3bcfd24aa96ba851e8ba728a0c5e94dba19d44ad;p=xonotic%2Fdarkplaces.git diff --git a/vid_shared.c b/vid_shared.c index 2d6497e5..26b69ad0 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,8 @@ 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_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_glslgamma_2d = {CVAR_SAVE, "v_glslgamma_2d", "1", "applies GLSL gamma to 2d pictures (HUD, fonts)"}; +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; @@ -1065,15 +1053,13 @@ void VID_CheckExtensions(void) vid.support.arb_draw_buffers = GL_CheckExtension("GL_ARB_draw_buffers", drawbuffersfuncs, "-nodrawbuffers", false); vid.support.arb_multitexture = GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false); vid.support.arb_occlusion_query = GL_CheckExtension("GL_ARB_occlusion_query", occlusionqueryfuncs, "-noocclusionquery", false); + vid.support.arb_query_buffer_object = GL_CheckExtension("GL_ARB_query_buffer_object", NULL, "-noquerybuffer", true); vid.support.arb_shadow = GL_CheckExtension("GL_ARB_shadow", NULL, "-noshadow", false); vid.support.arb_texture_compression = GL_CheckExtension("GL_ARB_texture_compression", texturecompressionfuncs, "-notexturecompression", false); vid.support.arb_texture_cube_map = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false); vid.support.arb_texture_env_combine = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false); vid.support.arb_texture_gather = GL_CheckExtension("GL_ARB_texture_gather", NULL, "-notexturegather", false); -#ifndef __APPLE__ - // LordHavoc: too many bugs on OSX! vid.support.arb_texture_non_power_of_two = GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false); -#endif vid.support.arb_vertex_buffer_object = GL_CheckExtension("GL_ARB_vertex_buffer_object", vbofuncs, "-novbo", false); vid.support.arb_uniform_buffer_object = GL_CheckExtension("GL_ARB_uniform_buffer_object", ubofuncs, "-noubo", false); vid.support.ati_separate_stencil = GL_CheckExtension("separatestencil", gl2separatestencilfuncs, "-noseparatestencil", true) || GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "-noseparatestencil", false); @@ -1094,6 +1080,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; @@ -1110,6 +1099,7 @@ void VID_CheckExtensions(void) // COMMANDLINEOPTION: GL: -nofbo disables GL_EXT_framebuffer_object (which accelerates rendering), only used if GL_ARB_fragment_shader is also available // COMMANDLINEOPTION: GL: -nomtex disables GL_ARB_multitexture (required for faster map rendering) // COMMANDLINEOPTION: GL: -noocclusionquery disables GL_ARB_occlusion_query (which allows coronas to fade according to visibility, and potentially used for rendering optimizations) +// COMMANDLINEOPTION: GL: -noquerybuffer disables GL_ARB_query_buffer_object (which allows corona fading without synchronous rendering) // COMMANDLINEOPTION: GL: -nos3tc disables GL_EXT_texture_compression_s3tc (which allows use of .dds texture caching) // COMMANDLINEOPTION: GL: -noseparatestencil disables use of OpenGL2.0 glStencilOpSeparate and GL_ATI_separate_stencil extensions (which accelerate shadow rendering) // COMMANDLINEOPTION: GL: -noshadow disables use of GL_ARB_shadow (required for hardware shadowmap filtering) @@ -1225,14 +1215,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) @@ -1469,7 +1459,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; @@ -1498,6 +1503,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; @@ -1535,36 +1542,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); @@ -1610,6 +1593,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; @@ -1630,64 +1614,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 @@ -1723,7 +1650,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); @@ -1746,8 +1672,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); Cvar_RegisterVariable(&v_psycho); @@ -1921,6 +1845,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(); } @@ -1929,6 +1854,7 @@ static void VID_CloseSystems(void) { S_Shutdown(); R_Modules_Shutdown(); + Key_ReleaseAll(); } qboolean vid_commandlinecheck = true; @@ -2122,6 +2048,7 @@ void VID_Soft_SharedSetup(void) vid.support.arb_depth_texture = true; vid.support.arb_draw_buffers = true; vid.support.arb_occlusion_query = true; + vid.support.arb_query_buffer_object = false; vid.support.arb_shadow = true; //vid.support.arb_texture_compression = true; vid.support.arb_texture_cube_map = true;